forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MDBoxSaveable.cpp
45 lines (39 loc) · 1.73 KB
/
MDBoxSaveable.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidDataObjects/MDBoxSaveable.h"
#include "MantidDataObjects/MDBox.h"
namespace Mantid::DataObjects {
MDBoxSaveable::MDBoxSaveable(API::IMDNode *const Host) : m_MDNode(Host) {}
/** flush data out of the file buffer to the HDD */
void MDBoxSaveable::flushData() const { m_MDNode->getBoxController()->getFileIO()->flushData(); }
//-----------------------------------------------------------------------------------------------
/** Physically save the box data. Tries to load any previous data from HDD
* Private function called from the DiskBuffer.
*/
void MDBoxSaveable::save() const {
/**Save the box at the disk position defined by this class. The IMDNode has to
* be file backed for this method to work */
API::IBoxControllerIO *fileIO = m_MDNode->getBoxController()->getFileIO();
if (this->wasSaved()) {
auto loader = const_cast<MDBoxSaveable *>(this);
loader->load();
}
m_MDNode->saveAt(fileIO, this->getFilePosition());
this->m_wasSaved = true;
}
/** Loads the data from HDD if these data has not been loaded before.
* private function called from the DiskBuffer
*/
void MDBoxSaveable::load() {
// Is the data in memory right now (cached copy)?
if (!m_isLoaded) {
API::IBoxControllerIO *fileIO = m_MDNode->getBoxController()->getFileIO();
m_MDNode->loadAndAddFrom(fileIO, this->getFilePosition(), this->getFileSize());
this->setLoaded(true);
}
}
} // namespace Mantid::DataObjects