Mantid
Loading...
Searching...
No Matches
SplittersWorkspace.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#include "MantidAPI/Column.h"
11#include "MantidDataObjects/DllConfig.h"
13
14using namespace Mantid::Kernel;
15using namespace Mantid::API;
16
17namespace Mantid::DataObjects {
18namespace {
20Kernel::Logger g_log("SplittersWorkspace");
21} // namespace
22
24
25//----------------------------------------------------------------------------------------------
29 this->addColumn("long64", "start");
30 this->addColumn("long64", "stop");
31 this->addColumn("int", "workspacegroup");
32}
33
34/*
35 * Add a Splitter to
36 */
38 Mantid::API::TableRow row = this->appendRow();
39 row << splitter.start().totalNanoseconds();
40 row << splitter.stop().totalNanoseconds();
41 row << splitter.index();
42}
43
45 API::TableRow row = this->getRow(index);
46 int64_t start, stop;
47 int wsgroup;
48 row >> start;
49 row >> stop;
50 row >> wsgroup;
51
52 Kernel::SplittingInterval splitter(Types::Core::DateAndTime(start), Types::Core::DateAndTime(stop), wsgroup);
53
54 return splitter;
55}
56
57size_t SplittersWorkspace::getNumberSplitters() const { return this->rowCount(); }
58
60 bool removed;
61 if (index >= this->rowCount()) {
62 g_log.error() << "Try to delete a non-existing splitter " << index << '\n';
63 removed = false;
64 } else {
65 this->removeRow(index);
66 removed = true;
67 }
68
69 return removed;
70}
71} // namespace Mantid::DataObjects
72
74
75namespace Mantid::Kernel {
76
77template <>
79IPropertyManager::getValue<Mantid::DataObjects::SplittersWorkspace_sptr>(const std::string &name) const {
80 auto *prop =
81 dynamic_cast<PropertyWithValue<Mantid::DataObjects::SplittersWorkspace_sptr> *>(getPointerToProperty(name));
82 if (prop) {
83 return *prop;
84 } else {
85 std::string message =
86 "Attempt to assign property " + name + " to incorrect type. Expected shared_ptr<SplittersWorkspace>.";
87 throw std::runtime_error(message);
88 }
89}
90
91template <>
93IPropertyManager::getValue<Mantid::DataObjects::SplittersWorkspace_const_sptr>(const std::string &name) const {
94 auto const *prop =
95 dynamic_cast<PropertyWithValue<Mantid::DataObjects::SplittersWorkspace_sptr> *>(getPointerToProperty(name));
96 if (prop) {
97 return prop->operator()();
98 } else {
99 std::string message =
100 "Attempt to assign property " + name + " to incorrect type. Expected const shared_ptr<SplittersWorkspace>.";
101 throw std::runtime_error(message);
102 }
103}
104
105} // namespace Mantid::Kernel
std::string name
Definition Run.cpp:60
std::map< DeltaEMode::Type, std::string > index
#define DECLARE_WORKSPACE(classname)
TableRowHelper appendRow()
Appends a row.
TableRowHelper getRow(size_t row)
Creates a TableRow object for row row.
TableRow represents a row in a TableWorkspace.
Definition TableRow.h:39
SplittersWorkspace : A TableWorkspace to contain TimeSplitters.
void addSplitter(const Kernel::SplittingInterval &splitter) override
Kernel::SplittingInterval getSplitter(size_t index) override
size_t rowCount() const override
Number of rows in the workspace.
void removeRow(size_t index) override
Delets a row if it exists.
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition Logger.h:51
void error(const std::string &msg)
Logs at error level.
Definition Logger.cpp:108
The concrete, templated class for properties.
Class holding a start/end time and a destination for splitting event lists and logs.
int index() const
Return the index (destination of this split time block)
const Types::Core::DateAndTime & start() const
Beginning of the interval.
Definition DateAndTime.h:34
const Types::Core::DateAndTime & stop() const
End of the interval.
Definition DateAndTime.h:36
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< SplittersWorkspace > SplittersWorkspace_sptr
std::shared_ptr< const SplittersWorkspace > SplittersWorkspace_const_sptr