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
19#include "dbe/dbaccessor.hpp"
20#include "dbe/confaccessor.hpp"
22#include "dbe/messenger.hpp"
23
24#include <algorithm>
25
26extern char const * const dbe_lib_config_api_version;
27
28namespace dbe
29{
30namespace config
31{
32namespace api
33{
34namespace info
35{
36
37template<typename T> inline T onclass::allnames()
38{
40 type_cmap const & baseclasses = dbaccessor::dbptr()->superclasses();
41
42 T config_class_list;
43
44 std::transform ( baseclasses.begin(), baseclasses.end(),
45 std::back_inserter ( config_class_list ),
46 [] ( type_cmap::value_type const & element )
47 {
48 return element.first->c_str();
49 } );
50
51 if ( not config_class_list.empty() )
52 {
53 std::sort ( std::begin ( config_class_list ), std::end ( config_class_list ) );
54 }
55
56 return config_class_list;
57}
58}
59//------------------------------------------------------------------------------------------
60
61//------------------------------------------------------------------------------------------
62namespace get
63{
64template<typename T> inline std::vector<std::string> attribute::read (
66{
67
68 if ( attr.p_is_multi_value )
69 {
70 std::vector<T> values;
71 obj.get ( attr.p_name, values );
72
73 std::vector<std::string> result;
74
76 {
77 result.assign(values.size(), "");
78 std::transform ( values.begin(), values.end(), result.begin(),
79 ( std::string ( * ) ( T const & ) ) convert::valtostr<T> );
80 }
81 else
82 {
83 for ( T i : values )
84 {
85 result.push_back ( convert::valtostr ( i, attr.p_int_format ) );
86 }
87 }
88
89 return result;
90 }
91 else
92 {
93 T value;
94 obj.get ( attr.p_name, value );
95
97 {
98 return
99 { convert::valtostr ( value ) };
100 }
101 else
102 {
103 return
104 { convert::valtostr ( value, attr.p_int_format ) };
105 }
106 }
107}
108}
109//------------------------------------------------------------------------------------------
110
111//------------------------------------------------------------------------------------------
112namespace commands
113{
114template<class T>
115void modobj ( tref Object, dunedaq::conffwk::attribute_t const & AttributeData, T Value )
116{
117 try
118 {
119 std::string const description = std::string ( "Attribute " ) + AttributeData.p_name;
120
122 {
124 description,
125 Object.UID(),
126 Object.class_name(),
127 Object.contained_in() };
128
130 new dbe::actions::ChangeAttribute<T> ( Object, AttributeData, Value ) );
132
133 }
134 catch ( daq::dbe::ObjectChangeWasNotSuccessful const & dbe_err )
135 {
136 WARN ( "The object attribute could not be changed", dbe::config::errors::parse ( dbe_err ).c_str() );
137 }
138 catch ( dunedaq::conffwk::Exception const & e )
139 {
140 WARN ( "Change Attribute: The attribute could not be changed",
141 dbe::config::errors::parse ( e ).c_str() );
142 }
143}
144//------------------------------------------------------------------------------------------
145
146//------------------------------------------------------------------------------------------
147template<>
149 dunedaq::conffwk::attribute_t const & AttributeData,
150 std::vector<std::string> Value );
151}
152//------------------------------------------------------------------------------------------
153
154//------------------------------------------------------------------------------------------
155template<class T>
157 dunedaq::conffwk::attribute_t const & AttributeData,
158 T NewValueData,
159 bool NotEmit )
160{
161 if ( not confaccessor::enabled() )
162 {
163 throw daq::dbe::ChangeNotAllowed ( ERS_HERE );
164 }
165
166 try
167 {
168 Object.set_by_ref ( AttributeData.p_name, NewValueData );
169
170 if ( !NotEmit )
171 {
173 }
174 }
175 catch ( dunedaq::conffwk::Exception const & error )
176 {
177 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, error );
178 }
179}
180//------------------------------------------------------------------------------------------
181
182//------------------------------------------------------------------------------------------
183template<typename T>
184void set::noactions::anenum ( tref Object, dunedaq::conffwk::attribute_t const & AttributeData,
185 T NewValueData,
186 bool NotEmit )
187{
188 if ( not confaccessor::enabled() )
189 {
190 throw daq::dbe::ChangeNotAllowed ( ERS_HERE );
191 }
192
193 try
194 {
195 Object.set_enum ( AttributeData.p_name, NewValueData );
196
197 if ( !NotEmit )
198 {
200 }
201 }
202 catch ( dunedaq::conffwk::Exception const & error )
203 {
204 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, error );
205 }
206}
207//------------------------------------------------------------------------------------------
208
209//------------------------------------------------------------------------------------------
210template<typename T>
211void set::noactions::aclass ( tref Object, dunedaq::conffwk::attribute_t const & AttributeData,
212 T NewValueData,
213 bool NotEmit )
214{
215 if ( not confaccessor::enabled() )
216 {
217 throw daq::dbe::ChangeNotAllowed ( ERS_HERE );
218 }
219
220 try
221 {
222 Object.set_class ( AttributeData.p_name, NewValueData );
223
224 if ( !NotEmit )
225 {
227 }
228 }
229 catch ( dunedaq::conffwk::Exception const & error )
230 {
231 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, error );
232 }
233}
234//------------------------------------------------------------------------------------------
235
236//------------------------------------------------------------------------------------------
237template<typename T>
238void set::noactions::adate ( tref Object, dunedaq::conffwk::attribute_t const & AttributeData,
239 T NewValueData,
240 bool NotEmit )
241{
242 if ( not confaccessor::enabled() )
243 {
244 throw daq::dbe::ChangeNotAllowed ( ERS_HERE );
245 }
246
247 try
248 {
249 Object.set_date ( AttributeData.p_name, NewValueData );
250
251 if ( !NotEmit )
252 {
254 }
255
256 }
257 catch ( dunedaq::conffwk::Exception const & error )
258 {
259 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, error );
260 }
261}
262//------------------------------------------------------------------------------------------
263
264//------------------------------------------------------------------------------------------
265template<typename T>
266void set::noactions::atime ( tref Object, dunedaq::conffwk::attribute_t const & AttributeData,
267 T NewValueData,
268 bool NotEmit )
269{
270 if ( not confaccessor::enabled() )
271 {
272 throw daq::dbe::ChangeNotAllowed ( ERS_HERE );
273 }
274
275 try
276 {
277 Object.set_time ( AttributeData.p_name, NewValueData );
278
279 if ( !NotEmit )
280 {
282 }
283 }
284 catch ( dunedaq::conffwk::Exception const & error )
285 {
286 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, error );
287 }
288}
289
290}
291/* namespace api */
292} /* namespace config */
293} /* namespace dbe */
294
295#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:85
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:35
Factory couldn t std::string alg_name Invalid configuration error
Definition Issues.hpp:34