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
11#include <memory>
12#include <sstream>
13#include <utility>
14
15using namespace Mantid::Kernel;
16using namespace Mantid::API;
17
18namespace Mantid::API {
19
20//----------------------------------------------------------------------------------------------
25
30
31//-----------------------------------------------------------------------------------------------
38 if (size_t(expInfoIndex) >= m_expInfos.size())
39 throw std::invalid_argument("MDWorkspace::getExperimentInfo(): expInfoIndex is out of range.");
40 return m_expInfos[expInfoIndex];
41}
42
43//-----------------------------------------------------------------------------------------------
50 if (size_t(expInfoIndex) >= m_expInfos.size())
51 throw std::invalid_argument("MDWorkspace::getExperimentInfo() const: expInfoIndex is out of range.");
52 return m_expInfos[expInfoIndex];
53}
54
55//-----------------------------------------------------------------------------------------------
63 m_expInfos.emplace_back(ei);
64 if (m_expInfos.size() >= static_cast<size_t>(std::numeric_limits<uint16_t>::max()))
65 throw std::runtime_error("MDWorkspace: Reached the capacity for the number "
66 "of ExperimentInfos of 65536.");
67 return uint16_t(m_expInfos.size() - 1);
68}
69
70//-----------------------------------------------------------------------------------------------
77 if (size_t(expInfoIndex) >= m_expInfos.size())
78 throw std::invalid_argument("MDEventWorkspace::setExperimentInfo(): expInfoIndex is out of range.");
79 m_expInfos[expInfoIndex] = std::move(ei);
80}
81
82//-----------------------------------------------------------------------------------------------
84uint16_t MultipleExperimentInfos::getNumExperimentInfo() const { return uint16_t(m_expInfos.size()); }
85
86//-----------------------------------------------------------------------------------------------
90 m_expInfos.clear();
91 m_expInfos.reserve(other.m_expInfos.size());
92 // Do a deep copy of ExperimentInfo's
93 for (const auto &expInfo : other.m_expInfos) {
94 auto copy(std::make_shared<ExperimentInfo>(*expInfo));
95 m_expInfos.emplace_back(copy);
96 }
97}
98
99//-----------------------------------------------------------------------------------------------
100/* Does this class have any oriented lattice associated with it?
101 * Returns true if any experiment info sample has an oriented lattice attached
102 */
104 for (uint16_t i = 0; i < getNumExperimentInfo(); i++) {
105 if (getExperimentInfo(i)->sample().hasOrientedLattice()) {
106 return true;
107 }
108 }
109 return false;
110}
111
112const std::string MultipleExperimentInfos::toString() const {
113 // if (m_expInfos.size() == 1)
114 // return m_expInfos[0]->toString();
115
116 // mess with things in multiple case
117 std::ostringstream os;
118 for (std::size_t i = 0; i < m_expInfos.size(); ++i) {
119 os << m_expInfos[i]->toString();
120 if (i + 1 != m_expInfos.size())
121 os << "\n";
122 }
123
124 return os.str();
125}
126
127} // 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.