19#include <boost/program_options/variables_map.hpp>
31template <VariantType T>
32inline Variant fromString(std::string
const&
str)
36 return VariantJSONHelpers::read<T>(ss);
40auto replaceLabels(LabeledArray<T>& input, LabeledArray<T>&& spec)
42 if (!input.getLabelsCols().empty() || !input.getLabelsRows().empty()) {
45 if (spec.getLabelsCols().empty() ==
false) {
46 input.replaceLabelsCols(spec.getLabelsCols());
48 if (spec.getLabelsRows().empty() ==
false) {
49 input.replaceLabelsRows(spec.getLabelsRows());
55template <
typename T, VariantType V>
56boost::property_tree::ptree labeledArrayFromStringToBranch(std::string
const&
str, Variant
const& defaultValue)
58 auto v = fromString<V>(
str).template get<LabeledArray<T>>();
59 if (defaultValue.type() == V) {
60 replaceLabels(
v, defaultValue.get<LabeledArray<T>>());
66 boost::property_tree::ptree& pt,
67 boost::property_tree::ptree& provenance)
70 O2_SIGNPOST_START(configuration, cid,
"populateDefaults",
"Filling with defaults");
71 for (
auto const& spec :
schema) {
72 std::string
key = spec.name.substr(0, spec.name.find(
','));
79 pt.put(
key, spec.defaultValue.get<
int>());
82 pt.put(
key, spec.defaultValue.get<
int8_t>());
85 pt.put(
key, spec.defaultValue.get<int16_t>());
100 pt.put(
key, spec.defaultValue.get<
int64_t>());
103 pt.put(
key, spec.defaultValue.get<
float>());
106 pt.put(
key, spec.defaultValue.get<
double>());
109 pt.put(
key, spec.defaultValue.get<std::string>());
112 bool value = spec.defaultValue.get<
bool>();
118 pt.put_child(
key, boost::property_tree::ptree{});
121 pt.put_child(
key,
vectorToBranch(spec.defaultValue.get<
int*>(), spec.defaultValue.size()));
124 pt.put_child(
key,
vectorToBranch(spec.defaultValue.get<
float*>(), spec.defaultValue.size()));
127 pt.put_child(
key,
vectorToBranch(spec.defaultValue.get<
double*>(), spec.defaultValue.size()));
130 pt.put_child(
key,
vectorToBranch(spec.defaultValue.get<
bool*>(), spec.defaultValue.size()));
133 pt.put_child(
key,
vectorToBranch(spec.defaultValue.get<std::string*>(), spec.defaultValue.size()));
161 provenance.put(
key,
"default");
162 }
catch (std::runtime_error& re) {
163 O2_SIGNPOST_END_WITH_ERROR(configuration, cid,
"populateDefaults",
"Aborting because of runtime_error %{public}s", re.what());
165 }
catch (std::exception&
e) {
167 throw std::invalid_argument(std::string(
"missing option: ") +
key +
" (" +
e.what() +
")");
170 throw std::invalid_argument(std::string(
"missing option: ") +
key);
177 boost::property_tree::ptree& pt,
178 boost::program_options::variables_map
const& vmap,
179 boost::property_tree::ptree& provenance)
182 O2_SIGNPOST_START(configuration, cid,
"populate",
"Filling parameters from variables_map");
183 for (
auto const& spec :
schema) {
185 std::string
key = spec.name.substr(0, spec.name.find(
','));
186 if (vmap.count(
key) == 0) {
192 pt.put(
key, vmap[
key].as<int>());
195 pt.put(
key, vmap[
key].as<int8_t>());
198 pt.put(
key, vmap[
key].as<int16_t>());
201 pt.put(
key, vmap[
key].as<uint8_t>());
204 pt.put(
key, vmap[
key].as<uint16_t>());
207 pt.put(
key, vmap[
key].as<uint32_t>());
210 pt.put(
key, vmap[
key].as<uint64_t>());
213 pt.put(
key, vmap[
key].as<int64_t>());
216 pt.put(
key, vmap[
key].as<float>());
219 pt.put(
key, vmap[
key].as<double>());
222 if (
auto const*
v = boost::any_cast<std::string>(&vmap[
key].
value())) {
227 auto v = vmap[
key].as<
bool>();
232 auto v = fromString<VariantType::ArrayInt>(vmap[
key].as<std::string>());
233 pt.put_child(
key, vectorToBranch<int>(
v.get<
int*>(),
v.size()));
236 auto v = fromString<VariantType::ArrayFloat>(vmap[
key].as<std::string>());
237 pt.put_child(
key, vectorToBranch<float>(
v.get<
float*>(),
v.size()));
240 auto v = fromString<VariantType::ArrayDouble>(vmap[
key].as<std::string>());
241 pt.put_child(
key, vectorToBranch<double>(
v.get<
double*>(),
v.size()));
247 auto v = fromString<VariantType::ArrayString>(vmap[
key].as<std::string>());
248 pt.put_child(
key, vectorToBranch<std::string>(
v.get<std::string*>(),
v.size()));
251 auto v = fromString<VariantType::Array2DInt>(vmap[
key].as<std::string>());
255 auto v = fromString<VariantType::Array2DFloat>(vmap[
key].as<std::string>());
259 auto v = fromString<VariantType::Array2DDouble>(vmap[
key].as<std::string>());
263 pt.put_child(
key, labeledArrayFromStringToBranch<int, VariantType::LabeledArrayInt>(vmap[
key].as<std::string>(), spec.defaultValue));
266 pt.put_child(
key, labeledArrayFromStringToBranch<float, VariantType::LabeledArrayFloat>(vmap[
key].as<std::string>(), spec.defaultValue));
269 pt.put_child(
key, labeledArrayFromStringToBranch<double, VariantType::LabeledArrayDouble>(vmap[
key].as<std::string>(), spec.defaultValue));
272 pt.put_child(
key, labeledArrayFromStringToBranch<std::string, VariantType::LabeledArrayString>(vmap[
key].as<std::string>(), spec.defaultValue));
275 pt.put_child(
key, vmap[
key].as<boost::property_tree::ptree>());
282 provenance.put(
key,
"fairmq");
283 }
catch (std::runtime_error& re) {
286 }
catch (std::exception&
e) {
288 throw std::invalid_argument(std::string(
"missing option: ") +
key +
" (" +
e.what() +
")");
291 throw std::invalid_argument(std::string(
"missing option: ") +
key);
298 boost::property_tree::ptree& pt,
299 boost::property_tree::ptree
const& in,
300 boost::property_tree::ptree& provenance,
301 std::string
const& provenanceLabel)
304 O2_SIGNPOST_START(configuration, cid,
"populate",
"Filling parameters from ptree");
305 for (
auto const& spec :
schema) {
307 std::string
key = spec.name.substr(0, spec.name.find(
','));
308 auto it = in.get_child_optional(
key);
310 it = in.get_child_optional(boost::property_tree::path(
key,
'/'));
318 pt.put(
key, (*it).get_value<
int>());
324 pt.put(
key, (*it).get_value<int16_t>());
342 pt.put(
key, (*it).get_value<
float>());
345 pt.put(
key, (*it).get_value<
double>());
348 pt.put(
key, (*it).get_value<std::string>());
351 auto v = (*it).get_value<
bool>();
353 pt.put(
key, (*it).get_value<
bool>());
364 pt.put_child(
key, *it);
367 auto v = labeledArrayFromBranch<int>(it.value());
369 pt.put_child(
key, *it);
375 auto v = labeledArrayFromBranch<float>(it.value());
377 pt.put_child(
key, *it);
383 auto v = labeledArrayFromBranch<double>(it.value());
385 pt.put_child(
key, *it);
393 pt.put_child(
key, *it);
401 throw std::runtime_error(
"Unknown variant type");
403 provenance.put(
key, provenanceLabel);
404 }
catch (std::runtime_error& re) {
405 O2_SIGNPOST_END_WITH_ERROR(configuration, cid,
"populate",
"Aborting during processing of %{public}s because of runtime_error %{public}s",
406 key.c_str(), re.what());
408 }
catch (std::exception&
e) {
410 throw std::invalid_argument(std::string(
"missing option: ") +
key +
" (" +
e.what() +
")");
413 throw std::invalid_argument(std::string(
"missing option: ") +
key);
421void traverseRecursive(
const boost::property_tree::ptree& parent,
422 const boost::property_tree::ptree::path_type& childPath,
423 const boost::property_tree::ptree& child,
426 using boost::property_tree::ptree;
428 method(parent, childPath, child);
429 for (ptree::const_iterator it = child.begin(); it != child.end(); ++it) {
430 ptree::path_type curPath = childPath / ptree::path_type(it->first);
431 traverseRecursive(parent, curPath, it->second, method);
439 traverseRecursive(parent,
"", parent, method);
std::shared_ptr< arrow::Schema > schema
unsigned short int uint16_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
#define O2_DECLARE_DYNAMIC_LOG(name)
#define O2_SIGNPOST_END(log, id, name, format,...)
#define O2_SIGNPOST_ID_GENERATE(name, log)
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, format,...)
#define O2_SIGNPOST_END_WITH_ERROR(log, id, name, format,...)
#define O2_SIGNPOST_START(log, id, name, format,...)
template o2::framework::LabeledArray< std::string > o2::framework::labeledArrayFromBranch< std::string >(boost::property_tree::ptree const &tree)
GLsizei const GLfloat * value
Defining ITS Vertex explicitly as messageable.
RuntimeErrorRef runtime_error(const char *)
boost::property_tree::ptree labeledArrayToBranch(LabeledArray< T > &&array)
boost::property_tree::ptree array2DToBranch(Array2D< T > &&array)
RuntimeErrorRef runtime_error_f(const char *,...)
boost::property_tree::ptree vectorToBranch(T const *values, size_t size)
static void populate(std::vector< ConfigParamSpec > const &schema, boost::property_tree::ptree &tree, boost::program_options::variables_map const &vmap, boost::property_tree::ptree &provenance)
std::function< void(boost::property_tree::ptree const &, typename T::path_type, boost::property_tree::ptree const &)> WalkerFunction
static void populateDefaults(std::vector< ConfigParamSpec > const &schema, boost::property_tree::ptree &tree, boost::property_tree::ptree &provenance)