casacore
HDF5File.h
Go to the documentation of this file.
1//# HDF5File.h: An class representing an HDF5 file
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: aips2-request@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//# $Id$
27
28#ifndef CASA_HDF5FILE_H
29#define CASA_HDF5FILE_H
30
31//# Includes
32#include <casacore/casa/aips.h>
33#include <casacore/casa/HDF5/HDF5Object.h>
34#include <casacore/casa/BasicSL/String.h>
35#include <casacore/casa/IO/ByteIO.h>
36
37namespace casacore { //# NAMESPACE CASACORE - BEGIN
38
39 // <summary>
40 // A class representing an HDF5 file.
41 // </summary>
42
43 // <use visibility=export>
44
45 // <reviewed reviewer="" date="" tests="tHDF5File.cc">
46 // </reviewed>
47
48 // <prerequisite>
49 // <li> <a href="http://hdf.ncsa.uiuc.edu">HDF5 system</a>
50 // </prerequisite>
51
52 // <synopsis>
53 // This class wraps the HDF5 functions to open, create, or close an
54 // HDF5 file.
55 // If the file is opened as readonly, it is possible to reopen it for
56 // read/write (provided the user has the correct privileges).
57 // It is also possible to temporarily close the file and reopen it later.
58 // <note> It is ensured that the class and the static function <tt>isHDF5</tt>
59 // are also defined if HDF5 is not compiled in. </note>
60 // </synopsis>
61
62 // <motivation>
63 // It was overkill to use the HDF5 C++ interface. Instead little wrappers
64 // have been written. HDF5File can be embedded in a shared pointer making
65 // it possible to share an HDF5 file amongst various HDF5Array objects.
66 // </motivation>
67
68 class HDF5File : public HDF5Object
69 {
70 public:
71 // Create an HDF5 file object with the given file name (possible tilde
72 // or environment variables in it will be expanded).
73 // The ByteIO option determines if the file will be created,
74 // opened for input and/or output, or possibly deleted by the destructor.
75 explicit HDF5File (const String& name,
77
78 // The destructor closes the file and deletes it when it was opened
79 // using ByteIO::Scratch or ByteIO::Delete.
81
82 // Test if the file with the given name is an HDF5 file.
83 static Bool isHDF5 (const String& name);
84
85 // Reopen the underlying file for read/write access.
86 // Nothing will be done if the stream is writable already.
87 // Otherwise it will be reopened and an exception will be thrown
88 // if it is not possible to reopen it for read/write access.
89 void reopenRW();
90
91 // Is the file writable?
93 { return itsOption == ByteIO::Update; }
94
95 // Is the file opened for delete?
97 { return itsDelete; }
98
99 // Is the file temporarily closed?
101 { return getHid()<0; }
102
103 // Close the file (temporarily).
104 // Note it will not delete the file; that is only done by the destructor.
105 virtual void close();
106
107 // Reopen the file if closed (which may change the HID).
108 void reopen();
109
110 // Flush the data to disk.
111 void flush();
112
113 // Get or set the chunk cache size (in bytes).
114 // Note that all data sets in a file share the cache.
115 // <group>
116 size_t getChunkCacheSize() const;
117 void setChunkCacheSize (size_t nbytes);
118 // </group>
119
120 private:
121 // Open or create the file.
122 void doOpen();
123
124
125 //# Data members
129
130 private:
131 // Copy constructor cannot be used.
132 HDF5File (const HDF5File& that);
133
134 // Assignment cannot be used.
136 };
137
138}
139
140#endif
OpenOption
Define the possible ByteIO open options.
Definition: ByteIO.h:65
@ Update
read/write; file must exist.
Definition: ByteIO.h:68
static Bool isHDF5(const String &name)
Test if the file with the given name is an HDF5 file.
void setChunkCacheSize(size_t nbytes)
void reopen()
Reopen the file if closed (which may change the HID).
Bool isOpenedForDelete() const
Is the file opened for delete?
Definition: HDF5File.h:96
Bool isWritable() const
Is the file writable?
Definition: HDF5File.h:92
void doOpen()
Open or create the file.
ByteIO::OpenOption itsOption
Definition: HDF5File.h:126
virtual void close()
Close the file (temporarily).
void flush()
Flush the data to disk.
HDF5File & operator=(const HDF5File &that)
Assignment cannot be used.
HDF5File(const String &name, ByteIO::OpenOption=ByteIO::Old)
Create an HDF5 file object with the given file name (possible tilde or environment variables in it wi...
size_t getChunkCacheSize() const
Get or set the chunk cache size (in bytes).
void reopenRW()
Reopen the underlying file for read/write access.
HDF5File(const HDF5File &that)
Copy constructor cannot be used.
~HDF5File()
The destructor closes the file and deletes it when it was opened using ByteIO::Scratch or ByteIO::Del...
Bool isClosed() const
Is the file temporarily closed?
Definition: HDF5File.h:100
hid_t getHid() const
Get the hid.
Definition: HDF5Object.h:92
String: the storage and methods of handling collections of characters.
Definition: String.h:225
this file contains all the compiler specific defines
Definition: mainpage.dox:28
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42