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