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