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 <string>
15
#include <vector>
16
#include <sstream>
17
#include <type_traits>
18
19
#include <QStringList>
20
21
namespace
dbe
22
{
23
24
namespace
convert
25
{
26
//------------------------------------------------------------------------------------------
33
template
<
typename
T>
inline
std::string
valtostr
( T
const
& value )
34
{
35
return
std::to_string ( value );
36
}
37
38
template
<>
inline
std::string
valtostr<std::string>
( std::string
const
& x )
39
{
40
return
x;
41
}
42
43
template
<>
inline
std::string
valtostr<bool>
(
bool
const
& s )
44
{
45
std::ostringstream ss;
46
ss << std::boolalpha << s;
47
return
ss.str();
48
}
49
//------------------------------------------------------------------------------------------
50
51
//------------------------------------------------------------------------------------------
58
template<typename T, typename std::enable_if<std::is_integral<T>::value,
int
>
::type
= 0>
59
inline
std::string
valtostr
( T
const
& value,
60
dunedaq::conffwk::int_format_t
const
format )
61
{
62
if
( format ==
dunedaq::conffwk::dec_int_format
)
63
{
64
return
std::to_string ( value );
65
}
66
else
67
{
68
std::ostringstream ss;
69
70
if
( format ==
dunedaq::conffwk::hex_int_format
)
71
{
72
ss << std::hex << std::showbase << +((
typename
std::make_unsigned<T>::type) value);
73
}
74
else
if
( format ==
dunedaq::conffwk::oct_int_format
)
75
{
76
ss << std::oct << std::showbase << +((
typename
std::make_unsigned<T>::type) value);
77
}
78
else
if
( format ==
dunedaq::conffwk::na_int_format
)
79
{
80
ss << value;
81
TLOG_DEBUG
(1) <<
" This conversion should not happen for value "
<< ss.str() ;
82
}
83
84
return
ss.str();
85
}
86
}
87
88
// Specialization for boolean (the std::make_unsigned is not defined for booleans)
89
template
<>
inline
std::string
valtostr<bool>
(
bool
const
& value,
90
dunedaq::conffwk::int_format_t
const
format )
91
{
92
Q_UNUSED ( format );
93
return
valtostr<bool>
(value);
94
}
95
96
// This is for floating point types
97
template<typename T, typename std::enable_if<std::is_floating_point<T>::value,
int
>
::type
= 0>
98
inline
std::string
valtostr
( T
const
& value,
99
dunedaq::conffwk::int_format_t
const
format )
100
{
101
Q_UNUSED ( format );
102
return
std::to_string(value);
103
}
104
105
// This is for simple strings
106
inline
std::string
valtostr
( std::string
const
& value,
107
dunedaq::conffwk::int_format_t
const
format )
108
{
109
Q_UNUSED ( format );
110
return
value;
111
}
112
//------------------------------------------------------------------------------------------
113
114
//------------------------------------------------------------------------------------------
115
template
<
typename
T>
116
T
to
( QStringList
const
& DataList )
117
{
118
Q_UNUSED ( DataList )
119
120
T Dummy;
121
return
Dummy;
122
}
123
124
template
<
typename
T>
125
T
to
( QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format )
126
{
127
Q_UNUSED ( Format )
128
Q_UNUSED ( DataList )
129
130
T Dummy;
131
return
Dummy;
132
}
133
134
template
<
typename
T>
135
T
to
( std::vector<std::string>
const
& x )
136
{
137
return
x;
138
}
139
//------------------------------------------------------------------------------------------
140
141
//------------------------------------------------------------------------------------------
143
144
template
<> QStringList
to
( std::vector<std::string>
const
& DataList );
145
146
template
<>
bool
to<bool>
( QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format );
147
template
<> std::vector<bool>
to<std::vector<bool>
> ( QStringList
const
& DataList,
148
dunedaq::conffwk::int_format_t
Format );
149
template
<> std::string
to<std::string>
( QStringList
const
& DataList );
150
template
<> std::vector<std::string>
to<std::vector<std::string>
> (
151
QStringList
const
& DataList );
152
template
<> std::string
to<std::string>
( QStringList
const
& DataList,
153
dunedaq::conffwk::int_format_t
Format );
154
template
<> std::vector<std::string>
to<std::vector<std::string>
> (
155
QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format );
156
template
<> u_int8_t
to<u_int8_t>
( QStringList
const
& DataList,
157
dunedaq::conffwk::int_format_t
Format );
158
template
<> std::vector<u_int8_t>
to<std::vector<u_int8_t>
> (
159
QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format );
160
template
<> int8_t
to<int8_t>
( QStringList
const
& DataList,
161
dunedaq::conffwk::int_format_t
Format );
162
template
<> std::vector<int8_t>
to<std::vector<int8_t>
> ( QStringList
const
& DataList,
163
dunedaq::conffwk::int_format_t
Format );
164
template
<> u_int16_t
to<u_int16_t>
( QStringList
const
& DataList,
165
dunedaq::conffwk::int_format_t
Format );
166
template
<> std::vector<u_int16_t>
to<std::vector<u_int16_t>
> (
167
QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format );
168
template
<> int16_t
to<int16_t>
( QStringList
const
& DataList,
169
dunedaq::conffwk::int_format_t
Format );
170
template
<> std::vector<int16_t>
to<std::vector<int16_t>
> ( QStringList
const
& DataList,
171
dunedaq::conffwk::int_format_t
Format );
172
template
<> u_int32_t
to<u_int32_t>
( QStringList
const
& DataList,
173
dunedaq::conffwk::int_format_t
Format );
174
template
<> std::vector<u_int32_t>
to<std::vector<u_int32_t>
> (
175
QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format );
176
template
<> int32_t
to<int32_t>
( QStringList
const
& DataList,
177
dunedaq::conffwk::int_format_t
Format );
178
template
<> std::vector<int32_t>
to<std::vector<int32_t>
> ( QStringList
const
& DataList,
179
dunedaq::conffwk::int_format_t
Format );
180
template
<> u_int64_t
to<u_int64_t>
( QStringList
const
& DataList,
181
dunedaq::conffwk::int_format_t
Format );
182
template
<> std::vector<u_int64_t>
to<std::vector<u_int64_t>
> (
183
QStringList
const
& DataList,
dunedaq::conffwk::int_format_t
Format );
184
template
<> int64_t
to<int64_t>
( QStringList
const
& DataList,
185
dunedaq::conffwk::int_format_t
Format );
186
template
<> std::vector<int64_t>
to<std::vector<int64_t>
> ( QStringList
const
& DataList,
187
dunedaq::conffwk::int_format_t
Format );
188
template
<>
float
to<float>
( QStringList
const
& DataList,
189
dunedaq::conffwk::int_format_t
Format );
190
template
<> std::vector<float>
to<std::vector<float>
> ( QStringList
const
& DataList,
191
dunedaq::conffwk::int_format_t
Format );
192
template
<>
double
to<double>
( QStringList
const
& DataList,
193
dunedaq::conffwk::int_format_t
Format );
194
template
<> std::vector<double>
to<std::vector<double>
> ( QStringList
const
& DataList,
195
dunedaq::conffwk::int_format_t
Format );
196
//------------------------------------------------------------------------------------------
197
198
}
199
}
200
201
#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:112
dbe::convert
Definition
Conversion.hpp:25
dbe::convert::to< int8_t >
int8_t to< int8_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
Definition
Conversion.cpp:115
dbe::convert::valtostr
std::string valtostr(T const &value)
Definition
Conversion.hpp:33
dbe::convert::to< u_int64_t >
u_int64_t to< u_int64_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
Definition
Conversion.cpp:335
dbe::convert::to< int16_t >
int16_t to< int16_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
Definition
Conversion.cpp:203
dbe::convert::to< u_int8_t >
u_int8_t to< u_int8_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
Definition
Conversion.cpp:71
dbe::convert::valtostr< bool >
std::string valtostr< bool >(bool const &s)
Definition
Conversion.hpp:43
dbe::convert::to< int64_t >
int64_t to< int64_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
Definition
Conversion.cpp:379
dbe::convert::to
T to(QStringList const &DataList)
Definition
Conversion.hpp:116
dbe::convert::to< std::string >
std::string to< std::string >(QStringList const &DataList)
Definition
Conversion.cpp:23
dbe::convert::to< int32_t >
int32_t to< int32_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
Definition
Conversion.cpp:291
dbe::convert::valtostr< std::string >
std::string valtostr< std::string >(std::string const &x)
Definition
Conversion.hpp:38
dbe::convert::to< u_int32_t >
u_int32_t to< u_int32_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
Definition
Conversion.cpp:247
dbe::convert::to< double >
double to< double >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
Definition
Conversion.cpp:449
dbe::convert::to< u_int16_t >
u_int16_t to< u_int16_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
Definition
Conversion.cpp:159
dbe::convert::to< float >
float to< float >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
Definition
Conversion.cpp:423
dbe::convert::to< bool >
bool to< bool >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
Definition
Conversion.cpp:475
dbe
Include QT Headers.
Definition
BatchChangeWidget.hpp:18
dunedaq::conffwk::int_format_t
int_format_t
Definition
Schema.hpp:49
dunedaq::conffwk::dec_int_format
@ dec_int_format
Definition
Schema.hpp:51
dunedaq::conffwk::na_int_format
@ na_int_format
Definition
Schema.hpp:53
dunedaq::conffwk::oct_int_format
@ oct_int_format
Definition
Schema.hpp:50
dunedaq::conffwk::hex_int_format
@ hex_int_format
Definition
Schema.hpp:52
Generated on
for DUNE-DAQ by
1.17.0