Project
Loading...
Searching...
No Matches
Configurable.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_CONFIGURABLE_H_
12#define O2_FRAMEWORK_CONFIGURABLE_H_
14#include "Framework/Traits.h"
16#include <fmt/format.h>
17#include <string>
18#include <vector>
19namespace o2::framework
20{
21namespace expressions
22{
23struct PlaceholderNode;
24}
25
26template <typename T, ConfigParamKind K>
28 ConfigurableBase(std::string const& name, T&& defaultValue, std::string const& help)
29 : name(name), value{std::forward<T>(defaultValue)}, help(help)
30 {
31 }
32 using type = T;
33 std::string name;
35 std::string help;
36 static constexpr ConfigParamKind kind = K;
37};
38
39template <typename T, ConfigParamKind K>
41 ConfigurablePolicyConst(std::string const& name, T&& defaultValue, std::string const& help)
42 : ConfigurableBase<T, K>{name, std::forward<T>(defaultValue), help}
43 {
44 }
45 operator T()
46 {
47 return this->value;
48 }
49 T const* operator->() const
50 {
51 return &this->value;
52 }
53};
54
55template <typename T, ConfigParamKind K>
57 ConfigurablePolicyMutable(std::string const& name, T&& defaultValue, std::string const& help)
58 : ConfigurableBase<T, K>{name, std::forward<T>(defaultValue), help}
59 {
60 }
61 operator T()
62 {
63 return this->value;
64 }
66 {
67 return &this->value;
68 }
69};
70
73template <typename T, ConfigParamKind K = ConfigParamKind::kGeneric, typename IP = ConfigurablePolicyConst<T, K>>
74struct Configurable : IP {
75 Configurable(std::string const& name, T&& defaultValue, std::string const& help)
76 : IP{name, std::forward<T>(defaultValue), help}
77 {
78 }
79 auto node()
80 {
81 return expressions::PlaceholderNode{*this};
82 }
83};
84
85template <typename T, ConfigParamKind K = ConfigParamKind::kGeneric>
87
98template <typename Column>
99struct ConfigurableCCDBPath : Configurable<std::string> {
101 : Configurable<std::string>{fmt::format("ccdb:{}", o2::framework::with_namespace_prefix<Column>()),
102 std::string{Column::query},
103 std::string{"CCDB path for "} + Column::mLabel + " (default: " + Column::query + ")"}
104 {
105 }
106};
107
108template <typename T>
109concept is_configurable = requires(T t) {
110 requires std::same_as<std::string, decltype(t.name)>;
111 requires std::same_as<std::string, decltype(t.help)>;
112 requires std::same_as<typename std::decay_t<T>::type, decltype(t.value)>;
113};
114
116
117template <typename T>
119 requires() {
121 };
122
123template <typename T, typename... As>
124struct ProcessConfigurable : Configurable<bool, ConfigParamKind::kProcessFlag> {
125 ProcessConfigurable(void (T::*process_)(As...), std::string const& name_, bool&& value_, std::string const& help_)
126 : process{process_},
127 Configurable<bool, ConfigParamKind::kProcessFlag>(name_, std::forward<bool>(value_), help_)
128 {
129 }
130 void (T::*process)(As...);
131};
132
133template <typename T>
134concept is_process_configurable = is_configurable<T> && requires(T t) { t.process; };
135
136#define PROCESS_SWITCH(_Class_, _Name_, _Help_, _Default_) \
137 decltype(o2::framework::ProcessConfigurable{&_Class_ ::_Name_, #_Name_, _Default_, _Help_}) do##_Name_ = o2::framework::ProcessConfigurable{&_Class_ ::_Name_, #_Name_, _Default_, _Help_};
138#define PROCESS_SWITCH_FULL(_Class_, _Method_, _Name_, _Help_, _Default_) \
139 decltype(o2::framework::ProcessConfigurable{&_Class_ ::_Method_, #_Name_, _Default_, _Help_}) do##_Name_ = o2::framework::ProcessConfigurable{&_Class_ ::_Method_, #_Name_, _Default_, _Help_};
140
141template <typename T, ConfigParamKind K, typename IP>
142std::ostream& operator<<(std::ostream& os, Configurable<T, K, IP> const& c)
143{
144 os << c.value;
145 return os;
146}
147
163};
164
165template <typename T>
166concept is_configurable_group = std::derived_from<T, ConfigurableGroup>;
167
168} // namespace o2::framework
169#endif // O2_FRAMEWORK_CONFIGURABLE_H_
std::vector< std::shared_ptr< gandiva::Expression > > expressions
uint32_t c
Definition RawData.h:2
GLsizei const GLchar *const * string
Definition glcorearb.h:809
GLuint const GLchar * name
Definition glcorearb.h:781
GLsizei const GLfloat * value
Definition glcorearb.h:819
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::ostream & operator<<(std::ostream &s, ChannelType const &type)
Stream operators so that we can use ChannelType with Boost.Test.
ConfigurableBase(std::string const &name, T &&defaultValue, std::string const &help)
static constexpr ConfigParamKind kind
ConfigurablePolicyConst(std::string const &name, T &&defaultValue, std::string const &help)
ConfigurablePolicyMutable(std::string const &name, T &&defaultValue, std::string const &help)
Configurable(std::string const &name, T &&defaultValue, std::string const &help)
ProcessConfigurable(void(T::*process_)(As...), std::string const &name_, bool &&value_, std::string const &help_)
A placeholder node for simple type configurable.