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