DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Conversion.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#include "dbe/Conversion.hpp"
7#include "dbe/Exceptions.hpp"
8
9namespace dbe {
10namespace convert {
11
12template<> QStringList to<QStringList>(std::vector<std::string> const & x) {
13 QStringList ret;
14
15 for(std::string const & a : x) {
16 ret.append(QString::fromStdString(a));
17 }
18
19 return ret;
20}
21
22template<>
23std::string to<std::string>(QStringList const & DataList) {
24 std::string rString;
25
26 for(int i = 0; i < DataList.size(); ++i) {
27 rString = DataList.at(i).toStdString();
28 }
29
30 return rString;
31}
32
33template<>
34std::vector<std::string> to<std::vector<std::string> >(QStringList const & DataList) {
35 std::vector<std::string> rVector;
36
37 for(int i = 0; i < DataList.size(); ++i) {
38 rVector.push_back(DataList.at(i).toStdString());
39 }
40
41 return rVector;
42}
43
44template<>
45std::string to<std::string>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
46 Q_UNUSED (Format)
47
48 std::string rString;
49
50 for(int i = 0; i < DataList.size(); ++i) {
51 rString = DataList.at(i).toStdString();
52 }
53
54 return rString;
55}
56
57template<>
58std::vector<std::string> to<std::vector<std::string>>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
59 Q_UNUSED (Format)
60
61 std::vector<std::string> rVector;
62
63 for(int i = 0; i < DataList.size(); ++i) {
64 rVector.push_back(DataList.at(i).toStdString());
65 }
66
67 return rVector;
68}
69
70template<>
71u_int8_t to<u_int8_t>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
72 bool ok = false;
73 u_int8_t uChar = 0;
74
75 if(DataList.size() > 0) {
77 uChar = (u_int8_t) (DataList.at(0).toULong(&ok, 10));
78 } else if(Format == dunedaq::conffwk::hex_int_format) {
79 uChar = (u_int8_t) (DataList.at(0).toULong(&ok, 16));
80 } else if(Format == dunedaq::conffwk::oct_int_format) {
81 uChar = (u_int8_t) (DataList.at(0).toULong(&ok, 8));
82 } else if(Format == dunedaq::conffwk::na_int_format) {
83 uChar = (u_int8_t) (DataList.at(0).toULong(&ok));
84 }
85 }
86
87 return uChar;
88}
89
90template<>
91std::vector<u_int8_t> to<std::vector<u_int8_t> >(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
92 std::vector<u_int8_t> rVector;
93
94 for(int i = 0; i < DataList.size(); ++i) {
95 bool ok = false;
96 u_int8_t uChar = 0;
97
99 uChar = (u_int8_t) (DataList.at(i).toULong(&ok, 10));
100 } else if(Format == dunedaq::conffwk::hex_int_format) {
101 uChar = (u_int8_t) (DataList.at(i).toULong(&ok, 16));
102 } else if(Format == dunedaq::conffwk::oct_int_format) {
103 uChar = (u_int8_t) (DataList.at(i).toULong(&ok, 8));
104 } else if(Format == dunedaq::conffwk::na_int_format) {
105 uChar = (u_int8_t) (DataList.at(i).toULong(&ok));
106 }
107
108 rVector.push_back(uChar);
109 }
110
111 return rVector;
112}
113
114template<>
115int8_t to<int8_t>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
116 bool ok = false;
117 int8_t sChar = 0;
118
119 if(DataList.size() > 0) {
121 sChar = (int8_t) (DataList.at(0).toLong(&ok, 10));
122 } else if(Format == dunedaq::conffwk::hex_int_format) {
123 sChar = (int8_t) (DataList.at(0).toLong(&ok, 16));
124 } else if(Format == dunedaq::conffwk::oct_int_format) {
125 sChar = (int8_t) (DataList.at(0).toLong(&ok, 8));
126 } else if(Format == dunedaq::conffwk::na_int_format) {
127 sChar = (int8_t) (DataList.at(0).toLong(&ok));
128 }
129 }
130
131 return sChar;
132}
133
134template<>
135std::vector<int8_t> to<std::vector<int8_t>>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
136 std::vector<int8_t> rVector;
137
138 for(int i = 0; i < DataList.size(); ++i) {
139 bool ok = false;
140 int8_t sChar = 0;
141
143 sChar = (int8_t) (DataList.at(i).toLong(&ok, 10));
144 } else if(Format == dunedaq::conffwk::hex_int_format) {
145 sChar = (int8_t) (DataList.at(i).toLong(&ok, 16));
146 } else if(Format == dunedaq::conffwk::oct_int_format) {
147 sChar = (int8_t) (DataList.at(i).toLong(&ok, 8));
148 } else if(Format == dunedaq::conffwk::na_int_format) {
149 sChar = (int8_t) (DataList.at(i).toLong(&ok));
150 }
151
152 rVector.push_back(sChar);
153 }
154
155 return rVector;
156}
157
158template<>
159u_int16_t to<u_int16_t>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
160 bool ok = false;
161 u_int16_t uShort = 0;
162
163 if(DataList.size() > 0) {
165 uShort = DataList.at(0).toUShort(&ok, 10);
166 } else if(Format == dunedaq::conffwk::hex_int_format) {
167 uShort = DataList.at(0).toUShort(&ok, 16);
168 } else if(Format == dunedaq::conffwk::oct_int_format) {
169 uShort = DataList.at(0).toUShort(&ok, 8);
170 } else if(Format == dunedaq::conffwk::na_int_format) {
171 uShort = DataList.at(0).toUShort(&ok);
172 }
173 }
174
175 return uShort;
176}
177
178template<>
179std::vector<u_int16_t> to<std::vector<u_int16_t>>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
180 std::vector<u_int16_t> rVector;
181
182 for(int i = 0; i < DataList.size(); ++i) {
183 bool ok = false;
184 u_int16_t uShort = 0;
185
187 uShort = DataList.at(i).toUShort(&ok, 10);
188 } else if(Format == dunedaq::conffwk::hex_int_format) {
189 uShort = DataList.at(i).toUShort(&ok, 16);
190 } else if(Format == dunedaq::conffwk::oct_int_format) {
191 uShort = DataList.at(i).toUShort(&ok, 8);
192 } else if(Format == dunedaq::conffwk::na_int_format) {
193 uShort = DataList.at(i).toUShort(&ok);
194 }
195
196 rVector.push_back(uShort);
197 }
198
199 return rVector;
200}
201
202template<>
203int16_t to<int16_t>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
204 bool ok = false;
205 int16_t sShort = 0;
206
207 if(DataList.size() > 0) {
209 sShort = DataList.at(0).toShort(&ok, 10);
210 } else if(Format == dunedaq::conffwk::hex_int_format) {
211 sShort = DataList.at(0).toShort(&ok, 16);
212 } else if(Format == dunedaq::conffwk::oct_int_format) {
213 sShort = DataList.at(0).toShort(&ok, 8);
214 } else if(Format == dunedaq::conffwk::na_int_format) {
215 sShort = DataList.at(0).toShort(&ok);
216 }
217 }
218
219 return sShort;
220}
221
222template<>
223std::vector<int16_t> to<std::vector<int16_t>>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
224 std::vector<int16_t> rVector;
225
226 for(int i = 0; i < DataList.size(); ++i) {
227 bool ok = false;
228 int16_t sShort = 0;
229
231 sShort = DataList.at(i).toShort(&ok, 10);
232 } else if(Format == dunedaq::conffwk::hex_int_format) {
233 sShort = DataList.at(i).toShort(&ok, 16);
234 } else if(Format == dunedaq::conffwk::oct_int_format) {
235 sShort = DataList.at(i).toShort(&ok, 8);
236 } else if(Format == dunedaq::conffwk::na_int_format) {
237 sShort = DataList.at(i).toShort(&ok);
238 }
239
240 rVector.push_back(sShort);
241 }
242
243 return rVector;
244}
245
246template<>
247u_int32_t to<u_int32_t>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
248 bool ok = false;
249 u_int32_t uLong = 0;
250
251 if(DataList.size() > 0) {
253 uLong = DataList.at(0).toULong(&ok, 10);
254 } else if(Format == dunedaq::conffwk::hex_int_format) {
255 uLong = DataList.at(0).toULong(&ok, 16);
256 } else if(Format == dunedaq::conffwk::oct_int_format) {
257 uLong = DataList.at(0).toULong(&ok, 8);
258 } else if(Format == dunedaq::conffwk::na_int_format) {
259 uLong = DataList.at(0).toULong(&ok);
260 }
261 }
262
263 return uLong;
264}
265
266template<>
267std::vector<u_int32_t> to<std::vector<u_int32_t>>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
268 std::vector<u_int32_t> rVector;
269
270 for(int i = 0; i < DataList.size(); ++i) {
271 bool ok = false;
272 u_int32_t uLong = 0;
273
275 uLong = DataList.at(i).toULong(&ok, 10);
276 } else if(Format == dunedaq::conffwk::hex_int_format) {
277 uLong = DataList.at(i).toULong(&ok, 16);
278 } else if(Format == dunedaq::conffwk::oct_int_format) {
279 uLong = DataList.at(i).toULong(&ok, 8);
280 } else if(Format == dunedaq::conffwk::na_int_format) {
281 uLong = DataList.at(i).toULong(&ok);
282 }
283
284 rVector.push_back(uLong);
285 }
286
287 return rVector;
288}
289
290template<>
291int32_t to<int32_t>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
292 bool ok = false;
293 int32_t sLong = 0;
294
295 if(DataList.size() > 0) {
297 sLong = DataList.at(0).toLong(&ok, 10);
298 } else if(Format == dunedaq::conffwk::hex_int_format) {
299 sLong = DataList.at(0).toLong(&ok, 16);
300 } else if(Format == dunedaq::conffwk::oct_int_format) {
301 sLong = DataList.at(0).toLong(&ok, 8);
302 } else if(Format == dunedaq::conffwk::na_int_format) {
303 sLong = DataList.at(0).toLong(&ok);
304 }
305 }
306
307 return sLong;
308}
309
310template<>
311std::vector<int32_t> to<std::vector<int32_t>>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
312 std::vector<int32_t> rVector;
313
314 for(int i = 0; i < DataList.size(); ++i) {
315 bool ok = false;
316 int32_t sLong = 0;
317
319 sLong = DataList.at(i).toLong(&ok, 10);
320 } else if(Format == dunedaq::conffwk::hex_int_format) {
321 sLong = DataList.at(i).toLong(&ok, 16);
322 } else if(Format == dunedaq::conffwk::oct_int_format) {
323 sLong = DataList.at(i).toLong(&ok, 8);
324 } else if(Format == dunedaq::conffwk::na_int_format) {
325 sLong = DataList.at(i).toLong(&ok, 10);
326 }
327
328 rVector.push_back(sLong);
329 }
330
331 return rVector;
332}
333
334template<>
335u_int64_t to<u_int64_t>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
336 bool ok = false;
337 u_int64_t u64 = 0;
338
339 if(DataList.size() > 0) {
341 u64 = (uint64_t) (DataList.at(0).toULongLong(&ok, 10));
342 } else if(Format == dunedaq::conffwk::hex_int_format) {
343 u64 = (uint64_t) (DataList.at(0).toULongLong(&ok, 16));
344 } else if(Format == dunedaq::conffwk::oct_int_format) {
345 u64 = (uint64_t) (DataList.at(0).toULongLong(&ok, 8));
346 } else if(Format == dunedaq::conffwk::na_int_format) {
347 u64 = (uint64_t) (DataList.at(0).toULongLong(&ok, 10));
348 }
349 }
350
351 return u64;
352}
353
354template<>
355std::vector<u_int64_t> to<std::vector<u_int64_t>>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
356 std::vector<u_int64_t> rVector;
357
358 for(int i = 0; i < DataList.size(); ++i) {
359 bool ok = false;
360 u_int64_t u64 = 0;
361
363 u64 = (uint64_t) (DataList.at(i).toULongLong(&ok, 10));
364 } else if(Format == dunedaq::conffwk::hex_int_format) {
365 u64 = (uint64_t) (DataList.at(i).toULongLong(&ok, 16));
366 } else if(Format == dunedaq::conffwk::oct_int_format) {
367 u64 = (uint64_t) (DataList.at(i).toULongLong(&ok, 8));
368 } else if(Format == dunedaq::conffwk::na_int_format) {
369 u64 = (uint64_t) (DataList.at(i).toULongLong(&ok, 10));
370 }
371
372 rVector.push_back(u64);
373 }
374
375 return rVector;
376}
377
378template<>
379int64_t to<int64_t>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
380 bool ok = false;
381 int64_t i64 = 0;
382
383 if(DataList.size() > 0) {
385 i64 = (int64_t) (DataList.at(0).toLongLong(&ok, 10));
386 } else if(Format == dunedaq::conffwk::hex_int_format) {
387 i64 = (int64_t) (DataList.at(0).toLongLong(&ok, 16));
388 } else if(Format == dunedaq::conffwk::oct_int_format) {
389 i64 = (int64_t) (DataList.at(0).toLongLong(&ok, 8));
390 } else if(Format == dunedaq::conffwk::na_int_format) {
391 i64 = (int64_t) (DataList.at(0).toLongLong(&ok, 10));
392 }
393 }
394
395 return i64;
396}
397
398template<>
399std::vector<int64_t> to<std::vector<int64_t>>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
400 std::vector<int64_t> rVector;
401
402 for(int i = 0; i < DataList.size(); ++i) {
403 bool ok = false;
404 int64_t i64 = 0;
405
407 i64 = (int64_t) (DataList.at(i).toLongLong(&ok, 10));
408 } else if(Format == dunedaq::conffwk::hex_int_format) {
409 i64 = (int64_t) (DataList.at(i).toLongLong(&ok, 16));
410 } else if(Format == dunedaq::conffwk::oct_int_format) {
411 i64 = (int64_t) (DataList.at(i).toLongLong(&ok, 8));
412 } else if(Format == dunedaq::conffwk::na_int_format) {
413 i64 = (int64_t) (DataList.at(i).toLongLong(&ok, 10));
414 }
415
416 rVector.push_back(i64);
417 }
418
419 return rVector;
420}
421
422template<>
423float to<float>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
424 Q_UNUSED (Format)
425
426 float f {0};
427
428 for(auto i = 0; i < DataList.size(); ++i) {
429 f = DataList.at(i).toFloat();
430 }
431
432 return f;
433}
434
435template<>
436std::vector<float> to<std::vector<float>>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
437 Q_UNUSED (Format)
438
439 std::vector<float> rVector;
440
441 for(int i = 0; i < DataList.size(); ++i) {
442 rVector.push_back(DataList.at(i).toFloat());
443 }
444
445 return rVector;
446}
447
448template<>
449double to<double>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
450 Q_UNUSED (Format)
451
452 double d {0};
453
454 for(int i = 0; i < DataList.size(); ++i) {
455 d = DataList.at(i).toDouble();
456 }
457
458 return d;
459}
460
461template<>
462std::vector<double> to<std::vector<double>>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
463 Q_UNUSED (Format)
464
465 std::vector<double> rVector;
466
467 for(int i = 0; i < DataList.size(); ++i) {
468 rVector.push_back(DataList.at(i).toDouble());
469 }
470
471 return rVector;
472}
473
474template<>
475bool to<bool>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
476 bool b = false;
477 Q_UNUSED (Format)
478
479 for(int i = 0; i < DataList.size(); ++i) {
480 if(QString::compare(DataList.at(i), QString("true"), Qt::CaseInsensitive) == 0
481 || QString::compare(DataList.at(i), QString("1"), Qt::CaseInsensitive) == 0) {
482 b = true;
483 } else if(QString::compare(DataList.at(i), QString("false"), Qt::CaseInsensitive) == 0
484 || QString::compare(DataList.at(i), QString("0"), Qt::CaseInsensitive) == 0) {
485 b = false;
486 } else {
487 std::string message = "Conversion to enum of " + DataList.at(i).toStdString() + " is not possible!";
488 throw daq::dbe::BadConversion( ERS_HERE, message.c_str() );
489 }
490 }
491
492 return b;
493}
494
495template<>
496std::vector<bool> to<std::vector<bool>>(QStringList const & DataList, dunedaq::conffwk::int_format_t Format) {
497 std::vector<bool> rVector;
498 Q_UNUSED (Format)
499
500 for(int i = 0; i < DataList.size(); ++i) {
501 if(QString::compare(DataList.at(i), QString("true"), Qt::CaseInsensitive) == 0
502 || QString::compare(DataList.at(i), QString("1"), Qt::CaseInsensitive) == 0) {
503 rVector.push_back(true);
504 } else if(QString::compare(DataList.at(i), QString("false"), Qt::CaseInsensitive) == 0
505 || QString::compare(DataList.at(i), QString("0"), Qt::CaseInsensitive) == 0) {
506 rVector.push_back(false);
507 } else {
508 std::string message = "Conversion to enum of " + DataList.at(i).toStdString() + " is not possible!";
509 throw daq::dbe::BadConversion( ERS_HERE, message.c_str() );
510 }
511 }
512
513 return rVector;
514}
515
516}
517}
#define ERS_HERE
Only Configuration DB opened by rdbconfig or oksconflibs plug in can be message
int8_t to< int8_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
u_int64_t to< u_int64_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
int16_t to< int16_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
u_int8_t to< u_int8_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
int64_t to< int64_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
T to(QStringList const &DataList)
QStringList to< QStringList >(std::vector< std::string > const &x)
std::string to< std::string >(QStringList const &DataList)
int32_t to< int32_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
u_int32_t to< u_int32_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
double to< double >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
u_int16_t to< u_int16_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
float to< float >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
bool to< bool >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
Include QT Headers.