DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
config_api.hpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: yes (from dbe/config_api.hpp to include/dbe/config_api.hpp).
5
6/*
7 * config_api.hpp
8 *
9 * Created on: Nov 9, 2015
10 * Author: lgeorgop
11 */
12
13#ifndef DBE_CONFIG_API_HPP_
14#define DBE_CONFIG_API_HPP_
15
17#include "dbe/confaccessor.hpp"
21#include "dbe/dbaccessor.hpp"
22#include "dbe/messenger.hpp"
23
24#include <algorithm>
25
26extern char const* const dbe_lib_config_api_version;
27
28namespace dbe {
29namespace config {
30namespace api {
31namespace info {
32
33template<typename T>
34inline T
36{
38 type_cmap const& baseclasses = dbaccessor::dbptr()->superclasses();
39
40 T config_class_list;
41
42 std::transform(baseclasses.begin(),
43 baseclasses.end(),
44 std::back_inserter(config_class_list),
45 [](type_cmap::value_type const& element) { return element.first->c_str(); });
46
47 if (not config_class_list.empty()) {
48 std::sort(std::begin(config_class_list), std::end(config_class_list));
49 }
50
51 return config_class_list;
52}
53}
54//------------------------------------------------------------------------------------------
55
56//------------------------------------------------------------------------------------------
57namespace get {
58template<typename T>
59inline std::vector<std::string>
61{
62
63 if (attr.p_is_multi_value) {
64 std::vector<T> values;
65 obj.get(attr.p_name, values);
66
67 std::vector<std::string> result;
68
70 result.assign(values.size(), "");
71 std::transform(values.begin(), values.end(), result.begin(), (std::string(*)(T const&))convert::valtostr<T>);
72 } else {
73 for (T i : values) {
74 result.push_back(convert::valtostr(i, attr.p_int_format));
75 }
76 }
77
78 return result;
79 } else {
80 T value;
81 obj.get(attr.p_name, value);
82
84 return { convert::valtostr(value) };
85 } else {
86 return { convert::valtostr(value, attr.p_int_format) };
87 }
88 }
89}
90}
91//------------------------------------------------------------------------------------------
92
93//------------------------------------------------------------------------------------------
94namespace commands {
95template<class T>
96void
97modobj(tref Object, dunedaq::conffwk::attribute_t const& AttributeData, T Value)
98{
99 try {
100 std::string const description = std::string("Attribute ") + AttributeData.p_name;
101
103 dbe::config_internal_change::MODIFIED, description, Object.UID(), Object.class_name(), Object.contained_in()
104 };
105
106 confaccessor::get_commands()->push(new dbe::actions::ChangeAttribute<T>(Object, AttributeData, Value));
108
109 } catch (daq::dbe::ObjectChangeWasNotSuccessful const& dbe_err) {
110 WARN("The object attribute could not be changed", dbe::config::errors::parse(dbe_err).c_str());
111 } catch (dunedaq::conffwk::Exception const& e) {
112 WARN("Change Attribute: The attribute could not be changed", dbe::config::errors::parse(e).c_str());
113 }
114}
115//------------------------------------------------------------------------------------------
116
117//------------------------------------------------------------------------------------------
118template<>
119void
121 dunedaq::conffwk::attribute_t const& AttributeData,
122 std::vector<std::string> Value);
123}
124//------------------------------------------------------------------------------------------
125
126//------------------------------------------------------------------------------------------
127template<class T>
128void
129set::noactions::attribute(tref Object, dunedaq::conffwk::attribute_t const& AttributeData, T NewValueData, bool NotEmit)
130{
131 if (not confaccessor::enabled()) {
132 throw daq::dbe::ChangeNotAllowed(ERS_HERE);
133 }
134
135 try {
136 Object.set_by_ref(AttributeData.p_name, NewValueData);
137
138 if (!NotEmit) {
140 }
141 } catch (dunedaq::conffwk::Exception const& error) {
142 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, error);
143 }
144}
145//------------------------------------------------------------------------------------------
146
147//------------------------------------------------------------------------------------------
148template<typename T>
149void
150set::noactions::anenum(tref Object, dunedaq::conffwk::attribute_t const& AttributeData, T NewValueData, bool NotEmit)
151{
152 if (not confaccessor::enabled()) {
153 throw daq::dbe::ChangeNotAllowed(ERS_HERE);
154 }
155
156 try {
157 Object.set_enum(AttributeData.p_name, NewValueData);
158
159 if (!NotEmit) {
161 }
162 } catch (dunedaq::conffwk::Exception const& error) {
163 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, error);
164 }
165}
166//------------------------------------------------------------------------------------------
167
168//------------------------------------------------------------------------------------------
169template<typename T>
170void
171set::noactions::aclass(tref Object, dunedaq::conffwk::attribute_t const& AttributeData, T NewValueData, bool NotEmit)
172{
173 if (not confaccessor::enabled()) {
174 throw daq::dbe::ChangeNotAllowed(ERS_HERE);
175 }
176
177 try {
178 Object.set_class(AttributeData.p_name, NewValueData);
179
180 if (!NotEmit) {
182 }
183 } catch (dunedaq::conffwk::Exception const& error) {
184 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, error);
185 }
186}
187//------------------------------------------------------------------------------------------
188
189//------------------------------------------------------------------------------------------
190template<typename T>
191void
192set::noactions::adate(tref Object, dunedaq::conffwk::attribute_t const& AttributeData, T NewValueData, bool NotEmit)
193{
194 if (not confaccessor::enabled()) {
195 throw daq::dbe::ChangeNotAllowed(ERS_HERE);
196 }
197
198 try {
199 Object.set_date(AttributeData.p_name, NewValueData);
200
201 if (!NotEmit) {
203 }
204
205 } catch (dunedaq::conffwk::Exception const& error) {
206 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, error);
207 }
208}
209//------------------------------------------------------------------------------------------
210
211//------------------------------------------------------------------------------------------
212template<typename T>
213void
214set::noactions::atime(tref Object, dunedaq::conffwk::attribute_t const& AttributeData, T NewValueData, bool NotEmit)
215{
216 if (not confaccessor::enabled()) {
217 throw daq::dbe::ChangeNotAllowed(ERS_HERE);
218 }
219
220 try {
221 Object.set_time(AttributeData.p_name, NewValueData);
222
223 if (!NotEmit) {
225 }
226 } catch (dunedaq::conffwk::Exception const& error) {
227 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, error);
228 }
229}
230
231}
232/* namespace api */
233} /* namespace config */
234} /* namespace dbe */
235
236#endif /* DBE_CONFIG_API_HPP_ */
#define ERS_HERE
static t_undo_stack_cptr get_commands()
static bool enabled()
void force_emit_object_changed(QString const &, dref const)
static t_internal_changes_stack_cptr get_internal_change_stack()
static confaccessor & ref()
static std::vector< std::string > read(dunedaq::conffwk::ConfigObject &, dunedaq::conffwk::attribute_t const &)
static cptr< dunedaq::conffwk::Configuration > dbptr()
void set_enum(std::string const &name, std::string const &val)
void set_by_ref(std::string const &name, U &val)
void set_class(std::string const &name, std::string const &val)
void set_date(std::string const &name, std::string const &val)
void set_time(std::string const &name, std::string const &val)
char const *const dbe_lib_config_api_version
#define WARN(...)
Definition messenger.hpp:82
void modobj(tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T Value)
void adate(inner::configobject::tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T NewValueData, bool NotEmit=false)
void aclass(inner::configobject::tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T NewValueData, bool NotEmit=false)
void anenum(inner::configobject::tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T NewValueData, bool NotEmit=false)
void atime(inner::configobject::tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T NewValueData, bool NotEmit=false)
void attribute(inner::configobject::tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T NewValueData, bool NotEmit=false)
std::string const parse(ers::Issue const &)
std::string valtostr(T const &value)
Include QT Headers.
inner::configobject::tref tref
Definition tref.hpp:36
Factory couldn t std::string alg_name Invalid configuration error
Definition Issues.hpp:34