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