Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
MantidTestHelpers::BoxControllerDummyIO Class Reference

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>

Inheritance diagram for MantidTestHelpers::BoxControllerDummyIO:
Mantid::API::IBoxControllerIO Mantid::Kernel::DiskBuffer

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_tgetFreeSpaceMap ()
 
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...
 
DiskBufferoperator= (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::BoxControllerm_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_tm_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...
 

Detailed Description

The class responsible for dummy IO operations, which mimic saving events into a direct access file using generic box controller interface.

Date
March 15, 2013

Definition at line 33 of file BoxControllerDummyIO.h.

Constructor & Destructor Documentation

◆ BoxControllerDummyIO()

MantidTestHelpers::BoxControllerDummyIO::BoxControllerDummyIO ( const Mantid::API::BoxController bc)

Constructor.

Parameters
bcshared 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.

◆ ~BoxControllerDummyIO()

MantidTestHelpers::BoxControllerDummyIO::~BoxControllerDummyIO ( )
override

Definition at line 163 of file BoxControllerDummyIO.cpp.

References closeFile().

Member Function Documentation

◆ closeFile()

void MantidTestHelpers::BoxControllerDummyIO::closeFile ( )
inlineoverridevirtual

Close the file.

Implements Mantid::API::IBoxControllerIO.

Definition at line 59 of file BoxControllerDummyIO.h.

Referenced by ~BoxControllerDummyIO().

◆ copyFileTo()

void MantidTestHelpers::BoxControllerDummyIO::copyFileTo ( const std::string &  destFilename)
inlineoverridevirtual

Copy the file contents to a new location.

Implements Mantid::API::IBoxControllerIO.

Definition at line 40 of file BoxControllerDummyIO.h.

◆ flushData()

void MantidTestHelpers::BoxControllerDummyIO::flushData ( ) const
inlineoverridevirtual

flush the IO buffers

Implements Mantid::API::IBoxControllerIO.

Definition at line 58 of file BoxControllerDummyIO.h.

◆ getDataChunk()

size_t MantidTestHelpers::BoxControllerDummyIO::getDataChunk ( ) const
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.

◆ getDataType()

void MantidTestHelpers::BoxControllerDummyIO::getDataType ( size_t &  CoordSize,
std::string &  typeName 
) const
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

Returns
CoordSize – size (in bytes) of the blockPosition and blockSize used in save/load operations
typeName – the name of the event used in the operations. The name itself defines the size and the format of the event

Implements Mantid::API::IBoxControllerIO.

Definition at line 74 of file BoxControllerDummyIO.cpp.

References m_CoordSize, and m_TypeName.

◆ getFileName()

const std::string & MantidTestHelpers::BoxControllerDummyIO::getFileName ( ) const
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.

◆ getNDataColums()

int64_t MantidTestHelpers::BoxControllerDummyIO::getNDataColums ( ) const
inline

Definition at line 68 of file BoxControllerDummyIO.h.

◆ isOpened()

bool MantidTestHelpers::BoxControllerDummyIO::isOpened ( ) const
inlineoverridevirtual
Returns
true if the file to write events is opened and false otherwise

Implements Mantid::API::IBoxControllerIO.

Definition at line 37 of file BoxControllerDummyIO.h.

◆ loadBlock() [1/2]

void MantidTestHelpers::BoxControllerDummyIO::loadBlock ( std::vector< double > &  ,
const uint64_t  ,
const  size_t 
) const
inlineoverridevirtual

Implements Mantid::API::IBoxControllerIO.

Definition at line 52 of file BoxControllerDummyIO.h.

◆ loadBlock() [2/2]

void MantidTestHelpers::BoxControllerDummyIO::loadBlock ( std::vector< float > &  Block,
const uint64_t  blockPosition,
const size_t  nPoints 
) const
overridevirtual

Load a block of data from properly prepared direct access data file.

Parameters
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.

◆ openFile()

bool MantidTestHelpers::BoxControllerDummyIO::openFile ( const std::string &  fileName,
const std::string &  mode 
)
overridevirtual

Open the file to use in IO operations with events.

Parameters
fileNamethe 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
modeopening 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().

◆ saveBlock() [1/2]

void MantidTestHelpers::BoxControllerDummyIO::saveBlock ( const std::vector< double > &  ,
const uint64_t   
) const
inlineoverridevirtual

Save a double data block in the specified file position.

Implements Mantid::API::IBoxControllerIO.

Definition at line 46 of file BoxControllerDummyIO.h.

◆ saveBlock() [2/2]

void MantidTestHelpers::BoxControllerDummyIO::saveBlock ( const std::vector< float > &  DataBlock,
const uint64_t  blockPosition 
) const
overridevirtual

Save block of data into properly opened and initiated direct access data file.

Parameters
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().

◆ setDataType()

void MantidTestHelpers::BoxControllerDummyIO::setDataType ( const size_t  blockSize,
const std::string &  typeName 
)
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

Parameters
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.

Member Data Documentation

◆ fileContents

std::vector<float> MantidTestHelpers::BoxControllerDummyIO::fileContents
mutableprivate

Definition at line 76 of file BoxControllerDummyIO.h.

Referenced by loadBlock(), openFile(), and saveBlock().

◆ m_bc

const Mantid::API::BoxController* MantidTestHelpers::BoxControllerDummyIO::m_bc
private

shared pointer to the box controller, which is repsoponsible for this IO

Definition at line 78 of file BoxControllerDummyIO.h.

Referenced by setDataType().

◆ m_CoordSize

unsigned int MantidTestHelpers::BoxControllerDummyIO::m_CoordSize
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().

◆ m_EventSize

unsigned int MantidTestHelpers::BoxControllerDummyIO::m_EventSize
private

◆ m_fileMutex

std::mutex MantidTestHelpers::BoxControllerDummyIO::m_fileMutex
mutableprivate

Definition at line 80 of file BoxControllerDummyIO.h.

Referenced by loadBlock(), and saveBlock().

◆ m_fileName

std::string MantidTestHelpers::BoxControllerDummyIO::m_fileName
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().

◆ m_isOpened

bool MantidTestHelpers::BoxControllerDummyIO::m_isOpened
private

identified of the file state, if it is open or not.

Definition at line 90 of file BoxControllerDummyIO.h.

Referenced by openFile().

◆ m_ReadOnly

bool MantidTestHelpers::BoxControllerDummyIO::m_ReadOnly
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().

◆ m_TypeName

std::string MantidTestHelpers::BoxControllerDummyIO::m_TypeName
private

Definition at line 85 of file BoxControllerDummyIO.h.

Referenced by getDataType(), and setDataType().


The documentation for this class was generated from the following files: