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
9namespace Mantid::Kernel {
10
13 : m_Busy(false), m_dataChanged(false), m_wasSaved(false), m_isLoaded(false), m_BufMemorySize(0),
14 m_fileIndexStart(std::numeric_limits<uint64_t>::max()), m_fileNumEvents(0) {}
15
16//----------------------------------------------------------------------------------------------
21 : m_Busy(other.m_Busy), m_dataChanged(other.m_dataChanged), m_wasSaved(other.m_wasSaved), m_isLoaded(false),
22 m_BufPosition(other.m_BufPosition), m_BufMemorySize(other.m_BufMemorySize),
23 m_fileIndexStart(other.m_fileIndexStart), m_fileNumEvents(other.m_fileNumEvents)
24
25{}
26
27//---------------------------------------------------------------------------
28
34void ISaveable::setFilePosition(uint64_t newPos, size_t newSize, bool wasSaved) {
35 std::lock_guard<std::mutex> lock(m_setter);
36 this->m_fileIndexStart = newPos;
37 this->m_fileNumEvents = static_cast<uint64_t>(newSize);
39}
40
41// ----------- PRIVATE, only DB availible
42
48void ISaveable::saveAt(uint64_t newPos, uint64_t newSize) {
49 std::lock_guard<std::mutex> lock(m_setter);
50 // load old contents if it was there
51 if (this->wasSaved())
52 this->load();
53 // set new position, derived by the disk buffer
54 m_fileIndexStart = newPos;
55 m_fileNumEvents = newSize;
56 // save in the new location
57 this->save();
58 this->clearDataFromMemory();
59}
60
68size_t ISaveable::setBufferPosition(std::list<ISaveable *>::iterator bufPosition) {
69 std::lock_guard<std::mutex> lock(m_setter);
70 m_BufPosition = std::optional<std::list<ISaveable *>::iterator>(bufPosition);
72
73 return m_BufMemorySize;
74}
75
79 std::lock_guard<std::mutex> lock(m_setter);
80
82 m_BufPosition = std::optional<std::list<ISaveable *>::iterator>();
83}
84
85} // 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:78
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.
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:68
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:48
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:34
std::optional< std::list< ISaveable * >::iterator > m_BufPosition
Definition ISaveable.h:140
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.