Line data Source code
1 : /**
2 : * @file wibeth.cpp Python bindings for the WIBEthFrame 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/WIBEthFrame.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 : void
19 0 : register_wibeth(py::module& m)
20 : {
21 :
22 : // NOLINTBEGIN(build/unsigned)
23 :
24 0 : py::class_<WIBEthFrame::WIBEthHeader>(m, "WIBEthHeader")
25 0 : .def_property(
26 : "channel",
27 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.channel; },
28 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t channel) { self.channel = channel; })
29 0 : .def_property(
30 : "version",
31 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.version; },
32 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t version) { self.version = version; })
33 0 : .def_property(
34 : "cd",
35 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.cd; },
36 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t cd) { self.cd = cd; })
37 0 : .def_property(
38 : "context",
39 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.context; },
40 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t context) { self.context = context; })
41 0 : .def_property(
42 : "ready",
43 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.ready; },
44 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t ready) { self.ready = ready; })
45 0 : .def_property(
46 : "calibration",
47 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.calibration; },
48 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t calibration) { self.calibration = calibration; })
49 0 : .def_property(
50 : "pulser",
51 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.pulser; },
52 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t pulser) { self.pulser = pulser; })
53 0 : .def_property(
54 : "femb_sync",
55 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.femb_sync; },
56 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t femb_sync) { self.femb_sync = femb_sync; })
57 0 : .def_property(
58 : "wib_sync",
59 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.wib_sync; },
60 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t wib_sync) { self.wib_sync = wib_sync; })
61 0 : .def_property(
62 : "lol",
63 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.lol; },
64 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t lol) { self.lol = lol; })
65 0 : .def_property(
66 : "link_valid",
67 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.link_valid; },
68 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t link_valid) { self.link_valid = link_valid; })
69 0 : .def_property(
70 : "crc_err",
71 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.crc_err; },
72 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t crc_err) { self.crc_err = crc_err; })
73 0 : .def_property(
74 : "colddata_timestamp_1",
75 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.colddata_timestamp_1; },
76 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t colddata_timestamp_1) {
77 0 : self.colddata_timestamp_1 = colddata_timestamp_1;
78 0 : })
79 0 : .def_property(
80 : "colddata_timestamp_0",
81 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.colddata_timestamp_0; },
82 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t colddata_timestamp_0) {
83 0 : self.colddata_timestamp_0 = colddata_timestamp_0;
84 0 : })
85 0 : .def_property(
86 : "extra_data",
87 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint64_t { return self.extra_data; },
88 0 : [](WIBEthFrame::WIBEthHeader& self, uint64_t extra_data) { self.extra_data = extra_data; })
89 0 : .def_property_readonly_static("s_expected_bytes",
90 0 : [](py::object /*self*/) { return WIBEthFrame::WIBEthHeader::s_expected_bytes; });
91 :
92 0 : py::class_<WIBEthFrame>(m, "WIBEthFrame", py::buffer_protocol())
93 0 : .def(py::init())
94 0 : .def(py::init([](py::capsule capsule) {
95 0 : auto wfp = *static_cast<WIBEthFrame*>(capsule.get_pointer());
96 0 : return wfp;
97 : }))
98 0 : .def(py::init([](py::bytes bytes) {
99 0 : py::buffer_info info(py::buffer(bytes).request());
100 0 : auto wfp = *static_cast<WIBEthFrame*>(info.ptr);
101 0 : return wfp;
102 0 : }))
103 0 : .def(
104 : "get_daqheader",
105 0 : [](WIBEthFrame& self) -> const detdataformats::DAQEthHeader& { return self.daq_header; },
106 0 : py::return_value_policy::reference_internal)
107 0 : .def(
108 : "get_wibheader",
109 0 : [](WIBEthFrame& self) -> const WIBEthFrame::WIBEthHeader& { return self.header; },
110 0 : py::return_value_policy::reference_internal)
111 0 : .def_property_readonly(
112 : "daq_header",
113 0 : [](WIBEthFrame& self) -> detdataformats::DAQEthHeader& { return self.daq_header; },
114 0 : py::return_value_policy::reference_internal)
115 0 : .def_property_readonly(
116 : "header",
117 0 : [](WIBEthFrame& self) -> WIBEthFrame::WIBEthHeader& { return self.header; },
118 0 : py::return_value_policy::reference_internal)
119 0 : .def("get_adc", &WIBEthFrame::get_adc)
120 0 : .def("set_adc", &WIBEthFrame::set_adc)
121 0 : .def("get_timestamp", &WIBEthFrame::get_timestamp)
122 0 : .def("set_timestamp", &WIBEthFrame::set_timestamp)
123 0 : .def("get_channel", &WIBEthFrame::get_channel)
124 0 : .def("set_channel", &WIBEthFrame::set_channel)
125 0 : .def("__lt__", [](const WIBEthFrame& lhs, const WIBEthFrame& rhs) { return lhs < rhs; })
126 0 : .def_property_readonly_static("s_bits_per_adc", [](py::object /*self*/) { return WIBEthFrame::s_bits_per_adc; })
127 0 : .def_property_readonly_static("s_bits_per_word", [](py::object /*self*/) { return WIBEthFrame::s_bits_per_word; })
128 0 : .def_property_readonly_static("s_time_samples_per_frame",
129 0 : [](py::object /*self*/) { return WIBEthFrame::s_time_samples_per_frame; })
130 0 : .def_property_readonly_static("s_channels_per_half_femb",
131 0 : [](py::object /*self*/) { return WIBEthFrame::s_channels_per_half_femb; })
132 0 : .def_property_readonly_static("s_half_fembs_per_frame",
133 0 : [](py::object /*self*/) { return WIBEthFrame::s_half_fembs_per_frame; })
134 0 : .def_property_readonly_static("s_num_channels", [](py::object /*self*/) { return WIBEthFrame::s_num_channels; })
135 0 : .def_property_readonly_static("s_num_adc_words_per_ts",
136 0 : [](py::object /*self*/) { return WIBEthFrame::s_num_adc_words_per_ts; })
137 0 : .def_property_readonly_static("s_expected_bytes", [](py::object /*self*/) { return WIBEthFrame::s_expected_bytes; })
138 0 : .def_static("sizeof", []() { return sizeof(WIBEthFrame); })
139 0 : .def("get_bytes", [](WIBEthFrame* fr) -> py::bytes {
140 0 : return py::bytes(reinterpret_cast<char*>(fr), sizeof(WIBEthFrame)); // NOLINT reinterpret_cast
141 : });
142 0 : } // NOLINT function length
143 :
144 : // NOLINTEND(build/unsigned)
145 :
146 : } // namespace dunedaq::fddetdataformats::python
|