DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
wibeth.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
18void
19register_wibeth(py::module& m)
20{
21
22 // NOLINTBEGIN(build/unsigned)
23
24 py::class_<WIBEthFrame::WIBEthHeader>(m, "WIBEthHeader")
25 .def_property(
26 "channel",
27 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.channel; },
28 [](WIBEthFrame::WIBEthHeader& self, uint32_t channel) { self.channel = channel; })
29 .def_property(
30 "version",
31 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.version; },
32 [](WIBEthFrame::WIBEthHeader& self, uint32_t version) { self.version = version; })
33 .def_property(
34 "cd",
35 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.cd; },
36 [](WIBEthFrame::WIBEthHeader& self, uint32_t cd) { self.cd = cd; })
37 .def_property(
38 "context",
39 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.context; },
40 [](WIBEthFrame::WIBEthHeader& self, uint32_t context) { self.context = context; })
41 .def_property(
42 "ready",
43 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.ready; },
44 [](WIBEthFrame::WIBEthHeader& self, uint32_t ready) { self.ready = ready; })
45 .def_property(
46 "calibration",
47 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.calibration; },
48 [](WIBEthFrame::WIBEthHeader& self, uint32_t calibration) { self.calibration = calibration; })
49 .def_property(
50 "pulser",
51 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.pulser; },
52 [](WIBEthFrame::WIBEthHeader& self, uint32_t pulser) { self.pulser = pulser; })
53 .def_property(
54 "femb_sync",
55 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.femb_sync; },
56 [](WIBEthFrame::WIBEthHeader& self, uint32_t femb_sync) { self.femb_sync = femb_sync; })
57 .def_property(
58 "wib_sync",
59 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.wib_sync; },
60 [](WIBEthFrame::WIBEthHeader& self, uint32_t wib_sync) { self.wib_sync = wib_sync; })
61 .def_property(
62 "lol",
63 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.lol; },
64 [](WIBEthFrame::WIBEthHeader& self, uint32_t lol) { self.lol = lol; })
65 .def_property(
66 "link_valid",
67 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.link_valid; },
68 [](WIBEthFrame::WIBEthHeader& self, uint32_t link_valid) { self.link_valid = link_valid; })
69 .def_property(
70 "crc_err",
71 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.crc_err; },
72 [](WIBEthFrame::WIBEthHeader& self, uint32_t crc_err) { self.crc_err = crc_err; })
73 .def_property(
74 "colddata_timestamp_1",
75 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.colddata_timestamp_1; },
76 [](WIBEthFrame::WIBEthHeader& self, uint32_t colddata_timestamp_1) {
77 self.colddata_timestamp_1 = colddata_timestamp_1;
78 })
79 .def_property(
80 "colddata_timestamp_0",
81 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.colddata_timestamp_0; },
82 [](WIBEthFrame::WIBEthHeader& self, uint32_t colddata_timestamp_0) {
83 self.colddata_timestamp_0 = colddata_timestamp_0;
84 })
85 .def_property(
86 "extra_data",
87 [](WIBEthFrame::WIBEthHeader& self) -> uint64_t { return self.extra_data; },
88 [](WIBEthFrame::WIBEthHeader& self, uint64_t extra_data) { self.extra_data = extra_data; })
89 .def_property_readonly_static("s_expected_bytes", [](py::object /*self*/) {
91 });
92
93 py::class_<WIBEthFrame>(m, "WIBEthFrame", py::buffer_protocol())
94 .def(py::init())
95 .def(py::init([](py::capsule capsule) {
96 auto wfp = *static_cast<WIBEthFrame*>(capsule.get_pointer());
97 return wfp;
98 }))
99 .def(py::init([](py::bytes bytes) {
100 py::buffer_info info(py::buffer(bytes).request());
101 auto wfp = *static_cast<WIBEthFrame*>(info.ptr);
102 return wfp;
103 }))
104 .def(
105 "get_daqheader",
106 [](WIBEthFrame& self) -> const detdataformats::DAQEthHeader& { return self.daq_header; },
107 py::return_value_policy::reference_internal)
108 .def(
109 "get_wibheader",
110 [](WIBEthFrame& self) -> const WIBEthFrame::WIBEthHeader& { return self.header; },
111 py::return_value_policy::reference_internal)
112 .def_property_readonly(
113 "daq_header",
114 [](WIBEthFrame& self) -> detdataformats::DAQEthHeader& { return self.daq_header; },
115 py::return_value_policy::reference_internal)
116 .def_property_readonly(
117 "header",
118 [](WIBEthFrame& self) -> WIBEthFrame::WIBEthHeader& { return self.header; },
119 py::return_value_policy::reference_internal)
120 .def("get_adc", &WIBEthFrame::get_adc)
121 .def("set_adc", &WIBEthFrame::set_adc)
122 .def("get_timestamp", &WIBEthFrame::get_timestamp)
123 .def("set_timestamp", &WIBEthFrame::set_timestamp)
124 .def("get_channel", &WIBEthFrame::get_channel)
125 .def("set_channel", &WIBEthFrame::set_channel)
126 .def("__lt__", [](const WIBEthFrame& lhs, const WIBEthFrame& rhs) { return lhs < rhs; })
127 .def_property_readonly_static("s_bits_per_adc", [](py::object /*self*/) {
129 })
130 .def_property_readonly_static("s_bits_per_word", [](py::object /*self*/) {
132 })
133 .def_property_readonly_static("s_time_samples_per_frame", [](py::object /*self*/) {
135 })
136 .def_property_readonly_static("s_channels_per_half_femb", [](py::object /*self*/) {
138 })
139 .def_property_readonly_static("s_half_fembs_per_frame", [](py::object /*self*/) {
141 })
142 .def_property_readonly_static("s_num_channels", [](py::object /*self*/) {
144 })
145 .def_property_readonly_static("s_num_adc_words_per_ts", [](py::object /*self*/) {
147 })
148 .def_property_readonly_static("s_expected_bytes", [](py::object /*self*/) {
150 })
151 .def_static("sizeof", []() { return sizeof(WIBEthFrame); })
152 .def("get_bytes", [](WIBEthFrame* fr) -> py::bytes {
153 return py::bytes(reinterpret_cast<char*>(fr), sizeof(WIBEthFrame)); // NOLINT reinterpret_cast
154 });
155} // NOLINT function length
156
157// NOLINTEND(build/unsigned)
158
159} // namespace dunedaq::fddetdataformats::python
void register_wibeth(pybind11::module &)
DAQEthHeader is a versioned and unified structure for every FE electronics.
struct for accessing raw WIB eth frames, as used in ProtoDUNE-II
uint64_t get_timestamp() const
Get the starting 64-bit timestamp of the frame.
static constexpr int s_half_fembs_per_frame
void set_channel(const uint8_t new_channel)
Set the channel identifier of the frame.
static constexpr size_t s_expected_bytes
uint8_t get_channel() const
Get the channel identifier of the frame.
uint16_t get_adc(int i_channel, int i_sample=0) const
Get the i_channel-th ADC value in the i_sample-th time sample.
void set_adc(int i_channel, int i_sample, uint16_t adc_val)
Set the i_channel-th ADC value in the i_sample-th time sample to adc_val.
static constexpr int s_time_samples_per_frame
void set_timestamp(const uint64_t new_timestamp)
Set the starting 64-bit timestamp of the frame.
static constexpr int s_num_adc_words_per_ts
static constexpr int s_channels_per_half_femb