Mantid
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
Mantid::Kernel::ISaveable Class Referenceabstract

An interface for objects that can be cached or saved to disk. More...

#include <ISaveable.h>

Inheritance diagram for Mantid::Kernel::ISaveable:
Mantid::DataObjects::MDBoxSaveable

Public Member Functions

void clearDataChanged ()
 this method has to be called if the object has been discarded from memory and is not changed any more. More...
 
virtual void clearDataFromMemory ()=0
 remove objects data from memory More...
 
virtual void flushData () const =0
 Method to flush the data to disk and ensure it is written. More...
 
virtual size_t getDataMemorySize () const =0
 the data size kept in memory More...
 
virtual uint64_t getFilePosition () const
 
uint64_t getFileSize () const
 Return the number of units this block occipies on file. More...
 
virtual uint64_t getTotalDataSize () const =0
 
 ISaveable ()
 Constructor
More...
 
 ISaveable (const ISaveable &other)
 Copy constructor --> needed for std containers and not to copy mutexes Note setting isLoaded to false to break connection with the file object which is not copyale. More...
 
bool isBusy () const
 
bool isDataChanged () const
 
bool isLoaded () const
 
virtual void load ()=0
 Load the data - to be overriden. More...
 
virtual void save () const =0
 Save the data - to be overriden. More...
 
void setBusy (bool On)
 @ set the data busy to prevent from removing them from memory. More...
 
void setDataChanged ()
 Call this method from the method which changes the object but keeps the object size the same to tell DiskBuffer to write it back the dataChanged ID is reset after save from the DataBuffer is emptied
More...
 
void setFilePosition (uint64_t newPos, size_t newSize, bool wasSaved)
 Sets the location of the object on HDD. More...
 
void setLoaded (bool Yes)
 sets the value of the isLoad parameter, indicating that data from HDD have its image in memory More...
 
bool wasSaved () const
 
virtual ~ISaveable ()=default
 

Protected Attributes

bool m_Busy
 a user needs to set this variable to true preventing from deleting data from buffer More...
 
bool m_dataChanged
 a user needs to set this variable to true to allow DiskBuffer saving the object to HDD when it decides it suitable, if the size of iSavable object in cache is unchanged from the previous save/load operation More...
 
bool m_isLoaded
 this boolean indicates, if the data have its copy in memory More...
 
bool m_wasSaved
 this boolean indicates if the data were saved on HDD and have physical representation on it (though this representation may be incorrect as data changed in memory) More...
 

Private Member Functions

void clearBufferState ()
 clears the state of the object, and indicate that it is not stored in buffer any more More...
 
size_t getBufferSize () const
 return the amount of memory, this object had when it was stored in buffer last time; More...
 
boost::optional< std::list< ISaveable * >::iterator > & getBufPostion ()
 returns the iterator pointing to the position of this object within the memory to-write buffer More...
 
void saveAt (uint64_t newPos, uint64_t newSize)
 save at specific file location the specific amount of data; used by DiskBuffer which asks this object where to save it and calling overloaded object specific save operation above
More...
 
size_t setBufferPosition (std::list< ISaveable * >::iterator bufPosition)
 sets the iterator pointing to the location of this object in the memory buffer to write later More...
 
void setBufferSize (size_t newSize)
 

Private Attributes

size_t m_BufMemorySize
 
boost::optional< std::list< ISaveable * >::iterator > m_BufPosition
 
uint64_t m_fileIndexStart
 Start point in the NXS file where the events are located. More...
 
uint64_t m_fileNumEvents
 Number of events saved in the file, after the start index location. More...
 
std::mutex m_setter
 

Friends

class DiskBuffer
 the functions below have to be availible to DiskBuffer and nobody else. More...
 

Detailed Description

An interface for objects that can be cached or saved to disk.

This is implemented by MDBox and is used in the in-memory cache of file-backed MDEventWorkspaces.

Author
Janik Zikovsky
Date
2011-07-28

Definition at line 28 of file ISaveable.h.

Constructor & Destructor Documentation

◆ ISaveable() [1/2]

Mantid::Kernel::ISaveable::ISaveable ( )

Constructor

Definition at line 13 of file ISaveable.cpp.

◆ ISaveable() [2/2]

Mantid::Kernel::ISaveable::ISaveable ( const ISaveable other)

Copy constructor --> needed for std containers and not to copy mutexes Note setting isLoaded to false to break connection with the file object which is not copyale.

Definition at line 21 of file ISaveable.cpp.

◆ ~ISaveable()

virtual Mantid::Kernel::ISaveable::~ISaveable ( )
virtualdefault

Member Function Documentation

◆ clearBufferState()

void Mantid::Kernel::ISaveable::clearBufferState ( )
private

clears the state of the object, and indicate that it is not stored in buffer any more

Definition at line 79 of file ISaveable.cpp.

References m_BufMemorySize, m_BufPosition, and m_setter.

Referenced by Mantid::Kernel::DiskBuffer::objectDeleted().

◆ clearDataChanged()

void Mantid::Kernel::ISaveable::clearDataChanged ( )
inline

this method has to be called if the object has been discarded from memory and is not changed any more.

It expected to be called from clearDataFromMemory.

Definition at line 90 of file ISaveable.h.

◆ clearDataFromMemory()

virtual void Mantid::Kernel::ISaveable::clearDataFromMemory ( )
pure virtual

remove objects data from memory

Implemented in Mantid::DataObjects::MDBoxSaveable.

Referenced by saveAt().

◆ flushData()

virtual void Mantid::Kernel::ISaveable::flushData ( ) const
pure virtual

Method to flush the data to disk and ensure it is written.

Implemented in Mantid::DataObjects::MDBoxSaveable.

◆ getBufferSize()

size_t Mantid::Kernel::ISaveable::getBufferSize ( ) const
inlineprivate

return the amount of memory, this object had when it was stored in buffer last time;

Definition at line 165 of file ISaveable.h.

Referenced by Mantid::Kernel::DiskBuffer::objectDeleted(), and Mantid::Kernel::DiskBuffer::toWrite().

◆ getBufPostion()

boost::optional< std::list< ISaveable * >::iterator > & Mantid::Kernel::ISaveable::getBufPostion ( )
inlineprivate

returns the iterator pointing to the position of this object within the memory to-write buffer

Definition at line 162 of file ISaveable.h.

Referenced by Mantid::Kernel::DiskBuffer::objectDeleted(), and Mantid::Kernel::DiskBuffer::toWrite().

◆ getDataMemorySize()

virtual size_t Mantid::Kernel::ISaveable::getDataMemorySize ( ) const
pure virtual

the data size kept in memory

Implemented in Mantid::DataObjects::MDBoxSaveable.

Referenced by setBufferPosition(), and Mantid::Kernel::DiskBuffer::toWrite().

◆ getFilePosition()

virtual uint64_t Mantid::Kernel::ISaveable::getFilePosition ( ) const
inlinevirtual

◆ getFileSize()

uint64_t Mantid::Kernel::ISaveable::getFileSize ( ) const
inline

Return the number of units this block occipies on file.

Definition at line 38 of file ISaveable.h.

Referenced by Mantid::DataObjects::MDBoxSaveable::load(), and Mantid::Kernel::DiskBuffer::objectDeleted().

◆ getTotalDataSize()

virtual uint64_t Mantid::Kernel::ISaveable::getTotalDataSize ( ) const
pure virtual
Returns
the amount of memory that the object takes as a whole. For filebased objects it should be the amount the object occupies in memory plus the size it occupies in file if the object has not been fully loaded or modified. If the object has never been loaded, this should be equal to number of data points in the file

Implemented in Mantid::DataObjects::MDBoxSaveable.

◆ isBusy()

bool Mantid::Kernel::ISaveable::isBusy ( ) const
inline
Returns
true if it the data of the object is busy and so cannot be cleared; false if the data was released and can be cleared/written.

Definition at line 68 of file ISaveable.h.

◆ isDataChanged()

bool Mantid::Kernel::ISaveable::isDataChanged ( ) const
inline
Returns
the state of the parameter, which tells disk buffer to force writing data to disk despite the size of the object have not changed (so one have probably done something with object contents.

Definition at line 79 of file ISaveable.h.

◆ isLoaded()

bool Mantid::Kernel::ISaveable::isLoaded ( ) const
inline
Returns
true if the object has been load in the memory – the load function should call setter, or if the object was constructed in memory it should be loaded too

Definition at line 56 of file ISaveable.h.

◆ load()

virtual void Mantid::Kernel::ISaveable::load ( )
pure virtual

Load the data - to be overriden.

Implemented in Mantid::DataObjects::MDBoxSaveable.

Referenced by saveAt().

◆ save()

virtual void Mantid::Kernel::ISaveable::save ( ) const
pure virtual

Save the data - to be overriden.

Implemented in Mantid::DataObjects::MDBoxSaveable.

Referenced by saveAt().

◆ saveAt()

void Mantid::Kernel::ISaveable::saveAt ( uint64_t  newPos,
uint64_t  newSize 
)
private

save at specific file location the specific amount of data; used by DiskBuffer which asks this object where to save it and calling overloaded object specific save operation above

private function which used by the disk buffer to save the contents of the object

Parameters
newPos– new position to save object to
newSize– new size of the saveable object

Definition at line 49 of file ISaveable.cpp.

References clearDataFromMemory(), load(), m_fileIndexStart, m_fileNumEvents, m_setter, save(), and wasSaved().

◆ setBufferPosition()

size_t Mantid::Kernel::ISaveable::setBufferPosition ( std::list< ISaveable * >::iterator  bufPosition)
private

sets the iterator pointing to the location of this object in the memory buffer to write later

Method stores the position of the object in Disc buffer and returns the size of this object for disk buffer to store.

Parameters
bufPosition– the allocator which specifies the position of the object in the list of objects to write
Returns
the size of the object it currently occupies in memory. This size is also stored by the object itself for further references

Definition at line 69 of file ISaveable.cpp.

References getDataMemorySize(), m_BufMemorySize, m_BufPosition, and m_setter.

Referenced by Mantid::Kernel::DiskBuffer::toWrite().

◆ setBufferSize()

void Mantid::Kernel::ISaveable::setBufferSize ( size_t  newSize)
inlineprivate

Definition at line 166 of file ISaveable.h.

Referenced by Mantid::Kernel::DiskBuffer::toWrite().

◆ setBusy()

void Mantid::Kernel::ISaveable::setBusy ( bool  On)
inline

@ set the data busy to prevent from removing them from memory.

The process which does that should clean the data when finished with them

Definition at line 71 of file ISaveable.h.

◆ setDataChanged()

void Mantid::Kernel::ISaveable::setDataChanged ( )
inline

Call this method from the method which changes the object but keeps the object size the same to tell DiskBuffer to write it back the dataChanged ID is reset after save from the DataBuffer is emptied

Definition at line 83 of file ISaveable.h.

◆ setFilePosition()

void Mantid::Kernel::ISaveable::setFilePosition ( uint64_t  newPos,
size_t  newSize,
bool  wasSaved 
)

Sets the location of the object on HDD.

Set the start/end point in the file where the events are located.

Parameters
newPos:: start point,
newSize:: number of events in the file
wasSaved:: flag to mark if the info was saved, by default it does

Definition at line 35 of file ISaveable.cpp.

References m_fileIndexStart, m_fileNumEvents, m_setter, m_wasSaved, and wasSaved().

◆ setLoaded()

void Mantid::Kernel::ISaveable::setLoaded ( bool  Yes)
inline

sets the value of the isLoad parameter, indicating that data from HDD have its image in memory

Parameters
Yes– boolean true or false –usually only load functiomn should set it to true

Definition at line 64 of file ISaveable.h.

Referenced by Mantid::DataObjects::MDBoxSaveable::load().

◆ wasSaved()

bool Mantid::Kernel::ISaveable::wasSaved ( ) const
inline
Returns
true if the object have ever been saved on HDD and knows it place there

Definition at line 47 of file ISaveable.h.

Referenced by Mantid::Kernel::DiskBuffer::objectDeleted(), Mantid::DataObjects::MDBoxSaveable::save(), saveAt(), and setFilePosition().

Friends And Related Function Documentation

◆ DiskBuffer

friend class DiskBuffer
friend

the functions below have to be availible to DiskBuffer and nobody else.

To highlight this we make them private

Definition at line 151 of file ISaveable.h.

Member Data Documentation

◆ m_BufMemorySize

size_t Mantid::Kernel::ISaveable::m_BufMemorySize
private

Definition at line 143 of file ISaveable.h.

Referenced by clearBufferState(), and setBufferPosition().

◆ m_BufPosition

boost::optional<std::list<ISaveable *>::iterator> Mantid::Kernel::ISaveable::m_BufPosition
private

Definition at line 140 of file ISaveable.h.

Referenced by clearBufferState(), and setBufferPosition().

◆ m_Busy

bool Mantid::Kernel::ISaveable::m_Busy
protected

a user needs to set this variable to true preventing from deleting data from buffer

Definition at line 122 of file ISaveable.h.

◆ m_dataChanged

bool Mantid::Kernel::ISaveable::m_dataChanged
protected

a user needs to set this variable to true to allow DiskBuffer saving the object to HDD when it decides it suitable, if the size of iSavable object in cache is unchanged from the previous save/load operation

Definition at line 128 of file ISaveable.h.

◆ m_fileIndexStart

uint64_t Mantid::Kernel::ISaveable::m_fileIndexStart
private

Start point in the NXS file where the events are located.

Definition at line 145 of file ISaveable.h.

Referenced by saveAt(), and setFilePosition().

◆ m_fileNumEvents

uint64_t Mantid::Kernel::ISaveable::m_fileNumEvents
private

Number of events saved in the file, after the start index location.

Definition at line 147 of file ISaveable.h.

Referenced by saveAt(), and setFilePosition().

◆ m_isLoaded

bool Mantid::Kernel::ISaveable::m_isLoaded
protected

this boolean indicates, if the data have its copy in memory

Definition at line 135 of file ISaveable.h.

Referenced by Mantid::DataObjects::MDBoxSaveable::load().

◆ m_setter

std::mutex Mantid::Kernel::ISaveable::m_setter
private

Definition at line 173 of file ISaveable.h.

Referenced by clearBufferState(), saveAt(), setBufferPosition(), and setFilePosition().

◆ m_wasSaved

bool Mantid::Kernel::ISaveable::m_wasSaved
mutableprotected

this boolean indicates if the data were saved on HDD and have physical representation on it (though this representation may be incorrect as data changed in memory)

Definition at line 133 of file ISaveable.h.

Referenced by Mantid::DataObjects::MDBoxSaveable::save(), and setFilePosition().


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