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