casacore
Loading...
Searching...
No Matches
HDF5DataSet.h
Go to the documentation of this file.
1// # HDF5DataSet.h: An class representing an HDF5 data set
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_HDF5DATASET_H
27#define CASA_HDF5DATASET_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/HDF5/HDF5DataType.h>
34#include <casacore/casa/Arrays/Slicer.h>
35#include <casacore/casa/BasicSL/String.h>
36#include <casacore/casa/Utilities/DataType.h>
37
38namespace casacore { // # NAMESPACE CASACORE - BEGIN
39
40// # Forward Declarations
41class ArrayBase;
42template <typename T>
43class Block;
44
45// <summary>
46// A class representing an HDF5 data set.
47// </summary>
48
49// <use visibility=export>
50
51// <reviewed reviewer="" date="" tests="tHDF5DataSet.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 and open a data set.
60// It is meant to be used in class HDF5Lattice, but can be used in itself
61// as well.
62// A dataset of any HDF5DataType (including compound types) can be created.
63// For a limited number of data types special constructors exist which
64// create the appropriate HDF5DataType themselves.
65// <br>
66// A data set can be created extendible by defining the appropriate
67// axis with length 0, whereafter the extend function can be used to
68// extend the data set.
69// The data can be stored in a tiled (chunked) way by specifying the tile
70// shape when creating it.
71// <br>
72// When opening an existing data set, it is checked if the given data type
73// matches the data set's data type. For a compound data type, it only
74// checks if its size matches; it does not check if the fields match.
75// <br>
76// It is possible to read or write a section of the data set by using an
77// appropriate Slicer object. Note that the Slicer object must be fully
78// filled; it does not infer missing info from the array shape.
79// <p>
80// Note that Casacore arrays are in Fortran order, while HDF5 uses C order.
81// Therefore array axes are reversed, thus axes in shapes, slicers, etc.
82// </synopsis>
83
84// <motivation>
85// It was overkill to use the HDF5 C++ interface. Instead little wrappers
86// have been written. HDF5DataSet can be embedded in a shared pointer making
87// it possible to share an HDF5 data set amongst various HDF5Lattice objects
88// and close (i.e. destruct) the HDF5 data set object when needed.
89// </motivation>
90
91class HDF5DataSet : public HDF5Object {
92 public:
93 // Create an HDF5 data set in the given hid (file or group).
94 // It gets the given name, shape (also tile shape), and data type.
95 // <group>
97 const Bool*);
99 const uChar*);
101 const Short*);
103 const Int*);
105 const Int64*);
107 const Float*);
109 const Double*);
111 const Complex*);
113 const DComplex*);
115 const HDF5DataType&);
116 // </group>
117
118 // Open an existing HDF5 data set in the given hid (file or group).
119 // It checks if the internal type matches the given type.
120 // <group>
121 HDF5DataSet(const HDF5Object&, const String&, const Bool*);
122 HDF5DataSet(const HDF5Object&, const String&, const uChar*);
123 HDF5DataSet(const HDF5Object&, const String&, const Short*);
124 HDF5DataSet(const HDF5Object&, const String&, const Int*);
125 HDF5DataSet(const HDF5Object&, const String&, const Int64*);
126 HDF5DataSet(const HDF5Object&, const String&, const Float*);
127 HDF5DataSet(const HDF5Object&, const String&, const Double*);
128 HDF5DataSet(const HDF5Object&, const String&, const Complex*);
129 HDF5DataSet(const HDF5Object&, const String&, const DComplex*);
130 HDF5DataSet(const HDF5Object&, const String&, const HDF5DataType&);
131 // </group>
132
133 // The destructor closes the HDF5 dataset object.
134 virtual ~HDF5DataSet();
135
136 // Close the hid if valid.
137 virtual void close();
138
139 // Set the cache size (in chunks) for the data set.
140 // It needs to close and reopen the DataSet to take effect.
141 void setCacheSize(uInt nchunks);
142
143 // Get the data type for the data set with the given name.
144 static DataType getDataType(hid_t, const String& name);
145
146 // Get the shape.
147 const IPosition& shape() const { return itsShape; }
148
149 // Get the tile (chunk) shape.
150 const IPosition& tileShape() const { return itsTileShape; }
151
152 // Get a section of data into the array.
153 // The array is resized if its shape does not match the slicer's shape.
154 // This is only possible if the array is empty or if resize=True.
155 // It is not checked if the data type of array and HDF5DataSet match.
156 void get(const Slicer&, ArrayBase& buf, Bool resize = False);
157
158 // Get a section of data.
159 // The buffer must be large enough to hold the section.
160 void get(const Slicer&, void* buf);
161
162 // Put a section of data.
163 // The shape of the array and slicer must match.
164 // It is not checked if the data type of array and HDF5DataSet match.
165 void put(const Slicer&, const ArrayBase& buf);
166
167 // Put a section of data.
168 // The buffer must be large enough to hold the section.
169 void put(const Slicer&, const void* buf);
170
171 // Extend the dataset if an axis in the new shape is larger.
172 void extend(const IPosition& shape);
173
174 protected:
175 // Create the data set.
176 void create(const HDF5Object&, const String&, const IPosition& shape, const IPosition& tileShape);
177
178 // Open the data set and check if the external data type matches.
179 void open(const HDF5Object&, const String&);
180
181 // Close the dataset (but not other hids).
183
184 private:
185 // Copy constructor cannot be used.
187 // Assignment cannot be used.
189
190 HDF5HidDataSpace itsDSid; // # data space id
191 HDF5HidProperty itsPLid; // # create property list id
192 HDF5HidProperty itsDaplid; // # access property list id
197};
198
199} // namespace casacore
200
201#endif
Non-templated base class for templated Array class.
Definition ArrayBase.h:69
HDF5DataSet(const HDF5Object &, const String &, const Int64 *)
HDF5DataSet(const HDF5Object &, const String &, const Double *)
HDF5DataSet(const HDF5Object &, const String &, const IPosition &shape, const IPosition &tileShape, const DComplex *)
void closeDataSet()
Close the dataset (but not other hids).
HDF5DataSet(const HDF5Object &, const String &, const IPosition &shape, const IPosition &tileShape, const HDF5DataType &)
void put(const Slicer &, const void *buf)
Put a section of data.
HDF5DataSet(const HDF5Object &, const String &, const IPosition &shape, const IPosition &tileShape, const Bool *)
Create an HDF5 data set in the given hid (file or group).
void get(const Slicer &, void *buf)
Get a section of data.
HDF5DataSet(const HDF5DataSet &that)
Copy constructor cannot be used.
HDF5DataSet(const HDF5Object &, const String &, const Complex *)
HDF5DataSet(const HDF5Object &, const String &, const IPosition &shape, const IPosition &tileShape, const Float *)
void put(const Slicer &, const ArrayBase &buf)
Put a section of data.
HDF5DataSet(const HDF5Object &, const String &, const Bool *)
Open an existing HDF5 data set in the given hid (file or group).
HDF5DataSet(const HDF5Object &, const String &, const IPosition &shape, const IPosition &tileShape, const Int64 *)
HDF5DataSet(const HDF5Object &, const String &, const IPosition &shape, const IPosition &tileShape, const Short *)
HDF5DataSet(const HDF5Object &, const String &, const Int *)
HDF5HidDataSpace itsDSid
HDF5DataSet(const HDF5Object &, const String &, const IPosition &shape, const IPosition &tileShape, const Complex *)
HDF5DataSet(const HDF5Object &, const String &, const IPosition &shape, const IPosition &tileShape, const Double *)
HDF5DataSet & operator=(const HDF5DataSet &that)
Assignment cannot be used.
HDF5DataSet(const HDF5Object &, const String &, const uChar *)
HDF5DataSet(const HDF5Object &, const String &, const IPosition &shape, const IPosition &tileShape, const uChar *)
virtual ~HDF5DataSet()
The destructor closes the HDF5 dataset object.
HDF5HidProperty itsDaplid
HDF5DataSet(const HDF5Object &, const String &, const HDF5DataType &)
HDF5DataSet(const HDF5Object &, const String &, const Float *)
virtual void close()
Close the hid if valid.
void create(const HDF5Object &, const String &, const IPosition &shape, const IPosition &tileShape)
Create the data set.
void extend(const IPosition &shape)
Extend the dataset if an axis in the new shape is larger.
static DataType getDataType(hid_t, const String &name)
Get the data type for the data set with the given name.
HDF5HidProperty itsPLid
HDF5DataSet(const HDF5Object &, const String &, const Short *)
void open(const HDF5Object &, const String &)
Open the data set and check if the external data type matches.
HDF5DataSet(const HDF5Object &, const String &, const IPosition &shape, const IPosition &tileShape, const Int *)
void get(const Slicer &, ArrayBase &buf, Bool resize=False)
Get a section of data into the array.
HDF5DataType itsDataType
const IPosition & tileShape() const
Get the tile (chunk) shape.
const IPosition & shape() const
Get the shape.
HDF5DataSet(const HDF5Object &, const String &, const DComplex *)
void setCacheSize(uInt nchunks)
Set the cache size (in chunks) for the data set.
const HDF5Object * itsParent
A class representing an HDF5 dataspace hid.
HDF5Object()
Default constructor sets to invalid hid.
Definition HDF5Object.h:70
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
const Bool False
Definition aipstype.h:42
short Short
Definition aipstype.h:46
unsigned int uInt
Definition aipstype.h:49
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
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
double Double
Definition aipstype.h:53