Newer
Older
Janik Zikovsky
committed
#ifndef MANTID_API_ISPECTRUM_H_
#define MANTID_API_ISPECTRUM_H_
Janik Zikovsky
committed
#include "MantidGeometry/IDTypes.h"
#include "MantidHistogramData/Histogram.h"
#include "MantidKernel/System.h"
#include "MantidKernel/cow_ptr.h"
Janik Zikovsky
committed
#include <set>
namespace Mantid {
namespace API {
Janik Zikovsky
committed
/** A "spectrum" is an object that holds the data for a particular spectrum,
* in particular:
* - The X/Y/E arrays
* - The spectrum number
* - A list of detector ids associated with it.
*
* This is an interface that can be used for both Workspace2D's Spectrum
objects,
* and EventWorkspace's EventList objects
Janik Zikovsky
committed
@author Janik Zikovsky
@date 2011-07-01
Janik Zikovsky
committed
Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
Janik Zikovsky
committed
Janik Zikovsky
committed
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Janik Zikovsky
committed
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Janik Zikovsky
committed
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Janik Zikovsky
committed
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport ISpectrum {
public:
ISpectrum();
ISpectrum(const specnum_t specNo);
virtual ~ISpectrum() = default;
Janik Zikovsky
committed
void copyInfoFrom(const ISpectrum &other);
Janik Zikovsky
committed
virtual void setX(const Kernel::cow_ptr<HistogramData::HistogramX> &X) = 0;
virtual MantidVec &dataX() = 0;
virtual const MantidVec &dataX() const = 0;
virtual const MantidVec &readX() const = 0;
virtual Kernel::cow_ptr<HistogramData::HistogramX> ptrX() const = 0;
Janik Zikovsky
committed
virtual MantidVec &dataDx() = 0;
virtual const MantidVec &dataDx() const = 0;
virtual const MantidVec &readDx() const = 0;
Janik Zikovsky
committed
virtual MantidVec &dataY() = 0;
virtual MantidVec &dataE() = 0;
Janik Zikovsky
committed
virtual const MantidVec &dataY() const = 0;
virtual const MantidVec &dataE() const = 0;
virtual const MantidVec &readY() const;
virtual const MantidVec &readE() const;
Janik Zikovsky
committed
virtual size_t getMemorySize() const = 0;
Janik Zikovsky
committed
virtual std::pair<double, double> getXDataRange() const;
// ---------------------------------------------------------
void addDetectorID(const detid_t detID);
void addDetectorIDs(const std::set<detid_t> &detIDs);
void addDetectorIDs(const std::vector<detid_t> &detIDs);
void setDetectorID(const detid_t detID);
void setDetectorIDs(const std::set<detid_t> &detIDs);
void setDetectorIDs(std::set<detid_t> &&detIDs);
Janik Zikovsky
committed
bool hasDetectorID(const detid_t detID) const;
std::set<detid_t> &getDetectorIDs();
const std::set<detid_t> &getDetectorIDs() const;
Janik Zikovsky
committed
// ---------------------------------------------------------
specnum_t getSpectrumNo() const;
Janik Zikovsky
committed
void setSpectrumNo(specnum_t num);
Janik Zikovsky
committed
bool hasDx() const;
void resetHasDx();
/// Returns the Histogram associated with this spectrum.
virtual HistogramData::Histogram histogram() const { return histogramRef(); }
/// Sets the Histogram associated with this spectrum.
template <typename... T> void setHistogram(T &&... data) {
HistogramData::Histogram histogram(std::forward<T>(data)...);
// Check for the special case EventList, it only accepts histograms without
// Y and E data.
checkHistogram(histogram);
mutableHistogramRef() = std::move(histogram);
}
HistogramData::BinEdges binEdges() const { return histogramRef().binEdges(); }
HistogramData::Points points() const { return histogramRef().points(); }
HistogramData::PointStandardDeviations pointStandardDeviations() const {
return histogramRef().pointStandardDeviations();
}
template <typename... T> void setBinEdges(T &&... data) & {
mutableHistogramRef().setBinEdges(std::forward<T>(data)...);
}
template <typename... T> void setPoints(T &&... data) & {
// Check for the special case EventList, it only works with BinEdges.
checkWorksWithPoints();
mutableHistogramRef().setPoints(std::forward<T>(data)...);
}
template <typename... T> void setPointVariances(T &&... data) & {
checkWorksWithPoints();
mutableHistogramRef().setPointVariances(std::forward<T>(data)...);
}
template <typename... T> void setPointStandardDeviations(T &&... data) & {
checkWorksWithPoints();
mutableHistogramRef().setPointStandardDeviations(std::forward<T>(data)...);
}
virtual HistogramData::Counts counts() const {
return histogramRef().counts();
}
virtual HistogramData::CountVariances countVariances() const {
return histogramRef().countVariances();
}
virtual HistogramData::CountStandardDeviations
countStandardDeviations() const {
return histogramRef().countStandardDeviations();
}
virtual HistogramData::Frequencies frequencies() const {
return histogramRef().frequencies();
}
virtual HistogramData::FrequencyVariances frequencyVariances() const {
return histogramRef().frequencyVariances();
}
virtual HistogramData::FrequencyStandardDeviations
frequencyStandardDeviations() const {
return histogramRef().frequencyStandardDeviations();
}
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
template <typename... T> void setCounts(T &&... data) & {
// Check for the special case EventList, cannot set Y and E there.
checkIsYAndEWritable();
mutableHistogramRef().setCounts(std::forward<T>(data)...);
}
template <typename... T> void setCountVariances(T &&... data) & {
checkIsYAndEWritable();
mutableHistogramRef().setCountVariances(std::forward<T>(data)...);
}
template <typename... T> void setCountStandardDeviations(T &&... data) & {
checkIsYAndEWritable();
mutableHistogramRef().setCountStandardDeviations(std::forward<T>(data)...);
}
template <typename... T> void setFrequencies(T &&... data) & {
checkIsYAndEWritable();
mutableHistogramRef().setFrequencies(std::forward<T>(data)...);
}
template <typename... T> void setFrequencyVariances(T &&... data) & {
checkIsYAndEWritable();
mutableHistogramRef().setFrequencyVariances(std::forward<T>(data)...);
}
template <typename... T> void setFrequencyStandardDeviations(T &&... data) & {
checkIsYAndEWritable();
mutableHistogramRef().setFrequencyStandardDeviations(
std::forward<T>(data)...);
}
const HistogramData::HistogramX &x() const { return histogramRef().x(); }
virtual const HistogramData::HistogramY &y() const {
return histogramRef().y();
}
virtual const HistogramData::HistogramE &e() const {
return histogramRef().e();
}
const HistogramData::HistogramDx &dx() const { return histogramRef().dx(); }
HistogramData::HistogramX &mutableX() & {
return mutableHistogramRef().mutableX();
}
HistogramData::HistogramDx &mutableDx() & {
return mutableHistogramRef().mutableDx();
}
HistogramData::HistogramY &mutableY() & {
checkIsYAndEWritable();
return mutableHistogramRef().mutableY();
}
HistogramData::HistogramE &mutableE() & {
checkIsYAndEWritable();
return mutableHistogramRef().mutableE();
}
Kernel::cow_ptr<HistogramData::HistogramX> sharedX() const {
return histogramRef().sharedX();
}
virtual Kernel::cow_ptr<HistogramData::HistogramY> sharedY() const {
return histogramRef().sharedY();
}
virtual Kernel::cow_ptr<HistogramData::HistogramE> sharedE() const {
return histogramRef().sharedE();
}
Kernel::cow_ptr<HistogramData::HistogramDx> sharedDx() const {
return histogramRef().sharedDx();
}
void setSharedX(const Kernel::cow_ptr<HistogramData::HistogramX> &x) & {
mutableHistogramRef().setSharedX(x);
}
void setSharedDx(const Kernel::cow_ptr<HistogramData::HistogramDx> &dx) & {
mutableHistogramRef().setSharedDx(dx);
}
void setSharedY(const Kernel::cow_ptr<HistogramData::HistogramY> &y) & {
checkIsYAndEWritable();
mutableHistogramRef().setSharedY(y);
}
void setSharedE(const Kernel::cow_ptr<HistogramData::HistogramE> &e) & {
checkIsYAndEWritable();
mutableHistogramRef().setSharedE(e);
}
virtual void checkHistogram(const HistogramData::Histogram &) const {}
virtual void checkWorksWithPoints() const {}
virtual void checkIsYAndEWritable() const {}
// Copy and move are not public since this is an abstract class, but protected
// such that derived classes can implement copy and move.
ISpectrum(const ISpectrum &) = default;
ISpectrum(ISpectrum &&) = default;
ISpectrum &operator=(const ISpectrum &) = default;
ISpectrum &operator=(ISpectrum &&) = default;
/// The spectrum number of this spectrum
specnum_t m_specNo;
Janik Zikovsky
committed
/// Set of the detector IDs associated with this spectrum
std::set<detid_t> detectorIDs;
Janik Zikovsky
committed
private:
virtual const HistogramData::Histogram &histogramRef() const = 0;
virtual HistogramData::Histogram &mutableHistogramRef() = 0;
Janik Zikovsky
committed
} // namespace API
} // namespace Mantid
#endif /* MANTID_API_ISPECTRUM_H_ */