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