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