Project
Loading...
Searching...
No Matches
ConfigParamRegistry.h
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.
11#ifndef O2_FRAMEWORK_CONFIGPARAMREGISTRY_H_
12#define O2_FRAMEWORK_CONFIGPARAMREGISTRY_H_
13
15#include <boost/property_tree/ptree.hpp>
16
17#include <concepts>
18#include <cstdint>
19#include <memory>
20#include <string>
21
22template <typename T>
23concept SimpleConfigValueType = std::same_as<T, int> ||
24 std::same_as<T, int8_t> ||
25 std::same_as<T, int16_t> ||
26 std::same_as<T, uint8_t> ||
27 std::same_as<T, uint16_t> ||
28 std::same_as<T, unsigned int> ||
29 std::same_as<T, unsigned long> ||
30 std::same_as<T, unsigned long long> ||
31 std::same_as<T, long> ||
32 std::same_as<T, long long> ||
33 std::same_as<T, float> ||
34 std::same_as<T, double> ||
35 std::same_as<T, bool>;
36
37template <typename T>
38concept VectorConfigValueType = std::same_as<T, std::vector<int>> ||
39 std::same_as<T, std::vector<float>> ||
40 std::same_as<T, std::vector<double>> ||
41 std::same_as<T, std::vector<std::string>> ||
42 std::same_as<T, std::vector<bool>>;
43
44template <typename T>
45concept StringConfigValueType = std::same_as<T, std::string>;
46
47template <typename T>
48concept PtreeConfigValueType = std::same_as<T, boost::property_tree::ptree> || std::constructible_from<T, boost::property_tree::ptree>;
49
50template <typename T>
51concept Array2DLike = requires(T& t) { t.is_array_2d(); };
52
53template <typename T>
54concept LabeledArrayLike = requires(T& t) { t.is_labeled_array(); };
55
56template <typename T>
58
59namespace o2::framework
60{
61class ConfigParamStore;
62
70{
71 public:
72 ConfigParamRegistry(std::unique_ptr<ConfigParamStore> store);
73
74 bool isSet(const char* key) const;
75
76 bool hasOption(const char* key) const;
77
78 bool isDefault(const char* key) const;
79
80 [[nodiscard]] std::vector<ConfigParamSpec> const& specs() const;
81
82 template <ConfigValueType T>
83 T get(const char* key) const;
84
85 template <typename T>
86 T get(const char* key) const;
87
88 void override(const char* key, ConfigValueType auto const& val) const;
89
90 // Load extra parameters discovered while we process data
91 void loadExtra(std::vector<ConfigParamSpec>& extras);
92
93 private:
94 std::unique_ptr<ConfigParamStore> mStore;
95};
96
97template <typename T>
98T ConfigParamRegistry::get(const char* key) const
99{
100 try {
101 return T{mStore->store().get_child(key)};
102 } catch (std::exception& e) {
103 throw std::invalid_argument(std::string("missing option: ") + key + " (" + e.what() + ")");
104 } catch (...) {
105 throw std::invalid_argument(std::string("error parsing option: ") + key);
106 }
107}
108
109} // namespace o2::framework
110
111#endif // O2_FRAMEWORK_CONFIGPARAMREGISTRY_H_
StringRef key
void loadExtra(std::vector< ConfigParamSpec > &extras)
T get(const char *key) const
bool isDefault(const char *key) const
bool hasOption(const char *key) const
std::vector< ConfigParamSpec > const & specs() const
GLuint GLfloat * val
Definition glcorearb.h:1582
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20