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(
52 "peaks_data",
53 [](DAPHNEFrame& self) -> DAPHNEFrame::PeakDescriptorData& { return self.peaks_data; },
54 py::return_value_policy::reference_internal)
55 .def("get_adc", static_cast<uint16_t (DAPHNEFrame::*)(const int) const>(&DAPHNEFrame::get_adc))
56 .def("set_adc", &DAPHNEFrame::set_adc)
57 .def("get_timestamp", &DAPHNEFrame::get_timestamp)
58 .def("set_timestamp", &DAPHNEFrame::set_timestamp)
59 .def("get_channel", &DAPHNEFrame::get_channel)
60 .def("set_channel", &DAPHNEFrame::set_channel)
61 .def("__lt__", [](const DAPHNEFrame& lhs, const DAPHNEFrame& rhs) { return lhs < rhs; })
62 .def_property_readonly_static("version", [](py::object /*self*/) { return DAPHNEFrame::version; })
63 .def_property_readonly_static("s_bits_per_adc", [](py::object /*self*/) { return DAPHNEFrame::s_bits_per_adc; })
64 .def_property_readonly_static("s_bits_per_word", [](py::object /*self*/) { return DAPHNEFrame::s_bits_per_word; })
65 .def_property_readonly_static("s_num_adcs", [](py::object /*self*/) { return DAPHNEFrame::s_num_adcs; })
66 .def_property_readonly_static("s_num_adc_words", [](py::object /*self*/) { return DAPHNEFrame::s_num_adc_words; })
67 .def_property_readonly_static("s_expected_bytes", [](py::object /*self*/) { return DAPHNEFrame::s_expected_bytes; })
68 .def_static("sizeof", []() { return sizeof(DAPHNEFrame); })
69 .def("get_bytes", [](DAPHNEFrame* fr) -> py::bytes {
70 return py::bytes(reinterpret_cast<char*>(fr), sizeof(DAPHNEFrame)); // NOLINT
71 });
72
73 py::class_<DAPHNEFrame::Header>(m, "DAPHNEFrameHeader")
74 .def_property(
75 "channel",
76 [](DAPHNEFrame::Header& self) -> uint8_t { return self.channel; },
77 [](DAPHNEFrame::Header& self, uint8_t channel) { self.channel = channel; })
78 .def_property(
79 "algorithm_id",
80 [](DAPHNEFrame::Header& self) -> uint8_t { return self.algorithm_id; },
81 [](DAPHNEFrame::Header& self, uint8_t algorithm_id) { self.algorithm_id = algorithm_id; })
82 .def_property(
83 "r1",
84 [](DAPHNEFrame::Header& self) -> uint8_t { return self.r1; },
85 [](DAPHNEFrame::Header& self, uint8_t r1) { self.r1 = r1; })
86 .def_property(
87 "trigger_sample_value",
88 [](DAPHNEFrame::Header& self) -> uint16_t { return self.trigger_sample_value; },
89 [](DAPHNEFrame::Header& self, uint16_t tsv) { self.trigger_sample_value = tsv; })
90 .def_property(
91 "threshold",
92 [](DAPHNEFrame::Header& self) -> uint16_t { return self.threshold; },
93 [](DAPHNEFrame::Header& self, uint16_t threshold) { self.threshold = threshold; })
94 .def_property(
95 "baseline",
96 [](DAPHNEFrame::Header& self) -> uint16_t { return self.baseline; },
97 [](DAPHNEFrame::Header& self, uint16_t baseline) { self.baseline = baseline; })
98 .def_property_readonly_static("s_expected_bytes", [](py::object /*self*/) { return sizeof(DAPHNEFrame::Header); });
99
100 py::class_<DAPHNEFrame::PeakDescriptorData>(m, "DAPHNEFramePeakDescriptorData")
101 .def_property_readonly_static("s_expected_bytes",
102 [](py::object /*self*/) { return DAPHNEFrame::PeakDescriptorData::s_expected_bytes; })
103 .def_property_readonly_static("max_peaks",
104 [](py::object /*self*/) { return DAPHNEFrame::PeakDescriptorData::max_peaks; })
107
110
113
114 .def("get_samples_over_baseline", &DAPHNEFrame::PeakDescriptorData::get_samples_over_baseline)
115 .def("set_samples_over_baseline", &DAPHNEFrame::PeakDescriptorData::set_samples_over_baseline)
116
119
122
125
126 .def_property(
127 "num_subpeaks_0",
128 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_0; },
129 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_0 = val; })
130 .def_property(
131 "adc_integral_0",
132 [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_0; },
133 [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_0 = val; })
134 .def_property(
135 "found_0",
136 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_0; },
137 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_0 = val; })
138 .def_property(
139 "adc_max_0",
140 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_0; },
141 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_0 = val; })
142 .def_property(
143 "sample_max_0",
144 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_0; },
145 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_0 = val; })
146 .def_property(
147 "samples_over_baseline_0",
148 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_0; },
149 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_0 = val; })
150
151 .def_property(
152 "num_subpeaks_1",
153 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_1; },
154 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_1 = val; })
155 .def_property(
156 "adc_integral_1",
157 [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_1; },
158 [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_1 = val; })
159 .def_property(
160 "found_1",
161 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_1; },
162 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_1 = val; })
163 .def_property(
164 "adc_max_1",
165 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_1; },
166 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_1 = val; })
167 .def_property(
168 "sample_max_1",
169 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_1; },
170 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_1 = val; })
171 .def_property(
172 "samples_over_baseline_1",
173 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_1; },
174 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_1 = val; })
175
176 .def_property(
177 "num_subpeaks_2",
178 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_2; },
179 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_2 = val; })
180 .def_property(
181 "adc_integral_2",
182 [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_2; },
183 [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_2 = val; })
184 .def_property(
185 "found_2",
186 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_2; },
187 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_2 = val; })
188 .def_property(
189 "adc_max_2",
190 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_2; },
191 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_2 = val; })
192 .def_property(
193 "sample_max_2",
194 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_2; },
195 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_2 = val; })
196 .def_property(
197 "samples_over_baseline_2",
198 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_2; },
199 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_2 = val; })
200
201 .def_property(
202 "num_subpeaks_3",
203 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_3; },
204 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_3 = val; })
205 .def_property(
206 "adc_integral_3",
207 [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_3; },
208 [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_3 = val; })
209 .def_property(
210 "found_3",
211 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_3; },
212 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_3 = val; })
213 .def_property(
214 "adc_max_3",
215 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_3; },
216 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_3 = val; })
217 .def_property(
218 "sample_max_3",
219 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_3; },
220 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_3 = val; })
221 .def_property(
222 "samples_over_baseline_3",
223 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_3; },
224 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_3 = val; })
225
226 .def_property(
227 "num_subpeaks_4",
228 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_4; },
229 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_4 = val; })
230 .def_property(
231 "adc_integral_4",
232 [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_4; },
233 [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_4 = val; })
234 .def_property(
235 "found_4",
236 [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_4; },
237 [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_4 = val; })
238 .def_property(
239 "adc_max_4",
240 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_4; },
241 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_4 = val; })
242 .def_property(
243 "sample_max_4",
244 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_4; },
245 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_4 = val; })
246 .def_property(
247 "samples_over_baseline_4",
248 [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_4; },
249 [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_4 = val; });
250
251} // NOLINT function length
252
253// NOLINTEND(build/unsigned)
254
255} // 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.