HDF5File.h

Go to the documentation of this file.
00001 //# HDF5File.h: An class representing an HDF5 file
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_HDF5FILE_H
00029 #define CASA_HDF5FILE_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/casa/HDF5/HDF5Object.h>
00034 #include <casacore/casa/BasicSL/String.h>
00035 #include <casacore/casa/IO/ByteIO.h>
00036 
00037 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00038 
00039   // <summary>
00040   // A class representing an HDF5 file.
00041   // </summary>
00042 
00043   // <use visibility=export>
00044 
00045   // <reviewed reviewer="" date="" tests="tHDF5File.cc">
00046   // </reviewed>
00047 
00048   // <prerequisite>
00049   //   <li> <a href="http://hdf.ncsa.uiuc.edu">HDF5 system</a>
00050   // </prerequisite>
00051 
00052   // <synopsis>
00053   // This class wraps the HDF5 functions to open, create, or close an
00054   // HDF5 file.
00055   // If the file is opened as readonly, it is possible to reopen it for
00056   // read/write (provided the user has the correct privileges).
00057   // It is also possible to temporarily close the file and reopen it later.
00058   // <note> It is ensured that the class and the static function <tt>isHDF5</tt>
00059   // are also defined if HDF5 is not compiled in. </note>
00060   // </synopsis> 
00061 
00062   // <motivation>
00063   // It was overkill to use the HDF5 C++ interface. Instead little wrappers
00064   // have been written. HDF5File can be embedded in a shared pointer making
00065   // it possible to share an HDF5 file amongst various HDF5Array objects.
00066   // </motivation>
00067 
00068   class HDF5File : public HDF5Object
00069   {
00070   public:
00071     // Create an HDF5 file object with the given file name (possible tilde
00072     // or environment variables in it will be expanded).
00073     // The ByteIO option determines if the file will be created,
00074     // opened for input and/or output, or possibly deleted by the destructor.
00075     explicit HDF5File (const String& name,
00076                        ByteIO::OpenOption = ByteIO::Old);
00077 
00078     // The destructor closes the file and deletes it when it was opened
00079     // using ByteIO::Scratch or ByteIO::Delete.
00080     ~HDF5File();
00081 
00082     // Test if the file with the given name is an HDF5 file.
00083     static Bool isHDF5 (const String& name);
00084 
00085     // Reopen the underlying file for read/write access.
00086     // Nothing will be done if the stream is writable already.
00087     // Otherwise it will be reopened and an exception will be thrown
00088     // if it is not possible to reopen it for read/write access.
00089     void reopenRW();
00090 
00091     // Is the file writable?
00092     Bool isWritable() const
00093       { return itsOption == ByteIO::Update; }
00094 
00095     // Is the file opened for delete?
00096     Bool isOpenedForDelete() const
00097       { return itsDelete; }
00098 
00099     // Is the file temporarily closed?
00100     Bool isClosed() const
00101       { return getHid()<0; }
00102 
00103     // Close the file (temporarily).
00104     // Note it will not delete the file; that is only done by the destructor.
00105     virtual void close();
00106 
00107     // Reopen the file if closed (which may change the HID).
00108     void reopen();
00109 
00110     // Flush the data to disk.
00111     void flush();
00112 
00113     // Get or set the chunk cache size (in bytes).
00114     // Note that all data sets in a file share the cache.
00115     // <group>
00116     size_t getChunkCacheSize() const;
00117     void setChunkCacheSize (size_t nbytes);
00118     // </group>
00119 
00120   private:
00121     // Open or create the file.
00122     void doOpen();
00123 
00124 
00125     //# Data members
00126     ByteIO::OpenOption itsOption;
00127     String             itsName;
00128     Bool               itsDelete;
00129 
00130   private:
00131     // Copy constructor cannot be used.
00132     HDF5File (const HDF5File& that);
00133 
00134     // Assignment cannot be used.
00135     HDF5File& operator= (const HDF5File& that);
00136   };
00137 
00138 }
00139 
00140 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1