Mantid
Loading...
Searching...
No Matches
ISpectrum.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 "MantidHistogramData/Histogram.h"
10#include "MantidKernel/System.h"
11
12namespace Mantid::API {
13
17ISpectrum::ISpectrum(const specnum_t specNo) : m_specNo(specNo) {}
18
25 m_specNo = other.m_specNo;
26 detectorIDs = other.detectorIDs;
29}
30
36std::pair<double, double> ISpectrum::getXDataRange() const {
37 const auto &xdata = readX();
38 return std::pair<double, double>(xdata.front(), xdata.back());
39}
40
42const MantidVec &ISpectrum::readY() const { return this->dataY(); }
43
45const MantidVec &ISpectrum::readE() const { return this->dataE(); }
46
51void ISpectrum::addDetectorID(const detid_t detID) {
52 size_t oldSize = detectorIDs.size();
53 this->detectorIDs.insert(detID);
54 if (detectorIDs.size() != oldSize)
56}
57
62void ISpectrum::addDetectorIDs(const std::set<detid_t> &detIDs) {
63 size_t oldSize = detectorIDs.size();
64 this->detectorIDs.insert(detIDs.begin(), detIDs.end());
65 if (detectorIDs.size() != oldSize)
67}
68
73void ISpectrum::addDetectorIDs(const std::vector<detid_t> &detIDs) {
74 size_t oldSize = detectorIDs.size();
75 this->detectorIDs.insert(detIDs.begin(), detIDs.end());
76 if (detectorIDs.size() != oldSize)
78}
79
84void ISpectrum::setDetectorID(const detid_t detID) {
85 this->detectorIDs.clear();
86 this->detectorIDs.insert(detID);
88}
89
94void ISpectrum::setDetectorIDs(const std::set<detid_t> &detIDs) {
95 detectorIDs = detIDs;
97}
98
103void ISpectrum::setDetectorIDs(std::set<detid_t> &&detIDs) {
104 detectorIDs = std::move(detIDs);
106}
107
109bool ISpectrum::hasDetectorID(const detid_t detID) const { return (detectorIDs.find(detID) != detectorIDs.end()); }
110
113const std::set<detid_t> &ISpectrum::getDetectorIDs() const { return this->detectorIDs; }
114
118 this->detectorIDs.clear();
120}
121
124
128 m_specNo = num;
130}
131
136bool ISpectrum::hasDx() const { return bool(histogramRef().sharedDx()); }
137
141void ISpectrum::resetHasDx() { mutableHistogramRef().setSharedDx(nullptr); }
142
144ISpectrum::ISpectrum(const ISpectrum &other) : m_specNo(other.m_specNo), detectorIDs(other.detectorIDs) {
145 // m_matrixWorkspace and m_index are not copied: A copy should not refer to
146 // the parent of the source. m_experimentInfo will be nullptr.
147}
148
150ISpectrum::ISpectrum(ISpectrum &&other) : m_specNo(other.m_specNo), detectorIDs(std::move(other.detectorIDs)) {
151 // m_matrixWorkspace and m_index are not copied: A copy should not refer to
152 // the parent of the source. m_experimentInfo will be nullptr.
153}
154
157 m_specNo = other.m_specNo;
158 detectorIDs = other.detectorIDs;
159 // m_matrixWorkspace and m_index are not assigned: The lhs of the assignment
160 // keeps its current values.
163 return *this;
164}
165
168 m_specNo = other.m_specNo;
169 detectorIDs = std::move(other.detectorIDs);
170 // m_matrixWorkspace and m_index are not assigned: The lhs of the assignment
171 // keeps its current values.
174 return *this;
175}
176
183void ISpectrum::setMatrixWorkspace(MatrixWorkspace *matrixWorkspace, const size_t index) {
184 m_matrixWorkspace = matrixWorkspace;
185 m_index = index;
186}
187
192}
193
198}
199
202 throw std::runtime_error("Incompatible types in ISpectrum::copyDataFrom");
206 throw std::runtime_error("Incompatible types in ISpectrum::copyDataFrom");
207}
208
210void ISpectrum::copyDataInto(SpectrumTester & /*unused*/) const {
211 throw std::runtime_error("Incompatible types in ISpectrum::copyDataFrom");
212}
213
214} // namespace Mantid::API
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
void invalidateSpectrumDefinition(const size_t index)
Notifies the ExperimentInfo that a spectrum definition has changed.
A "spectrum" is an object that holds the data for a particular spectrum, in particular:
Definition: ISpectrum.h:39
MatrixWorkspace * m_matrixWorkspace
Definition: ISpectrum.h:225
void setMatrixWorkspace(MatrixWorkspace *matrixWorkspace, const size_t index)
Sets the MatrixWorkspace pointer (pointer to the owning workspace).
Definition: ISpectrum.cpp:183
void addDetectorIDs(const std::set< detid_t > &detIDs)
Add a set of detector IDs to the set of detector IDs.
Definition: ISpectrum.cpp:62
void invalidateSpectrumDefinition() const
Invalidates spectrum definitions in the owning workspace.
Definition: ISpectrum.cpp:195
virtual MantidVec & dataY()=0
virtual const MantidVec & readX() const =0
virtual MantidVec & dataE()=0
specnum_t getSpectrumNo() const
Definition: ISpectrum.cpp:123
std::set< detid_t > detectorIDs
Set of the detector IDs associated with this spectrum.
Definition: ISpectrum.h:233
virtual std::pair< double, double > getXDataRange() const
Return the min/max X values for this spectrum.
Definition: ISpectrum.cpp:36
void setDetectorIDs(const std::set< detid_t > &detIDs)
Set the detector IDs to be the set given.
Definition: ISpectrum.cpp:94
bool hasDetectorID(const detid_t detID) const
Return true if the given detector ID is in the list for this ISpectrum.
Definition: ISpectrum.cpp:109
virtual const MantidVec & readE() const
Deprecated, use e() instead. Returns the y error data const.
Definition: ISpectrum.cpp:45
void clearDetectorIDs()
Clear the detector IDs set.
Definition: ISpectrum.cpp:117
void resetHasDx()
Resets the hasDx flag.
Definition: ISpectrum.cpp:141
void addDetectorID(const detid_t detID)
Add a detector ID to the set of detector IDs.
Definition: ISpectrum.cpp:51
virtual HistogramData::Histogram & mutableHistogramRef()=0
bool hasDx() const
Gets the value of the use flag.
Definition: ISpectrum.cpp:136
void copyInfoFrom(const ISpectrum &other)
Copy spectrum number and detector IDs, but not X vector, from another ISpectrum.
Definition: ISpectrum.cpp:24
virtual const MantidVec & readY() const
Deprecated, use y() instead. Returns the y data const.
Definition: ISpectrum.cpp:42
void setDetectorID(const detid_t detID)
Clear the list of detector IDs, then add one.
Definition: ISpectrum.cpp:84
void invalidateCachedSpectrumNumbers() const
Invalidates cached spectrum numbers in the owning workspace.
Definition: ISpectrum.cpp:189
const std::set< detid_t > & getDetectorIDs() const
Get a const reference to the detector IDs set.
Definition: ISpectrum.cpp:113
virtual const HistogramData::Histogram & histogramRef() const =0
virtual void copyDataInto(DataObjects::EventList &) const
Override in child classes for polymorphic copying of data.
Definition: ISpectrum.cpp:201
ISpectrum & operator=(const ISpectrum &other)
Copy assignment.
Definition: ISpectrum.cpp:156
void setSpectrumNo(specnum_t num)
Sets the the spectrum number of this spectrum.
Definition: ISpectrum.cpp:127
specnum_t m_specNo
The spectrum number of this spectrum.
Definition: ISpectrum.h:230
Kernel::cow_ptr< HistogramData::HistogramDx > sharedDx() const
Definition: ISpectrum.h:189
Base MatrixWorkspace Abstract Class.
A class for holding :
Definition: EventList.h:56
1D histogram implementation.
Definition: Histogram1D.h:18
Helper class that implements ISpectrum.
Definition: FakeObjects.h:55
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Definition: cow_ptr.h:172
int32_t specnum_t
Typedef for a spectrum Number.
Definition: IDTypes.h:16
STL namespace.