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
21 initialize(1, 1, 1);
22 // Set the "histogram" to the single value
23 data.dataX().resize(1, 0.0);
24 data.setCounts(1, value);
25 data.setCountStandardDeviations(1, error);
26 data.setPointStandardDeviations(1, 0.0);
27 setDistribution(true);
28 // Add a set of axes to the workspace
29 m_axes.resize(2);
30 m_axes[0] = std::make_unique<API::RefAxis>(this);
31 m_axes[1] = std::make_unique<API::SpectraAxis>(this);
32}
33
35 : HistoWorkspace(other), data(other.data) {
36 setDistribution(true);
37}
38
45void WorkspaceSingleValue::init(const std::size_t &NVectors, const std::size_t &XLength, const std::size_t &YLength) {
46 (void)NVectors;
47 (void)XLength;
48 (void)YLength; // Avoid compiler warning
49}
50
51void WorkspaceSingleValue::init(const HistogramData::Histogram &histogram) { UNUSED_ARG(histogram); }
52
58
61 bool skipError) const {
65 UNUSED_ARG(E);
66 UNUSED_ARG(skipError);
67 throw std::runtime_error("generateHistogram() not implemented for WorkspaceSingleValue.");
68}
69
71size_t WorkspaceSingleValue::getNumDims() const { return 0; }
72
73} // namespace Mantid::DataObjects
74
75namespace Mantid::Kernel {
76template <>
78IPropertyManager::getValue<Mantid::DataObjects::WorkspaceSingleValue_sptr>(const std::string &name) const {
79 auto *prop =
81 if (prop) {
82 return *prop;
83 } else {
84 std::string message =
85 "Attempt to assign property " + name + " to incorrect type. Expected shared_ptr<WorkspaceSingleValue>.";
86 throw std::runtime_error(message);
87 }
88}
89
90template <>
92IPropertyManager::getValue<Mantid::DataObjects::WorkspaceSingleValue_const_sptr>(const std::string &name) const {
93 const auto *prop =
95 if (prop) {
96 return prop->operator()();
97 } else {
98 std::string message =
99 "Attempt to assign property " + name + " to incorrect type. Expected const shared_ptr<WorkspaceSingleValue>.";
100 throw std::runtime_error(message);
101 }
102}
103
104} // namespace Mantid::Kernel
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
double error
std::map< DeltaEMode::Type, std::string > index
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition System.h:37
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition System.h:48
#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).
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)
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