11 #include <framework/gearbox/Interface.h>
12 #include <framework/gearbox/GearDir.h>
13 #include <framework/gearbox/Unit.h>
14 #include <framework/logging/Logger.h>
16 #include <boost/lexical_cast.hpp>
17 #include <boost/tokenizer.hpp>
18 #include <boost/algorithm/string.hpp>
19 #include <boost/format.hpp>
21 namespace Belle2::gearbox {
26 std::vector<GearDir> result;
28 for (
int i = 1; i <= size; ++i) {
29 result.emplace_back(*
this, path, i);
38 }
catch (PathEmptyError&) {
45 std::string value = getString(path);
47 return boost::lexical_cast<double>(value);
48 }
catch (boost::bad_lexical_cast&) {
49 throw ConversionError() << path << value;
56 return getDouble(path);
57 }
catch (PathEmptyError&) {
64 std::string value = getString(path);
67 return boost::lexical_cast<int>(value);
68 }
catch (boost::bad_lexical_cast&) {
69 throw ConversionError() << path << value;
73 int Interface::getInt(
const std::string& path,
int defaultValue)
const noexcept(
false)
77 }
catch (PathEmptyError&) {
84 std::string value = getString(path);
85 boost::to_lower(value);
86 if (value.empty() || value ==
"false" || value ==
"off" || value ==
"0")
return false;
94 }
catch (PathEmptyError&) {
101 std::pair<std::string, std::string> value = getStringWithUnit(path);
104 numValue = boost::lexical_cast<double>(value.first);
105 }
catch (boost::bad_lexical_cast&) {
106 throw ConversionError() << path << value.first;
108 if (value.second.empty()) {
109 B2WARNING(
"Requested unit conversion for parameter '" << path <<
"' but no unit found");
119 return getWithUnit(path);
120 }
catch (PathEmptyError&) {
127 using tokenizer = boost::tokenizer<boost::char_separator<char> >;
128 boost::char_separator<char> sep(
",; \t\n\r");
130 std::pair<std::string, std::string> value = getStringWithUnit(path);
131 tokenizer tokens(value.first, sep);
132 std::vector<double> result;
134 for (
const std::string& tok : tokens) {
136 numValue = boost::lexical_cast<double>(tok);
137 }
catch (boost::bad_lexical_cast&) {
138 throw (ConversionError() << path << value.first);
140 if (!value.second.empty()) {
143 result.push_back(numValue);
148 std::vector<double>
Interface::getArray(
const std::string& path,
const std::vector<double>& defaultValue)
const noexcept(
false)
151 return getArray(path);
152 }
catch (PathEmptyError&) {
160 return boost::trim_right_copy_if(path, boost::is_any_of(
"/"));
170 static boost::format index_fmt(
"%1%[%2%]");
176 return ensurePath(path) + boost::trim_left_copy_if(subpath, boost::is_any_of(
"/"));