Mantid
|
The class responsible for dummy IO operations, which mimic saving events into a direct access file using generic box controller interface. More...
#include <BoxControllerDummyIO.h>
Public Member Functions | |
BoxControllerDummyIO (const Mantid::API::BoxController *bc) | |
Constructor. More... | |
void | closeFile () override |
Close the file. More... | |
void | copyFileTo (const std::string &) override |
Copy the file contents to a new location. More... | |
void | flushData () const override |
flush the IO buffers More... | |
size_t | getDataChunk () const override |
Return the size of the NeXus data block used in NeXus data array. More... | |
void | getDataType (size_t &CoordSize, std::string &typeName) const override |
As save/load operations use void data type, these function allow set up/get the type name provided for the IO operations and the size of the data type in bytes (e.g. More... | |
const std::string & | getFileName () const override |
get the full file name of the file used for IO operations More... | |
int64_t | getNDataColums () const |
bool | isOpened () const override |
void | loadBlock (std::vector< double > &, const uint64_t, const size_t) const override |
void | loadBlock (std::vector< float > &, const uint64_t, const size_t) const override |
Load a block of data from properly prepared direct access data file. More... | |
bool | openFile (const std::string &fileName, const std::string &mode) override |
Open the file to use in IO operations with events. More... | |
void | saveBlock (const std::vector< double > &, const uint64_t) const override |
Save a double data block in the specified file position. More... | |
void | saveBlock (const std::vector< float > &, const uint64_t) const override |
Save block of data into properly opened and initiated direct access data file. More... | |
void | setDataType (const size_t blockSize, const std::string &typeName) override |
The optional method to set up the event type and the size of the event coordinate As save/load operations use void data type, these function allow set up/get the type name provided for the IO operations and the size of the data type in bytes (e.g. More... | |
~BoxControllerDummyIO () override | |
virtual void | closeFile ()=0 |
Close the file. More... | |
virtual void | copyFileTo (const std::string &destFilename)=0 |
Copy the file contents to a new location. More... | |
virtual void | flushData () const =0 |
flush the IO buffers More... | |
virtual size_t | getDataChunk () const =0 |
the method which returns the size of data block used in IO operations More... | |
virtual void | getDataType (size_t &blockSize, std::string &typeName) const =0 |
virtual const std::string & | getFileName () const =0 |
virtual bool | isOpened () const =0 |
virtual void | loadBlock (std::vector< double > &, const uint64_t, const size_t) const =0 |
virtual void | loadBlock (std::vector< float > &, const uint64_t, const size_t) const =0 |
load known size float data block from spefied file position More... | |
virtual bool | openFile (const std::string &fileName, const std::string &mode)=0 |
open file for i/o operations More... | |
virtual void | saveBlock (const std::vector< double > &, const uint64_t) const =0 |
Save a double data block in the specified file position. More... | |
virtual void | saveBlock (const std::vector< float > &, const uint64_t) const =0 |
Save a float data block in the specified file position. More... | |
virtual void | setDataType (const size_t blockSize, const std::string &typeName)=0 |
As save/load operations use void data type, these function allow set up/get the type name provided for the IO operations and the size of the data type in bytes (e.g. More... | |
Public Member Functions inherited from Mantid::Kernel::DiskBuffer | |
uint64_t | allocate (uint64_t const newSize) |
Allocate a block of the given size in a free spot in the file, or at the end of the file if there is no space. More... | |
void | defragFreeBlocks () |
Method that defrags free blocks by combining adjacent ones together NOTE: This is not necessary to run since the freeBlock() methods automatically defrags neighboring blocks. More... | |
DiskBuffer () | |
Constructor. More... | |
DiskBuffer (const DiskBuffer &)=delete | |
DiskBuffer (uint64_t m_writeBufferSize) | |
Constructor. More... | |
void | flushCache () |
Flush out all the data in the memory; and writes out everything in the to-write cache. More... | |
void | freeBlock (uint64_t const pos, uint64_t const size) |
This method is called by this->relocate when object that has shrunk and so has left a bit of free space after itself on the file; or when an object gets moved to a new spot. More... | |
uint64_t | getFileLength () const |
freeSpace_t & | getFreeSpaceMap () |
void | getFreeSpaceVector (std::vector< uint64_t > &free) const |
Returns a vector with two entries per free block: position and size. More... | |
std::string | getMemoryStr () const |
uint64_t | getWriteBufferSize () const |
uint64_t | getWriteBufferUsed () const |
void | objectDeleted (ISaveable *item) |
Call this method when an object that might be in the cache is getting deleted. More... | |
DiskBuffer & | operator= (const DiskBuffer &)=delete |
uint64_t | relocate (uint64_t const oldPos, uint64_t const oldSize, const uint64_t newSize) |
This method is called by an ISaveable object that has outgrown its space allocated on file and needs to relocate. More... | |
void | setFileLength (const uint64_t length) const |
Set the length of the file that this MRU writes to. More... | |
void | setFreeSpaceVector (std::vector< uint64_t > &free) |
Sets the free space map. More... | |
void | setWriteBufferSize (uint64_t buffer) |
Set the size of the to-write buffer, in number of events. More... | |
void | toWrite (ISaveable *item) |
Call this method when an object is ready to be written out to disk. More... | |
virtual | ~DiskBuffer ()=default |
Private Attributes | |
std::vector< float > | fileContents |
const Mantid::API::BoxController * | m_bc |
shared pointer to the box controller, which is repsoponsible for this IO More... | |
unsigned int | m_CoordSize |
number of bytes in the event coorinates (coord_t length). More... | |
unsigned int | m_EventSize |
std::mutex | m_fileMutex |
std::string | m_fileName |
full file name (with path) of the Nexis file responsible for the IO operations (as NeXus filename has very strange properties and often trunkated to 64 bytes) More... | |
bool | m_isOpened |
identified of the file state, if it is open or not. More... | |
bool | m_ReadOnly |
identifier if the file open only for reading or is in read/write More... | |
std::string | m_TypeName |
Additional Inherited Members | |
Public Types inherited from Mantid::Kernel::DiskBuffer | |
using | freeSpace_bySize_t = freeSpace_t::nth_index< 1 >::type |
A way to index the free space by their size. More... | |
using | freeSpace_t = boost::multi_index::multi_index_container< FreeBlock, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< ::boost::multi_index::const_mem_fun< FreeBlock, uint64_t, &FreeBlock::getFilePosition > >, boost::multi_index::ordered_non_unique< ::boost::multi_index::const_mem_fun< FreeBlock, uint64_t, &FreeBlock::getSize > > > > |
A map for the list of free space blocks in the file. More... | |
Protected Member Functions inherited from Mantid::Kernel::DiskBuffer | |
void | writeOldObjects () |
Method to write out the old objects that have been stored in the "toWrite" buffer. More... | |
Protected Attributes inherited from Mantid::Kernel::DiskBuffer | |
uint64_t | m_fileLength |
Length of the file. This is where new blocks that don't fit get placed. More... | |
freeSpace_t | m_free |
Map of the free blocks in the file. More... | |
freeSpace_bySize_t & | m_free_bySize |
Index into m_free, but indexed by block size. More... | |
std::mutex | m_freeMutex |
Mutex for modifying the free space list. More... | |
std::mutex | m_mutex |
Mutex for modifying the the toWrite buffer. More... | |
size_t | m_nObjectsToWrite |
number of objects stored in to write buffer list More... | |
std::list< ISaveable * > | m_toWriteBuffer |
A forward list for the buffer of "toWrite" objects. More... | |
size_t | m_writeBufferSize |
Do we use the write buffer? Always now. More... | |
size_t | m_writeBufferUsed |
Total amount of memory in the "toWrite" buffer. More... | |
The class responsible for dummy IO operations, which mimic saving events into a direct access file using generic box controller interface.
Definition at line 33 of file BoxControllerDummyIO.h.
MantidTestHelpers::BoxControllerDummyIO::BoxControllerDummyIO | ( | const Mantid::API::BoxController * | bc | ) |
Constructor.
bc | shared pointer to the box controller which will use this IO operations |
Definition at line 28 of file BoxControllerDummyIO.cpp.
References Mantid::API::BoxController::getNDims(), and m_EventSize.
|
override |
Definition at line 163 of file BoxControllerDummyIO.cpp.
References closeFile().
|
inlineoverridevirtual |
Close the file.
Implements Mantid::API::IBoxControllerIO.
Definition at line 59 of file BoxControllerDummyIO.h.
Referenced by ~BoxControllerDummyIO().
|
inlineoverridevirtual |
Copy the file contents to a new location.
Implements Mantid::API::IBoxControllerIO.
Definition at line 40 of file BoxControllerDummyIO.h.
|
inlineoverridevirtual |
flush the IO buffers
Implements Mantid::API::IBoxControllerIO.
Definition at line 58 of file BoxControllerDummyIO.h.
|
inlineoverridevirtual |
Return the size of the NeXus data block used in NeXus data array.
Implements Mantid::API::IBoxControllerIO.
Definition at line 42 of file BoxControllerDummyIO.h.
|
overridevirtual |
As save/load operations use void data type, these function allow set up/get the type name provided for the IO operations and the size of the data type in bytes (e.g.
the class dependant physical meaning of the blockSize and blockPosition used by save/load operations
Implements Mantid::API::IBoxControllerIO.
Definition at line 74 of file BoxControllerDummyIO.cpp.
References m_CoordSize, and m_TypeName.
|
inlineoverridevirtual |
get the full file name of the file used for IO operations
Implements Mantid::API::IBoxControllerIO.
Definition at line 39 of file BoxControllerDummyIO.h.
|
inline |
Definition at line 68 of file BoxControllerDummyIO.h.
|
inlineoverridevirtual |
Implements Mantid::API::IBoxControllerIO.
Definition at line 37 of file BoxControllerDummyIO.h.
|
inlineoverridevirtual |
Implements Mantid::API::IBoxControllerIO.
Definition at line 52 of file BoxControllerDummyIO.h.
|
overridevirtual |
Load a block of data from properly prepared direct access data file.
Block | – the vector for data to place into. If the size of the block is smaller then the requested size, the vector will be realocated. The data are placed at the beginnign of the block. |
blockPosition | – the position of the data block within the data file |
nPoints | – number of data points to read from the file. The datapoint size is defined when opened file or by calling the setDataType directrly |
Throws if attempted to read data outside of the file.
Implements Mantid::API::IBoxControllerIO.
Definition at line 151 of file BoxControllerDummyIO.cpp.
References fileContents, Mantid::Kernel::DiskBuffer::getFileLength(), m_EventSize, m_fileMutex, and m_fileName.
|
overridevirtual |
Open the file to use in IO operations with events.
fileName | the name of the file to open. if file name has word exist, the file is opened as existing with 100 floats equal 2. othewise if assumed to be new and size 0 |
mode | opening mode (read ("r" ) or read/write "w") |
Implements Mantid::API::IBoxControllerIO.
Definition at line 87 of file BoxControllerDummyIO.cpp.
References fileContents, m_EventSize, m_fileName, m_isOpened, m_ReadOnly, and Mantid::Kernel::DiskBuffer::setFileLength().
|
inlineoverridevirtual |
Save a double data block in the specified file position.
Implements Mantid::API::IBoxControllerIO.
Definition at line 46 of file BoxControllerDummyIO.h.
|
overridevirtual |
Save block of data into properly opened and initiated direct access data file.
DataBlock | – the vector with the data to write |
blockPosition | – the position of the data block within the data file itself |
Implements Mantid::API::IBoxControllerIO.
Definition at line 125 of file BoxControllerDummyIO.cpp.
References fileContents, m_EventSize, m_fileMutex, position, and Mantid::Kernel::DiskBuffer::setFileLength().
|
overridevirtual |
The optional method to set up the event type and the size of the event coordinate As save/load operations use void data type, these function allow set up/get the type name provided for the IO operations and the size of the data type in bytes (e.g.
the class dependant physical meaning of the blockSize and blockPosition used by save/load operations
blockSize | – size (in bytes) of the blockPosition and blockSize used in save/load operations. 4 and 8 are supported only (float and double) |
typeName | – the name of the event used in the operations. The name itself defines the size and the format of the event The events described in the class header are supported only |
Implements Mantid::API::IBoxControllerIO.
Definition at line 47 of file BoxControllerDummyIO.cpp.
References Mantid::API::BoxController::getNDims(), m_bc, m_CoordSize, m_EventSize, and m_TypeName.
|
mutableprivate |
Definition at line 76 of file BoxControllerDummyIO.h.
Referenced by loadBlock(), openFile(), and saveBlock().
|
private |
shared pointer to the box controller, which is repsoponsible for this IO
Definition at line 78 of file BoxControllerDummyIO.h.
Referenced by setDataType().
|
private |
number of bytes in the event coorinates (coord_t length).
Set by setDataType but can be defined statically with coord_t
Definition at line 83 of file BoxControllerDummyIO.h.
Referenced by getDataType(), and setDataType().
|
private |
Definition at line 84 of file BoxControllerDummyIO.h.
Referenced by BoxControllerDummyIO(), loadBlock(), openFile(), saveBlock(), and setDataType().
|
mutableprivate |
Definition at line 80 of file BoxControllerDummyIO.h.
Referenced by loadBlock(), and saveBlock().
|
private |
full file name (with path) of the Nexis file responsible for the IO operations (as NeXus filename has very strange properties and often trunkated to 64 bytes)
Definition at line 74 of file BoxControllerDummyIO.h.
Referenced by loadBlock(), and openFile().
|
private |
identified of the file state, if it is open or not.
Definition at line 90 of file BoxControllerDummyIO.h.
Referenced by openFile().
|
private |
identifier if the file open only for reading or is in read/write
Definition at line 88 of file BoxControllerDummyIO.h.
Referenced by openFile().
|
private |
Definition at line 85 of file BoxControllerDummyIO.h.
Referenced by getDataType(), and setDataType().