forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SplittersWorkspace.cpp
102 lines (87 loc) · 3.08 KB
/
SplittersWorkspace.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// 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/SplittersWorkspace.h"
#include "MantidAPI/Column.h"
#include "MantidAPI/TableRow.h"
#include "MantidKernel/IPropertyManager.h"
using namespace Mantid::Kernel;
using namespace Mantid::API;
namespace Mantid::DataObjects {
namespace {
/// static logger
Kernel::Logger g_log("SplittersWorkspace");
} // namespace
//----------------------------------------------------------------------------------------------
/** Constructor
*/
SplittersWorkspace::SplittersWorkspace() {
this->addColumn("long64", "start");
this->addColumn("long64", "stop");
this->addColumn("int", "workspacegroup");
}
/*
* Add a Splitter to
*/
void SplittersWorkspace::addSplitter(Mantid::Kernel::SplittingInterval splitter) {
Mantid::API::TableRow row = this->appendRow();
row << splitter.start().totalNanoseconds();
row << splitter.stop().totalNanoseconds();
row << splitter.index();
}
Kernel::SplittingInterval SplittersWorkspace::getSplitter(size_t index) {
API::TableRow row = this->getRow(index);
int64_t start, stop;
int wsgroup;
row >> start;
row >> stop;
row >> wsgroup;
Kernel::SplittingInterval splitter(Types::Core::DateAndTime(start), Types::Core::DateAndTime(stop), wsgroup);
return splitter;
}
size_t SplittersWorkspace::getNumberSplitters() const { return this->rowCount(); }
bool SplittersWorkspace::removeSplitter(size_t index) {
bool removed;
if (index >= this->rowCount()) {
g_log.error() << "Try to delete a non-existing splitter " << index << '\n';
removed = false;
} else {
this->removeRow(index);
removed = true;
}
return removed;
}
} // namespace Mantid::DataObjects
///\cond TEMPLATE
namespace Mantid::Kernel {
template <>
DLLExport Mantid::DataObjects::SplittersWorkspace_sptr
IPropertyManager::getValue<Mantid::DataObjects::SplittersWorkspace_sptr>(const std::string &name) const {
auto *prop =
dynamic_cast<PropertyWithValue<Mantid::DataObjects::SplittersWorkspace_sptr> *>(getPointerToProperty(name));
if (prop) {
return *prop;
} else {
std::string message =
"Attempt to assign property " + name + " to incorrect type. Expected shared_ptr<SplittersWorkspace>.";
throw std::runtime_error(message);
}
}
template <>
DLLExport Mantid::DataObjects::SplittersWorkspace_const_sptr
IPropertyManager::getValue<Mantid::DataObjects::SplittersWorkspace_const_sptr>(const std::string &name) const {
auto *prop =
dynamic_cast<PropertyWithValue<Mantid::DataObjects::SplittersWorkspace_sptr> *>(getPointerToProperty(name));
if (prop) {
return prop->operator()();
} else {
std::string message =
"Attempt to assign property " + name + " to incorrect type. Expected const shared_ptr<SplittersWorkspace>.";
throw std::runtime_error(message);
}
}
} // namespace Mantid::Kernel
///\endcond