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 // Remove an option (a leaf or a whole subtree) from the active store, no-op if it is missing
91 void erase(const char* key) const;
92
93 // Load extra parameters discovered while we process data
94 void loadExtra(std::vector<ConfigParamSpec>& extras);
95
96 private:
97 std::unique_ptr<ConfigParamStore> mStore;
98};
99
100template <typename T>
101T ConfigParamRegistry::get(const char* key) const
102{
103 try {
104 return T{mStore->store().get_child(key)};
105 } catch (std::exception& e) {
106 throw std::invalid_argument(std::string("missing option: ") + key + " (" + e.what() + ")");
107 } catch (...) {
108 throw std::invalid_argument(std::string("error parsing option: ") + key);
109 }
110}
111
112} // namespace o2::framework
113
114#endif // O2_FRAMEWORK_CONFIGPARAMREGISTRY_H_
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
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 ITS Vertex explicitly as messageable.
Definition Cartesian.h:288