"Framework/git@code.ornl.gov:mantidproject/mantid.git" did not exist on "48926ef512fb83f276194152ab3ce2e2abfa7d31"
Newer
Older
#include "MantidAPI/ExperimentInfo.h"
#include "MantidAPI/MultipleExperimentInfos.h"
#include "MantidKernel/System.h"
using namespace Mantid::Kernel;
using namespace Mantid::API;
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
103
namespace Mantid {
namespace API {
//----------------------------------------------------------------------------------------------
/** Constructor
*/
MultipleExperimentInfos::MultipleExperimentInfos() {}
//----------------------------------------------------------------------------------------------
/** Copy constructor
*
* @param other :: other workspace to copy */
MultipleExperimentInfos::MultipleExperimentInfos(
const MultipleExperimentInfos &other) {
this->copyExperimentInfos(other);
}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
MultipleExperimentInfos::~MultipleExperimentInfos() {}
//-----------------------------------------------------------------------------------------------
/** Get the ExperimentInfo for the given run Index
*
* @param runIndex :: 0-based index of the run to get.
* @return shared ptr to the ExperimentInfo class
*/
ExperimentInfo_sptr
MultipleExperimentInfos::getExperimentInfo(const uint16_t runIndex) {
if (size_t(runIndex) >= m_expInfos.size())
throw std::invalid_argument(
"MDWorkspace::getExperimentInfo(): runIndex is out of range.");
return m_expInfos[runIndex];
}
//-----------------------------------------------------------------------------------------------
/** Get the ExperimentInfo for the given run Index
*
* @param runIndex :: 0-based index of the run to get.
* @return shared ptr to the ExperimentInfo class
*/
ExperimentInfo_const_sptr
MultipleExperimentInfos::getExperimentInfo(const uint16_t runIndex) const {
if (size_t(runIndex) >= m_expInfos.size())
throw std::invalid_argument(
"MDWorkspace::getExperimentInfo() const: runIndex is out of range.");
return m_expInfos[runIndex];
}
//-----------------------------------------------------------------------------------------------
/** Add a new ExperimentInfo to this MDEventWorkspace
*
* @param ei :: shared ptr to the ExperimentInfo class to add
* @return the runIndex at which it was added
* @throw std::runtime_error if you reach the limit of 65536 entries.
*/
uint16_t MultipleExperimentInfos::addExperimentInfo(ExperimentInfo_sptr ei) {
m_expInfos.push_back(ei);
if (m_expInfos.size() >=
static_cast<size_t>(std::numeric_limits<uint16_t>::max()))
throw std::runtime_error("MDWorkspace: Reached the capacity for the number "
"of ExperimentInfos of 65536.");
return uint16_t(m_expInfos.size() - 1);
}
//-----------------------------------------------------------------------------------------------
/** Replace the ExperimentInfo entry at a given place
*
* @param runIndex :: 0-based index of the run to replace
* @param ei :: shared ptr to the ExperimentInfo class to add
*/
void MultipleExperimentInfos::setExperimentInfo(const uint16_t runIndex,
ExperimentInfo_sptr ei) {
if (size_t(runIndex) >= m_expInfos.size())
throw std::invalid_argument(
"MDEventWorkspace::setExperimentInfo(): runIndex is out of range.");
m_expInfos[runIndex] = ei;
}
//-----------------------------------------------------------------------------------------------
/// @return the number of ExperimentInfo's in this workspace
uint16_t MultipleExperimentInfos::getNumExperimentInfo() const {
return uint16_t(m_expInfos.size());
}
//-----------------------------------------------------------------------------------------------
/** Copy the experiment infos from another. Deep copy.
* @param other :: other workspace to copy */
void MultipleExperimentInfos::copyExperimentInfos(
const MultipleExperimentInfos &other) {
m_expInfos.clear();
// Do a deep copy of ExperimentInfo's
for (size_t i = 0; i < other.m_expInfos.size(); i++) {
ExperimentInfo_sptr copy(new ExperimentInfo(*other.m_expInfos[i]));
m_expInfos.push_back(copy);
}
const std::string MultipleExperimentInfos::toString() const {
// if (m_expInfos.size() == 1)
// return m_expInfos[0]->toString();
// mess with things in multiple case
std::ostringstream os;
for (std::size_t i = 0; i < m_expInfos.size(); ++i) {
os << m_expInfos[i]->toString();
if (i + 1 != m_expInfos.size())
os << "\n";
} // namespace Mantid
} // namespace API