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
66 class HDF5File : public HDF5Object
67 {
68 public:
69 // Create an HDF5 file object with the given file name (possible tilde
70 // or environment variables in it will be expanded).
71 // The ByteIO option determines if the file will be created,
72 // opened for input and/or output, or possibly deleted by the destructor.
73 explicit HDF5File (const String& name,
75
76 // The destructor closes the file and deletes it when it was opened
77 // using ByteIO::Scratch or ByteIO::Delete.
79
80 // Test if the file with the given name is an HDF5 file.
81 static Bool isHDF5 (const String& name);
82
83 // Reopen the underlying file for read/write access.
84 // Nothing will be done if the stream is writable already.
85 // Otherwise it will be reopened and an exception will be thrown
86 // if it is not possible to reopen it for read/write access.
87 void reopenRW();
88
89 // Is the file writable?
91 { return itsOption == ByteIO::Update; }
92
93 // Is the file opened for delete?
95 { return itsDelete; }
96
97 // Is the file temporarily closed?
98 Bool isClosed() const
99 { return getHid()<0; }
100
101 // Close the file (temporarily).
102 // Note it will not delete the file; that is only done by the destructor.
103 virtual void close();
104
105 // Reopen the file if closed (which may change the HID).
106 void reopen();
107
108 // Flush the data to disk.
109 void flush();
110
111 // Get or set the chunk cache size (in bytes).
112 // Note that all data sets in a file share the cache.
113 // <group>
114 size_t getChunkCacheSize() const;
115 void setChunkCacheSize (size_t nbytes);
116 // </group>
117
118 private:
119 // Open or create the file.
120 void doOpen();
121
122
123 //# Data members
127
128 private:
129 // Copy constructor cannot be used.
130 HDF5File (const HDF5File& that);
131
132 // Assignment cannot be used.
134 };
135
136}
137
138#endif
OpenOption
Define the possible ByteIO open options.
Definition ByteIO.h:63
@ Update
read/write; file must exist.
Definition ByteIO.h:66
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:94
Bool isWritable() const
Is the file writable?
Definition HDF5File.h:90
void doOpen()
Open or create the file.
ByteIO::OpenOption itsOption
Definition HDF5File.h:124
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:98
hid_t getHid() const
Get the hid.
Definition HDF5Object.h:96
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40