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
41 class IPosition;
42 template<typename T> class Block;
43
44 // <summary>
45 // A class representing an HDF5 data type.
46 // </summary>
47
48 // <use visibility=local>
49
50 // <reviewed reviewer="" date="" tests="tHDF5DataType.cc">
51 // </reviewed>
52
53 // <prerequisite>
54 // <li> <a href="http://hdf.ncsa.uiuc.edu">HDF5 system</a>
55 // </prerequisite>
56
57 // <synopsis>
58 // This class wraps the HDF5 functions to create a data type
59 // for the data in memory and for the file.
60 // The HDF5 file data type order is set to LittleEndian.
61 // <br>
62 // The basic constructors define a scalar of a basic data type or
63 // data type Complex and DComplex. Strings are also supported.
64 // However, it is also possible to define a fixed shaped array for any
65 // HDF5DataType. Furthermore, it is possible to define a compound data
66 // type consisting of named fields of any HDF5DataType with a fixed size.
67 // Arrays and/or compounds can be nested at will.
68 // <br>
69 // Variable length strings are supported, but cannot be used in compounds.
70 // <br>
71 // Older HDF5 versions did not support empty arrays. Therefore they are
72 // represented as a compound with 3 fields. Also they did not support
73 // boolean values; they are represented as a signed char.
74 // HDF5 does not support complex values either. They are represented
75 // as a compound with fields 're' and 'im'.
76 // </synopsis>
77
78 // <motivation>
79 // The HDF5 C++ interface only supports the HDF5 C functionality and
80 // resembles that to much. For instance, it does not use STL containers.
81 // It does not support non-basic data types, in particular Complex.
82 // </motivation>
83
85 {
86 public:
87 // The default constructor makes an invalid object.
88 // It is needed to make a vector of objects.
90 : itsSize(0)
91 {}
92
93 // Create an HDF5 datatype object for the given fixed length type.
94 // It uses the corresponding native HDF5 data type. Only for Bool it
95 // uses a uchar, because the HDF5 bool type is a uint.
96 // For the complex types it makes a compound HDF5 data type.
97 // The String type is meant for an array of strings.
98 // <group>
99 explicit HDF5DataType (const Bool*);
100 explicit HDF5DataType (const uChar*);
101 explicit HDF5DataType (const Short*);
102 explicit HDF5DataType (const uShort*);
103 explicit HDF5DataType (const Int*);
104 explicit HDF5DataType (const uInt*);
105 explicit HDF5DataType (const Int64*);
106 explicit HDF5DataType (const Float*);
107 explicit HDF5DataType (const Double*);
108 explicit HDF5DataType (const Complex*);
109 explicit HDF5DataType (const DComplex*);
110 explicit HDF5DataType (const String*);
111 // </group>
112
113 // Create an HDF5 datatype object for a scalar string.
114 // The length of the string is part of the type.
115 explicit HDF5DataType (const String& value);
116
117 // Create an HDF5 datatype object for an empty array.
118 // Both arguments are dummy (needed to distinguish the constructor).
119 // An empty array as represented as a compound data type with integer
120 // field names emptyarray, rank and casatype.
122
123 // Define a compound data type consisting of the given fields and types.
124 // An exception is thrown if the vectors are empty or have mismatching
125 // sizes.
126 HDF5DataType (const std::vector<String>& names,
127 const std::vector<HDF5DataType>& types);
128
129 // Create an array of the given data type.
130 // An exception is thrown if the shape is empty.
132
133 // The copy constructor makes a deep copy.
135
136 // The destructor closes the HDF5 data type object.
138
139 // Assignment makes a deep copy.
141
142 // Get the Casacore data type for the given HDF5 data type.
143 // TpRecord is returned for a compound data type.
144 static DataType getDataType (hid_t);
145
146 // Get the HID for the data type in memory.
147 hid_t getHidMem() const
148 { return itsHidMem; }
149
150 // Get the HID for the data type in the file.
151 hid_t getHidFile() const
152 { return itsHidFile; }
153
154 // Get the size in bytes of the data type (in memory).
155 // Note that the size of a string is variable, thus 0.
156 uInt size() const
157 { return itsSize; }
158
159 // Test if the data type is Complex or DComplex.
160 static Bool isComplex (hid_t dtid);
161
162 // Test if the data type is an empty array.
163 static Bool isEmptyArray (hid_t dtid);
164
165 // Get the shape of an array data type.
166 // It returns an empty IPosition for non-arrays.
167 static IPosition getShape (hid_t dtid);
168
169 // Helper functions to convert shapes.
170 // It reverses the axes, because HDF5 uses C-order.
171 // <group>
174 // </group>
175
176 private:
177 // Add a field to a compound data type.
178 // It does it for the memory and file data type.
179 void addToCompound (const char* name,
180 uInt offset,
181 const HDF5DataType& dtype);
182
183 //# Data members
187 };
188
189}
190
191#endif
simple 1-D array
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.
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned char uChar
Definition aipstype.h:45
short Short
Definition aipstype.h:46
unsigned int uInt
Definition aipstype.h:49
unsigned short uShort
Definition aipstype.h:47
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition ExprNode.h:1991
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
float Float
Definition aipstype.h:52
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
double Double
Definition aipstype.h:53