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/config_api.hpp"
16#include "dbe/dbaccessor.hpp"
17#include "dbe/messenger.hpp"
18
19using namespace dunedaq::conffwk;
20
21//------------------------------------------------------------------------------------------
22// NAMESPACE DBE::CONFIG::API::GET
23//------------------------------------------------------------------------------------------
24
25namespace dbe {
26
27namespace config {
28
29namespace api {
30
31namespace get {
32//------------------------------------------------------------------------------------------
33
34template<typename T>
35inline std::vector<std::string>
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//------------------------------------------------------------------------------------------
60template<typename T>
61inline T
63{
64 T value;
65 input.get(attr.p_name, value);
66 return value;
67}
68
69//------------------------------------------------------------------------------------------
70
71//------------------------------------------------------------------------------------------
72template<>
73QStringList
75{
76 std::vector<std::string> data;
77
78 switch (attr.p_type) {
79
81 data = get::attribute::read<bool>(input, attr);
82 break;
83
85
87
89
91
93 data = get::attribute::read<std::string>(input, attr);
94 break;
95
97 data = get::attribute::read<float>(input, attr);
98 break;
99
101 data = get::attribute::read<double>(input, attr);
102 break;
103
105 data = get::attribute::read<int8_t>(input, attr);
106 break;
107
109 data = get::attribute::read<u_int8_t>(input, attr);
110 break;
111
113 data = get::attribute::read<int16_t>(input, attr);
114 break;
115
117 data = get::attribute::read<u_int16_t>(input, attr);
118 break;
119
121 data = get::attribute::read<int32_t>(input, attr);
122 break;
123
125 data = get::attribute::read<u_int32_t>(input, attr);
126 break;
127
129 data = get::attribute::read<int64_t>(input, attr);
130 break;
131
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
146template QStringList
148
149template ConfigObject
151
152template std::vector<ConfigObject>
154
155//------------------------------------------------------------------------------------------
156
157//------------------------------------------------------------------------------------------
158template<typename T>
159inline T
161{
162 std::vector<std::string> attrvalues;
163
164 switch (Attribute.p_type) {
165
167 attrvalues = get::attribute::read<bool>(obj, Attribute);
168 break;
169
171
173
175
177
179 attrvalues = get::attribute::read<std::string>(obj, Attribute);
180 break;
181
183 attrvalues = get::attribute::read<float>(obj, Attribute);
184 break;
185
187 attrvalues = get::attribute::read<double>(obj, Attribute);
188 break;
189
191 attrvalues = get::attribute::read<int8_t>(obj, Attribute);
192 break;
193
195 attrvalues = get::attribute::read<u_int8_t>(obj, Attribute);
196 break;
197
199 attrvalues = get::attribute::read<int16_t>(obj, Attribute);
200 break;
201
203 attrvalues = get::attribute::read<u_int16_t>(obj, Attribute);
204 break;
205
207 attrvalues = get::attribute::read<int32_t>(obj, Attribute);
208 break;
209
211 attrvalues = get::attribute::read<u_int32_t>(obj, Attribute);
212 break;
213
215 attrvalues = get::attribute::read<int64_t>(obj, Attribute);
216 break;
217
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
227template QStringList
229//------------------------------------------------------------------------------------------
230
231//------------------------------------------------------------------------------------------
232QStringList
233file::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//------------------------------------------------------------------------------------------
281QStringList
282file::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//------------------------------------------------------------------------------------------
305QStringList
307{
308 return QString::fromStdString(attr.p_default_value).split(",");
309}
310
311//------------------------------------------------------------------------------------------
312
313//------------------------------------------------------------------------------------------
314}
315}
316}
317}
318
319//------------------------------------------------------------------------------------------
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:90
#define WARN(...)
Definition messenger.hpp:82
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 &)