HDF5DataSet.h

Go to the documentation of this file.
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$
00027 
00028 #ifndef CASA_HDF5DATASET_H
00029 #define CASA_HDF5DATASET_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/casa/HDF5/HDF5Object.h>
00034 #include <casacore/casa/HDF5/HDF5HidMeta.h>
00035 #include <casacore/casa/HDF5/HDF5DataType.h>
00036 #include <casacore/casa/Arrays/Slicer.h>
00037 #include <casacore/casa/BasicSL/String.h>
00038 #include <casacore/casa/Utilities/DataType.h>
00039 
00040 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00041 
00042   //# Forward Declarations
00043   template<typename T> class Block;
00044 
00045   // <summary>
00046   // A class representing an HDF5 data set.
00047   // </summary>
00048 
00049   // <use visibility=export>
00050 
00051   // <reviewed reviewer="" date="" tests="tHDF5DataSet.cc">
00052   // </reviewed>
00053 
00054   // <prerequisite>
00055   //   <li> <a href="http://hdf.ncsa.uiuc.edu">HDF5 system</a>
00056   // </prerequisite>
00057 
00058   // <synopsis>
00059   // This class wraps the HDF5 functions to create and open a data set.
00060   // It is meant to be used in class HDF5Array, but can be used in itself
00061   // as well.
00062   // Only a limited number of data types are supported.
00063   // They are: boolean (stored as chars), 4-byte integer, and single and
00064   // double precision real and complex.
00065   // <br>
00066   // The data set has a fixed shape, thus cannot be extended nor resized.
00067   // It can be stored in a tiled (chunked) way by specifying the tile shape
00068   // when creating it.
00069   // <br>
00070   // It is possible to read or write a section of the data set by using an
00071   // appropriate Slicer object. Note that the Slicer object must be fully
00072   // filled; it does not infer missing info from the array shape.
00073   // <p>
00074   // Casacore arrays are in Fortran order, while HDF5 uses C order.
00075   // Therefore array axes are reversed, thus axes in shapes, slicers, etc.
00076   // </synopsis> 
00077 
00078   // <motivation>
00079   // It was overkill to use the HDF5 C++ interface. Instead little wrappers
00080   // have been written. HDF5DataSet can be embedded in a shared pointer making
00081   // it possible to share an HDF5 data set amongst various HDF5Array objects
00082   // and close (i.e. destruct) the HDF5 data set object when needed.
00083   // </motivation>
00084 
00085   class HDF5DataSet : public HDF5Object
00086   {
00087   public: 
00088     // Create an HDF5 data set in the given hid (file or group).
00089     // It gets the given name, shape (also tile shape), and data type.
00090     // <group>
00091     HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
00092                  const IPosition& tileShape, const Bool*);
00093     HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
00094                  const IPosition& tileShape, const uChar*);
00095     HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
00096                  const IPosition& tileShape, const Int*);
00097     HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
00098                  const IPosition& tileShape, const Int64*);
00099     HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
00100                  const IPosition& tileShape, const Float*);
00101     HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
00102                  const IPosition& tileShape, const Double*);
00103     HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
00104                  const IPosition& tileShape, const Complex*);
00105     HDF5DataSet (const HDF5Object&, const String&, const IPosition& shape,
00106                  const IPosition& tileShape, const DComplex*);
00107     // </group>
00108 
00109     // Open an existing HDF5 data set in the given hid (file or group).
00110     // It checks if the internal type matches the given type.
00111     // <group>
00112     HDF5DataSet (const HDF5Object&, const String&, const Bool*);
00113     HDF5DataSet (const HDF5Object&, const String&, const uChar*);
00114     HDF5DataSet (const HDF5Object&, const String&, const Int*);
00115     HDF5DataSet (const HDF5Object&, const String&, const Int64*);
00116     HDF5DataSet (const HDF5Object&, const String&, const Float*);
00117     HDF5DataSet (const HDF5Object&, const String&, const Double*);
00118     HDF5DataSet (const HDF5Object&, const String&, const Complex*);
00119     HDF5DataSet (const HDF5Object&, const String&, const DComplex*);
00120     // </group>
00121 
00122     // The destructor closes the HDF5 dataset object.
00123     ~HDF5DataSet();
00124 
00125     // Close the hid if valid.
00126     virtual void close();
00127 
00128     // Set the cache size (in chunks) for the data set.
00129     // It needs to close and reopen the DataSet to take effect.
00130     void setCacheSize (uInt nchunks);
00131 
00132     // Get the data type for the data set with the given name.
00133     static DataType getDataType (hid_t, const String& name);
00134 
00135     // Get the shape.
00136     const IPosition& shape() const
00137       { return itsShape; }
00138 
00139     // Get the tile (chunk) shape.
00140     const IPosition& tileShape() const
00141       { return itsTileShape; }
00142 
00143     // Get a section of data.
00144     // The buffer must be large enough to hold the section.
00145     void get (const Slicer&, void* buf);
00146 
00147     // Put a section of data.
00148     void put (const Slicer&, const void* buf);
00149 
00150     // Extend the dataset if an axis in the new shape is larger.
00151     void extend (const IPosition& shape);
00152 
00153     // Helper functions to convert shapes.
00154     // It reverses the axes, because HDF5 uses C-order.
00155     // <group>
00156     static Block<hsize_t> fromShape (const IPosition& shape);
00157     static IPosition toShape (const Block<hsize_t>& b);
00158     // </group>
00159 
00160   private:
00161     // Copy constructor cannot be used.
00162     HDF5DataSet (const HDF5DataSet& that);
00163     // Assignment cannot be used.
00164     HDF5DataSet& operator= (const HDF5DataSet& that);
00165 
00166     // Create the data set.
00167     void create (const HDF5Object&, const String&,
00168                  const IPosition& shape, const IPosition& tileShape);
00169 
00170     // Open the data set and check if the external data type matches.
00171     void open (const HDF5Object&, const String&);
00172 
00173     // Close the dataset (but not other hids).
00174     void closeDataSet();
00175 
00176     HDF5HidDataSpace   itsDSid;        //# data space id
00177     HDF5HidProperty    itsPLid;        //# create property list id
00178     HDF5HidProperty    itsDaplid;      //# access property list id
00179     IPosition          itsShape;
00180     IPosition          itsTileShape;
00181     HDF5DataType       itsDataType;
00182     const HDF5Object*  itsParent;
00183   };
00184 
00185 }
00186 
00187 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1