Line data Source code
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 0 : attribute::read(ConfigObject& input, dunedaq::conffwk::attribute_t const& attr)
37 : {
38 0 : std::vector<T> attrvalues;
39 :
40 0 : if (attr.p_is_multi_value) {
41 0 : attrvalues = direct::attribute<std::vector<T>>(input, attr);
42 : } else {
43 0 : attrvalues = { direct::attribute<T>(input, attr) };
44 : }
45 :
46 0 : std::vector<std::string> strings(attrvalues.size());
47 0 : std::transform(attrvalues.begin(),
48 : attrvalues.end(),
49 : strings.begin(),
50 0 : [&attr](T const& x) { return convert::valtostr(x, attr.p_int_format); }
51 :
52 : );
53 :
54 0 : return strings;
55 0 : }
56 :
57 : //------------------------------------------------------------------------------------------
58 :
59 : //------------------------------------------------------------------------------------------
60 : template<typename T>
61 : inline T
62 0 : direct::attribute(ConfigObject& input, dunedaq::conffwk::attribute_t const& attr)
63 : {
64 0 : T value;
65 0 : input.get(attr.p_name, value);
66 0 : return value;
67 0 : }
68 :
69 : //------------------------------------------------------------------------------------------
70 :
71 : //------------------------------------------------------------------------------------------
72 : template<>
73 : QStringList
74 0 : direct::attribute<QStringList>(ConfigObject& input, dunedaq::conffwk::attribute_t const& attr)
75 : {
76 0 : std::vector<std::string> data;
77 :
78 0 : switch (attr.p_type) {
79 :
80 0 : case dunedaq::conffwk::bool_type:
81 0 : data = get::attribute::read<bool>(input, attr);
82 0 : break;
83 :
84 0 : case dunedaq::conffwk::enum_type:
85 :
86 0 : case dunedaq::conffwk::date_type:
87 :
88 0 : case dunedaq::conffwk::time_type:
89 :
90 0 : case dunedaq::conffwk::string_type:
91 :
92 0 : case dunedaq::conffwk::class_type:
93 0 : data = get::attribute::read<std::string>(input, attr);
94 0 : break;
95 :
96 0 : case dunedaq::conffwk::float_type:
97 0 : data = get::attribute::read<float>(input, attr);
98 0 : break;
99 :
100 0 : case dunedaq::conffwk::double_type:
101 0 : data = get::attribute::read<double>(input, attr);
102 0 : break;
103 :
104 0 : case dunedaq::conffwk::s8_type:
105 0 : data = get::attribute::read<int8_t>(input, attr);
106 0 : break;
107 :
108 0 : case dunedaq::conffwk::u8_type:
109 0 : data = get::attribute::read<u_int8_t>(input, attr);
110 0 : break;
111 :
112 0 : case dunedaq::conffwk::s16_type:
113 0 : data = get::attribute::read<int16_t>(input, attr);
114 0 : break;
115 :
116 0 : case dunedaq::conffwk::u16_type:
117 0 : data = get::attribute::read<u_int16_t>(input, attr);
118 0 : break;
119 :
120 0 : case dunedaq::conffwk::s32_type:
121 0 : data = get::attribute::read<int32_t>(input, attr);
122 0 : break;
123 :
124 0 : case dunedaq::conffwk::u32_type:
125 0 : data = get::attribute::read<u_int32_t>(input, attr);
126 0 : break;
127 :
128 0 : case dunedaq::conffwk::s64_type:
129 0 : data = get::attribute::read<int64_t>(input, attr);
130 0 : break;
131 :
132 0 : case dunedaq::conffwk::u64_type:
133 0 : data = get::attribute::read<u_int64_t>(input, attr);
134 0 : break;
135 : }
136 :
137 0 : QStringList result;
138 :
139 0 : for (auto const& x : data) {
140 0 : result.push_back(x.c_str());
141 : }
142 :
143 0 : return result;
144 0 : }
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 0 : attribute::list(dbe::inner::configobject::tref obj, dunedaq::conffwk::attribute_t const& Attribute)
161 : {
162 0 : std::vector<std::string> attrvalues;
163 :
164 0 : switch (Attribute.p_type) {
165 :
166 0 : case dunedaq::conffwk::bool_type:
167 0 : attrvalues = get::attribute::read<bool>(obj, Attribute);
168 0 : break;
169 :
170 0 : 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 0 : attrvalues = get::attribute::read<std::string>(obj, Attribute);
180 0 : break;
181 :
182 0 : case dunedaq::conffwk::float_type:
183 0 : attrvalues = get::attribute::read<float>(obj, Attribute);
184 0 : break;
185 :
186 0 : case dunedaq::conffwk::double_type:
187 0 : attrvalues = get::attribute::read<double>(obj, Attribute);
188 0 : break;
189 :
190 0 : case dunedaq::conffwk::s8_type:
191 0 : attrvalues = get::attribute::read<int8_t>(obj, Attribute);
192 0 : break;
193 :
194 0 : case dunedaq::conffwk::u8_type:
195 0 : attrvalues = get::attribute::read<u_int8_t>(obj, Attribute);
196 0 : break;
197 :
198 0 : case dunedaq::conffwk::s16_type:
199 0 : attrvalues = get::attribute::read<int16_t>(obj, Attribute);
200 0 : break;
201 :
202 0 : case dunedaq::conffwk::u16_type:
203 0 : attrvalues = get::attribute::read<u_int16_t>(obj, Attribute);
204 0 : break;
205 :
206 0 : case dunedaq::conffwk::s32_type:
207 0 : attrvalues = get::attribute::read<int32_t>(obj, Attribute);
208 0 : break;
209 :
210 0 : case dunedaq::conffwk::u32_type:
211 0 : attrvalues = get::attribute::read<u_int32_t>(obj, Attribute);
212 0 : break;
213 :
214 0 : case dunedaq::conffwk::s64_type:
215 0 : attrvalues = get::attribute::read<int64_t>(obj, Attribute);
216 0 : break;
217 :
218 0 : case dunedaq::conffwk::u64_type:
219 0 : attrvalues = get::attribute::read<u_int64_t>(obj, Attribute);
220 0 : break;
221 : }
222 :
223 0 : return dbe::convert::to<T>(attrvalues);
224 0 : }
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 0 : file::inclusions(QStringList const& candidates, QStringList files)
234 : {
235 0 : if (candidates.isEmpty()) {
236 0 : return files;
237 : } else {
238 0 : QStringList newcandidates = {};
239 :
240 0 : for (QString const& fname : candidates) {
241 0 : if (not(fname.endsWith("schema.xml") or files.contains(fname))) {
242 0 : files.push_back(fname);
243 : // Query the current file for other inclusions
244 0 : std::list<std::string> configfiles;
245 :
246 0 : try {
247 0 : if (not(fname.contains("rdbconfig:") or fname.contains("roksconflibs:"))) {
248 : // Process file based sources
249 0 : dbaccessor::dbptr()->get_includes(fname.toStdString(), configfiles);
250 : } else {
251 : // Process other sources (e.g. Oracle and RDB )
252 0 : dbaccessor::dbptr()->get_includes("", configfiles);
253 0 : files.removeAll(fname); // Once used RDB / Oracle sources must be removed
254 : }
255 0 : } catch (dunedaq::conffwk::Exception const& ex) {
256 0 : ERROR("Include did not succeed for ",
257 : dbe::config::errors::parse(ex).c_str(),
258 : "filename:",
259 0 : fname.toStdString().c_str());
260 0 : }
261 :
262 : // Keep only files that have not already been processed
263 : // i.e. they are not in the list of given files.
264 0 : for (std::string const& configfile : configfiles) {
265 0 : QString const& qconfigfile = QString::fromStdString(configfile);
266 :
267 0 : if (not files.contains(qconfigfile)) {
268 0 : newcandidates.push_back(qconfigfile);
269 : }
270 0 : }
271 0 : }
272 : }
273 :
274 0 : return get::file::inclusions(newcandidates, files);
275 0 : }
276 : }
277 :
278 : //------------------------------------------------------------------------------------------
279 :
280 : //------------------------------------------------------------------------------------------
281 : QStringList
282 0 : file::inclusions_singlefile(QString const& FileName)
283 : {
284 0 : std::string dbname = FileName.toStdString();
285 0 : std::list<std::string> incList;
286 :
287 0 : QStringList dbfiles;
288 :
289 0 : try {
290 0 : dbaccessor::dbptr()->get_includes(dbname, incList);
291 :
292 0 : for (std::string const& includeName : incList) {
293 0 : dbfiles.push_back(QString(includeName.c_str()));
294 : }
295 0 : } catch (dunedaq::conffwk::Exception& ex) {
296 0 : WARN("Include : Could not retrieve included files", dbe::config::errors::parse(ex).c_str());
297 0 : }
298 :
299 0 : return dbfiles;
300 0 : }
301 :
302 : //------------------------------------------------------------------------------------------
303 :
304 : //------------------------------------------------------------------------------------------
305 : QStringList
306 0 : get::defaults::attribute::value(dunedaq::conffwk::attribute_t const& attr)
307 : {
308 0 : return QString::fromStdString(attr.p_default_value).split(",");
309 : }
310 :
311 : //------------------------------------------------------------------------------------------
312 :
313 : //------------------------------------------------------------------------------------------
314 : }
315 : }
316 : }
317 : }
318 :
319 : //------------------------------------------------------------------------------------------
|