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