casa
$Rev:20696$
|
00001 //# HDF5DataSet.h: An class representing an HDF5 data set 00002 //# Copyright (C) 2008 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: HDF5DataSet.h 20901 2010-06-09 07:23:37Z gervandiepen $ 00027 00028 #ifndef CASA_HDF5DATASET_H 00029 #define CASA_HDF5DATASET_H 00030 00031 //# Includes 00032 #include <casa/HDF5/HDF5Object.h> 00033 #include <casa/HDF5/HDF5HidMeta.h> 00034 #include <casa/HDF5/HDF5DataType.h> 00035 #include <casa/Arrays/Slicer.h> 00036 #include <casa/BasicSL/String.h> 00037 #include <casa/Utilities/DataType.h> 00038 00039 namespace casa { //# NAMESPACE CASA - BEGIN 00040 00041 //# Forward Declarations 00042 template<typename T> class Block; 00043 00044 // <summary> 00045 // A class representing an HDF5 data set. 00046 // </summary> 00047 00048 // <use visibility=export> 00049 00050 // <reviewed reviewer="" date="" tests="tHDF5DataSet.cc"> 00051 // </reviewed> 00052 00053 // <prerequisite> 00054 // <li> <a href="http://hdf.ncsa.uiuc.edu">HDF5 system</a> 00055 // </prerequisite> 00056 00057 // <synopsis> 00058 // This class wraps the HDF5 functions to create and open a data set. 00059 // It is meant to be used in class HDF5Array, but can be used in itself 00060 // as well. 00061 // Only a limited number of data types are supported. 00062 // They are: boolean (stored as chars), 4-byte integer, and single and 00063 // double precision real and complex. 00064 // <br> 00065 // The data set has a fixed shape, thus cannot be extended nor resized. 00066 // It can be stored in a tiled (chunked) way by specifying the tile shape 00067 // when creating it. 00068 // <br> 00069 // It is possible to read or write a section of the data set by using an 00070 // appropriate Slicer object. Note that the Slicer object must be fully 00071 // filled; it does not infer missing info from the array shape. 00072 // <p> 00073 // AIPS++ arrays are in Fortran order, while HDF5 uses C order. 00074 // Therefore array axes are reversed, thus axes in shapes, slicers, etc. 00075 // </synopsis> 00076 00077 // <motivation> 00078 // It was overkill to use the HDF5 C++ interface. Instead little wrappers 00079 // have been written. HDF5DataSet can be embedded in a shared pointer making 00080 // it possible to share an HDF5 data set amongst various HDF5Array objects 00081 // and close (i.e. destruct) the HDF5 data set object when needed. 00082 // </motivation> 00083 00084 class HDF5DataSet : public HDF5Object 00085 { 00086 public: 00087 // Create an HDF5 data set in the given hid (file or group). 00088 // It gets the given name, shape (also tile shape), and data type. 00089 // <group> 00090 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape, 00091 const IPosition& tileShape, const Bool*); 00092 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape, 00093 const IPosition& tileShape, const Int*); 00094 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape, 00095 const IPosition& tileShape, const Int64*); 00096 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape, 00097 const IPosition& tileShape, const Float*); 00098 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape, 00099 const IPosition& tileShape, const Double*); 00100 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape, 00101 const IPosition& tileShape, const Complex*); 00102 HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape, 00103 const IPosition& tileShape, const DComplex*); 00104 // </group> 00105 00106 // Open an existing HDF5 data set in the given hid (file or group). 00107 // It checks if the internal type matches the given type. 00108 // <group> 00109 HDF5DataSet (const HDF5Object&, const String&, const Bool*); 00110 HDF5DataSet (const HDF5Object&, const String&, const Int*); 00111 HDF5DataSet (const HDF5Object&, const String&, const Int64*); 00112 HDF5DataSet (const HDF5Object&, const String&, const Float*); 00113 HDF5DataSet (const HDF5Object&, const String&, const Double*); 00114 HDF5DataSet (const HDF5Object&, const String&, const Complex*); 00115 HDF5DataSet (const HDF5Object&, const String&, const DComplex*); 00116 // </group> 00117 00118 // The destructor closes the HDF5 dataset object. 00119 ~HDF5DataSet(); 00120 00121 // Close the hid if valid. 00122 virtual void close(); 00123 00124 // Set the cache size (in chunks) for the data set. 00125 // It needs to close and reopen the DataSet to take effect. 00126 void setCacheSize (uInt nchunks); 00127 00128 // Get the data type for the data set with the given name. 00129 static DataType getDataType (hid_t, const String& name); 00130 00131 // Get the shape. 00132 const IPosition& shape() const 00133 { return itsShape; } 00134 00135 // Get the tile (chunk) shape. 00136 const IPosition& tileShape() const 00137 { return itsTileShape; } 00138 00139 // Get a section of data. 00140 // The buffer must be large enough to hold the section. 00141 void get (const Slicer&, void* buf); 00142 00143 // Put a section of data. 00144 void put (const Slicer&, const void* buf); 00145 00146 // Helper functions to convert shapes. 00147 // It reverses the axes, because HDF5 uses C-order. 00148 // <group> 00149 static Block<hsize_t> fromShape (const IPosition& shape); 00150 static IPosition toShape (const Block<hsize_t>& b); 00151 // </group> 00152 00153 private: 00154 // Copy constructor cannot be used. 00155 HDF5DataSet (const HDF5DataSet& that); 00156 // Assignment cannot be used. 00157 HDF5DataSet& operator= (const HDF5DataSet& that); 00158 00159 // Create the data set. 00160 void create (const HDF5Object&, const String&, 00161 const IPosition& shape, const IPosition& tileShape); 00162 00163 // Open the data set and check if the external data type matches. 00164 void open (const HDF5Object&, const String&); 00165 00166 // Close the dataset (but not other hids). 00167 void closeDataSet(); 00168 00169 HDF5HidDataSpace itsDSid; //# data space id 00170 HDF5HidProperty itsPLid; //# create property list id 00171 HDF5HidProperty itsDaplid; //# access property list id 00172 IPosition itsShape; 00173 IPosition itsTileShape; 00174 HDF5DataType itsDataType; 00175 const HDF5Object* itsParent; 00176 }; 00177 00178 } 00179 00180 #endif