Skip to content

Commit

Permalink
DPL Analysis: fix for parsing non-integer arrays in configurables (#5035
Browse files Browse the repository at this point in the history
)
  • Loading branch information
aalkin committed Dec 14, 2020
1 parent 6f421d5 commit 97d1b2c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Framework/Core/src/BoostOptionsRetriever.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void BoostOptionsRetriever::update(std::vector<ConfigParamSpec> const& specs,
case VariantType::ArrayFloat:
case VariantType::ArrayDouble:
case VariantType::ArrayBool:
options = options(name, bpo::value<std::string>()->multitoken()->default_value(spec.defaultValue.asString(), help));
options = options(name, bpo::value<std::string>()->default_value(spec.defaultValue.asString(), help));
break;
case VariantType::Unknown:
case VariantType::Empty:
Expand Down
9 changes: 5 additions & 4 deletions Framework/Core/src/DataProcessingDevice.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,14 @@ void DataProcessingDevice::Init()
/// Dump the configuration so that we can get it from the driver.
for (auto& entry : configStore->store()) {
std::stringstream ss;
std::string str;
if (entry.second.size() != 0) {
boost::property_tree::json_parser::write_json(ss, configStore->store().get_child(entry.first), false);
boost::property_tree::json_parser::write_json(ss, entry.second, false);
str = ss.str();
str.pop_back(); //remove EoL
} else {
ss << configStore->store().get<std::string>(entry.first) << "\n";
str = entry.second.get_value<std::string>();
}
auto str = ss.str();
str.pop_back(); //remove EoL
LOG(INFO) << "[CONFIG] " << entry.first << "=" << str << " 1 " << configStore->provenance(entry.first.c_str());
}

Expand Down
11 changes: 6 additions & 5 deletions Framework/Core/src/PropertyTreeHelpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

#include <boost/property_tree/ptree.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>

#include <vector>
#include <string>
#include <regex>

namespace o2::framework
{
Expand Down Expand Up @@ -98,10 +98,11 @@ std::vector<T> toVector(std::string const& input)
std::vector<T> result;
//check if the array string has correct array type symbol
assert(input[0] == variant_array_symbol<T>::symbol);
//strip type symbol and parentheses
boost::tokenizer<> tokenizer(input.substr(2, input.size() - 3));
for (auto it = tokenizer.begin(); it != tokenizer.end(); ++it) {
result.push_back(boost::lexical_cast<T>(*it));
std::regex nmatch(R"((?:(?!=,)|(?!=\[))[+-]?\d+\.?\d*(?:[eE][+-]?\d+)?(?=,|\]))", std::regex_constants::ECMAScript);
auto end = std::sregex_iterator();
auto values = std::sregex_iterator(input.begin(), input.end(), nmatch);
for (auto v = values; v != end; ++v) {
result.push_back(boost::lexical_cast<T>(v->str()));
}
return result;
}
Expand Down
65 changes: 33 additions & 32 deletions Framework/Core/src/RootConfigParamHelpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ void ptreeToMember(boost::property_tree::ptree const& value,
TDataMember* dm,
void* ptr)
{

if (dm->IsSTLContainer()) {
auto type = dm->GetTypeName();
switch (compile_time_hash(type)) {
case compile_time_hash("vector<int>"):
*static_cast<std::vector<int>*>(ptr) = extractVector<int>(value);
return;
case compile_time_hash("vector<float>"):
*static_cast<std::vector<float>*>(ptr) = extractVector<float>(value);
return;
case compile_time_hash("vector<double>"):
*static_cast<std::vector<double>*>(ptr) = extractVector<double>(value);
return;
case compile_time_hash("vector<bool>"):
default:
throw std::runtime_error("Not and int/float/double/bool vector");
}
}
auto dt = dm->GetDataType();
if (dt != nullptr) {
switch (dt->GetType()) {
Expand Down Expand Up @@ -165,33 +183,32 @@ void ptreeToMember(boost::property_tree::ptree const& value,
}
}
}
// if we get here none of the above worked
if (strcmp(tname, "string") == 0 || strcmp(tname, "std::string")) {
*(std::string*)ptr = value.get_value<std::string>();
}
throw std::runtime_error("Unable to override value");
}

// Convert a DataMember to a ConfigParamSpec
ConfigParamSpec memberToConfigParamSpec(const char* tname, TDataMember* dm, void* ptr)
{
if (dm->IsSTLContainer()) {
auto type = dm->GetTypeName();
switch (compile_time_hash(type)) {
case compile_time_hash("vector<int>"):
*static_cast<std::vector<int>*>(ptr) = extractVector<int>(value);
return;
return ConfigParamSpec{tname, VariantType::ArrayInt, *static_cast<std::vector<int>*>(ptr), {"No help"}};
case compile_time_hash("vector<float>"):
*static_cast<std::vector<float>*>(ptr) = extractVector<float>(value);
return;
return ConfigParamSpec{tname, VariantType::ArrayFloat, *static_cast<std::vector<float>*>(ptr), {"No help"}};
case compile_time_hash("vector<double>"):
*static_cast<std::vector<double>*>(ptr) = extractVector<double>(value);
return;
return ConfigParamSpec{tname, VariantType::ArrayDouble, *static_cast<std::vector<double>*>(ptr), {"No help"}};
case compile_time_hash("vector<bool>"):
throw std::runtime_error("bool vector not supported yet");
// return ConfigParamSpec{tname, VariantType::ArrayBool, *static_cast<std::vector<bool>*>(ptr), {"No help"}};
default:
throw std::runtime_error("Not and int/float/double/bool vector");
}
}
// if we get here none of the above worked
if (strcmp(tname, "string") == 0 || strcmp(tname, "std::string")) {
*(std::string*)ptr = value.get_value<std::string>();
}
throw std::runtime_error("Unable to override value");
}

// Convert a DataMember to a ConfigParamSpec
ConfigParamSpec memberToConfigParamSpec(const char* tname, TDataMember* dm, void* ptr)
{
auto dt = dm->GetDataType();
if (dt != nullptr) {
switch (dt->GetType()) {
Expand Down Expand Up @@ -242,22 +259,6 @@ ConfigParamSpec memberToConfigParamSpec(const char* tname, TDataMember* dm, void
}
}
}
if (dm->IsSTLContainer()) {
auto type = dm->GetTypeName();
switch (compile_time_hash(type)) {
case compile_time_hash("vector<int>"):
return ConfigParamSpec{tname, VariantType::ArrayInt, *static_cast<std::vector<int>*>(ptr), {"No help"}};
case compile_time_hash("vector<float>"):
return ConfigParamSpec{tname, VariantType::ArrayFloat, *static_cast<std::vector<float>*>(ptr), {"No help"}};
case compile_time_hash("vector<double>"):
return ConfigParamSpec{tname, VariantType::ArrayDouble, *static_cast<std::vector<double>*>(ptr), {"No help"}};
case compile_time_hash("vector<bool>"):
throw std::runtime_error("bool vector not supported yet");
// return ConfigParamSpec{tname, VariantType::ArrayBool, *static_cast<std::vector<bool>*>(ptr), {"No help"}};
default:
throw std::runtime_error("Not and int/float/double/bool vector");
}
}
// if we get here none of the above worked
if (strcmp(tname, "string") == 0 || strcmp(tname, "std::string")) {
return ConfigParamSpec{tname, VariantType::String, *(std::string*)ptr, {"No help"}};
Expand Down

0 comments on commit 97d1b2c

Please sign in to comment.