casacore
Loading...
Searching...
No Matches
MultiHDF5.h
Go to the documentation of this file.
1
2//# MultiHDF5.h: Class to combine multiple files in a single HDF5 file
3//# Copyright (C) 2015
4//# Associated Universities, Inc. Washington DC, USA.
5//#
6//# This library is free software; you can redistribute it and/or modify it
7//# under the terms of the GNU Library General Public License as published by
8//# the Free Software Foundation; either version 2 of the License, or (at your
9//# option) any later version.
10//#
11//# This library is distributed in the hope that it will be useful, but WITHOUT
12//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14//# License for more details.
15//#
16//# You should have received a copy of the GNU Library General Public License
17//# along with this library; if not, write to the Free Software Foundation,
18//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19//#
20//# Correspondence concerning AIPS++ should be addressed as follows:
21//# Internet email: casa-feedback@nrao.edu.
22//# Postal address: AIPS++ Project Office
23//# National Radio Astronomy Observatory
24//# 520 Edgemont Road
25//# Charlottesville, VA 22903-2475 USA
26
27#ifndef CASA_MULTIHDF5_H
28#define CASA_MULTIHDF5_H
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/casa/IO/MultiFile.h>
33#include <casacore/casa/HDF5/HDF5File.h>
34#include <casacore/casa/HDF5/HDF5Group.h>
35#include <memory>
36
37
38namespace casacore { //# NAMESPACE CASACORE - BEGIN
39
40 // <summary>
41 // Class to combine multiple files in a single HDF5 file.
42 // </summary>
43
44 // <use visibility=export>
45
46 // <reviewed reviewer="" date="" tests="tMultiHDF5" demos="">
47 // </reviewed>
48
49 // <synopsis>
50 // This class is a container file holding multiple virtual files. It is
51 // primarily meant as a container file for the storage manager files of a
52 // table to reduce the number of files used (especially for Lustre) and to
53 // reduce the number of open files (especially when concatenating tables).
54 // <br>A secondary goal is offering the ability to use an IO buffer size
55 // that matches the file system well (large buffer size for e.g. ZFS).
56 //
57 // The SetupNewTable constructor has a StorageOption argument to define
58 // if a MultiFile has to be used and if so, the buffer size to use.
59 // It is also possible to specify that through aipsrc variables.
60 //
61 // A virtual file is spread over multiple (fixed size) data blocks in the
62 // MultiFile. A data block is never shared by multiple files.
63 // For each virtual file MultiFile keeps a MultiFileInfo object telling
64 // the file size and the blocks numbers used for the file. When flushing
65 // the MultiFile, this meta info is written into a header block and,
66 // if needed, continuation blocks. On open and resync, it is read back.
67 // <br>
68 //
69 // A virtual file is represented by an MFFileIO object, which is derived
70 // from ByteIO and as such part of the casacore IO framework. It makes it
71 // possible for applications to access a virtual file in the same way as
72 // a regular file.
73 //
74 // It is possible to delete a virtual file. Its blocks will be added to
75 // the free block list (which is also stored in the meta info).
76 // </synopsis>
77
78 // <example>
79 // In principle it is possible to use the MultiFile functions directly.
80 // However, in general it is much easier to use an MFFileIO object
81 // per virtual file as shown below.
82 // <srcblock>
83 // // Create a new MultiFile using a block size of 1 MB.
84 // MultiFile mfile("file.mf', ByteIO::New, 1048576);
85 // // Create a virtual file in it.
86 // MFFileIO mf1(mfile, "mf1", ByteIO::New);
87 // // Use it (for example) as the sink of AipsIO.
88 // AipsIO stream (&mf1);
89 // // Write values.
90 // stream << (Int)10;
91 // stream << True;
92 // // Seek to beginning of file and read data in.
93 // stream.setpos (0);
94 // Int vali;
95 // Bool valb;
96 // stream >> vali >> valb;
97 // </srcblock>
98 // </example>
99
101 {
102 public:
103 // Open or create a MultiHDF5 with the given name.
104 // Upon creation the block size can be given. If 0, it uses the block size
105 // of the file system the file is on.
106 explicit MultiHDF5 (const String& name, ByteIO::OpenOption, Int blockSize=0);
107
108
109 // Open or create a MultiHDF5 which is nested in the given parent.
110 // The data are read/written in a group with the given name in the parent.
111 // Upon creation the block size can be given. If 0, it uses the block size
112 // of the parent.
113 explicit MultiHDF5 (const String& name,
114 const std::shared_ptr<MultiFileBase>& parent,
116
117 // The destructor flushes and closes the file.
118 ~MultiHDF5() override;
119
120 // Copy constructor and assignment not possible.
121 MultiHDF5 (const MultiHDF5&) = delete;
122 MultiHDF5& operator= (const MultiHDF5&) = delete;
123
124 // Make the correct MultiFileBase object for a nested file.
125 // It creates a new group under which the virtual files are created.
126 std::shared_ptr<MultiFileBase> makeNested
127 (const std::shared_ptr<MultiFileBase>& parent, const String& name,
128 ByteIO::OpenOption, Int blockSize) const override;
129
130 // Open the given logical file and return its file id.
131 // If the name is unknown, an exception is thrown.
132 // It creates the HDF5 group and dataset opbject.
133 // Reopen the underlying file for read/write access.
134 // Nothing will be done if the file is writable already.
135 // Otherwise it will be reopened and an exception will be thrown
136 // if it is not possible to reopen it for read/write access.
137 void reopenRW() override;
138
139 // Fsync the file (i.e., force the data to be physically written).
140 void fsync() override;
141
142 // Get the HDF5File object.
143 const std::shared_ptr<HDF5File>& getHDF5File() const
144 { return itsFile; }
146 { return *itsHDF5; }
147
148 private:
149 // Initialize the MultiFile object.
151 // Do the class-specific actions on opening a file.
152 void doOpenFile (MultiFileInfo&) override;
153 // Do the class-specific actions on closing a file.
154 void doCloseFile (MultiFileInfo&) override;
155 // Do the class-specific actions on adding a file.
156 void doAddFile (MultiFileInfo&) override;
157 // Do the class-specific actions on deleting a file.
158 void doDeleteFile (MultiFileInfo&) override;
159 // Truncate the file to <src>nrblk</src> blocks (does nothing).
160 void doTruncateFile (MultiFileInfo& info, uInt64 nrblk) override;
161 // Flush the file itself.
162 void doFlushFile() override;
163 // Flush and close the file.
164 void close() override;
165 // Write the header info.
166 void writeHeader() override;
167 // Read the header info. If always==False, the info is only read if the
168 // header counter has changed.
169 void readHeader (Bool always=True) override;
170 // Extend the virtual file to fit lastblk.
171 void extend (MultiFileInfo& info, Int64 lastblk) override;
172 // Read a data block.
174 void* buffer) override;
175 // Write a data block.
177 const void* buffer) override;
178
179 //# Data members
180 std::shared_ptr<HDF5File> itsFile;
181 std::shared_ptr<HDF5Group> itsGroup;
182 // This points to the HDF5Group if present, otherwise to the HDF5File.
183 // It tells where the HDF5 data are accessed.
185 };
186
187
188} //# NAMESPACE CASACORE - END
189
190#endif
OpenOption
Define the possible ByteIO open options.
Definition ByteIO.h:63
Abstract base class to combine multiple logical files in a single one.
Int64 blockSize() const
Get the block size used.
const std::vector< MultiFileInfo > & info() const
Get the info object (for test purposes mainly).
~MultiHDF5() override
The destructor flushes and closes the file.
std::shared_ptr< HDF5Group > itsGroup
Definition MultiHDF5.h:181
const std::shared_ptr< HDF5File > & getHDF5File() const
Get the HDF5File object.
Definition MultiHDF5.h:143
void init(ByteIO::OpenOption option)
Initialize the MultiFile object.
void doOpenFile(MultiFileInfo &) override
Do the class-specific actions on opening a file.
MultiHDF5(const String &name, const std::shared_ptr< MultiFileBase > &parent, ByteIO::OpenOption, Int blockSize=0)
Open or create a MultiHDF5 which is nested in the given parent.
std::shared_ptr< MultiFileBase > makeNested(const std::shared_ptr< MultiFileBase > &parent, const String &name, ByteIO::OpenOption, Int blockSize) const override
Make the correct MultiFileBase object for a nested file.
void fsync() override
Fsync the file (i.e., force the data to be physically written).
MultiHDF5 & operator=(const MultiHDF5 &)=delete
void reopenRW() override
Open the given logical file and return its file id.
const HDF5Object & getHDF5Object() const
Definition MultiHDF5.h:145
void readHeader(Bool always=True) override
Read the header info.
void doCloseFile(MultiFileInfo &) override
Do the class-specific actions on closing a file.
void doFlushFile() override
Flush the file itself.
std::shared_ptr< HDF5File > itsFile
Definition MultiHDF5.h:180
void doTruncateFile(MultiFileInfo &info, uInt64 nrblk) override
Truncate the file to nrblk blocks (does nothing).
void close() override
Flush and close the file.
void doAddFile(MultiFileInfo &) override
Do the class-specific actions on adding a file.
HDF5Object * itsHDF5
This points to the HDF5Group if present, otherwise to the HDF5File.
Definition MultiHDF5.h:184
void writeHeader() override
Write the header info.
void readBlock(MultiFileInfo &info, Int64 blknr, void *buffer) override
Read a data block.
void extend(MultiFileInfo &info, Int64 lastblk) override
Extend the virtual file to fit lastblk.
void writeBlock(MultiFileInfo &info, Int64 blknr, const void *buffer) override
Write a data block.
MultiHDF5(const MultiHDF5 &)=delete
Copy constructor and assignment not possible.
void doDeleteFile(MultiFileInfo &) override
Do the class-specific actions on deleting a file.
MultiHDF5(const String &name, ByteIO::OpenOption, Int blockSize=0)
Open or create a MultiHDF5 with the given name.
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
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
unsigned long long uInt64
Definition aipsxtype.h:37
Helper class for MultiFileBase containing info per logical file.