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
41 class ArrayBase;
42 template<typename T> class Block;
43
44 // <summary>
45 // A class representing an HDF5 data set.
46 // </summary>
47
48 // <use visibility=export>
49
50 // <reviewed reviewer="" date="" tests="tHDF5DataSet.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 and open a data set.
59 // It is meant to be used in class HDF5Lattice, but can be used in itself
60 // as well.
61 // A dataset of any HDF5DataType (including compound types) can be created.
62 // For a limited number of data types special constructors exist which
63 // create the appropriate HDF5DataType themselves.
64 // <br>
65 // A data set can be created extendible by defining the appropriate
66 // axis with length 0, whereafter the extend function can be used to
67 // extend the data set.
68 // The data can be stored in a tiled (chunked) way by specifying the tile
69 // shape when creating it.
70 // <br>
71 // When opening an existing data set, it is checked if the given data type
72 // matches the data set's data type. For a compound data type, it only
73 // checks if its size matches; it does not check if the fields match.
74 // <br>
75 // It is possible to read or write a section of the data set by using an
76 // appropriate Slicer object. Note that the Slicer object must be fully
77 // filled; it does not infer missing info from the array shape.
78 // <p>
79 // Note that Casacore arrays are in Fortran order, while HDF5 uses C order.
80 // Therefore array axes are reversed, thus axes in shapes, slicers, etc.
81 // </synopsis>
82
83 // <motivation>
84 // It was overkill to use the HDF5 C++ interface. Instead little wrappers
85 // have been written. HDF5DataSet can be embedded in a shared pointer making
86 // it possible to share an HDF5 data set amongst various HDF5Lattice objects
87 // and close (i.e. destruct) the HDF5 data set object when needed.
88 // </motivation>
89
90 class HDF5DataSet : public HDF5Object
91 {
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>
96 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
97 const IPosition& tileShape, const Bool*);
98 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
99 const IPosition& tileShape, const uChar*);
100 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
101 const IPosition& tileShape, const Short*);
102 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
103 const IPosition& tileShape, const Int*);
104 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
105 const IPosition& tileShape, const Int64*);
106 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
107 const IPosition& tileShape, const Float*);
108 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
109 const IPosition& tileShape, const Double*);
110 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
111 const IPosition& tileShape, const Complex*);
112 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
113 const IPosition& tileShape, const DComplex*);
114 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
115 const IPosition& tileShape, 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
148 { return itsShape; }
149
150 // Get the tile (chunk) shape.
151 const IPosition& tileShape() const
152 { return itsTileShape; }
153
154 // Get a section of data into the array.
155 // The array is resized if its shape does not match the slicer's shape.
156 // This is only possible if the array is empty or if resize=True.
157 // It is not checked if the data type of array and HDF5DataSet match.
158 void get (const Slicer&, ArrayBase& buf, Bool resize=False);
159
160 // Get a section of data.
161 // The buffer must be large enough to hold the section.
162 void get (const Slicer&, void* buf);
163
164 // Put a section of data.
165 // The shape of the array and slicer must match.
166 // It is not checked if the data type of array and HDF5DataSet match.
167 void put (const Slicer&, const ArrayBase& buf);
168
169 // Put a section of data.
170 // The buffer must be large enough to hold the section.
171 void put (const Slicer&, const void* buf);
172
173 // Extend the dataset if an axis in the new shape is larger.
174 void extend (const IPosition& shape);
175
176 protected:
177 // Create the data set.
178 void create (const HDF5Object&, const String&,
179 const IPosition& shape, const IPosition& tileShape);
180
181 // Open the data set and check if the external data type matches.
182 void open (const HDF5Object&, const String&);
183
184 // Close the dataset (but not other hids).
186
187 private:
188 // Copy constructor cannot be used.
190 // Assignment cannot be used.
192
193 HDF5HidDataSpace itsDSid; //# data space id
194 HDF5HidProperty itsPLid; //# create property list id
195 HDF5HidProperty itsDaplid; //# access property list id
200 };
201
202}
203
204#endif
Non-templated base class for templated Array class.
Definition ArrayBase.h:71
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.
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
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
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