casacore
MultiFile.h
Go to the documentation of this file.
1 //# MultiFile.h: Class to combine multiple files in a single one
2 //# Copyright (C) 2014
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: RegularFileIO.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
27 
28 #ifndef CASA_MULTIFILE_H
29 #define CASA_MULTIFILE_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/casa/IO/MultiFileBase.h>
34 #include <casacore/casa/IO/FiledesIO.h>
35 
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39  // <summary>
40  // Class to combine multiple files in a single one.
41  // </summary>
42 
43  // <use visibility=export>
44 
45  // <reviewed reviewer="" date="" tests="tMultiFile" demos="">
46  // </reviewed>
47 
48  // <synopsis>
49  // This class is a container file holding multiple virtual files. It is
50  // primarily meant as a container file for the storage manager files of a
51  // table to reduce the number of files used (especially for Lustre) and to
52  // reduce the number of open files (especially when concatenating tables).
53  // <br>A secondary goal is offering the ability to use an IO buffer size
54  // that matches the file system well (large buffer size for e.g. ZFS).
55  //
56  // The SetupNewTable constructor has a StorageOption argument to define
57  // if a MultiFile has to be used and if so, the buffer size to use.
58  // It is also possible to specify that through aipsrc variables.
59  //
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 the header block. If it
66  // does not fit in the header block, the rest is written in a separate "-ext"
67  // file.
68  // if needed, continuation blocks. On open and resync, it is read back.
69  // <br>
70  //
71  // A virtual file is represented by an MFFileIO object, which is derived
72  // from ByteIO and as such part of the casacore IO framework. It makes it
73  // possible for applications to access a virtual file in the same way as
74  // a regular file.
75  //
76  // It is possible to delete a virtual file. Its blocks will be added to
77  // the free block list (which is also stored in the meta info).
78  // </synopsis>
79 
80  // <example>
81  // In principle it is possible to use the MultiFile functions directly.
82  // However, in general it is much easier to use an MFFileIO object
83  // per virtual file as shown below.
84  // <srcblock>
85  // // Create a new MultiFile using a block size of 1 MB.
86  // MultiFile mfile("file.mf', ByteIO::New, 1048576);
87  // // Create a virtual file in it.
88  // MFFileIO mf1(mfile, "mf1", ByteIO::New);
89  // // Use it (for example) as the sink of AipsIO.
90  // AipsIO stream (&mf1);
91  // // Write values.
92  // stream << (Int)10;
93  // stream << True;
94  // // Seek to beginning of file and read data in.
95  // stream.setpos (0);
96  // Int vali;
97  // Bool valb;
98  // stream >> vali >> valb;
99  // </srcblock>
100  // </example>
101 
102  // <todo>
103  // <li> write headers at alternating file positions (for robustness)
104  // <li> possibly write headers entirely at the end if larger than blocksize
105  // </todo>
106 
107 
108  class MultiFile: public MultiFileBase
109  {
110  public:
111  // Open or create a MultiFile with the given name.
112  // Upon creation the block size can be given. If 0, it uses the block size
113  // of the file system the file is on.
114  MultiFile (const String& name, ByteIO::OpenOption, Int blockSize=0);
115 
116  // The destructor flushes and closes the file.
117  virtual ~MultiFile();
118 
119  // Reopen the underlying file for read/write access.
120  // Nothing will be done if the file is writable already.
121  // Otherwise it will be reopened and an exception will be thrown
122  // if it is not possible to reopen it for read/write access.
123  virtual void reopenRW();
124 
125  // Fsync the file (i.e., force the data to be physically written).
126  virtual void fsync();
127 
128  private:
129  // Do the class-specific actions on adding a file.
130  virtual void doAddFile (MultiFileInfo&);
131  // Do the class-specific actions on deleting a file.
132  virtual void doDeleteFile (MultiFileInfo&);
133  // Flush the file itself.
134  virtual void flushFile();
135  // Flush and close the file.
136  virtual void close();
137  // Write the header info.
138  virtual void writeHeader();
139  // Read the header info. If always==False, the info is only read if the
140  // header counter has changed.
141  virtual void readHeader (Bool always=True);
142  // Extend the virtual file to fit lastblk.
143  virtual void extend (MultiFileInfo& info, Int64 lastblk);
144  // Write a data block.
145  virtual void writeBlock (MultiFileInfo& info, Int64 blknr,
146  const void* buffer);
147  // Read a data block.
148  virtual void readBlock (MultiFileInfo& info, Int64 blknr,
149  void* buffer);
150 
151  private:
152  //# Data members
154  int itsFD;
155  };
156 
157 
158 } //# NAMESPACE CASACORE - END
159 
160 #endif
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
int Int
Definition: aipstype.h:47
virtual void writeBlock(MultiFileInfo &info, Int64 blknr, const void *buffer)
Write a data block.
Class to combine multiple files in a single one.
Definition: MultiFile.h:108
Abstract base class to combine multiple files in a single one.
Helper class for MultiFileBase containing info per internal file.
Definition: MultiFileBase.h:52
virtual void reopenRW()
Reopen the underlying file for read/write access.
virtual void doAddFile(MultiFileInfo &)
Do the class-specific actions on adding a file.
virtual void writeHeader()
Write the header info.
virtual void extend(MultiFileInfo &info, Int64 lastblk)
Extend the virtual file to fit lastblk.
virtual void close()
Flush and close the file.
Class for unbuffered IO on a file.
Definition: FiledesIO.h:88
virtual ~MultiFile()
The destructor flushes and closes the file.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:39
virtual void readBlock(MultiFileInfo &info, Int64 blknr, void *buffer)
Read a data block.
virtual void doDeleteFile(MultiFileInfo &)
Do the class-specific actions on deleting a file.
MultiFile(const String &name, ByteIO::OpenOption, Int blockSize=0)
Open or create a MultiFile with the given name.
Int64 blockSize() const
Get the block size used.
OpenOption
Define the possible ByteIO open options.
Definition: ByteIO.h:65
virtual void readHeader(Bool always=True)
Read the header info.
const vector< MultiFileInfo > & info() const
Get the info object (for test purposes mainly).
virtual void flushFile()
Flush the file itself.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual void fsync()
Fsync the file (i.e., force the data to be physically written).
const Bool True
Definition: aipstype.h:40
this file contains all the compiler specific defines
Definition: mainpage.dox:28