Skip to content

Commit 05bb51b

Browse files
committed
DPL: print an error when the configuration is not parsed correctly
This should probably be a fatal error not sure why the rethrown exception is ignored (and where).
1 parent d56b3e9 commit 05bb51b

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

Framework/Core/src/PropertyTreeHelpers.cxx

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
#include "Framework/VariantPropertyTreeHelpers.h"
1515
#include "Framework/RuntimeError.h"
1616
#include "Framework/VariantJSONHelpers.h"
17+
#include "Framework/Signpost.h"
1718

1819
#include <boost/program_options/variables_map.hpp>
1920

2021
#include <vector>
2122
#include <string>
2223

24+
O2_DECLARE_DYNAMIC_LOG(configuration);
25+
2326
namespace o2::framework
2427
{
2528
namespace
@@ -37,6 +40,9 @@ void PropertyTreeHelpers::populateDefaults(std::vector<ConfigParamSpec> const& s
3740
boost::property_tree::ptree& pt,
3841
boost::property_tree::ptree& provenance)
3942
{
43+
O2_LOG_ENABLE(configuration);
44+
O2_SIGNPOST_ID_GENERATE(cid, configuration);
45+
O2_SIGNPOST_START(configuration, cid, "populateDefaults", "Filling with defaults");
4046
for (auto const& spec : schema) {
4147
std::string key = spec.name.substr(0, spec.name.find(','));
4248
try {
@@ -77,9 +83,12 @@ void PropertyTreeHelpers::populateDefaults(std::vector<ConfigParamSpec> const& s
7783
case VariantType::String:
7884
pt.put(key, spec.defaultValue.get<std::string>());
7985
break;
80-
case VariantType::Bool:
81-
pt.put(key, spec.defaultValue.get<bool>());
86+
case VariantType::Bool: {
87+
bool value = spec.defaultValue.get<bool>();
88+
O2_SIGNPOST_EVENT_EMIT(configuration, cid, "populateDefaults", "Setting %{public}s: %{public}s", key.c_str(), value ? "true" : "false");
89+
pt.put(key, value);
8290
break;
91+
}
8392
case VariantType::Dict:
8493
pt.put_child(key, boost::property_tree::ptree{});
8594
break;
@@ -126,20 +135,27 @@ void PropertyTreeHelpers::populateDefaults(std::vector<ConfigParamSpec> const& s
126135
}
127136
provenance.put(key, "default");
128137
} catch (std::runtime_error& re) {
138+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populateDefaults", "Aborting because of runtime_error %{public}s", re.what());
129139
throw;
130140
} catch (std::exception& e) {
141+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populateDefaults", "Missing option %{public}s (%{public}s)", key.c_str(), e.what());
131142
throw std::invalid_argument(std::string("missing option: ") + key + " (" + e.what() + ")");
132143
} catch (...) {
144+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populateDefaults", "Aborting because of missing option %{public}s", key.c_str());
133145
throw std::invalid_argument(std::string("missing option: ") + key);
134146
}
135147
}
148+
O2_SIGNPOST_END(configuration, cid, "populateDefaults", "Done");
136149
}
137150

138151
void PropertyTreeHelpers::populate(std::vector<ConfigParamSpec> const& schema,
139152
boost::property_tree::ptree& pt,
140153
boost::program_options::variables_map const& vmap,
141154
boost::property_tree::ptree& provenance)
142155
{
156+
O2_LOG_ENABLE(configuration);
157+
O2_SIGNPOST_ID_GENERATE(cid, configuration);
158+
O2_SIGNPOST_START(configuration, cid, "populate", "Filling parameters from variables_map");
143159
for (auto const& spec : schema) {
144160
// strip short version to get the correct key
145161
std::string key = spec.name.substr(0, spec.name.find(','));
@@ -183,9 +199,11 @@ void PropertyTreeHelpers::populate(std::vector<ConfigParamSpec> const& schema,
183199
pt.put(key, *v);
184200
}
185201
break;
186-
case VariantType::Bool:
187-
pt.put(key, vmap[key].as<bool>());
188-
break;
202+
case VariantType::Bool: {
203+
auto v = vmap[key].as<bool>();
204+
O2_SIGNPOST_EVENT_EMIT(configuration, cid, "populate", "Setting %{public}s: %{public}s", key.c_str(), v ? "true" : "false");
205+
pt.put(key, v);
206+
} break;
189207
case VariantType::ArrayInt: {
190208
auto v = fromString<VariantType::ArrayInt>(vmap[key].as<std::string>());
191209
pt.put_child(key, vectorToBranch<int>(v.get<int*>(), v.size()));
@@ -243,13 +261,17 @@ void PropertyTreeHelpers::populate(std::vector<ConfigParamSpec> const& schema,
243261
}
244262
provenance.put(key, "fairmq");
245263
} catch (std::runtime_error& re) {
264+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populate", "Aborting because of runtime_error %{public}s", re.what());
246265
throw;
247266
} catch (std::exception& e) {
267+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populate", "Missing option %{public}s (%{public}s)", key.c_str(), e.what());
248268
throw std::invalid_argument(std::string("missing option: ") + key + " (" + e.what() + ")");
249269
} catch (...) {
270+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populate", "Aborting because of missing option %{public}s", key.c_str());
250271
throw std::invalid_argument(std::string("missing option: ") + key);
251272
}
252273
}
274+
O2_SIGNPOST_END(configuration, cid, "populate", "Done");
253275
}
254276

255277
template <typename T>
@@ -273,6 +295,9 @@ void PropertyTreeHelpers::populate(std::vector<ConfigParamSpec> const& schema,
273295
boost::property_tree::ptree& provenance,
274296
std::string const& provenanceLabel)
275297
{
298+
O2_LOG_ENABLE(configuration);
299+
O2_SIGNPOST_ID_GENERATE(cid, configuration);
300+
O2_SIGNPOST_START(configuration, cid, "populate", "Filling parameters from ptree");
276301
for (auto const& spec : schema) {
277302
// strip short version to get the correct key
278303
std::string key = spec.name.substr(0, spec.name.find(','));
@@ -318,9 +343,11 @@ void PropertyTreeHelpers::populate(std::vector<ConfigParamSpec> const& schema,
318343
case VariantType::String:
319344
pt.put(key, (*it).get_value<std::string>());
320345
break;
321-
case VariantType::Bool:
346+
case VariantType::Bool: {
347+
auto v = (*it).get_value<bool>();
348+
O2_SIGNPOST_EVENT_EMIT(configuration, cid, "populate", "Setting %{public}s: %{public}s", key.c_str(), v ? "true" : "false");
322349
pt.put(key, (*it).get_value<bool>());
323-
break;
350+
} break;
324351
case VariantType::Dict:
325352
case VariantType::ArrayInt:
326353
case VariantType::ArrayFloat:
@@ -371,13 +398,18 @@ void PropertyTreeHelpers::populate(std::vector<ConfigParamSpec> const& schema,
371398
}
372399
provenance.put(key, provenanceLabel);
373400
} catch (std::runtime_error& re) {
401+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populate", "Aborting during processing of %{public}s because of runtime_error %{public}s",
402+
key.c_str(), re.what());
374403
throw;
375404
} catch (std::exception& e) {
405+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populate", "Missing option %{public}s (%{public}s)", key.c_str(), e.what());
376406
throw std::invalid_argument(std::string("missing option: ") + key + " (" + e.what() + ")");
377407
} catch (...) {
408+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populate", "Aborting because of missing option %{public}s", key.c_str());
378409
throw std::invalid_argument(std::string("missing option: ") + key);
379410
}
380411
}
412+
O2_SIGNPOST_END(configuration, cid, "populate", "Done");
381413
}
382414

383415
namespace

0 commit comments

Comments
 (0)