DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
wibmod
src
wibmod
WIB1
conversions-impl.hh
Go to the documentation of this file.
1
2
// Implementations of Item value conversions
3
//
4
// note that these are classes declared in a source file;
5
// ItemConversion::FromString is the one and only interface
6
// for creating conversions
7
8
9
DEFINE_CONVERSION_CLASS
(
10
pass,
11
(
12
public
:
13
void
init
(unordered_map<std::string, std::string> params) {
14
(void) params;
// to make compiler not complain about unused arguments
15
data_size =
sizeof
(uint32_t);
16
data_description =
"i"
;
17
}
18
void
Convert
(uint32_t src,
void
*dest) {
19
uint32_t *val = (uint32_t *)dest;
20
*val = src;
21
}
22
))
23
24
DEFINE_CONVERSION_CLASS
(
25
linear,
26
(
27
double
scale
;
28
double
offset
;
29
public:
30
void
init
(unordered_map<
std
::
string
,
std
::
string
> params) {
31
data_size =
sizeof
(double);
32
data_description =
"d"
;
33
std::string scale_str = params[
"scale"
];
34
std::string offset_str = params[
"offset"
];
35
sscanf(scale_str.c_str(),
"%le"
, &
scale
);
36
sscanf(offset_str.c_str(),
"%le"
, &
offset
);
37
};
38
void
Convert
(uint32_t src,
void
*dest) {
39
double
*val = (
double
*)dest;
40
*val = ((double)src) *
scale
+
offset
;
41
}
42
))
43
44
DEFINE_CONVERSION_CLASS
(
45
enum
,
46
(
47
unordered_map<uint32_t, std::string> names;
48
public
:
49
void
init
(unordered_map<std::string, std::string> params) {
50
size_t
length = 16;
// enough for "???? 0x00000000\0"
51
BOOST_FOREACH(
STRIP
((std::pair<std::string, std::string>)) i, params ) {
52
long
int
number = 0;
53
std::string key = i.first;
54
std::string value = i.second;
55
if
(1 != sscanf(key.c_str(),
"%li"
, &number)) {
56
// error: unrecognized number
57
continue
;
58
}
59
names[(uint32_t)number] = value;
60
size_t
newlength = value.size();
61
length = (newlength > length ? newlength : length);
62
}
63
data_size = length;
64
const
size_t
descrlen = 16;
65
char
descr[descrlen];
66
snprintf(descr, descrlen,
"c:%zu;"
, length);
67
data_description = std::string(descr);
68
};
69
void
Convert
(uint32_t src,
void
*dest) {
70
char
*val = (
char
*)dest;
71
if
(names.count(src)) {
72
std::string name = names[src];
73
// strncpy pads to end of buffer with null byte
74
strncpy(val, name.c_str(), data_size);
75
}
else
{
76
// due to snprintf limitation we can't write to the last byte
77
// thus the formatted string uses 15 out of 16 characters
78
int
i = snprintf(val, data_size,
"???? 0x%08X"
, src);
79
// pad to end of buffer with null byte
80
while
(i < (
int
)data_size) {val[i] =
'\0'
; i++;}
81
}
82
}
83
))
84
offset
double offset
Definition
conversions-impl.hh:28
Convert
void Convert(uint32_t src, void *dest)
Definition
conversions-impl.hh:38
scale
double scale
Definition
conversions-impl.hh:27
init
void init(unordered_map< std::string, std::string > params)
Definition
conversions-impl.hh:30
STRIP
#define STRIP(x)
Definition
conversions.cpp:20
DEFINE_CONVERSION_CLASS
#define DEFINE_CONVERSION_CLASS(name, body)
Definition
conversions.cpp:21
std
Definition
SchemaUtils.hpp:118
Generated on
for DUNE-DAQ by
1.17.0