Newer
Older
#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 {
namespace DataObjects {
namespace {
/// static logger
Kernel::Logger g_log("SplittersWorkspace");
}
//----------------------------------------------------------------------------------------------
/** Constructor
*/
SplittersWorkspace::SplittersWorkspace() {
this->addColumn("long64", "start");
this->addColumn("long64", "stop");
this->addColumn("int", "workspacegroup");
}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
SplittersWorkspace::~SplittersWorkspace() {}
/*
* Add a Splitter to
*/
void SplittersWorkspace::addSplitter(
Mantid::Kernel::SplittingInterval splitter) {
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
Mantid::API::TableRow row = this->appendRow();
row << splitter.start().totalNanoseconds();
row << splitter.stop().totalNanoseconds();
row << splitter.index();
return;
}
Kernel::SplittingInterval SplittersWorkspace::getSplitter(size_t index) {
API::Column_const_sptr column = this->getColumn("start");
API::TableRow row = this->getRow(index);
int64_t start, stop;
int wsgroup;
row >> start;
row >> stop;
row >> wsgroup;
Kernel::SplittingInterval splitter(Kernel::DateAndTime(start),
Kernel::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
<< std::endl;
removed = false;
} else {
this->removeRow(index);
removed = true;
} // namespace Mantid
} // namespace DataObjects
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
namespace Mantid {
namespace Kernel {
template <>
DLLExport Mantid::DataObjects::SplittersWorkspace_sptr
IPropertyManager::getValue<Mantid::DataObjects::SplittersWorkspace_sptr>(
const std::string &name) const {
PropertyWithValue<Mantid::DataObjects::SplittersWorkspace_sptr> *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 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 {
PropertyWithValue<Mantid::DataObjects::SplittersWorkspace_sptr> *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 SplittersWorkspace.";
throw std::runtime_error(message);
}
}
} // namespace Kernel