-
Notifications
You must be signed in to change notification settings - Fork 122
/
WorkflowAlgorithmHelpers.cpp
156 lines (149 loc) · 5.43 KB
/
WorkflowAlgorithmHelpers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "MantidWorkflowAlgorithms/WorkflowAlgorithmHelpers.h"
using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid;
namespace WorkflowAlgorithmHelpers
{
/**
* This function tries to get a double value from a particular algorithm
* property. If that property is the default (EMPTY_DBL()), then the function
* tries to look up the parameter on the instrument in the given workspace
* for a given parameter name. If found, that value is returned. If not found,
* the default value (EMPTY_DBL()) is returned.
*
* @param pmProp : The name of the algorithm property to retrieve
* @param pm : The property manager pointer to retrieve a property value from
* @param instParam : The name of the instrument parameter to fetch from the workspace
* @param ws : A workspace that should house the alternate parameter
* @param overrideValue : A provided override value to hand back if nothing is found
* @return : Either the algorithm property or an instrument parameter.
*/
double getDblPropOrParam(const std::string &pmProp, Mantid::Kernel::PropertyManager_sptr &pm,
const std::string &instParam, Mantid::API::MatrixWorkspace_sptr &ws,
const double overrideValue)
{
double defaultValue = EMPTY_DBL();
double param = defaultValue;
if (pm->existsProperty(pmProp))
{
param = pm->getProperty(pmProp);
if (defaultValue == param)
{
std::vector<double> params = ws->getInstrument()->getNumberParameter(instParam);
if (!params.empty())
{
param = params[0];
}
}
}
else
{
std::vector<double> params = ws->getInstrument()->getNumberParameter(instParam);
if (!params.empty())
{
param = params[0];
}
}
if((defaultValue == param)&&(defaultValue!=overrideValue))
{
param = overrideValue;
}
return param;
}
/**
* This function tries to get an int value from a particular algorithm
* property. If that property is the default (EMPTY_INT()), then the function
* tries to look up the parameter on the instrument in the given workspace
* for a given parameter name. If found, that value is returned. If not found,
* the default value (EMPTY_INT()) is returned.
*
* @param pmProp : The name of the algorithm property to retrieve
* @param pm : The property manager pointer to retrieve a property value from
* @param instParam : The name of the instrument parameter to fetch from the workspace
* @param ws : A workspace that should house the alternate parameter
* @param overrideValue : A provided override value to hand back if nothing is found
* @return : Either the algorithm property or an instrument parameter.
*/
int getIntPropOrParam(const std::string &pmProp, Mantid::Kernel::PropertyManager_sptr &pm,
const std::string &instParam, Mantid::API::MatrixWorkspace_sptr &ws,
const int overrideValue)
{
int defaultValue = EMPTY_INT();
int param = defaultValue;
if (pm->existsProperty(pmProp))
{
param = pm->getProperty(pmProp);
if (defaultValue == param)
{
std::vector<int> params = ws->getInstrument()->getIntParameter(instParam);
if (!params.empty())
{
param = params[0];
}
}
}
else
{
std::vector<int> params = ws->getInstrument()->getIntParameter(instParam);
if (!params.empty())
{
param = params[0];
}
}
if((defaultValue == param)&&(defaultValue!=overrideValue))
{
param = overrideValue;
}
return param;
}
/**
* This function tries to get a boolean value from a particular algorithm
* property. If that property does not exist, then the function tries to look
* up the parameter on the instrument in the given workspace for a given
* parameter name. If found, that value is returned. If not found,
* the default value (false) is returned. If the property exists, just use
* the value provided.
*
* @param pmProp : The name of the algorithm property to retrieve
* @param pm : The property manager pointer to retrieve a property value from
* @param instParam : The name of the instrument parameter to fetch from the workspace
* @param ws : A workspace that should house the alternate parameter
* @param overrideValue : A provided override value to hand back if nothing is found
* @return : Either the algorithm property or an instrument parameter.
*/
bool getBoolPropOrParam(const std::string &pmProp, Mantid::Kernel::PropertyManager_sptr &pm,
const std::string &instParam, Mantid::API::MatrixWorkspace_sptr &ws,
const bool overrideValue)
{
bool defaultValue = false;
bool param = defaultValue;
if (pm->existsProperty(pmProp))
{
param = pm->getProperty(pmProp);
}
else
{
try
{
std::vector<bool> params = ws->getInstrument()->getBoolParameter(instParam);
if (!params.empty())
param = params[0];
else
param = false;
}
catch(std::runtime_error &) // Old style bool parameter expressed as double
{
std::vector<double> params = ws->getInstrument()->getNumberParameter(instParam);
if (!params.empty())
{
param = (params[0] != 0.0);
}
}
}
if((defaultValue == param)&&(defaultValue!=overrideValue))
{
param = overrideValue;
}
return param;
}
}