DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
include
dbe
Conversion.hpp
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: yes (from dbe/Conversion.h to include/dbe/Conversion.hpp).
5
6
#ifndef DBE_CONVERSION_H_
7
#define DBE_CONVERSION_H_
8
9
#include "
dbe/Exceptions.hpp
"
10
11
#include "
conffwk/Schema.hpp
"
12
#include "
logging/Logging.hpp
"
13
14
#include <sstream>
15
#include <string>
16
#include <type_traits>
17
#include <vector>
18
19
#include <QStringList>
20
21
namespace
dbe
{
22
23
namespace
convert
{
24
//------------------------------------------------------------------------------------------
31
template
<
typename
T>
32
inline
std::string
33
valtostr
(T
const
& value)
34
{
35
return
std::to_string(value);
36
}
37
38
template
<>
39
inline
std::string
40
valtostr<std::string>
(std::string
const
& x)
41
{
42
return
x;
43
}
44
45
template
<>
46
inline
std::string
47
valtostr<bool>
(
bool
const
& s)
48
{
49
std::ostringstream ss;
50
ss << std::boolalpha << s;
51
return
ss.str();
52
}
53
//------------------------------------------------------------------------------------------
54
55
//------------------------------------------------------------------------------------------
62
template<typename T, typename std::enable_if<std::is_integral<T>::value,
int
>
::type
= 0>
63
inline
std::string
64
valtostr
(T
const
& value,
dunedaq::conffwk::int_format_t
const
format)
65
{
66
if
(format ==
dunedaq::conffwk::dec_int_format
) {
67
return
std::to_string(value);
68
}
else
{
69
std::ostringstream ss;
70
71
if
(format ==
dunedaq::conffwk::hex_int_format
) {
72
ss << std::hex << std::showbase << +((
typename
std::make_unsigned<T>::type)value);
73
}
else
if
(format ==
dunedaq::conffwk::oct_int_format
) {
74
ss << std::oct << std::showbase << +((
typename
std::make_unsigned<T>::type)value);
75
}
else
if
(format ==
dunedaq::conffwk::na_int_format
) {
76
ss << value;
77
TLOG_DEBUG
(1) <<
" This conversion should not happen for value "
<< ss.str();
78
}
79
80
return
ss.str();
81
}
82
}
83
84
// Specialization for boolean (the std::make_unsigned is not defined for booleans)
85
template
<>
86
inline
std::string
87
valtostr<bool>
(
bool
const
& value,
dunedaq::conffwk::int_format_t
const
format)
88
{
89
Q_UNUSED(format);
90
return
valtostr<bool>
(value);
91
}
92
93
// This is for floating point types
94
template<typename T, typename std::enable_if<std::is_floating_point<T>::value,
int
>
::type
= 0>
95
inline
std::string
96
valtostr
(T
const
& value,
dunedaq::conffwk::int_format_t
const
format)
97
{
98
Q_UNUSED(format);
99
return
std::to_string(value);
100
}
101
102
// This is for simple strings
103
inline
std::string
104
valtostr
(std::string
const
& value,
dunedaq::conffwk::int_format_t
const
format)
105
{
106
Q_UNUSED(format);
107
return
value;
108
}
109
//------------------------------------------------------------------------------------------
110
111
//------------------------------------------------------------------------------------------
112
template
<
typename
T>
113
T
114
to
(QStringList
const
& DataList)
115
{
116
Q_UNUSED(DataList)
117
118
T Dummy;
119
return
Dummy;
120
}
121
122
template
<
typename
T>
123
T
124
to
(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format)
125
{
126
Q_UNUSED(Format)
127
Q_UNUSED(DataList)
128
129
T Dummy;
130
return
Dummy;
131
}
132
133
template
<
typename
T>
134
T
135
to
(std::vector<std::string>
const
& x)
136
{
137
return
x;
138
}
139
//------------------------------------------------------------------------------------------
140
141
//------------------------------------------------------------------------------------------
143
144
template
<>
145
QStringList
146
to
(std::vector<std::string>
const
& DataList);
147
148
template
<>
149
bool
150
to<bool>
(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
151
template
<>
152
std::vector<bool>
153
to<std::vector<bool>
>(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
154
template
<>
155
std::string
156
to<std::string>
(QStringList
const
& DataList);
157
template
<>
158
std::vector<std::string>
159
to<std::vector<std::string>
>(QStringList
const
& DataList);
160
template
<>
161
std::string
162
to<std::string>
(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
163
template
<>
164
std::vector<std::string>
165
to<std::vector<std::string>
>(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
166
template
<>
167
u_int8_t
168
to<u_int8_t>
(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
169
template
<>
170
std::vector<u_int8_t>
171
to<std::vector<u_int8_t>
>(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
172
template
<>
173
int8_t
174
to<int8_t>
(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
175
template
<>
176
std::vector<int8_t>
177
to<std::vector<int8_t>
>(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
178
template
<>
179
u_int16_t
180
to<u_int16_t>
(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
181
template
<>
182
std::vector<u_int16_t>
183
to<std::vector<u_int16_t>
>(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
184
template
<>
185
int16_t
186
to<int16_t>
(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
187
template
<>
188
std::vector<int16_t>
189
to<std::vector<int16_t>
>(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
190
template
<>
191
u_int32_t
192
to<u_int32_t>
(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
193
template
<>
194
std::vector<u_int32_t>
195
to<std::vector<u_int32_t>
>(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
196
template
<>
197
int32_t
198
to<int32_t>
(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
199
template
<>
200
std::vector<int32_t>
201
to<std::vector<int32_t>
>(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
202
template
<>
203
u_int64_t
204
to<u_int64_t>
(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
205
template
<>
206
std::vector<u_int64_t>
207
to<std::vector<u_int64_t>
>(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
208
template
<>
209
int64_t
210
to<int64_t>
(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
211
template
<>
212
std::vector<int64_t>
213
to<std::vector<int64_t>
>(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
214
template
<>
215
float
216
to<float>
(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
217
template
<>
218
std::vector<float>
219
to<std::vector<float>
>(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
220
template
<>
221
double
222
to<double>
(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
223
template
<>
224
std::vector<double>
225
to<std::vector<double>
>(QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format);
226
//------------------------------------------------------------------------------------------
227
228
}
229
}
230
231
#endif
// DBE_CONVERSION_H_
Exceptions.hpp
type
type
Definition
TriggerActivity_serialization.hpp:48
Schema.hpp
Logging.hpp
TLOG_DEBUG
#define TLOG_DEBUG(lvl,...)
Definition
Logging.hpp:116
dbe::convert
Definition
Conversion.hpp:23
dbe::convert::valtostr
std::string valtostr(T const &value)
Definition
Conversion.hpp:33
dbe::convert::to
T to(QStringList const &DataList)
Definition
Conversion.hpp:114
dbe::convert::to< std::string >
std::string to< std::string >(QStringList const &DataList)
Definition
Conversion.cpp:27
dbe::convert::valtostr< std::string >
std::string valtostr< std::string >(std::string const &x)
Definition
Conversion.hpp:40
dbe
Include QT Headers.
Definition
BatchChangeWidget.hpp:16
dunedaq::conffwk::int_format_t
int_format_t
Definition
Schema.hpp:50
dunedaq::conffwk::dec_int_format
@ dec_int_format
Definition
Schema.hpp:52
dunedaq::conffwk::na_int_format
@ na_int_format
Definition
Schema.hpp:54
dunedaq::conffwk::oct_int_format
@ oct_int_format
Definition
Schema.hpp:51
dunedaq::conffwk::hex_int_format
@ hex_int_format
Definition
Schema.hpp:53
Generated on
for DUNE-DAQ by
1.18.0