DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
src
internal
config_api_get.cpp
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: no.
5
6
/*
7
* config_api_get.cpp
8
*
9
* Created on: Apr 19, 2016
10
* Author: Leonidas Georgopoulos
11
*/
12
13
#include "
dbe/config_api_get.hpp
"
14
#include "
dbe/Conversion.hpp
"
15
#include "
dbe/dbaccessor.hpp
"
16
#include "
dbe/messenger.hpp
"
17
#include "
dbe/config_api.hpp
"
18
19
using namespace
dunedaq::conffwk
;
20
21
22
//------------------------------------------------------------------------------------------
23
// NAMESPACE DBE::CONFIG::API::GET
24
//------------------------------------------------------------------------------------------
25
26
namespace
dbe
27
{
28
29
namespace
config
30
{
31
32
namespace
api
33
{
34
35
namespace
get
36
{
37
//------------------------------------------------------------------------------------------
38
39
template
<
typename
T>
40
inline
std::vector<std::string>
attribute::read
(
41
ConfigObject
& input,
dunedaq::conffwk::attribute_t
const
& attr )
42
{
43
std::vector<T> attrvalues;
44
45
if
( attr.
p_is_multi_value
)
46
{
47
attrvalues =
direct::attribute<std::vector<T>
> ( input, attr );
48
}
49
else
50
{
51
attrvalues =
52
{
direct::attribute<T>
( input, attr ) };
53
}
54
55
std::vector<std::string> strings ( attrvalues.size() );
56
std::transform ( attrvalues.begin(), attrvalues.end(),
57
strings.begin(), [&attr] ( T
const
& x )
58
{
59
return convert::valtostr ( x, attr.p_int_format );
60
}
61
62
);
63
64
return
strings;
65
}
66
67
//------------------------------------------------------------------------------------------
68
69
//------------------------------------------------------------------------------------------
70
template
<
typename
T>
71
inline
T
direct::attribute
(
ConfigObject
& input,
72
dunedaq::conffwk::attribute_t
const
& attr )
73
{
74
T value;
75
input.
get
( attr.
p_name
, value );
76
return
value;
77
}
78
79
//------------------------------------------------------------------------------------------
80
81
//------------------------------------------------------------------------------------------
82
template
<>
83
QStringList
direct::attribute<QStringList>
(
ConfigObject
& input,
84
dunedaq::conffwk::attribute_t
const
& attr )
85
{
86
std::vector<std::string> data;
87
88
switch
( attr.
p_type
)
89
{
90
91
case
dunedaq::conffwk::bool_type
:
92
data =
get::attribute::read<bool>
( input, attr );
93
break
;
94
95
case
dunedaq::conffwk::enum_type
:
96
97
case
dunedaq::conffwk::date_type
:
98
99
case
dunedaq::conffwk::time_type
:
100
101
case
dunedaq::conffwk::string_type
:
102
103
case
dunedaq::conffwk::class_type
:
104
data =
get::attribute::read<std::string>
( input, attr );
105
break
;
106
107
case
dunedaq::conffwk::float_type
:
108
data =
get::attribute::read<float>
( input, attr );
109
break
;
110
111
case
dunedaq::conffwk::double_type
:
112
data =
get::attribute::read<double>
( input, attr );
113
break
;
114
115
case
dunedaq::conffwk::s8_type
:
116
data =
get::attribute::read<int8_t>
( input, attr );
117
break
;
118
119
case
dunedaq::conffwk::u8_type
:
120
data =
get::attribute::read<u_int8_t>
( input, attr );
121
break
;
122
123
case
dunedaq::conffwk::s16_type
:
124
data =
get::attribute::read<int16_t>
( input, attr );
125
break
;
126
127
case
dunedaq::conffwk::u16_type
:
128
data =
get::attribute::read<u_int16_t>
( input, attr );
129
break
;
130
131
case
dunedaq::conffwk::s32_type
:
132
data =
get::attribute::read<int32_t>
( input, attr );
133
break
;
134
135
case
dunedaq::conffwk::u32_type
:
136
data =
get::attribute::read<u_int32_t>
( input, attr );
137
break
;
138
139
case
dunedaq::conffwk::s64_type
:
140
data =
get::attribute::read<int64_t>
( input, attr );
141
break
;
142
143
case
dunedaq::conffwk::u64_type
:
144
data =
get::attribute::read<u_int64_t>
( input, attr );
145
break
;
146
}
147
148
QStringList result;
149
150
for
(
auto
const
& x : data )
151
{
152
result.push_back ( x.c_str() );
153
}
154
155
return
result;
156
157
}
158
159
template
160
QStringList
direct::attribute<QStringList>
161
(
ConfigObject
&,
162
dunedaq::conffwk::attribute_t
const
& );
163
164
template
165
ConfigObject
direct::attribute<ConfigObject>
166
(
ConfigObject
&,
167
dunedaq::conffwk::attribute_t
const
& );
168
169
template
170
std::vector<ConfigObject>
171
direct::attribute<std::vector<ConfigObject>
> (
172
ConfigObject
&,
dunedaq::conffwk::attribute_t
const
& );
173
174
//------------------------------------------------------------------------------------------
175
176
//------------------------------------------------------------------------------------------
177
template
<
typename
T>
178
inline
T
attribute::list
(
dbe::inner::configobject::tref
obj
,
179
dunedaq::conffwk::attribute_t
const
& Attribute )
180
{
181
std::vector<std::string> attrvalues;
182
183
switch
( Attribute.
p_type
)
184
{
185
186
case
dunedaq::conffwk::bool_type
:
187
attrvalues =
get::attribute::read<bool>
(
obj
, Attribute );
188
break
;
189
190
case
dunedaq::conffwk::enum_type
:
191
192
case
dunedaq::conffwk::date_type
:
193
194
case
dunedaq::conffwk::time_type
:
195
196
case
dunedaq::conffwk::string_type
:
197
198
case
dunedaq::conffwk::class_type
:
199
attrvalues =
get::attribute::read<std::string>
(
obj
, Attribute );
200
break
;
201
202
case
dunedaq::conffwk::float_type
:
203
attrvalues =
get::attribute::read<float>
(
obj
, Attribute );
204
break
;
205
206
case
dunedaq::conffwk::double_type
:
207
attrvalues =
get::attribute::read<double>
(
obj
, Attribute );
208
break
;
209
210
case
dunedaq::conffwk::s8_type
:
211
attrvalues =
get::attribute::read<int8_t>
(
obj
, Attribute );
212
break
;
213
214
case
dunedaq::conffwk::u8_type
:
215
attrvalues =
get::attribute::read<u_int8_t>
(
obj
, Attribute );
216
break
;
217
218
case
dunedaq::conffwk::s16_type
:
219
attrvalues =
get::attribute::read<int16_t>
(
obj
, Attribute );
220
break
;
221
222
case
dunedaq::conffwk::u16_type
:
223
attrvalues =
get::attribute::read<u_int16_t>
(
obj
, Attribute );
224
break
;
225
226
case
dunedaq::conffwk::s32_type
:
227
attrvalues =
get::attribute::read<int32_t>
(
obj
, Attribute );
228
break
;
229
230
case
dunedaq::conffwk::u32_type
:
231
attrvalues =
get::attribute::read<u_int32_t>
(
obj
, Attribute );
232
break
;
233
234
case
dunedaq::conffwk::s64_type
:
235
attrvalues =
get::attribute::read<int64_t>
(
obj
, Attribute );
236
break
;
237
238
case
dunedaq::conffwk::u64_type
:
239
attrvalues =
get::attribute::read<u_int64_t>
(
obj
, Attribute );
240
break
;
241
}
242
243
return
dbe::convert::to<T>
( attrvalues );
244
}
245
246
// Template method declaration of attribute::list for type QStringList
247
template
248
QStringList
attribute::list<QStringList>
(
dbe::inner::configobject::tref
obj
,
249
dunedaq::conffwk::attribute_t
const
& );
250
//------------------------------------------------------------------------------------------
251
252
//------------------------------------------------------------------------------------------
253
QStringList
file::inclusions
( QStringList
const
& candidates, QStringList files )
254
{
255
if
( candidates.isEmpty() )
256
{
257
return
files;
258
}
259
else
260
{
261
QStringList newcandidates =
262
{ };
263
264
for
( QString
const
& fname : candidates )
265
{
266
if
( not ( fname.endsWith (
"schema.xml"
) or files.contains ( fname ) ) )
267
{
268
files.push_back ( fname );
269
// Query the current file for other inclusions
270
std::list<std::string> configfiles;
271
272
try
273
{
274
if
( not ( fname.contains (
"rdbconfig:"
) or fname.contains (
"roksconflibs:"
) ) )
275
{
276
// Process file based sources
277
dbaccessor::dbptr
()->get_includes ( fname.toStdString(), configfiles );
278
}
279
else
280
{
281
// Process other sources (e.g. Oracle and RDB )
282
dbaccessor::dbptr
()->get_includes (
""
, configfiles );
283
files.removeAll ( fname );
// Once used RDB / Oracle sources must be removed
284
}
285
}
286
catch
( dunedaq::conffwk::Exception
const
& ex )
287
{
288
ERROR
(
"Include did not succeed for "
,
dbe::config::errors::parse
( ex ).c_str(),
289
"filename:"
, fname.toStdString().c_str() );
290
}
291
292
// Keep only files that have not already been processed
293
// i.e. they are not in the list of given files.
294
for
( std::string
const
& configfile : configfiles )
295
{
296
QString
const
& qconfigfile = QString::fromStdString ( configfile );
297
298
if
( not files.contains ( qconfigfile ) )
299
{
300
newcandidates.push_back ( qconfigfile );
301
}
302
}
303
304
}
305
306
}
307
308
return
get::file::inclusions
( newcandidates, files );
309
}
310
}
311
312
//------------------------------------------------------------------------------------------
313
314
//------------------------------------------------------------------------------------------
315
QStringList
file::inclusions_singlefile
( QString
const
& FileName )
316
{
317
std::string dbname = FileName.toStdString();
318
std::list<std::string> incList;
319
320
QStringList dbfiles;
321
322
try
323
{
324
dbaccessor::dbptr
()->get_includes ( dbname, incList );
325
326
for
( std::string
const
& includeName : incList )
327
{
328
dbfiles.push_back ( QString ( includeName.c_str() ) );
329
}
330
}
331
catch
( dunedaq::conffwk::Exception & ex )
332
{
333
WARN
(
"Include : Could not retrieve included files"
,
334
dbe::config::errors::parse
( ex ).c_str() );
335
}
336
337
return
dbfiles;
338
}
339
340
//------------------------------------------------------------------------------------------
341
342
//------------------------------------------------------------------------------------------
343
QStringList
get::defaults::attribute::value
(
dunedaq::conffwk::attribute_t
const
& attr )
344
{
345
return
QString::fromStdString ( attr.
p_default_value
).split (
","
);
346
}
347
348
//------------------------------------------------------------------------------------------
349
350
//------------------------------------------------------------------------------------------
351
}
352
}
353
}
354
}
355
356
//------------------------------------------------------------------------------------------
357
Conversion.hpp
dbe::config::api::get::attribute::list
static T list(dbe::inner::configobject::tref obj, dunedaq::conffwk::attribute_t const &attr)
Definition
config_api_get.cpp:178
dbe::config::api::get::attribute::read
static std::vector< std::string > read(dunedaq::conffwk::ConfigObject &, dunedaq::conffwk::attribute_t const &)
Definition
config_api_get.cpp:40
dbe::config::api::get::direct::attribute
friend class dbe::config::api::get::attribute
Definition
config_api_get.hpp:131
dbe::config::api::get::file::inclusions_singlefile
static QStringList inclusions_singlefile(QString const &)
Definition
config_api_get.cpp:315
dbe::config::api::get::file::inclusions
static QStringList inclusions(QStringList const &candidates, QStringList files={ })
Definition
config_api_get.cpp:253
dbe::dbaccessor::dbptr
static cptr< dunedaq::conffwk::Configuration > dbptr()
Definition
dbaccessor.cpp:23
dbe::inner::configobject::tref
Definition
config_reference.hpp:457
dunedaq::conffwk::ConfigObject
Represents database objects.
Definition
ConfigObject.hpp:53
dunedaq::conffwk::ConfigObject::get
void get(const std::string &name, T &value)
Get value of object's attribute or relationship.
Definition
ConfigObject.hpp:285
config_api.hpp
config_api_get.hpp
dbaccessor.hpp
messenger.hpp
ERROR
#define ERROR(...)
Definition
messenger.hpp:93
WARN
#define WARN(...)
Definition
messenger.hpp:85
dbe::config::api::get
Definition
config_api.hpp:63
dbe::config::api
Definition
config_api.hpp:33
dbe::config::errors::parse
std::string const parse(ers::Issue const &)
Definition
config_api.cpp:113
dbe::config
Definition
config_api.hpp:31
dbe::convert::to
T to(QStringList const &DataList)
Definition
Conversion.hpp:116
dbe
Include QT Headers.
Definition
BatchChangeWidget.hpp:18
dunedaq::conffwk
Definition
Change.hpp:23
dunedaq::conffwk::date_type
@ date_type
Definition
Schema.hpp:39
dunedaq::conffwk::u64_type
@ u64_type
Definition
Schema.hpp:36
dunedaq::conffwk::float_type
@ float_type
Definition
Schema.hpp:37
dunedaq::conffwk::s32_type
@ s32_type
Definition
Schema.hpp:33
dunedaq::conffwk::string_type
@ string_type
Definition
Schema.hpp:41
dunedaq::conffwk::s16_type
@ s16_type
Definition
Schema.hpp:31
dunedaq::conffwk::u32_type
@ u32_type
Definition
Schema.hpp:34
dunedaq::conffwk::enum_type
@ enum_type
Definition
Schema.hpp:42
dunedaq::conffwk::bool_type
@ bool_type
Definition
Schema.hpp:28
dunedaq::conffwk::class_type
@ class_type
Definition
Schema.hpp:43
dunedaq::conffwk::s8_type
@ s8_type
Definition
Schema.hpp:29
dunedaq::conffwk::time_type
@ time_type
Definition
Schema.hpp:40
dunedaq::conffwk::u8_type
@ u8_type
Definition
Schema.hpp:30
dunedaq::conffwk::s64_type
@ s64_type
Definition
Schema.hpp:35
dunedaq::conffwk::double_type
@ double_type
Definition
Schema.hpp:38
dunedaq::conffwk::u16_type
@ u16_type
Definition
Schema.hpp:32
dunedaq::obj
msgpack::object obj
Definition
Serialization.hpp:257
dbe::config::api::get::defaults::attribute::value
static QStringList value(dunedaq::conffwk::attribute_t const &)
Definition
config_api_get.cpp:343
dunedaq::conffwk::attribute_t
Definition
Schema.hpp:59
dunedaq::conffwk::attribute_t::p_is_multi_value
bool p_is_multi_value
Definition
Schema.hpp:66
dunedaq::conffwk::attribute_t::p_name
std::string p_name
Definition
Schema.hpp:61
dunedaq::conffwk::attribute_t::p_type
type_t p_type
Definition
Schema.hpp:62
dunedaq::conffwk::attribute_t::p_default_value
std::string p_default_value
Definition
Schema.hpp:67
Generated on
for DUNE-DAQ by
1.17.0