DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
trgdataformats
scripts
TriggerPrimitive_binding_test.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
3
from
trgdataformats
import
TriggerPrimitive
4
5
6
def
test_construction_and_sizeof
() -> int:
7
tp = TriggerPrimitive()
8
if
tp
is
None
:
9
print(
"FAIL: TriggerPrimitive default construction returned None"
)
10
return
1
11
12
size = TriggerPrimitive.sizeof()
13
if
size != TriggerPrimitive.s_expected_bytes:
14
print(
15
"FAIL: TriggerPrimitive.sizeof() and TriggerPrimitive.s_expected_bytes mismatch, "
16
f
"got {size} vs {TriggerPrimitive.s_expected_bytes}"
17
)
18
return
1
19
20
print(
"PASS: TriggerPrimitive construction and sizeof"
)
21
return
0
22
23
24
def
test_static_and_default_fields
() -> int:
25
tp = TriggerPrimitive()
26
27
# Providing this check will provide a nudge for developers to update these tests when the version changes
28
if
TriggerPrimitive.s_trigger_primitive_version != 2:
29
print(
30
"FAIL: TriggerPrimitive.s_trigger_primitive_version expected 2, "
31
f
"got {TriggerPrimitive.s_trigger_primitive_version}"
32
)
33
return
1
34
35
if
tp.version != TriggerPrimitive.s_trigger_primitive_version:
36
print(f
"FAIL: version mismatch, got {tp.version}"
)
37
return
1
38
39
if
tp.flag != 0:
40
print(f
"FAIL: flag expected 0, got {tp.flag}"
)
41
return
1
42
43
if
tp.detid != 2**8 - 1:
44
print(f
"FAIL: detid expected 2**8 - 1, got {tp.detid}"
)
45
return
1
46
47
if
tp.channel != 0xFFFFFF:
48
print(f
"FAIL: channel expected 0xFFFFFF, got {tp.channel}"
)
49
return
1
50
51
if
tp.samples_over_threshold != 2**16 - 1:
52
print(
53
"FAIL: samples_over_threshold expected 2**16 - 1, "
54
f
"got {tp.samples_over_threshold}"
55
)
56
return
1
57
58
if
tp.samples_to_peak != 2**16 - 1:
59
print(f
"FAIL: samples_to_peak expected 2**16 - 1, got {tp.samples_to_peak}"
)
60
return
1
61
62
if
tp.time_start != (2**64 - 1):
63
print(f
"FAIL: time_start expected 2**64-1, got {tp.time_start}"
)
64
return
1
65
66
if
tp.adc_integral != 0:
67
print(f
"FAIL: adc_integral expected 0, got {tp.adc_integral}"
)
68
return
1
69
70
if
tp.adc_peak != 0:
71
print(f
"FAIL: adc_peak expected 0, got {tp.adc_peak}"
)
72
return
1
73
74
expected_channel_invalid = 0xFFFFFF
75
if
TriggerPrimitive.s_invalid_samples_over_threshold != 2**16 - 1:
76
print(
77
"FAIL: TriggerPrimitive.s_invalid_samples_over_threshold expected 2**16 - 1, "
78
f
"got {TriggerPrimitive.s_invalid_samples_over_threshold}"
79
)
80
return
1
81
82
if
TriggerPrimitive.s_invalid_samples_to_peak != 2**16 - 1:
83
print(
84
"FAIL: TriggerPrimitive.s_invalid_samples_to_peak expected 2**16 - 1, "
85
f
"got {TriggerPrimitive.s_invalid_samples_to_peak}"
86
)
87
return
1
88
89
if
TriggerPrimitive.s_invalid_tp_channel != expected_channel_invalid:
90
print(
91
"FAIL: TriggerPrimitive.s_invalid_tp_channel expected 0xFFFFFF, "
92
f
"got {TriggerPrimitive.s_invalid_tp_channel}"
93
)
94
return
1
95
96
if
TriggerPrimitive.s_expected_bytes != 24:
97
print(
98
"FAIL: TriggerPrimitive.s_expected_bytes expected 24, "
99
f
"got {TriggerPrimitive.s_expected_bytes}"
100
)
101
return
1
102
103
print(
"PASS: TriggerPrimitive static/default field checks"
)
104
return
0
105
106
107
def
test_timestamp_methods_and_ordering
() -> int:
108
tp_a = TriggerPrimitive()
109
tp_b = TriggerPrimitive()
110
111
if
tp_a.get_timestamp() != tp_a.time_start:
112
print(
113
"FAIL: TriggerPrimitive get_timestamp() is inconsistent with time_start, "
114
f
"got {tp_a.get_timestamp()} vs {tp_a.time_start}"
115
)
116
return
1
117
118
tp_a.set_timestamp(100)
119
if
tp_a.get_timestamp() != 100:
120
print(f
"FAIL: TriggerPrimitive get/set timestamp mismatch, got {tp_a.get_timestamp()}"
)
121
return
1
122
123
tp_b.set_timestamp(200)
124
125
if
not
(tp_a < tp_b):
126
print(
"FAIL: TriggerPrimitive ordering expected tp_a < tp_b"
)
127
return
1
128
129
if
tp_b < tp_a:
130
print(
"FAIL: TriggerPrimitive ordering expected tp_b !< tp_a"
)
131
return
1
132
133
print(
"PASS: TriggerPrimitive timestamp methods and ordering operator"
)
134
return
0
135
136
137
def
main
() -> int:
138
failures = 0
139
failures +=
test_construction_and_sizeof
()
140
failures +=
test_static_and_default_fields
()
141
failures +=
test_timestamp_methods_and_ordering
()
142
143
if
failures == 0:
144
print(
"TriggerPrimitive binding tests passed"
)
145
else
:
146
print(f
"TriggerPrimitive binding tests had {failures} failure(s)"
)
147
148
return
failures
149
150
151
if
__name__ ==
"__main__"
:
152
raise
SystemExit(
main
())
TriggerPrimitive_binding_test.test_static_and_default_fields
int test_static_and_default_fields()
Definition
TriggerPrimitive_binding_test.py:24
TriggerPrimitive_binding_test.main
int main()
Definition
TriggerPrimitive_binding_test.py:137
TriggerPrimitive_binding_test.test_timestamp_methods_and_ordering
int test_timestamp_methods_and_ordering()
Definition
TriggerPrimitive_binding_test.py:107
TriggerPrimitive_binding_test.test_construction_and_sizeof
int test_construction_and_sizeof()
Definition
TriggerPrimitive_binding_test.py:6
Generated on
for DUNE-DAQ by
1.18.0