26#ifndef CASA_MULTIFILE_H
27#define CASA_MULTIFILE_H
30#include <casacore/casa/aips.h>
31#include <casacore/casa/IO/MultiFileBase.h>
165 const std::shared_ptr<MultiFileBase>& parent,
177 (
const std::shared_ptr<MultiFileBase>& parent,
const String& name,
190 void show (std::ostream&)
const;
193 static std::vector<Int64>
packIndex (
const std::vector<Int64>& blockNrs);
196 static std::vector<Int64>
unpackIndex (
const std::vector<Int64>& blockNrs);
255 const void* buffer)
override;
258 void* buffer)
override;
OpenOption
Define the possible ByteIO open options.
Abstract base class to combine multiple logical files in a single one.
virtual void doCloseFile(MultiFileInfo &)=0
Do the class-specific actions on closing a logical file.
Int64 blockSize() const
Get the block size used.
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.
virtual void readHeader(Bool always=True)=0
Read the header info.
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).
virtual void doOpenFile(MultiFileInfo &)=0
Do the class-specific actions on opening a logical file.
Bool useODirect() const
Is O_DIRECT used?
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 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.
virtual void doAddFile(MultiFileInfo &)=0
Do the class-specific actions on adding a logical file.
void readRemainder(Int64 headerSize, Int64 blockNr, std::vector< char > &buf)
Read the remainder of the header into the buffer.
void fsync() override
Fsync the file (i.e., force the data to be physically written).
static std::vector< Int64 > packIndex(const std::vector< Int64 > &blockNrs)
Compress a block index by looking for subsequent block numbers.
void writeVector(CanonicalIO &cio, const std::vector< Int64 > &index)
Write a vector of Int64.
MultiFile(const String &name, ByteIO::OpenOption, Int blockSize=0, Bool useODirect=False, Bool useCRC=False)
Open or create a MultiFile with the given name.
MultiFile(const String &name, const std::shared_ptr< MultiFileBase > &parent, ByteIO::OpenOption, Int blockSize=0)
Open or create a MultiFile with the given name which is nested in the given parent.
void readVector(CanonicalIO &cio, std::vector< Int64 > &index)
Read a vector of Int64.
void init(ByteIO::OpenOption option)
Initialize the MultiFile object.
MultiFile & operator=(const MultiFile &)=delete
std::shared_ptr< MultiFileBase > makeNested(const std::shared_ptr< MultiFileBase > &parent, const String &name, ByteIO::OpenOption, Int blockSize) const override
Make a nested MultiFile.
static std::vector< Int64 > unpackIndex(const std::vector< Int64 > &blockNrs)
Decompress a block index by inserting subsequent block numbers.
virtual void writeHeaderShow(Int64 ncont, Int64 todo) const
Header writing hooks (meant for derived test classes).
void reopenRW() override
Reopen the underlying file for read/write access.
~MultiFile() override
The destructor flushes and closes the file.
void show(std::ostream &) const
Show some info.
void writeRemainder(MemoryIO &mio, CanonicalIO &, MultiFileBuffer &mfbuf)
Write the remainder of the header (in case exceeding 1 block).
MultiFile(const MultiFile &)=delete
Copy constructor and assignment not possible.
void getInfoVersion2(Int64 contBlockNr, CanonicalIO &aio)
Read the file info for the new version 2.
void writeVector(CanonicalIO &cio, const std::vector< uInt > &index)
virtual void writeHeaderTest()
void readVector(CanonicalIO &cio, std::vector< uInt > &index)
void truncateIfNeeded()
Truncate the file if blocks are freed at the end.
String: the storage and methods of handling collections of characters.
this file contains all the compiler specific defines
void checkCRC(const void *buffer, Int64 blknr) const
Check the CRC of a data block read.
std::vector< uInt > itsCRC
uInt calcCRC(const void *buffer, Int64 size) const
Calculate the CRC of a data block.
void readHeader(Bool always=True) override
Read the header info.
void doDeleteFile(MultiFileInfo &) override
Do the class-specific actions on deleting a file.
void storeCRC(const void *buffer, Int64 blknr)
Store the CRC of a data block in the index.
void doAddFile(MultiFileInfo &) override
Do the class-specific actions on adding a file.
void doTruncateFile(MultiFileInfo &info, uInt64 nrblk) override
Truncate the file to nrblk blocks.
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
void close() override
Flush and close the file.
void readBlock(MultiFileInfo &info, Int64 blknr, void *buffer) override
Read a data block.
void readHeaderVersion2(std::vector< char > &buf)
Read the version 2 and higher header.
std::unique_ptr< ByteIO > itsIO
bool Bool
Define the standard types used by Casacore.
void readHeaderVersion1(Int64 headerSize, std::vector< char > &buf)
Read the version 1 header.
void writeHeader() override
Write the header info.
virtual void extendVF(MultiFileInfo &info, Int64 lastblk, Bool useFreeBlocks)
Extend the virtual file to fit lastblk.
void doFlushFile() override
Flush the file itself.
void writeBlock(MultiFileInfo &info, Int64 blknr, const void *buffer) override
Write a data block.
void doCloseFile(MultiFileInfo &) override
Do the class-specific actions on closing a file.
void extend(MultiFileInfo &info, Int64 lastblk) override
Extend the virtual file to fit lastblk.
void doOpenFile(MultiFileInfo &) override
Do the class-specific actions on opening a file.
MultiFileInfo itsHdrCont[2]
Define two continuation sets where the header overflow can be stored.
unsigned long long uInt64
Helper class for MultiFileBase containing info per logical file.