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