Skip to content

Commit 97d1b2c

Browse files
authored
DPL Analysis: fix for parsing non-integer arrays in configurables (#5035)
1 parent 6f421d5 commit 97d1b2c

File tree

4 files changed

+45
-42
lines changed

4 files changed

+45
-42
lines changed

Framework/Core/src/BoostOptionsRetriever.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void BoostOptionsRetriever::update(std::vector<ConfigParamSpec> const& specs,
6868
case VariantType::ArrayFloat:
6969
case VariantType::ArrayDouble:
7070
case VariantType::ArrayBool:
71-
options = options(name, bpo::value<std::string>()->multitoken()->default_value(spec.defaultValue.asString(), help));
71+
options = options(name, bpo::value<std::string>()->default_value(spec.defaultValue.asString(), help));
7272
break;
7373
case VariantType::Unknown:
7474
case VariantType::Empty:

Framework/Core/src/DataProcessingDevice.cxx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,14 @@ void DataProcessingDevice::Init()
250250
/// Dump the configuration so that we can get it from the driver.
251251
for (auto& entry : configStore->store()) {
252252
std::stringstream ss;
253+
std::string str;
253254
if (entry.second.size() != 0) {
254-
boost::property_tree::json_parser::write_json(ss, configStore->store().get_child(entry.first), false);
255+
boost::property_tree::json_parser::write_json(ss, entry.second, false);
256+
str = ss.str();
257+
str.pop_back(); //remove EoL
255258
} else {
256-
ss << configStore->store().get<std::string>(entry.first) << "\n";
259+
str = entry.second.get_value<std::string>();
257260
}
258-
auto str = ss.str();
259-
str.pop_back(); //remove EoL
260261
LOG(INFO) << "[CONFIG] " << entry.first << "=" << str << " 1 " << configStore->provenance(entry.first.c_str());
261262
}
262263

Framework/Core/src/PropertyTreeHelpers.cxx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
#include <boost/property_tree/ptree.hpp>
1616
#include <boost/program_options/variables_map.hpp>
17-
#include <boost/tokenizer.hpp>
1817
#include <boost/lexical_cast.hpp>
1918

2019
#include <vector>
2120
#include <string>
21+
#include <regex>
2222

2323
namespace o2::framework
2424
{
@@ -98,10 +98,11 @@ std::vector<T> toVector(std::string const& input)
9898
std::vector<T> result;
9999
//check if the array string has correct array type symbol
100100
assert(input[0] == variant_array_symbol<T>::symbol);
101-
//strip type symbol and parentheses
102-
boost::tokenizer<> tokenizer(input.substr(2, input.size() - 3));
103-
for (auto it = tokenizer.begin(); it != tokenizer.end(); ++it) {
104-
result.push_back(boost::lexical_cast<T>(*it));
101+
std::regex nmatch(R"((?:(?!=,)|(?!=\[))[+-]?\d+\.?\d*(?:[eE][+-]?\d+)?(?=,|\]))", std::regex_constants::ECMAScript);
102+
auto end = std::sregex_iterator();
103+
auto values = std::sregex_iterator(input.begin(), input.end(), nmatch);
104+
for (auto v = values; v != end; ++v) {
105+
result.push_back(boost::lexical_cast<T>(v->str()));
105106
}
106107
return result;
107108
}

Framework/Core/src/RootConfigParamHelpers.cxx

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ void ptreeToMember(boost::property_tree::ptree const& value,
101101
TDataMember* dm,
102102
void* ptr)
103103
{
104+
105+
if (dm->IsSTLContainer()) {
106+
auto type = dm->GetTypeName();
107+
switch (compile_time_hash(type)) {
108+
case compile_time_hash("vector<int>"):
109+
*static_cast<std::vector<int>*>(ptr) = extractVector<int>(value);
110+
return;
111+
case compile_time_hash("vector<float>"):
112+
*static_cast<std::vector<float>*>(ptr) = extractVector<float>(value);
113+
return;
114+
case compile_time_hash("vector<double>"):
115+
*static_cast<std::vector<double>*>(ptr) = extractVector<double>(value);
116+
return;
117+
case compile_time_hash("vector<bool>"):
118+
default:
119+
throw std::runtime_error("Not and int/float/double/bool vector");
120+
}
121+
}
104122
auto dt = dm->GetDataType();
105123
if (dt != nullptr) {
106124
switch (dt->GetType()) {
@@ -165,33 +183,32 @@ void ptreeToMember(boost::property_tree::ptree const& value,
165183
}
166184
}
167185
}
186+
// if we get here none of the above worked
187+
if (strcmp(tname, "string") == 0 || strcmp(tname, "std::string")) {
188+
*(std::string*)ptr = value.get_value<std::string>();
189+
}
190+
throw std::runtime_error("Unable to override value");
191+
}
192+
193+
// Convert a DataMember to a ConfigParamSpec
194+
ConfigParamSpec memberToConfigParamSpec(const char* tname, TDataMember* dm, void* ptr)
195+
{
168196
if (dm->IsSTLContainer()) {
169197
auto type = dm->GetTypeName();
170198
switch (compile_time_hash(type)) {
171199
case compile_time_hash("vector<int>"):
172-
*static_cast<std::vector<int>*>(ptr) = extractVector<int>(value);
173-
return;
200+
return ConfigParamSpec{tname, VariantType::ArrayInt, *static_cast<std::vector<int>*>(ptr), {"No help"}};
174201
case compile_time_hash("vector<float>"):
175-
*static_cast<std::vector<float>*>(ptr) = extractVector<float>(value);
176-
return;
202+
return ConfigParamSpec{tname, VariantType::ArrayFloat, *static_cast<std::vector<float>*>(ptr), {"No help"}};
177203
case compile_time_hash("vector<double>"):
178-
*static_cast<std::vector<double>*>(ptr) = extractVector<double>(value);
179-
return;
204+
return ConfigParamSpec{tname, VariantType::ArrayDouble, *static_cast<std::vector<double>*>(ptr), {"No help"}};
180205
case compile_time_hash("vector<bool>"):
206+
throw std::runtime_error("bool vector not supported yet");
207+
// return ConfigParamSpec{tname, VariantType::ArrayBool, *static_cast<std::vector<bool>*>(ptr), {"No help"}};
181208
default:
182209
throw std::runtime_error("Not and int/float/double/bool vector");
183210
}
184211
}
185-
// if we get here none of the above worked
186-
if (strcmp(tname, "string") == 0 || strcmp(tname, "std::string")) {
187-
*(std::string*)ptr = value.get_value<std::string>();
188-
}
189-
throw std::runtime_error("Unable to override value");
190-
}
191-
192-
// Convert a DataMember to a ConfigParamSpec
193-
ConfigParamSpec memberToConfigParamSpec(const char* tname, TDataMember* dm, void* ptr)
194-
{
195212
auto dt = dm->GetDataType();
196213
if (dt != nullptr) {
197214
switch (dt->GetType()) {
@@ -242,22 +259,6 @@ ConfigParamSpec memberToConfigParamSpec(const char* tname, TDataMember* dm, void
242259
}
243260
}
244261
}
245-
if (dm->IsSTLContainer()) {
246-
auto type = dm->GetTypeName();
247-
switch (compile_time_hash(type)) {
248-
case compile_time_hash("vector<int>"):
249-
return ConfigParamSpec{tname, VariantType::ArrayInt, *static_cast<std::vector<int>*>(ptr), {"No help"}};
250-
case compile_time_hash("vector<float>"):
251-
return ConfigParamSpec{tname, VariantType::ArrayFloat, *static_cast<std::vector<float>*>(ptr), {"No help"}};
252-
case compile_time_hash("vector<double>"):
253-
return ConfigParamSpec{tname, VariantType::ArrayDouble, *static_cast<std::vector<double>*>(ptr), {"No help"}};
254-
case compile_time_hash("vector<bool>"):
255-
throw std::runtime_error("bool vector not supported yet");
256-
// return ConfigParamSpec{tname, VariantType::ArrayBool, *static_cast<std::vector<bool>*>(ptr), {"No help"}};
257-
default:
258-
throw std::runtime_error("Not and int/float/double/bool vector");
259-
}
260-
}
261262
// if we get here none of the above worked
262263
if (strcmp(tname, "string") == 0 || strcmp(tname, "std::string")) {
263264
return ConfigParamSpec{tname, VariantType::String, *(std::string*)ptr, {"No help"}};

0 commit comments

Comments
 (0)