DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
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
14#include "dbe/Conversion.hpp"
15#include "dbe/dbaccessor.hpp"
16#include "dbe/messenger.hpp"
17#include "dbe/config_api.hpp"
18
19using namespace dunedaq::conffwk;
20
21
22//------------------------------------------------------------------------------------------
23// NAMESPACE DBE::CONFIG::API::GET
24//------------------------------------------------------------------------------------------
25
26namespace dbe
27{
28
29namespace config
30{
31
32namespace api
33{
34
35namespace get
36{
37//------------------------------------------------------------------------------------------
38
39template<typename T>
40inline 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//------------------------------------------------------------------------------------------
70template<typename T>
73{
74 T value;
75 input.get ( attr.p_name, value );
76 return value;
77}
78
79//------------------------------------------------------------------------------------------
80
81//------------------------------------------------------------------------------------------
82template<>
85{
86 std::vector<std::string> data;
87
88 switch ( attr.p_type )
89 {
90
92 data = get::attribute::read<bool> ( input, attr );
93 break;
94
96
98
100
102
104 data = get::attribute::read<std::string> ( input, attr );
105 break;
106
108 data = get::attribute::read<float> ( input, attr );
109 break;
110
112 data = get::attribute::read<double> ( input, attr );
113 break;
114
116 data = get::attribute::read<int8_t> ( input, attr );
117 break;
118
120 data = get::attribute::read<u_int8_t> ( input, attr );
121 break;
122
124 data = get::attribute::read<int16_t> ( input, attr );
125 break;
126
128 data = get::attribute::read<u_int16_t> ( input, attr );
129 break;
130
132 data = get::attribute::read<int32_t> ( input, attr );
133 break;
134
136 data = get::attribute::read<u_int32_t> ( input, attr );
137 break;
138
140 data = get::attribute::read<int64_t> ( input, attr );
141 break;
142
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
159template
161( ConfigObject &,
163
164template
166( ConfigObject &,
168
169template
170std::vector<ConfigObject>
173
174//------------------------------------------------------------------------------------------
175
176//------------------------------------------------------------------------------------------
177template<typename T>
179 dunedaq::conffwk::attribute_t const & Attribute )
180{
181 std::vector<std::string> attrvalues;
182
183 switch ( Attribute.p_type )
184 {
185
187 attrvalues = get::attribute::read<bool> ( obj, Attribute );
188 break;
189
191
193
195
197
199 attrvalues = get::attribute::read<std::string> ( obj, Attribute );
200 break;
201
203 attrvalues = get::attribute::read<float> ( obj, Attribute );
204 break;
205
207 attrvalues = get::attribute::read<double> ( obj, Attribute );
208 break;
209
211 attrvalues = get::attribute::read<int8_t> ( obj, Attribute );
212 break;
213
215 attrvalues = get::attribute::read<u_int8_t> ( obj, Attribute );
216 break;
217
219 attrvalues = get::attribute::read<int16_t> ( obj, Attribute );
220 break;
221
223 attrvalues = get::attribute::read<u_int16_t> ( obj, Attribute );
224 break;
225
227 attrvalues = get::attribute::read<int32_t> ( obj, Attribute );
228 break;
229
231 attrvalues = get::attribute::read<u_int32_t> ( obj, Attribute );
232 break;
233
235 attrvalues = get::attribute::read<int64_t> ( obj, Attribute );
236 break;
237
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
247template
250//------------------------------------------------------------------------------------------
251
252//------------------------------------------------------------------------------------------
253QStringList 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//------------------------------------------------------------------------------------------
315QStringList 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//------------------------------------------------------------------------------------------
344{
345 return QString::fromStdString ( attr.p_default_value ).split ( "," );
346}
347
348//------------------------------------------------------------------------------------------
349
350//------------------------------------------------------------------------------------------
351}
352}
353}
354}
355
356//------------------------------------------------------------------------------------------
357
static T list(dbe::inner::configobject::tref obj, dunedaq::conffwk::attribute_t const &attr)
static std::vector< std::string > read(dunedaq::conffwk::ConfigObject &, dunedaq::conffwk::attribute_t const &)
friend class dbe::config::api::get::attribute
static QStringList inclusions_singlefile(QString const &)
static QStringList inclusions(QStringList const &candidates, QStringList files={ })
static cptr< dunedaq::conffwk::Configuration > dbptr()
Represents database objects.
void get(const std::string &name, T &value)
Get value of object's attribute or relationship.
#define ERROR(...)
Definition messenger.hpp:93
#define WARN(...)
Definition messenger.hpp:85
std::string const parse(ers::Issue const &)
T to(QStringList const &DataList)
Include QT Headers.
msgpack::object obj
static QStringList value(dunedaq::conffwk::attribute_t const &)