19#include <boost/algorithm/string.hpp>
27using namespace Kernel;
28using namespace Geometry;
48 std::make_shared<InstrumentValidator>()),
49 "Workspace to add the log entry to");
51 "The name of the component to attach "
52 "the parameter to. Default: the whole "
55 "The detector ID list to attach the parameter to. If set "
56 "this will override any ComponentName");
58 "The name that will identify the parameter");
60 std::vector<std::string> propOptions{
"String",
"Number",
"Bool"};
61 declareProperty(
"ParameterType",
"String", std::make_shared<StringListValidator>(propOptions),
62 "The type that the parameter value will be.");
69 std::map<std::string, std::string> errors;
70 const std::set<std::string> allowedBoolValues{
"1",
"0",
"true",
"false"};
75 boost::algorithm::to_lower(val);
76 if (allowedBoolValues.find(val) == allowedBoolValues.end()) {
77 errors[
"Value"] =
"Invalid value for Bool type.";
79 }
else if (type ==
"Number") {
83 errors[
"Value"] =
"Invalid value for Number type.";
100 experimentInfo = inputW;
102 experimentInfo = inputP;
104 throw std::runtime_error(
"Could not get a valid instrument from the "
105 "workspace which does not seem to be valid as "
106 "input (must be either MatrixWorkspace or "
109 auto &componentInfo = experimentInfo->mutableComponentInfo();
112 std::string cmptName =
getProperty(
"ComponentName");
114 std::string paramName =
getProperty(
"ParameterName");
115 std::string paramType =
getProperty(
"ParameterType");
123 std::vector<size_t> componentIndices{componentInfo.root()};
125 const auto &detectorInfo = experimentInfo->detectorInfo();
126 componentIndices.clear();
130 componentIndices.emplace_back(detectorInfo.indexOf(detID));
131 }
catch (
const std::out_of_range &) {
136 }
else if (cmptName.length() > 0) {
141 if (componentIndices.empty()) {
142 g_log.
warning(
"Could not find the component requested.");
144 for (
const auto componentIndex : componentIndices) {
145 addParameter(componentInfo, componentIndex, paramName, paramType, paramValue);
156 const std::string &
name) {
157 std::vector<size_t> matches;
158 const auto root = componentInfo.
root();
159 if (componentInfo.
name(root) ==
name) {
160 matches.emplace_back(root);
162 std::deque<size_t> toSearch{root};
163 while (!toSearch.empty()) {
164 const auto index = toSearch.front();
165 toSearch.pop_front();
167 if (componentInfo.
name(child) ==
name) {
168 matches.emplace_back(child);
170 toSearch.emplace_back(child);
185 const std::string ¶mName,
const std::string ¶mType,
186 const std::string ¶mValue)
const {
191 if (paramType ==
"String") {
192 componentInfo.
addString(componentIndex, paramName, paramValue);
193 }
else if (paramType ==
"Number") {
196 componentInfo.
addInt(componentIndex, paramName, intVal);
200 componentInfo.
addDouble(componentIndex, paramName, dblVal);
202 }
else if (paramType ==
"Bool") {
203 std::string paramValueLower(paramValue);
204 boost::algorithm::to_lower(paramValueLower);
205 bool paramBoolValue = (paramValueLower ==
"true" || paramValue ==
"1");
206 componentInfo.
addBool(componentIndex, paramName, paramBoolValue);
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
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.
static std::vector< size_t > componentsWithName(const Mantid::Geometry::ComponentInfo &componentInfo, const std::string &name)
The components with the given name, as Instrument::getAllComponentsWithName() finds them: in breadth-...
void addParameter(Mantid::Geometry::ComponentInfo &componentInfo, const size_t componentIndex, const std::string ¶mName, const std::string ¶mType, const std::string ¶mValue) const
Adds a parameter to the component.
void init() override
Initialize the algorithm's properties.
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.
ComponentInfo : Provides a component centric view on to the instrument.
void clearParameter(const size_t componentIndex, const std::string &name)
Remove every parameter of this name from this component.
const std::vector< size_t > & children(size_t componentIndex) const
void addString(const size_t componentIndex, const std::string &name, const std::string &value, const std::string *const pDescription=nullptr, const std::string &pVisible="true")
Add or replace a named string parameter at a specific component index.
void addInt(const size_t componentIndex, const std::string &name, int value, const std::string *const pDescription=nullptr, const std::string &pVisible="true")
Add or replace a named integer parameter at a specific component index.
const std::string & name(const size_t componentIndex) const
void addDouble(const size_t componentIndex, const std::string &name, double value, const std::string *const pDescription=nullptr, const std::string &pVisible="true")
Add or replace a named double parameter at a specific component index.
void addBool(const size_t componentIndex, const std::string &name, bool value, const std::string *const pDescription=nullptr, const std::string &pVisible="true")
Add or replace a named boolean parameter at a specific component index.
Support for a property that holds an array of values.
Exception for when an item is not found in a collection.
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< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
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.
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.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ InOut
Both an input & output workspace.