Mantid
Loading...
Searching...
No Matches
ISaveable.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8//#include "MantidKernel/INode.h"
9
10namespace Mantid::Kernel {
11
14 : m_Busy(false), m_dataChanged(false), m_wasSaved(false), m_isLoaded(false), m_BufMemorySize(0),
15 m_fileIndexStart(std::numeric_limits<uint64_t>::max()), m_fileNumEvents(0) {}
16
17//----------------------------------------------------------------------------------------------
22 : m_Busy(other.m_Busy), m_dataChanged(other.m_dataChanged), m_wasSaved(other.m_wasSaved), m_isLoaded(false),
23 m_BufPosition(other.m_BufPosition), m_BufMemorySize(other.m_BufMemorySize),
24 m_fileIndexStart(other.m_fileIndexStart), m_fileNumEvents(other.m_fileNumEvents)
25
26{}
27
28//---------------------------------------------------------------------------
29
35void ISaveable::setFilePosition(uint64_t newPos, size_t newSize, bool wasSaved) {
36 std::lock_guard<std::mutex> lock(m_setter);
37 this->m_fileIndexStart = newPos;
38 this->m_fileNumEvents = static_cast<uint64_t>(newSize);
40}
41
42// ----------- PRIVATE, only DB availible
43
49void ISaveable::saveAt(uint64_t newPos, uint64_t newSize) {
50 std::lock_guard<std::mutex> lock(m_setter);
51 // load old contents if it was there
52 if (this->wasSaved())
53 this->load();
54 // set new position, derived by the disk buffer
55 m_fileIndexStart = newPos;
56 m_fileNumEvents = newSize;
57 // save in the new location
58 this->save();
59 this->clearDataFromMemory();
60}
61
69size_t ISaveable::setBufferPosition(std::list<ISaveable *>::iterator bufPosition) {
70 std::lock_guard<std::mutex> lock(m_setter);
71 m_BufPosition = boost::optional<std::list<ISaveable *>::iterator>(bufPosition);
73
74 return m_BufMemorySize;
75}
76
80 std::lock_guard<std::mutex> lock(m_setter);
81
83 m_BufPosition = boost::optional<std::list<ISaveable *>::iterator>();
84}
85
86} // namespace Mantid::Kernel
An interface for objects that can be cached or saved to disk.
Definition: ISaveable.h:28
void clearBufferState()
clears the state of the object, and indicate that it is not stored in buffer any more
Definition: ISaveable.cpp:79
uint64_t m_fileIndexStart
Start point in the NXS file where the events are located.
Definition: ISaveable.h:145
virtual void load()=0
Load the data - to be overriden.
bool wasSaved() const
Definition: ISaveable.h:47
boost::optional< std::list< ISaveable * >::iterator > m_BufPosition
Definition: ISaveable.h:140
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
Definition: ISaveable.cpp:69
virtual void save() const =0
Save the data - to be overriden.
uint64_t m_fileNumEvents
Number of events saved in the file, after the start index location.
Definition: ISaveable.h:147
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...
Definition: ISaveable.cpp:49
virtual void clearDataFromMemory()=0
remove objects data from memory
void setFilePosition(uint64_t newPos, size_t newSize, bool wasSaved)
Sets the location of the object on HDD.
Definition: ISaveable.cpp:35
bool m_wasSaved
this boolean indicates if the data were saved on HDD and have physical representation on it (though t...
Definition: ISaveable.h:133
virtual size_t getDataMemorySize() const =0
the data size kept in memory
STL namespace.