Mantid
Loading...
Searching...
No Matches
WorkspaceSingleValue.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 +
8#include "MantidAPI/RefAxis.h"
12
13namespace Mantid::DataObjects {
14
15using std::size_t;
16
17DECLARE_WORKSPACE(WorkspaceSingleValue)
18
19
20WorkspaceSingleValue::WorkspaceSingleValue(double value, double error, const Parallel::StorageMode storageMode)
21 : API::HistoWorkspace(storageMode) {
22 initialize(1, 1, 1);
23 // Set the "histogram" to the single value
24 data.dataX().resize(1, 0.0);
25 data.setCounts(1, value);
26 data.setCountStandardDeviations(1, error);
27 data.setPointStandardDeviations(1, 0.0);
28 setDistribution(true);
29 // Add a set of axes to the workspace
30 m_axes.resize(2);
31 m_axes[0] = std::make_unique<API::RefAxis>(this);
32 m_axes[1] = std::make_unique<API::SpectraAxis>(this);
33}
34
36 : HistoWorkspace(other), data(other.data) {
37 setDistribution(true);
38}
39
46void WorkspaceSingleValue::init(const std::size_t &NVectors, const std::size_t &XLength, const std::size_t &YLength) {
47 (void)NVectors;
48 (void)XLength;
49 (void)YLength; // Avoid compiler warning
50}
51
52void WorkspaceSingleValue::init(const HistogramData::Histogram &histogram) { UNUSED_ARG(histogram); }
53
56 data.setMatrixWorkspace(this, 0);
57 return data;
58}
59
62 bool skipError) const {
66 UNUSED_ARG(E);
67 UNUSED_ARG(skipError);
68 throw std::runtime_error("generateHistogram() not implemented for WorkspaceSingleValue.");
69}
70
72size_t WorkspaceSingleValue::getNumDims() const { return 0; }
73
74} // namespace Mantid::DataObjects
75
76namespace Mantid::Kernel {
77template <>
79IPropertyManager::getValue<Mantid::DataObjects::WorkspaceSingleValue_sptr>(const std::string &name) const {
80 auto *prop =
81 dynamic_cast<PropertyWithValue<Mantid::DataObjects::WorkspaceSingleValue_sptr> *>(getPointerToProperty(name));
82 if (prop) {
83 return *prop;
84 } else {
85 std::string message =
86 "Attempt to assign property " + name + " to incorrect type. Expected shared_ptr<WorkspaceSingleValue>.";
87 throw std::runtime_error(message);
88 }
89}
90
91template <>
93IPropertyManager::getValue<Mantid::DataObjects::WorkspaceSingleValue_const_sptr>(const std::string &name) const {
94 auto *prop =
95 dynamic_cast<PropertyWithValue<Mantid::DataObjects::WorkspaceSingleValue_sptr> *>(getPointerToProperty(name));
96 if (prop) {
97 return prop->operator()();
98 } else {
99 std::string message =
100 "Attempt to assign property " + name + " to incorrect type. Expected const shared_ptr<WorkspaceSingleValue>.";
101 throw std::runtime_error(message);
102 }
103}
104
105} // namespace Mantid::Kernel
106
double value
The value of the point.
Definition: FitMW.cpp:51
double error
Definition: IndexPeaks.cpp:133
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
#define DECLARE_WORKSPACE(classname)
HistoWorkspace is an abstract base class for MatrixWorkspace types that are NOT event workspaces.
void setMatrixWorkspace(MatrixWorkspace *matrixWorkspace, const size_t index)
Sets the MatrixWorkspace pointer (pointer to the owning workspace).
Definition: ISpectrum.cpp:183
HistogramData::Histogram histogram(const size_t index) const
Returns the Histogram at the given workspace index.
void setDistribution(bool newValue)
Set the flag for whether the Y-values are dimensioned.
1D histogram implementation.
Definition: Histogram1D.h:18
Concrete workspace implementation.
WorkspaceSingleValue(double value=0.0, double error=0.0, const Parallel::StorageMode storageMode=Parallel::StorageMode::Cloned)
Constructor.
Histogram1D & getSpectrumWithoutInvalidation(const size_t index) override
Return the underlying Histogram1D at the given workspace index.
Histogram1D data
Instance of Histogram1D that holds the "spectrum" (AKA the single value);.
size_t getNumDims() const override
Returns the number of dimensions, 0 in this case.
void generateHistogram(const std::size_t index, const MantidVec &X, MantidVec &Y, MantidVec &E, bool skipError=false) const override
Rebin the workspace. Not implemented for this workspace.
void init(const std::size_t &NVectors, const std::size_t &XLength, const std::size_t &YLength) override
Does nothing in this case.
The concrete, templated class for properties.
std::shared_ptr< WorkspaceSingleValue > WorkspaceSingleValue_sptr
shared pointer to the WorkspaceSingleValue class
std::shared_ptr< const WorkspaceSingleValue > WorkspaceSingleValue_const_sptr
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Definition: cow_ptr.h:172