17#include <boost/algorithm/string.hpp>
24using namespace Kernel;
25using namespace Geometry;
45 std::make_shared<InstrumentValidator>()),
46 "Workspace to add the log entry to");
48 "The name of the component to attach "
49 "the parameter to. Default: the whole "
52 "The detector ID list to attach the parameter to. If set "
53 "this will override any ComponentName");
55 "The name that will identify the parameter");
57 std::vector<std::string> propOptions{
"String",
"Number",
"Bool"};
58 declareProperty(
"ParameterType",
"String", std::make_shared<StringListValidator>(propOptions),
59 "The type that the parameter value will be.");
66 std::map<std::string, std::string> errors;
67 const std::set<std::string> allowedBoolValues{
"1",
"0",
"true",
"false"};
72 boost::algorithm::to_lower(val);
73 if (allowedBoolValues.find(val) == allowedBoolValues.end()) {
74 errors[
"Value"] =
"Invalid value for Bool type.";
76 }
else if (type ==
"Number") {
80 errors[
"Value"] =
"Invalid value for Number type.";
98 inst = std::const_pointer_cast<Instrument>(inputW->getInstrument());
100 throw std::runtime_error(
"Could not get a valid instrument from the "
101 "MatrixWorkspace provided as input");
103 inst = std::const_pointer_cast<Instrument>(inputP->getInstrument());
105 throw std::runtime_error(
"Could not get a valid instrument from the "
106 "PeaksWorkspace provided as input");
108 throw std::runtime_error(
"Could not get a valid instrument from the "
109 "workspace which does not seem to be valid as "
110 "input (must be either MatrixWorkspace or "
115 std::string cmptName =
getProperty(
"ComponentName");
117 std::string paramName =
getProperty(
"ParameterName");
118 std::string paramType =
getProperty(
"ParameterType");
125 std::vector<IDetector_const_sptr> dets;
126 std::vector<IComponent_const_sptr> cmptList;
128 cmptList.emplace_back(inst);
132 }
else if (cmptName.length() > 0) {
134 cmptList = inst->getAllComponentsWithName(cmptName);
138 auto ¶mMap = inputW->instrumentParameters();
140 for (
auto &det : dets) {
141 addParameter(paramMap, det.get(), paramName, paramType, paramValue);
144 if (!cmptList.empty()) {
145 for (
auto &cmpt : cmptList) {
146 addParameter(paramMap, cmpt.get(), paramName, paramType, paramValue);
149 g_log.
warning(
"Could not find the component requested.");
154 auto ¶mMap = inputP->instrumentParameters();
156 for (
auto &det : dets) {
157 addParameter(paramMap, det.get(), paramName, paramType, paramValue);
160 if (!cmptList.empty()) {
161 for (
auto &cmpt : cmptList) {
162 addParameter(paramMap, cmpt.get(), paramName, paramType, paramValue);
165 g_log.
warning(
"Could not find the component requested.");
180 const std::string ¶mType,
const std::string ¶mValue)
const {
183 pmap.clearParametersByName(paramName, cmptId);
185 if (paramType ==
"String") {
186 pmap.addString(cmptId, paramName, paramValue);
187 }
else if (paramType ==
"Number") {
190 pmap.addInt(cmptId, paramName, intVal);
194 pmap.addDouble(cmptId, paramName, dblVal);
196 }
else if (paramType ==
"Bool") {
197 std::string paramValueLower(paramValue);
198 boost::algorithm::to_lower(paramValueLower);
199 bool paramBoolValue = (paramValueLower ==
"true" || paramValue ==
"1");
200 pmap.addBool(cmptId, paramName, paramBoolValue);
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
A property class for workspaces.
void exec() override
Execute the algorithm.
const std::string category() const override
Algorithm's category for identification.
int version() const override
Algorithm's version for identification.
void init() override
Initialize the algorithm's properties.
void addParameter(Mantid::Geometry::ParameterMap &pmap, const Mantid::Geometry::IComponent *cmptId, const std::string ¶mName, const std::string ¶mType, const std::string ¶mValue) const
Adds a parameter to the component.
std::map< std::string, std::string > validateInputs() override
Perform validation of ALL the input properties of the algorithm.
const std::string name() const override
Algorithm's name for identification.
base class for Geometric IComponent
Support for a property that holds an array of values.
void warning(const std::string &msg)
Logs at warning level.
Validator to check that a property is not left empty.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< Instrument > Instrument_sptr
Shared pointer to an instrument object.
MANTID_KERNEL_DLL std::string strip(const std::string &A)
strip pre/post spaces
int convert(const std::string &A, T &out)
Convert a string into a number.
Generate a tableworkspace to store the calibration results.
@ InOut
Both an input & output workspace.