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