casacore
Loading...
Searching...
No Matches
HDF5DataType.h
Go to the documentation of this file.
1// # HDF5DataType.h: An class representing an HDF5 data type
2// # Copyright (C) 2008
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_HDF5DATATYPE_H
27#define CASA_HDF5DATATYPE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/HDF5/HDF5Object.h>
32#include <casacore/casa/HDF5/HDF5HidMeta.h>
33#include <casacore/casa/BasicSL/Complex.h>
34#include <casacore/casa/BasicSL/String.h>
35#include <casacore/casa/Utilities/DataType.h>
36#include <vector>
37
38namespace casacore { // # NAMESPACE CASACORE - BEGIN
39
40// # Forward Declarations
41class IPosition;
42template <typename T>
43class Block;
44
45// <summary>
46// A class representing an HDF5 data type.
47// </summary>
48
49// <use visibility=local>
50
51// <reviewed reviewer="" date="" tests="tHDF5DataType.cc">
52// </reviewed>
53
54// <prerequisite>
55// <li> <a href="http://hdf.ncsa.uiuc.edu">HDF5 system</a>
56// </prerequisite>
57
58// <synopsis>
59// This class wraps the HDF5 functions to create a data type
60// for the data in memory and for the file.
61// The HDF5 file data type order is set to LittleEndian.
62// <br>
63// The basic constructors define a scalar of a basic data type or
64// data type Complex and DComplex. Strings are also supported.
65// However, it is also possible to define a fixed shaped array for any
66// HDF5DataType. Furthermore, it is possible to define a compound data
67// type consisting of named fields of any HDF5DataType with a fixed size.
68// Arrays and/or compounds can be nested at will.
69// <br>
70// Variable length strings are supported, but cannot be used in compounds.
71// <br>
72// Older HDF5 versions did not support empty arrays. Therefore they are
73// represented as a compound with 3 fields. Also they did not support
74// boolean values; they are represented as a signed char.
75// HDF5 does not support complex values either. They are represented
76// as a compound with fields 're' and 'im'.
77// </synopsis>
78
79// <motivation>
80// The HDF5 C++ interface only supports the HDF5 C functionality and
81// resembles that to much. For instance, it does not use STL containers.
82// It does not support non-basic data types, in particular Complex.
83// </motivation>
84
86 public:
87 // The default constructor makes an invalid object.
88 // It is needed to make a vector of objects.
90
91 // Create an HDF5 datatype object for the given fixed length type.
92 // It uses the corresponding native HDF5 data type. Only for Bool it
93 // uses a uchar, because the HDF5 bool type is a uint.
94 // For the complex types it makes a compound HDF5 data type.
95 // The String type is meant for an array of strings.
96 // <group>
97 explicit HDF5DataType(const Bool*);
98 explicit HDF5DataType(const uChar*);
99 explicit HDF5DataType(const Short*);
100 explicit HDF5DataType(const uShort*);
101 explicit HDF5DataType(const Int*);
102 explicit HDF5DataType(const uInt*);
103 explicit HDF5DataType(const Int64*);
104 explicit HDF5DataType(const Float*);
105 explicit HDF5DataType(const Double*);
106 explicit HDF5DataType(const Complex*);
107 explicit HDF5DataType(const DComplex*);
108 explicit HDF5DataType(const String*);
109 // </group>
110
111 // Create an HDF5 datatype object for a scalar string.
112 // The length of the string is part of the type.
113 explicit HDF5DataType(const String& value);
114
115 // Create an HDF5 datatype object for an empty array.
116 // Both arguments are dummy (needed to distinguish the constructor).
117 // An empty array as represented as a compound data type with integer
118 // field names emptyarray, rank and casatype.
120
121 // Define a compound data type consisting of the given fields and types.
122 // An exception is thrown if the vectors are empty or have mismatching
123 // sizes.
124 HDF5DataType(const std::vector<String>& names, const std::vector<HDF5DataType>& types);
125
126 // Create an array of the given data type.
127 // An exception is thrown if the shape is empty.
129
130 // The copy constructor makes a deep copy.
132
133 // The destructor closes the HDF5 data type object.
135
136 // Assignment makes a deep copy.
138
139 // Get the Casacore data type for the given HDF5 data type.
140 // TpRecord is returned for a compound data type.
141 static DataType getDataType(hid_t);
142
143 // Get the HID for the data type in memory.
144 hid_t getHidMem() const { return itsHidMem; }
145
146 // Get the HID for the data type in the file.
147 hid_t getHidFile() const { return itsHidFile; }
148
149 // Get the size in bytes of the data type (in memory).
150 // Note that the size of a string is variable, thus 0.
151 uInt size() const { return itsSize; }
152
153 // Test if the data type is Complex or DComplex.
154 static Bool isComplex(hid_t dtid);
155
156 // Test if the data type is an empty array.
157 static Bool isEmptyArray(hid_t dtid);
158
159 // Get the shape of an array data type.
160 // It returns an empty IPosition for non-arrays.
161 static IPosition getShape(hid_t dtid);
162
163 // Helper functions to convert shapes.
164 // It reverses the axes, because HDF5 uses C-order.
165 // <group>
168 // </group>
169
170 private:
171 // Add a field to a compound data type.
172 // It does it for the memory and file data type.
173 void addToCompound(const char* name, uInt offset, const HDF5DataType& dtype);
174
175 // # Data members
179};
180
181} // namespace casacore
182
183#endif
HDF5DataType(const Short *)
HDF5DataType(const HDF5DataType &, const IPosition &shape)
Create an array of the given data type.
HDF5DataType(const Bool *)
Create an HDF5 datatype object for the given fixed length type.
void addToCompound(const char *name, uInt offset, const HDF5DataType &dtype)
Add a field to a compound data type.
HDF5DataType(const DComplex *)
~HDF5DataType()
The destructor closes the HDF5 data type object.
HDF5DataType(const uInt *)
HDF5DataType(const std::vector< String > &names, const std::vector< HDF5DataType > &types)
Define a compound data type consisting of the given fields and types.
HDF5HidDataType itsHidFile
static IPosition toShape(const Block< hsize_t > &b)
HDF5HidDataType itsHidMem
HDF5DataType & operator=(const HDF5DataType &that)
Assignment makes a deep copy.
HDF5DataType(Int, Int)
Create an HDF5 datatype object for an empty array.
static Bool isComplex(hid_t dtid)
Test if the data type is Complex or DComplex.
hid_t getHidMem() const
Get the HID for the data type in memory.
HDF5DataType(const Complex *)
HDF5DataType(const Int *)
HDF5DataType(const String &value)
Create an HDF5 datatype object for a scalar string.
HDF5DataType(const Int64 *)
hid_t getHidFile() const
Get the HID for the data type in the file.
HDF5DataType(const String *)
HDF5DataType(const HDF5DataType &that)
The copy constructor makes a deep copy.
HDF5DataType(const Double *)
uInt size() const
Get the size in bytes of the data type (in memory).
static Bool isEmptyArray(hid_t dtid)
Test if the data type is an empty array.
HDF5DataType()
The default constructor makes an invalid object.
static DataType getDataType(hid_t)
Get the Casacore data type for the given HDF5 data type.
static Block< hsize_t > fromShape(const IPosition &shape)
Helper functions to convert shapes.
HDF5DataType(const uShort *)
static IPosition getShape(hid_t dtid)
Get the shape of an array data type.
HDF5DataType(const uChar *)
HDF5DataType(const Float *)
A class representing an HDF5 datatype hid.
Definition HDF5HidMeta.h:95
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned char uChar
Definition aipstype.h:45
int offset(int, int) const
compute a linear offset from array indicies
short Short
Definition aipstype.h:46
unsigned int uInt
Definition aipstype.h:49
unsigned short uShort
Definition aipstype.h:47
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
Definition aipsxtype.h:36
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
float Float
Definition aipstype.h:52
String name() const
Return the name of the field.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
double Double
Definition aipstype.h:53