Skip to content
Snippets Groups Projects
ISpectrum.h 9.03 KiB
Newer Older
#ifndef MANTID_API_ISPECTRUM_H_
#define MANTID_API_ISPECTRUM_H_
#include "MantidHistogramData/Histogram.h"
#include "MantidKernel/System.h"
#include "MantidKernel/cow_ptr.h"
namespace Mantid {
namespace API {
/** 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
  @author Janik Zikovsky
  @date 2011-07-01
  Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
 National Laboratory & European Spallation Source
  This file is part of Mantid.
  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.
  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.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  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;
  void copyInfoFrom(const ISpectrum &other);
  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;
  virtual MantidVec &dataDx() = 0;
  virtual const MantidVec &dataDx() const = 0;
  virtual const MantidVec &readDx() const = 0;

  virtual void clearData() = 0;
  virtual MantidVec &dataY() = 0;
  virtual MantidVec &dataE() = 0;
  virtual const MantidVec &dataY() const = 0;
  virtual const MantidVec &dataE() const = 0;
  virtual const MantidVec &readY() const;
  virtual const MantidVec &readE() const;
  virtual size_t getMemorySize() const = 0;
  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);
  bool hasDetectorID(const detid_t detID) const;
  std::set<detid_t> &getDetectorIDs();
  const std::set<detid_t> &getDetectorIDs() const;
  void clearDetectorIDs();
  // ---------------------------------------------------------
  specnum_t getSpectrumNo() const;
  void setSpectrumNo(specnum_t num);
  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 {
  virtual HistogramData::FrequencyVariances frequencyVariances() const {
    return histogramRef().frequencyVariances();
  }
  virtual HistogramData::FrequencyStandardDeviations
  frequencyStandardDeviations() const {
    return histogramRef().frequencyStandardDeviations();
  }
  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() & {
    return mutableHistogramRef().mutableY();
  }
  HistogramData::HistogramE &mutableE() & {
    return mutableHistogramRef().mutableE();
  }
  Kernel::cow_ptr<HistogramData::HistogramX> sharedX() const {
    return histogramRef().sharedX();
  }
  virtual Kernel::cow_ptr<HistogramData::HistogramY> sharedY() const {
  virtual Kernel::cow_ptr<HistogramData::HistogramE> sharedE() const {
  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) & {
    mutableHistogramRef().setSharedY(y);
  }
  void setSharedE(const Kernel::cow_ptr<HistogramData::HistogramE> &e) & {
    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
  /// Set of the detector IDs associated with this spectrum
  std::set<detid_t> detectorIDs;
private:
  virtual const HistogramData::Histogram &histogramRef() const = 0;
  virtual HistogramData::Histogram &mutableHistogramRef() = 0;
#endif /* MANTID_API_ISPECTRUM_H_ */