Mantid
Loading...
Searching...
No Matches
ISaveable.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2011 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 +
7#pragma once
8
9#include "MantidKernel/DllConfig.h"
10#include <list>
11#include <mutex>
12#ifndef Q_MOC_RUN
13#include <boost/optional.hpp>
14#endif
15
16namespace Mantid {
17namespace Kernel {
18
26// forward declaration
27
28class MANTID_KERNEL_DLL ISaveable {
29public:
30 ISaveable();
31 ISaveable(const ISaveable &other);
32 virtual ~ISaveable() = default;
33
36 virtual uint64_t getFilePosition() const { return m_fileIndexStart; }
38 uint64_t getFileSize() const { return m_fileNumEvents; }
40 void setFilePosition(uint64_t newPos, size_t newSize, bool wasSaved);
41 //-----------------------------------------------------------------------------------------------
42 // Saveable functions interface, which controls the logic of working with
43 // objects on HDD
44
47 bool wasSaved() const // for speed it returns this boolean, but for
48 // relaibility this should be
49 // m_wasSaved&&(m_fileIndexStart!=max())
50 {
51 return m_wasSaved;
52 }
56 bool isLoaded() const { return m_isLoaded; }
57
58 // protected?
64 void setLoaded(bool Yes) { m_isLoaded = Yes; }
65
68 bool isBusy() const { return m_Busy; }
71 void setBusy(bool On) { m_Busy = On; }
72
73 // protected?
74
79 bool isDataChanged() const { return m_dataChanged; }
84 if (this->wasSaved())
85 m_dataChanged = true;
86 }
90 void clearDataChanged() { m_dataChanged = false; }
91
92 //-----------------------------------------------------------------------------------------------
93 // INTERFACE:
94
96 virtual void save() const = 0;
97
99 virtual void load() = 0;
100
102 virtual void flushData() const = 0;
104 virtual void clearDataFromMemory() = 0;
105
114 virtual uint64_t getTotalDataSize() const = 0;
116 virtual size_t getDataMemorySize() const = 0;
117
118protected:
119 //--------------
122 bool m_Busy;
129 // this tracks the history of operations, occuring over the data.
133 mutable bool m_wasSaved;
136
137private:
138 // the iterator which describes the position of this object in the DiskBuffer.
139 // Undefined if not placed to buffer
140 boost::optional<std::list<ISaveable *>::iterator> m_BufPosition;
141 // the size of the object in the memory buffer, used to calculate the total
142 // amount of memory the objects occupy
148
151 friend class DiskBuffer;
155 void saveAt(uint64_t newPos, uint64_t newSize);
156
159 size_t setBufferPosition(std::list<ISaveable *>::iterator bufPosition);
162 boost::optional<std::list<ISaveable *>::iterator> &getBufPostion() { return m_BufPosition; }
165 size_t getBufferSize() const { return m_BufMemorySize; }
166 void setBufferSize(size_t newSize) { m_BufMemorySize = newSize; }
167
170 void clearBufferState();
171
172 // the mutex to protect changes in this memory
173 std::mutex m_setter;
174};
175
176} // namespace Kernel
177} // namespace Mantid
Buffer objects that need to be written out to disk so as to optimize writing operations.
Definition: DiskBuffer.h:42
An interface for objects that can be cached or saved to disk.
Definition: ISaveable.h:28
virtual ~ISaveable()=default
bool isLoaded() const
Definition: ISaveable.h:56
uint64_t m_fileIndexStart
Start point in the NXS file where the events are located.
Definition: ISaveable.h:145
void setDataChanged()
Call this method from the method which changes the object but keeps the object size the same to tell ...
Definition: ISaveable.h:83
void setBufferSize(size_t newSize)
Definition: ISaveable.h:166
virtual uint64_t getFilePosition() const
Definition: ISaveable.h:36
bool isDataChanged() const
Definition: ISaveable.h:79
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
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
virtual void flushData() const =0
Method to flush the data to disk and ensure it is written.
boost::optional< std::list< ISaveable * >::iterator > & getBufPostion()
returns the iterator pointing to the position of this object within the memory to-write buffer
Definition: ISaveable.h:162
void setBusy(bool On)
@ set the data busy to prevent from removing them from memory.
Definition: ISaveable.h:71
uint64_t getFileSize() const
Return the number of units this block occipies on file.
Definition: ISaveable.h:38
bool m_Busy
a user needs to set this variable to true preventing from deleting data from buffer
Definition: ISaveable.h:122
void setLoaded(bool Yes)
sets the value of the isLoad parameter, indicating that data from HDD have its image in memory
Definition: ISaveable.h:64
virtual void clearDataFromMemory()=0
remove objects data from memory
void clearDataChanged()
this method has to be called if the object has been discarded from memory and is not changed any more...
Definition: ISaveable.h:90
bool m_dataChanged
a user needs to set this variable to true to allow DiskBuffer saving the object to HDD when it decide...
Definition: ISaveable.h:128
virtual uint64_t getTotalDataSize() const =0
bool m_isLoaded
this boolean indicates, if the data have its copy in memory
Definition: ISaveable.h:135
size_t getBufferSize() const
return the amount of memory, this object had when it was stored in buffer last time;
Definition: ISaveable.h:165
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
Helper class which provides the Collimation Length for SANS instruments.