Mantid
Loading...
Searching...
No Matches
MultipleExperimentInfos.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 +
9#include "MantidAPI/Sample.h"
10#include "MantidKernel/System.h"
11
12#include <memory>
13#include <sstream>
14#include <utility>
15
16using namespace Mantid::Kernel;
17using namespace Mantid::API;
18
19namespace Mantid::API {
20
21//----------------------------------------------------------------------------------------------
26
28 this->copyExperimentInfos(other);
29 return *this;
30}
31
32//-----------------------------------------------------------------------------------------------
39 if (size_t(expInfoIndex) >= m_expInfos.size())
40 throw std::invalid_argument("MDWorkspace::getExperimentInfo(): expInfoIndex is out of range.");
41 return m_expInfos[expInfoIndex];
42}
43
44//-----------------------------------------------------------------------------------------------
51 if (size_t(expInfoIndex) >= m_expInfos.size())
52 throw std::invalid_argument("MDWorkspace::getExperimentInfo() const: expInfoIndex is out of range.");
53 return m_expInfos[expInfoIndex];
54}
55
56//-----------------------------------------------------------------------------------------------
64 m_expInfos.emplace_back(ei);
65 if (m_expInfos.size() >= static_cast<size_t>(std::numeric_limits<uint16_t>::max()))
66 throw std::runtime_error("MDWorkspace: Reached the capacity for the number "
67 "of ExperimentInfos of 65536.");
68 return uint16_t(m_expInfos.size() - 1);
69}
70
71//-----------------------------------------------------------------------------------------------
78 if (size_t(expInfoIndex) >= m_expInfos.size())
79 throw std::invalid_argument("MDEventWorkspace::setExperimentInfo(): expInfoIndex is out of range.");
80 m_expInfos[expInfoIndex] = std::move(ei);
81}
82
83//-----------------------------------------------------------------------------------------------
85uint16_t MultipleExperimentInfos::getNumExperimentInfo() const { return uint16_t(m_expInfos.size()); }
86
87//-----------------------------------------------------------------------------------------------
91 m_expInfos.clear();
92 m_expInfos.reserve(other.m_expInfos.size());
93 // Do a deep copy of ExperimentInfo's
94 for (const auto &expInfo : other.m_expInfos) {
95 auto copy(std::make_shared<ExperimentInfo>(*expInfo));
96 m_expInfos.emplace_back(copy);
97 }
98}
99
100//-----------------------------------------------------------------------------------------------
101/* Does this class have any oriented lattice associated with it?
102 * Returns true if any experiment info sample has an oriented lattice attached
103 */
105 for (uint16_t i = 0; i < getNumExperimentInfo(); i++) {
106 if (getExperimentInfo(i)->sample().hasOrientedLattice()) {
107 return true;
108 }
109 }
110 return false;
111}
112
113const std::string MultipleExperimentInfos::toString() const {
114 // if (m_expInfos.size() == 1)
115 // return m_expInfos[0]->toString();
116
117 // mess with things in multiple case
118 std::ostringstream os;
119 for (std::size_t i = 0; i < m_expInfos.size(); ++i) {
120 os << m_expInfos[i]->toString();
121 if (i + 1 != m_expInfos.size())
122 os << "\n";
123 }
124
125 return os.str();
126}
127
128} // namespace Mantid::API
Small class that allows a MDEventWorkspace or a MDHistoWorkspace to hold several ExperimentInfo class...
std::vector< ExperimentInfo_sptr > m_expInfos
Vector for each ExperimentInfo class.
void copyExperimentInfos(const MultipleExperimentInfos &other)
Copy the experiment infos from another.
ExperimentInfo_sptr getExperimentInfo(const uint16_t expInfoIndex)
Get the ExperimentInfo for the given Experiment-Info Index.
MultipleExperimentInfos & operator=(const MultipleExperimentInfos &other)
const std::string toString() const
Returns a string description of the object.
uint16_t addExperimentInfo(const ExperimentInfo_sptr &ei)
Add a new ExperimentInfo to this MDEventWorkspace.
void setExperimentInfo(const uint16_t expInfoIndex, ExperimentInfo_sptr ei)
Replace the ExperimentInfo entry at a given place.
std::shared_ptr< const ExperimentInfo > ExperimentInfo_const_sptr
Shared pointer to const ExperimentInfo.
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.