26#ifndef CASA_MULTIFILEBASE_H
27#define CASA_MULTIFILEBASE_H
30#include <casacore/casa/aips.h>
31#include <casacore/casa/IO/ByteIO.h>
32#include <casacore/casa/BasicSL/String.h>
33#include <casacore/casa/ostream.h>
82 {
buffer = std::make_shared<MultiFileBuffer>(bufSize, useODirect); }
90 std::shared_ptr<MultiFileBuffer>
buffer;
91 std::shared_ptr<HDF5Group>
group;
154 (
const std::shared_ptr<MultiFileBase>& parent,
const String& name,
223 const std::vector<MultiFileInfo>&
info()
const
283 const void* buffer) = 0;
OpenOption
Define the possible ByteIO open options.
@ New
read/write; create file if not exist.
Abstract base class to combine multiple logical files in a single one.
void flushFile(Int fileId)
Flush the possible dirty buffer of the given logical file.
virtual void doCloseFile(MultiFileInfo &)=0
Do the class-specific actions on closing a logical file.
Int64 nblock() const
Get the total nr of data blocks used.
Int64 blockSize() const
Get the block size used.
static std::shared_ptr< MultiFileBase > openMF(const String &fileName)
Open the correct MultiFileBase (as plain or HDF5).
MultiFileBase & operator=(const MultiFileBase &)=delete
Forbid assignment.
virtual void extend(MultiFileInfo &info, Int64 lastblk)=0
Extend a logical file to fit lastblk.
virtual void doFlushFile()=0
Flush the container file.
virtual void writeHeader()=0
Write the header info.
std::vector< Int64 > itsFreeBlocks
MultiFileBase(const String &name, Int blockSize, Bool useODirect)
Create a MultiFileBase object with the given name.
MultiFileBase(const MultiFileBase &)=delete
Forbid copy constructor.
virtual void fsync()=0
Fsync the file (i.e., force the data to be physically written).
virtual void readHeader(Bool always=True)=0
Read the header info.
Int64 write(Int fileId, const void *buffer, Int64 size, Int64 offset)
Write a block at the given offset in the logical file.
void resync()
Resync with another process by clearing the buffers and rereading the header.
virtual std::shared_ptr< MultiFileBase > makeNested(const std::shared_ptr< MultiFileBase > &parent, const String &name, ByteIO::OpenOption, Int blockSize) const =0
Make the correct MultiFileBase object for a nested file.
Int createFile(const String &name, ByteIO::OpenOption=ByteIO::New)
Create a new logical file and return its file id.
Int addFile(const String &name)
Add a file to the MultiFileBase object.
Int openFile(const String &name)
Open the given logical file and return its file id.
Int fileId(const String &name, Bool throwExcp=True) const
Return the file id of a file in the MultiFileBase object.
virtual void doTruncateFile(MultiFileInfo &info, uInt64 nrblk)=0
Truncate the container file to nrblk blocks.
const std::vector< MultiFileInfo > & info() const
Get the info object (for test purposes mainly).
const std::vector< Int64 > & freeBlocks() const
Get the free blocks (for test purposes mainly).
Int64 fileSize(Int fileId) const
Get the size of a logical file.
void deleteFile(Int fileId)
Delete a logical file.
virtual void doOpenFile(MultiFileInfo &)=0
Do the class-specific actions on opening a logical file.
Int64 read(Int fileId, void *buffer, Int64 size, Int64 offset)
Read a block at the given offset in the logical file.
String fileName() const
Get the file name of the MultiFileBase container file.
Bool useODirect() const
Is O_DIRECT used?
void truncate(Int fileId, Int64 size)
Truncate the logical file to the given size.
virtual ~MultiFileBase()
The destructor flushes dirty blocks and closes the container file.
Bool isWritable() const
Is the container file writable?
virtual void doDeleteFile(MultiFileInfo &)=0
Do the class-specific actions on deleting a logical file.
virtual void writeBlock(MultiFileInfo &info, Int64 blknr, const void *buffer)=0
Write a data block of a logical file into the container file.
virtual void reopenRW()=0
Reopen the underlying file for read/write access.
std::vector< MultiFileInfo > itsInfo
virtual void readBlock(MultiFileInfo &info, Int64 blknr, void *buffer)=0
Read a data block of a logical file from the container file.
virtual void close()=0
Flush and close the container file.
void setNewFile()
Set the flags and blockSize for a new MultiFile/HDF5.
virtual void doAddFile(MultiFileInfo &)=0
Do the class-specific actions on adding a logical file.
void flush()
Flush the file by writing all dirty data and all header info.
uInt nfile() const
Get the nr of logical files.
void closeFile(Int fileId)
Close a logical file.
std::shared_ptr< MultiFileBuffer > itsBuffer
void writeDirty(MultiFileInfo &info)
Write the dirty block and clear dirty flag.
char * itsData
Data members.
MultiFileBuffer(size_t bufSize, Bool useODirect)
MultiFileBuffer(const MultiFileBuffer &)=delete
Forbid copy constructor.
MultiFileBuffer & operator=(const MultiFileBuffer &)=delete
Forbid assignment.
String: the storage and methods of handling collections of characters.
this file contains all the compiler specific defines
AipsIO & operator>>(AipsIO &os, Record &rec)
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
bool Bool
Define the standard types used by Casacore.
void getInfoVersion1(AipsIO &, std::vector< MultiFileInfo > &)
unsigned long long uInt64
Helper class for MultiFileBase containing info per logical file.
void allocBuffer(size_t bufSize, Bool useODirect)
Allocate the buffer.
std::shared_ptr< MultiFileBuffer > buffer
std::vector< Int64 > blockNrs
std::shared_ptr< HDF5Group > group
MultiFileInfo()
Initialize the object.
std::shared_ptr< HDF5DataSet > dataSet