Mantid
Loading...
Searching...
No Matches
BoostOptionalToAlgorithmProperty.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 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
9namespace Mantid::API {
10template <>
11std::string checkForMandatoryInstrumentDefault(Mantid::API::Algorithm *const alg, const std::string &propName,
13 const std::string &idf_name) {
14 auto algProperty = alg->getPointerToProperty(propName);
15 if (algProperty->isDefault()) {
16 auto defaults = instrument->getStringParameter(idf_name);
17 if (defaults.empty()) {
18 throw std::runtime_error("No data could be retrieved from the parameters "
19 "and argument wasn't provided: " +
20 propName);
21 }
22 return defaults[0];
23 } else {
24 return algProperty->value();
25 }
26}
27
28template <>
29boost::optional<std::string>
30checkForOptionalInstrumentDefault(Mantid::API::Algorithm *const alg, const std::string &propName,
32 const std::string &idf_name) {
33 auto algProperty = alg->getPointerToProperty(propName);
34 if (algProperty->isDefault()) {
35 auto defaults = instrument->getStringParameter(idf_name);
36 if (!defaults.empty()) {
37 return boost::optional<std::string>(defaults[0]);
38 } else {
39 return boost::optional<std::string>();
40 }
41 } else {
42 return boost::optional<std::string>(algProperty->value());
43 }
44}
45} // namespace Mantid::API
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
Kernel::Property * getPointerToProperty(const std::string &name) const override
Get a property by name.
Definition: Algorithm.cpp:2033
T checkForMandatoryInstrumentDefault(Mantid::API::Algorithm *const alg, const std::string &propName, const Mantid::Geometry::Instrument_const_sptr &instrument, const std::string &idf_name)
BoostOptionalToAlgorithmProperty : Checks for default values of an algorithm property if the user has...
boost::optional< T > checkForOptionalInstrumentDefault(Mantid::API::Algorithm *const alg, const std::string &propName, const Mantid::Geometry::Instrument_const_sptr &instrument, const std::string &idf_name)
Checks for the default values of an optional algorithm property associated with an instrument compone...
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.