DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
daphne.cpp
Go to the documentation of this file.
1
8
10
11#include <pybind11/pybind11.h>
12#include <pybind11/stl.h>
13
14namespace py = pybind11;
15
17
18// NOLINTBEGIN(build/unsigned)
19
20void
21register_daphne(py::module& m)
22{
23
24 py::class_<DAPHNEFrame>(m, "DAPHNEFrame", py::buffer_protocol())
25 .def(py::init())
26 .def(py::init([](py::capsule capsule) {
27 auto wfp = *static_cast<DAPHNEFrame*>(capsule.get_pointer());
28 return wfp;
29 }))
30 .def(py::init([](py::bytes bytes) {
31 py::buffer_info info(py::buffer(bytes).request());
32 auto wfp = *static_cast<DAPHNEFrame*>(info.ptr);
33 return wfp;
34 }))
35 .def(
36 "get_daqheader",
37 [](DAPHNEFrame& self) -> const detdataformats::DAQHeader& { return self.daq_header; },
38 py::return_value_policy::reference_internal)
39 .def(
40 "get_header",
41 [](DAPHNEFrame& self) -> const DAPHNEFrame::Header& { return self.header; },
42 py::return_value_policy::reference_internal)
43 .def_property_readonly(
44 "daq_header",
45 [](DAPHNEFrame& self) -> detdataformats::DAQHeader& { return self.daq_header; },
46 py::return_value_policy::reference_internal)
47 .def_property_readonly(
48 "header",
49 [](DAPHNEFrame& self) -> DAPHNEFrame::Header& { return self.header; },
50 py::return_value_policy::reference_internal)
51 .def("peaks_data",
52 [](DAPHNEFrame& self) -> DAPHNEFrame::PeakDescriptorData& { return self.peaks_data; },
53 py::return_value_policy::reference_internal)
54 .def("get_adc", static_cast<uint16_t (DAPHNEFrame::*)(const int) const>(&DAPHNEFrame::get_adc))
55 .def("set_adc", &DAPHNEFrame::set_adc)
56 .def("get_timestamp", &DAPHNEFrame::get_timestamp)
57 .def("set_timestamp", &DAPHNEFrame::set_timestamp)
58 .def("get_channel", &DAPHNEFrame::get_channel)
59 .def("set_channel", &DAPHNEFrame::set_channel)
60 .def("__lt__", [](const DAPHNEFrame& lhs, const DAPHNEFrame& rhs) { return lhs < rhs; })
61 .def_property_readonly_static("version", [](py::object /*self*/) { return DAPHNEFrame::version; })
62 .def_property_readonly_static("s_bits_per_adc", [](py::object /*self*/) {
64 })
65 .def_property_readonly_static("s_bits_per_word", [](py::object /*self*/) {
67 })
68 .def_property_readonly_static("s_num_adcs", [](py::object /*self*/) { return DAPHNEFrame::s_num_adcs; })
69 .def_property_readonly_static("s_num_adc_words", [](py::object /*self*/) {
71 })
72 .def_property_readonly_static("s_expected_bytes", [](py::object /*self*/) {
74 })
75 .def_static("sizeof", []() { return sizeof(DAPHNEFrame); })
76 .def("get_bytes", [](DAPHNEFrame* fr) -> py::bytes {
77 return py::bytes(reinterpret_cast<char*>(fr), sizeof(DAPHNEFrame)); // NOLINT
78 });
79
80 py::class_<DAPHNEFrame::Header>(m, "DAPHNEFrameHeader")
81 .def_property(
82 "channel",
83 [](DAPHNEFrame::Header& self) -> uint8_t { return self.channel; },
84 [](DAPHNEFrame::Header& self, uint8_t channel) { self.channel = channel; })
85 .def_property(
86 "algorithm_id",
87 [](DAPHNEFrame::Header& self) -> uint8_t { return self.algorithm_id; },
88 [](DAPHNEFrame::Header& self, uint8_t algorithm_id) { self.algorithm_id = algorithm_id; })
89 .def_property(
90 "r1",
91 [](DAPHNEFrame::Header& self) -> uint8_t { return self.r1; },
92 [](DAPHNEFrame::Header& self, uint8_t r1) { self.r1 = r1; })
93 .def_property(
94 "trigger_sample_value",
95 [](DAPHNEFrame::Header& self) -> uint16_t { return self.trigger_sample_value; },
96 [](DAPHNEFrame::Header& self, uint16_t tsv) { self.trigger_sample_value = tsv; })
97 .def_property(
98 "threshold",
99 [](DAPHNEFrame::Header& self) -> uint16_t { return self.threshold; },
100 [](DAPHNEFrame::Header& self, uint16_t threshold) { self.threshold = threshold; })
101 .def_property(
102 "baseline",
103 [](DAPHNEFrame::Header& self) -> uint16_t { return self.baseline; },
104 [](DAPHNEFrame::Header& self, uint16_t baseline) { self.baseline = baseline; })
105 .def_property_readonly_static("s_expected_bytes", [](py::object /*self*/) {
106 return sizeof(DAPHNEFrame::Header);
107 });
108
109 py::class_<DAPHNEFrame::PeakDescriptorData>(m, "DAPHNEFramePeakDescriptorData")
110 .def_property_readonly_static("s_expected_bytes", [](py::object /*self*/) {
112 })
113 .def_property_readonly_static("max_peaks", [](py::object /*self*/) {
115 })
118
121
124
125 .def("get_samples_over_baseline", &DAPHNEFrame::PeakDescriptorData::get_samples_over_baseline)
126 .def("set_samples_over_baseline", &DAPHNEFrame::PeakDescriptorData::set_samples_over_baseline)
127
130
133
136
137 .def_property(
138 "num_subpeaks_0",
139 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_0; },
140 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_0 = val; })
141 .def_property(
142 "adc_integral_0",
143 [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_0; },
144 [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_0 = val; })
145 .def_property(
146 "found_0",
147 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_0; },
148 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_0 = val; })
149 .def_property(
150 "adc_max_0",
151 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_0; },
152 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_0 = val; })
153 .def_property(
154 "sample_max_0",
155 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_0; },
156 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_0 = val; })
157 .def_property(
158 "samples_over_baseline_0",
159 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_0; },
160 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_0 = val; })
161
162 .def_property(
163 "num_subpeaks_1",
164 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_1; },
165 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_1 = val; })
166 .def_property(
167 "adc_integral_1",
168 [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_1; },
169 [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_1 = val; })
170 .def_property(
171 "found_1",
172 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_1; },
173 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_1 = val; })
174 .def_property(
175 "adc_max_1",
176 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_1; },
177 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_1 = val; })
178 .def_property(
179 "sample_max_1",
180 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_1; },
181 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_1 = val; })
182 .def_property(
183 "samples_over_baseline_1",
184 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_1; },
185 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_1 = val; })
186
187 .def_property(
188 "num_subpeaks_2",
189 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_2; },
190 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_2 = val; })
191 .def_property(
192 "adc_integral_2",
193 [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_2; },
194 [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_2 = val; })
195 .def_property(
196 "found_2",
197 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_2; },
198 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_2 = val; })
199 .def_property(
200 "adc_max_2",
201 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_2; },
202 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_2 = val; })
203 .def_property(
204 "sample_max_2",
205 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_2; },
206 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_2 = val; })
207 .def_property(
208 "samples_over_baseline_2",
209 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_2; },
210 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_2 = val; })
211
212 .def_property(
213 "num_subpeaks_3",
214 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_3; },
215 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_3 = val; })
216 .def_property(
217 "adc_integral_3",
218 [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_3; },
219 [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_3 = val; })
220 .def_property(
221 "found_3",
222 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_3; },
223 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_3 = val; })
224 .def_property(
225 "adc_max_3",
226 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_3; },
227 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_3 = val; })
228 .def_property(
229 "sample_max_3",
230 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_3; },
231 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_3 = val; })
232 .def_property(
233 "samples_over_baseline_3",
234 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_3; },
235 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_3 = val; })
236
237 .def_property(
238 "num_subpeaks_4",
239 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_4; },
240 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_4 = val; })
241 .def_property(
242 "adc_integral_4",
243 [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_4; },
244 [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_4 = val; })
245 .def_property(
246 "found_4",
247 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_4; },
248 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_4 = val; })
249 .def_property(
250 "adc_max_4",
251 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_4; },
252 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_4 = val; })
253 .def_property(
254 "sample_max_4",
255 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_4; },
256 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_4 = val; })
257 .def_property(
258 "samples_over_baseline_4",
259 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_4; },
260 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_4 = val; });
261
262} // NOLINT function length
263
264// NOLINTEND(build/unsigned)
265
266} // namespace dunedaq::fddetdataformats::python
void register_daphne(py::module &m)
Definition daphne.cpp:21
DAQHeader is a versioned and unified structure for every FE electronics.
Definition DAQHeader.hpp:23
bool is_found(int idx) const
Get the Found value for a specific peak (channel) from the trailer. (Word 2*idx, bit 31).
void set_adc_integral(uint32_t val, int idx)
Set the ADC_Integral value for a specific peak.
uint16_t get_adc_max(int idx) const
Get the ADC Max value for a specific peak. (Word 2*idx+1, bits [31:18]).
void set_num_subpeaks(uint8_t val, int idx)
Set the Num_SubPeaks value for a specific peak.
uint16_t get_sample_start(int idx) const
Get the Time_Start value for a given index (0-4).
uint16_t get_sample_max(int idx) const
Get the Time_Peak value for a specific peak. (Word 2*idx+1, bits [17:9]).
void set_sample_max(uint16_t val, int idx)
Set the Time_Peak value for a specific peak.
void set_found(uint8_t val, int idx)
Set the Found value for a specific peak (channel) in the trailer.
uint32_t get_adc_integral(int idx) const
Get the ADC_Integral value for a specific peak. (Word 2*idx, bits [30:8]).
void set_sample_start(uint16_t val, int idx)
Set the time_start field for Peak index 0–4 using bit shifts.
void set_adc_max(uint16_t val, int idx)
Set the ADC Max value for a specific peak.
uint8_t get_num_subpeaks(int idx) const
Get the Num_SubPeaks value for a specific peak. (Word 2*idx, bits [3:0]).
uint16_t get_samples_over_baseline(int idx) const
Get the Time_Over_Baseline value for a specific peak. (Word 2*idx+1, bits [8:0]).
detdataformats::DAQHeader daq_header
void set_adc(int i, uint16_t val)
Set the ith ADC value in the frame to val.
uint64_t get_timestamp() const
Get the 64-bit timestamp of the frame.
static constexpr std::size_t s_expected_bytes
uint16_t get_adc(int i) const
Get the ith ADC value in the frame.