Line data Source code
1 : /**
2 : * @file daphne.cpp Python bindings for the DAPHNEFrame format
3 : *
4 : * This is part of the DUNE DAQ Software Suite, copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #include "fddetdataformats/DAPHNEFrame.hpp"
10 :
11 : #include <pybind11/pybind11.h>
12 : #include <pybind11/stl.h>
13 :
14 : namespace py = pybind11;
15 :
16 : namespace dunedaq::fddetdataformats::python {
17 :
18 : // NOLINTBEGIN(build/unsigned)
19 :
20 : void
21 0 : register_daphne(py::module& m)
22 : {
23 :
24 0 : py::class_<DAPHNEFrame>(m, "DAPHNEFrame", py::buffer_protocol())
25 0 : .def(py::init())
26 0 : .def(py::init([](py::capsule capsule) {
27 0 : auto wfp = *static_cast<DAPHNEFrame*>(capsule.get_pointer());
28 0 : return wfp;
29 : }))
30 0 : .def(py::init([](py::bytes bytes) {
31 0 : py::buffer_info info(py::buffer(bytes).request());
32 0 : auto wfp = *static_cast<DAPHNEFrame*>(info.ptr);
33 0 : return wfp;
34 0 : }))
35 0 : .def(
36 : "get_daqheader",
37 0 : [](DAPHNEFrame& self) -> const detdataformats::DAQHeader& { return self.daq_header; },
38 0 : py::return_value_policy::reference_internal)
39 0 : .def(
40 : "get_header",
41 0 : [](DAPHNEFrame& self) -> const DAPHNEFrame::Header& { return self.header; },
42 0 : py::return_value_policy::reference_internal)
43 0 : .def_property_readonly(
44 : "daq_header",
45 0 : [](DAPHNEFrame& self) -> detdataformats::DAQHeader& { return self.daq_header; },
46 0 : py::return_value_policy::reference_internal)
47 0 : .def_property_readonly(
48 : "header",
49 0 : [](DAPHNEFrame& self) -> DAPHNEFrame::Header& { return self.header; },
50 0 : py::return_value_policy::reference_internal)
51 0 : .def("peaks_data",
52 0 : [](DAPHNEFrame& self) -> DAPHNEFrame::PeakDescriptorData& { return self.peaks_data; },
53 0 : py::return_value_policy::reference_internal)
54 0 : .def("get_adc", static_cast<uint16_t (DAPHNEFrame::*)(const int) const>(&DAPHNEFrame::get_adc))
55 0 : .def("set_adc", &DAPHNEFrame::set_adc)
56 0 : .def("get_timestamp", &DAPHNEFrame::get_timestamp)
57 0 : .def("set_timestamp", &DAPHNEFrame::set_timestamp)
58 0 : .def("get_channel", &DAPHNEFrame::get_channel)
59 0 : .def("set_channel", &DAPHNEFrame::set_channel)
60 0 : .def("__lt__", [](const DAPHNEFrame& lhs, const DAPHNEFrame& rhs) { return lhs < rhs; })
61 0 : .def_property_readonly_static("version", [](py::object /*self*/) { return DAPHNEFrame::version; })
62 0 : .def_property_readonly_static("s_bits_per_adc", [](py::object /*self*/) {
63 : return DAPHNEFrame::s_bits_per_adc;
64 : })
65 0 : .def_property_readonly_static("s_bits_per_word", [](py::object /*self*/) {
66 : return DAPHNEFrame::s_bits_per_word;
67 : })
68 0 : .def_property_readonly_static("s_num_adcs", [](py::object /*self*/) { return DAPHNEFrame::s_num_adcs; })
69 0 : .def_property_readonly_static("s_num_adc_words", [](py::object /*self*/) {
70 : return DAPHNEFrame::s_num_adc_words;
71 : })
72 0 : .def_property_readonly_static("s_expected_bytes", [](py::object /*self*/) {
73 : return DAPHNEFrame::s_expected_bytes;
74 : })
75 0 : .def_static("sizeof", []() { return sizeof(DAPHNEFrame); })
76 0 : .def("get_bytes", [](DAPHNEFrame* fr) -> py::bytes {
77 0 : return py::bytes(reinterpret_cast<char*>(fr), sizeof(DAPHNEFrame)); // NOLINT
78 : });
79 :
80 0 : py::class_<DAPHNEFrame::Header>(m, "DAPHNEFrameHeader")
81 0 : .def_property(
82 : "channel",
83 0 : [](DAPHNEFrame::Header& self) -> uint8_t { return self.channel; },
84 0 : [](DAPHNEFrame::Header& self, uint8_t channel) { self.channel = channel; })
85 0 : .def_property(
86 : "algorithm_id",
87 0 : [](DAPHNEFrame::Header& self) -> uint8_t { return self.algorithm_id; },
88 0 : [](DAPHNEFrame::Header& self, uint8_t algorithm_id) { self.algorithm_id = algorithm_id; })
89 0 : .def_property(
90 : "r1",
91 0 : [](DAPHNEFrame::Header& self) -> uint8_t { return self.r1; },
92 0 : [](DAPHNEFrame::Header& self, uint8_t r1) { self.r1 = r1; })
93 0 : .def_property(
94 : "trigger_sample_value",
95 0 : [](DAPHNEFrame::Header& self) -> uint16_t { return self.trigger_sample_value; },
96 0 : [](DAPHNEFrame::Header& self, uint16_t tsv) { self.trigger_sample_value = tsv; })
97 0 : .def_property(
98 : "threshold",
99 0 : [](DAPHNEFrame::Header& self) -> uint16_t { return self.threshold; },
100 0 : [](DAPHNEFrame::Header& self, uint16_t threshold) { self.threshold = threshold; })
101 0 : .def_property(
102 : "baseline",
103 0 : [](DAPHNEFrame::Header& self) -> uint16_t { return self.baseline; },
104 0 : [](DAPHNEFrame::Header& self, uint16_t baseline) { self.baseline = baseline; })
105 0 : .def_property_readonly_static("s_expected_bytes", [](py::object /*self*/) {
106 : return sizeof(DAPHNEFrame::Header);
107 : });
108 :
109 0 : py::class_<DAPHNEFrame::PeakDescriptorData>(m, "DAPHNEFramePeakDescriptorData")
110 0 : .def_property_readonly_static("s_expected_bytes", [](py::object /*self*/) {
111 : return DAPHNEFrame::PeakDescriptorData::s_expected_bytes;
112 : })
113 0 : .def_property_readonly_static("max_peaks", [](py::object /*self*/) {
114 : return DAPHNEFrame::PeakDescriptorData::max_peaks;
115 : })
116 0 : .def("is_found", &DAPHNEFrame::PeakDescriptorData::is_found)
117 0 : .def("set_found", &DAPHNEFrame::PeakDescriptorData::set_found)
118 :
119 0 : .def("get_adc_integral", &DAPHNEFrame::PeakDescriptorData::get_adc_integral)
120 0 : .def("set_adc_integral", &DAPHNEFrame::PeakDescriptorData::set_adc_integral)
121 :
122 0 : .def("get_num_subpeaks", &DAPHNEFrame::PeakDescriptorData::get_num_subpeaks)
123 0 : .def("set_num_subpeaks", &DAPHNEFrame::PeakDescriptorData::set_num_subpeaks)
124 :
125 0 : .def("get_samples_over_baseline", &DAPHNEFrame::PeakDescriptorData::get_samples_over_baseline)
126 0 : .def("set_samples_over_baseline", &DAPHNEFrame::PeakDescriptorData::set_samples_over_baseline)
127 :
128 0 : .def("get_sample_max", &DAPHNEFrame::PeakDescriptorData::get_sample_max)
129 0 : .def("set_sample_max", &DAPHNEFrame::PeakDescriptorData::set_sample_max)
130 :
131 0 : .def("get_adc_max", &DAPHNEFrame::PeakDescriptorData::get_adc_max)
132 0 : .def("set_adc_max", &DAPHNEFrame::PeakDescriptorData::set_adc_max)
133 :
134 0 : .def("get_sample_start", &DAPHNEFrame::PeakDescriptorData::get_sample_start)
135 0 : .def("set_sample_start", &DAPHNEFrame::PeakDescriptorData::set_sample_start)
136 :
137 0 : .def_property(
138 : "num_subpeaks_0",
139 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_0; },
140 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_0 = val; })
141 0 : .def_property(
142 : "adc_integral_0",
143 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_0; },
144 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_0 = val; })
145 0 : .def_property(
146 : "found_0",
147 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_0; },
148 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_0 = val; })
149 0 : .def_property(
150 : "adc_max_0",
151 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_0; },
152 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_0 = val; })
153 0 : .def_property(
154 : "sample_max_0",
155 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_0; },
156 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_0 = val; })
157 0 : .def_property(
158 : "samples_over_baseline_0",
159 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_0; },
160 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_0 = val; })
161 :
162 0 : .def_property(
163 : "num_subpeaks_1",
164 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_1; },
165 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_1 = val; })
166 0 : .def_property(
167 : "adc_integral_1",
168 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_1; },
169 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_1 = val; })
170 0 : .def_property(
171 : "found_1",
172 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_1; },
173 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_1 = val; })
174 0 : .def_property(
175 : "adc_max_1",
176 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_1; },
177 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_1 = val; })
178 0 : .def_property(
179 : "sample_max_1",
180 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_1; },
181 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_1 = val; })
182 0 : .def_property(
183 : "samples_over_baseline_1",
184 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_1; },
185 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_1 = val; })
186 :
187 0 : .def_property(
188 : "num_subpeaks_2",
189 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_2; },
190 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_2 = val; })
191 0 : .def_property(
192 : "adc_integral_2",
193 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_2; },
194 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_2 = val; })
195 0 : .def_property(
196 : "found_2",
197 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_2; },
198 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_2 = val; })
199 0 : .def_property(
200 : "adc_max_2",
201 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_2; },
202 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_2 = val; })
203 0 : .def_property(
204 : "sample_max_2",
205 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_2; },
206 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_2 = val; })
207 0 : .def_property(
208 : "samples_over_baseline_2",
209 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_2; },
210 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_2 = val; })
211 :
212 0 : .def_property(
213 : "num_subpeaks_3",
214 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_3; },
215 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_3 = val; })
216 0 : .def_property(
217 : "adc_integral_3",
218 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_3; },
219 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_3 = val; })
220 0 : .def_property(
221 : "found_3",
222 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_3; },
223 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_3 = val; })
224 0 : .def_property(
225 : "adc_max_3",
226 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_3; },
227 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_3 = val; })
228 0 : .def_property(
229 : "sample_max_3",
230 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_3; },
231 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_3 = val; })
232 0 : .def_property(
233 : "samples_over_baseline_3",
234 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_3; },
235 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_3 = val; })
236 :
237 0 : .def_property(
238 : "num_subpeaks_4",
239 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.num_subpeaks_4; },
240 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.num_subpeaks_4 = val; })
241 0 : .def_property(
242 : "adc_integral_4",
243 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint32_t { return self.adc_integral_4; },
244 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint32_t val) { self.adc_integral_4 = val; })
245 0 : .def_property(
246 : "found_4",
247 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint8_t { return self.found_4; },
248 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint8_t val) { self.found_4 = val; })
249 0 : .def_property(
250 : "adc_max_4",
251 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.adc_max_4; },
252 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.adc_max_4 = val; })
253 0 : .def_property(
254 : "sample_max_4",
255 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.sample_max_4; },
256 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.sample_max_4 = val; })
257 0 : .def_property(
258 : "samples_over_baseline_4",
259 0 : [](DAPHNEFrame::PeakDescriptorData& self) -> uint16_t { return self.samples_over_baseline_4; },
260 0 : [](DAPHNEFrame::PeakDescriptorData& self, uint16_t val) { self.samples_over_baseline_4 = val; });
261 :
262 0 : } // NOLINT function length
263 :
264 : // NOLINTEND(build/unsigned)
265 :
266 : } // namespace dunedaq::fddetdataformats::python
|