Project
Loading...
Searching...
No Matches
ConfigParamRegistry.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
13#include "Framework/Array2D.h"
14
15namespace o2::framework
16{
17
18ConfigParamRegistry::ConfigParamRegistry(std::unique_ptr<ConfigParamStore> store)
19 : mStore{std::move(store)}
20{
21}
22
23bool ConfigParamRegistry::isSet(const char* key) const
24{
25 return mStore->store().count(key);
26}
27
28bool ConfigParamRegistry::hasOption(const char* key) const
29{
30 return mStore->store().get_child_optional(key).is_initialized();
31}
32
33bool ConfigParamRegistry::isDefault(const char* key) const
34{
35 return mStore->store().count(key) > 0 && mStore->provenance(key) != "default";
36}
37
38namespace
39{
40template <SimpleConfigValueType T>
41T getImpl(boost::property_tree::ptree const& tree, const char* key)
42{
43 return tree.get<T>(key);
44}
45
46template <StringConfigValueType T>
47T getImpl(boost::property_tree::ptree const& tree, const char* key)
48{
49 return tree.get<std::string>(key);
50}
51
52template <typename T>
54auto getImpl(boost::property_tree::ptree const& tree, const char* key)
55{
56 return o2::framework::vectorFromBranch<typename T::value_type>(tree.get_child(key));
57}
58
59template <Array2DLike T>
60auto getImpl(boost::property_tree::ptree& tree, const char* key)
61{
62 return array2DFromBranch<typename T::element_t>(tree.get_child(key));
63}
64
65template <LabeledArrayLike T>
66auto getImpl(boost::property_tree::ptree& tree, const char* key)
67{
68 return labeledArrayFromBranch<typename T::element_t>(tree.get_child(key));
69}
70} // namespace
71
72template <ConfigValueType T>
73T ConfigParamRegistry::get(const char* key) const
74{
75 try {
76 return getImpl<T>(this->mStore->store(), key);
77 } catch (std::exception& e) {
78 throw std::invalid_argument(std::string("missing option: ") + key + " (" + e.what() + ")");
79 } catch (...) {
80 throw std::invalid_argument(std::string("error parsing option: ") + key);
81 }
82}
83
84void ConfigParamRegistry::override(const char* key, ConfigValueType auto const& val) const
85{
86 try {
87 mStore->store().put(key, val);
88 } catch (std::exception& e) {
89 throw std::invalid_argument(std::string("failed to store an option: ") + key + " (" + e.what() + ")");
90 } catch (...) {
91 throw std::invalid_argument(std::string("failed to store an option: ") + key);
92 }
93}
94
95// Load extra parameters discovered while we process data
96void ConfigParamRegistry::loadExtra(std::vector<ConfigParamSpec>& extras)
97{
98 mStore->load(extras);
99}
100
101[[nodiscard]] std::vector<ConfigParamSpec> const& ConfigParamRegistry::specs() const
102{
103 return mStore->specs();
104}
105
106template int8_t ConfigParamRegistry::get<int8_t>(const char* key) const;
107template short ConfigParamRegistry::get<short>(const char* key) const;
108template int ConfigParamRegistry::get<int>(const char* key) const;
109template long ConfigParamRegistry::get<long>(const char* key) const;
110template long long ConfigParamRegistry::get<long long>(const char* key) const;
111template uint8_t ConfigParamRegistry::get<uint8_t>(const char* key) const;
112template uint16_t ConfigParamRegistry::get<uint16_t>(const char* key) const;
113template unsigned long ConfigParamRegistry::get<unsigned long>(const char* key) const;
114template unsigned long long ConfigParamRegistry::get<unsigned long long>(const char* key) const;
115template unsigned int ConfigParamRegistry::get<unsigned int>(const char* key) const;
116template LabeledArray<std::string> ConfigParamRegistry::get<LabeledArray<std::string>>(const char* key) const;
117template LabeledArray<double> ConfigParamRegistry::get<LabeledArray<double>>(const char* key) const;
118template LabeledArray<float> ConfigParamRegistry::get<LabeledArray<float>>(const char* key) const;
119template LabeledArray<int> ConfigParamRegistry::get<LabeledArray<int>>(const char* key) const;
120template Array2D<std::string> ConfigParamRegistry::get<Array2D<std::string>>(const char* key) const;
121template Array2D<double> ConfigParamRegistry::get<Array2D<double>>(const char* key) const;
122template Array2D<float> ConfigParamRegistry::get<Array2D<float>>(const char* key) const;
123template Array2D<int> ConfigParamRegistry::get<Array2D<int>>(const char* key) const;
124template std::vector<std::string> ConfigParamRegistry::get<std::vector<std::string>>(const char* key) const;
125template std::vector<double> ConfigParamRegistry::get<std::vector<double>>(const char* key) const;
126template std::vector<float> ConfigParamRegistry::get<std::vector<float>>(const char* key) const;
127template std::vector<int> ConfigParamRegistry::get<std::vector<int>>(const char* key) const;
128template float ConfigParamRegistry::get<float>(const char* key) const;
129template double ConfigParamRegistry::get<double>(const char* key) const;
130template std::string ConfigParamRegistry::get<std::string>(const char* key) const;
131template bool ConfigParamRegistry::get<bool>(const char* key) const;
132
133template void ConfigParamRegistry::override(const char* key, int8_t const&) const;
134template void ConfigParamRegistry::override(const char* key, int16_t const&) const;
135template void ConfigParamRegistry::override(const char* key, int32_t const&) const;
136template void ConfigParamRegistry::override(const char* key, int64_t const&) const;
137template void ConfigParamRegistry::override(const char* key, uint8_t const&) const;
138template void ConfigParamRegistry::override(const char* key, uint16_t const&) const;
139template void ConfigParamRegistry::override(const char* key, uint32_t const&) const;
140template void ConfigParamRegistry::override(const char* key, uint64_t const&) const;
141template void ConfigParamRegistry::override(const char* key, float const&) const;
142template void ConfigParamRegistry::override(const char* key, double const&) const;
143template void ConfigParamRegistry::override(const char* key, std::string const&) const;
144template void ConfigParamRegistry::override(const char* key, bool const&) const;
145
146// template void ConfigParamRegistry::override(char const* key, LabeledArray<std::string> const&) const;
147// template void ConfigParamRegistry::override(char const* key, LabeledArray<double> const&) const;
148// template void ConfigParamRegistry::override(char const* key, LabeledArray<float> const&) const;
149// template void ConfigParamRegistry::override(char const* key, LabeledArray<int> const&) const;
150// template void ConfigParamRegistry::override(char const* key, Array2D<std::string> const&) const;
151// template void ConfigParamRegistry::override(char const* key, Array2D<double> const&) const;
152// template void ConfigParamRegistry::override(char const* key, Array2D<float> const&) const;
153// template void ConfigParamRegistry::override(char const* key, Array2D<int> const&) const;
154// template void ConfigParamRegistry::override(char const* key, std::vector<std::string> const&) const;
155// template void ConfigParamRegistry::override(char const* key, std::vector<double> const&) const;
156// template void ConfigParamRegistry::override(char const* key, std::vector<float> const&) const;
157// template void ConfigParamRegistry::override(char const* key, std::vector<int> const&) const;
158} // namespace o2::framework
StringRef key
void loadExtra(std::vector< ConfigParamSpec > &extras)
ConfigParamRegistry(std::unique_ptr< ConfigParamStore > store)
bool isDefault(const char *key) const
bool hasOption(const char *key) const
void override(const char *key, ConfigValueType auto const &val) const
std::vector< ConfigParamSpec > const & specs() const
GLuint GLfloat * val
Definition glcorearb.h:1582
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
Defining DataPointCompositeObject explicitly as copiable.
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))