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("reserved",
34 // [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.reserved;},
35 // [](WIBEthFrame::WIBEthHeader& self, uint32_t reserved) {self.reserved = reserved;}
36 // )
37 .def_property(
38 "cd",
39 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.cd; },
40 [](WIBEthFrame::WIBEthHeader& self, uint32_t cd) { self.version = cd; })
41 .def_property(
42 "context",
43 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.context; },
44 [](WIBEthFrame::WIBEthHeader& self, uint32_t context) { self.version = context; })
45 .def_property(
46 "ready",
47 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.ready; },
48 [](WIBEthFrame::WIBEthHeader& self, uint32_t ready) { self.ready = ready; })
49 .def_property(
50 "calibration",
51 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.calibration; },
52 [](WIBEthFrame::WIBEthHeader& self, uint32_t calibration) { self.calibration = calibration; })
53 .def_property(
54 "pulser",
55 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.pulser; },
56 [](WIBEthFrame::WIBEthHeader& self, uint32_t pulser) { self.pulser = pulser; })
57 .def_property(
58 "femb_sync",
59 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.femb_sync; },
60 [](WIBEthFrame::WIBEthHeader& self, uint32_t femb_sync) { self.femb_sync = femb_sync; })
61 .def_property(
62 "wib_sync",
63 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.wib_sync; },
64 [](WIBEthFrame::WIBEthHeader& self, uint32_t wib_sync) { self.wib_sync = wib_sync; })
65 .def_property(
66 "lol",
67 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.lol; },
68 [](WIBEthFrame::WIBEthHeader& self, uint32_t lol) { self.lol = lol; })
69 .def_property(
70 "link_valid",
71 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.link_valid; },
72 [](WIBEthFrame::WIBEthHeader& self, uint32_t link_valid) { self.link_valid = link_valid; })
73 .def_property(
74 "crc_err",
75 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.crc_err; },
76 [](WIBEthFrame::WIBEthHeader& self, uint32_t crc_err) { self.crc_err = crc_err; })
77 .def_property(
78 "colddata_timestamp_1",
79 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.colddata_timestamp_1; },
80 [](WIBEthFrame::WIBEthHeader& self, uint32_t colddata_timestamp_1) { self.lol = colddata_timestamp_1; })
81 .def_property(
82 "colddata_timestamp_0",
83 [](WIBEthFrame::WIBEthHeader& self) -> uint32_t { return self.colddata_timestamp_0; },
84 [](WIBEthFrame::WIBEthHeader& self, uint32_t colddata_timestamp_0) {
85 self.colddata_timestamp_0 = colddata_timestamp_0;
86 })
87 .def_property(
88 "extra_data",
89 [](WIBEthFrame::WIBEthHeader& self) -> uint64_t { return self.extra_data; },
90 [](WIBEthFrame::WIBEthHeader& self, uint64_t extra_data) { self.extra_data = extra_data; });
91
92 py::class_<WIBEthFrame>(m, "WIBEthFrame", py::buffer_protocol())
93 .def(py::init())
94 .def(py::init([](py::capsule capsule) {
95 auto wfp = *static_cast<WIBEthFrame*>(capsule.get_pointer());
96 return wfp;
97 }))
98 .def(py::init([](py::bytes bytes) {
99 py::buffer_info info(py::buffer(bytes).request());
100 auto wfp = *static_cast<WIBEthFrame*>(info.ptr);
101 return wfp;
102 }))
103 .def(
104 "get_daqheader",
105 [](WIBEthFrame& self) -> const detdataformats::DAQEthHeader& { return self.daq_header; },
106 py::return_value_policy::reference_internal)
107 .def(
108 "get_wibheader",
109 [](WIBEthFrame& self) -> const WIBEthFrame::WIBEthHeader& { return self.header; },
110 py::return_value_policy::reference_internal)
111 .def("get_adc", &WIBEthFrame::get_adc)
112 .def("set_adc", &WIBEthFrame::set_adc)
113 .def("get_timestamp", &WIBEthFrame::get_timestamp)
114 .def("set_timestamp", &WIBEthFrame::set_timestamp)
115 .def("get_channel", &WIBEthFrame::get_channel)
116 .def("set_channel", &WIBEthFrame::set_channel)
117 .def_static("sizeof", []() { return sizeof(WIBEthFrame); })
118 .def("get_bytes", [](WIBEthFrame* fr) -> py::bytes {
119 return py::bytes(reinterpret_cast<char*>(fr), sizeof(WIBEthFrame)); // NOLINT reinterpret_cast
120 });
121} // NOLINT function length
122
123// NOLINTEND(build/unsigned)
124
125} // namespace dunedaq::fddetdataformats::python
Class 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.
void set_channel(const uint8_t new_channel)
Set the channel identifier of the frame.
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.
void set_timestamp(const uint64_t new_timestamp)
Set the starting 64-bit timestamp of the frame.
void register_wibeth(pybind11::module &)
DAQEthHeader is a versioned and unified structure for every FE electronics.