Mantid
Loading...
Searching...
No Matches
WorkflowAlgorithmHelpers.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
11
12using namespace Mantid::API;
13using namespace Mantid::Kernel;
14using namespace Mantid;
15
33double getDblPropOrParam(const std::string &pmProp, Mantid::Kernel::PropertyManager_sptr &pm,
34 const std::string &instParam, Mantid::API::MatrixWorkspace_sptr &ws,
35 const double overrideValue) {
36 double defaultValue = EMPTY_DBL();
37 double param = defaultValue;
38 if (pm->existsProperty(pmProp)) {
39 param = pm->getProperty(pmProp);
40 if (defaultValue == param) {
41 std::vector<double> params = ws->getInstrument()->getNumberParameter(instParam);
42 if (!params.empty()) {
43 param = params[0];
44 }
45 }
46 } else {
47 std::vector<double> params = ws->getInstrument()->getNumberParameter(instParam);
48 if (!params.empty()) {
49 param = params[0];
50 }
51 }
52 if ((defaultValue == param) && (defaultValue != overrideValue)) {
53 param = overrideValue;
54 }
55 return param;
56}
57
74int getIntPropOrParam(const std::string &pmProp, Mantid::Kernel::PropertyManager_sptr &pm, const std::string &instParam,
75 Mantid::API::MatrixWorkspace_sptr &ws, const int overrideValue) {
76 int defaultValue = EMPTY_INT();
77 int param = defaultValue;
78 if (pm->existsProperty(pmProp)) {
79 param = pm->getProperty(pmProp);
80 if (defaultValue == param) {
81 std::vector<int> params = ws->getInstrument()->getIntParameter(instParam);
82 if (!params.empty()) {
83 param = params[0];
84 }
85 }
86 } else {
87 std::vector<int> params = ws->getInstrument()->getIntParameter(instParam);
88 if (!params.empty()) {
89 param = params[0];
90 }
91 }
92 if ((defaultValue == param) && (defaultValue != overrideValue)) {
93 param = overrideValue;
94 }
95 return param;
96}
97
116 const std::string &instParam, Mantid::API::MatrixWorkspace_sptr &ws, const bool overrideValue) {
117 bool defaultValue = false;
118 bool param = defaultValue;
119 if (pm->existsProperty(pmProp)) {
120 param = pm->getProperty(pmProp);
121 } else {
122 try {
123 std::vector<bool> params = ws->getInstrument()->getBoolParameter(instParam);
124 if (!params.empty())
125 param = params[0];
126 else
127 param = false;
128 } catch (std::runtime_error &) // Old style bool parameter expressed as double
129 {
130 std::vector<double> params = ws->getInstrument()->getNumberParameter(instParam);
131 if (!params.empty()) {
132 param = (params[0] != 0.0);
133 }
134 }
135 }
136 if ((defaultValue == param) && (defaultValue != overrideValue)) {
137 param = overrideValue;
138 }
139 return param;
140}
141} // namespace WorkflowAlgorithmHelpers
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< PropertyManager > PropertyManager_sptr
Typedef for a shared pointer to a PropertyManager.
Helper class which provides the Collimation Length for SANS instruments.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
Definition: EmptyValues.h:25
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
Definition: EmptyValues.h:43
int getIntPropOrParam(const std::string &pmProp, Mantid::Kernel::PropertyManager_sptr &pm, const std::string &instParam, Mantid::API::MatrixWorkspace_sptr &ws, const int overrideValue=Mantid::EMPTY_INT())
Function to get int property or instrument parameter value.
bool getBoolPropOrParam(const std::string &pmProp, Mantid::Kernel::PropertyManager_sptr &pm, const std::string &instParam, Mantid::API::MatrixWorkspace_sptr &ws, const bool overrideValue=false)
Function to get boolean property or instrument parameter value.
double getDblPropOrParam(const std::string &pmProp, Mantid::Kernel::PropertyManager_sptr &pm, const std::string &instParam, Mantid::API::MatrixWorkspace_sptr &ws, const double overrideValue=Mantid::EMPTY_DBL())
Function to get double property or instrument parameter value.