DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
daphneeth.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
18// NOLINTBEGIN(build/unsigned)
19
20void
21register_daphneeth(py::module& m)
22{
23
24 py::class_<DAPHNEEthFrame::Header>(m, "DAPHNEEthHeader")
25 // .def_property("w0",
26 // [](DAPHNEEthFrame::Header& self) -> uint32_t {return self.w0;},
27 // [](DAPHNEEthFrame::Header& self, uint32_t w0) {self.w0 = w0;}
28 // )
29 .def_property(
30 "w1",
31 [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.w1; },
32 [](DAPHNEEthFrame::Header& self, uint32_t w1) { self.w1 = w1; })
33 .def_property(
34 "w2",
35 [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.w2; },
36 [](DAPHNEEthFrame::Header& self, uint32_t w2) { self.w2 = w2; })
37 .def_property(
38 "w3",
39 [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.w3; },
40 [](DAPHNEEthFrame::Header& self, uint32_t w3) { self.w3 = w3; })
41 .def_property(
42 "w4",
43 [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.w4; },
44 [](DAPHNEEthFrame::Header& self, uint32_t w4) { self.w4 = w4; })
45 .def_property(
46 "w5",
47 [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.w5; },
48 [](DAPHNEEthFrame::Header& self, uint32_t w5) { self.w5 = w5; })
49 .def_property(
50 "w6",
51 [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.w6; },
52 [](DAPHNEEthFrame::Header& self, uint32_t w6) { self.w6 = w6; })
53 .def_property(
54 "channel",
55 [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.channel; },
56 [](DAPHNEEthFrame::Header& self, uint32_t channel) { self.channel = channel; })
57 .def_property(
58 "version",
59 [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.version; },
60 [](DAPHNEEthFrame::Header& self, uint32_t version) { self.version = version; })
61 .def_property(
62 "trigger_sample_value",
63 [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.trigger_sample_value; },
64 [](DAPHNEEthFrame::Header& self, uint32_t trigger_sample_value) { self.trigger_sample_value = trigger_sample_value; })
65 .def_property(
66 "threshold",
67 [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.threshold; },
68 [](DAPHNEEthFrame::Header& self, uint32_t threshold) { self.threshold = threshold; })
69 .def_property(
70 "baseline",
71 [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.baseline; },
72 [](DAPHNEEthFrame::Header& self, uint32_t baseline) { self.baseline = baseline; })
73 .def_property_readonly_static("s_expected_bytes", [](py::object /*self*/) {
75 });
76
77 py::class_<DAPHNEEthFrame>(m, "DAPHNEEthFrame", py::buffer_protocol())
78 .def(py::init())
79 .def(py::init([](py::capsule capsule) {
80 auto wfp = *static_cast<DAPHNEEthFrame*>(capsule.get_pointer());
81 return wfp;
82 }))
83 .def(py::init([](py::bytes bytes) {
84 py::buffer_info info(py::buffer(bytes).request());
85 auto wfp = *static_cast<DAPHNEEthFrame*>(info.ptr);
86 return wfp;
87 }))
88 .def(
89 "get_daqheader",
90 [](DAPHNEEthFrame& self) -> const detdataformats::DAQEthHeader& { return self.daq_header; },
91 py::return_value_policy::reference_internal)
92 .def(
93 "get_daphneheader",
94 [](DAPHNEEthFrame& self) -> const DAPHNEEthFrame::Header& { return self.header; },
95 py::return_value_policy::reference_internal)
96 .def(
97 "get_header",
98 [](DAPHNEEthFrame& self) -> const DAPHNEEthFrame::Header& { return self.header; },
99 py::return_value_policy::reference_internal)
100 .def_property_readonly(
101 "daq_header",
102 [](DAPHNEEthFrame& self) -> detdataformats::DAQEthHeader& { return self.daq_header; },
103 py::return_value_policy::reference_internal)
104 .def_property_readonly(
105 "header",
106 [](DAPHNEEthFrame& self) -> DAPHNEEthFrame::Header& { return self.header; },
107 py::return_value_policy::reference_internal)
108 .def("get_adc", &DAPHNEEthFrame::get_adc)
109 .def("set_adc", &DAPHNEEthFrame::set_adc)
110 .def("get_timestamp", &DAPHNEEthFrame::get_timestamp)
111 .def("set_timestamp", &DAPHNEEthFrame::set_timestamp)
112 .def("get_channel", &DAPHNEEthFrame::get_channel)
113 .def("set_channel", &DAPHNEEthFrame::set_channel)
114 .def("__lt__", [](const DAPHNEEthFrame& lhs, const DAPHNEEthFrame& rhs) { return lhs < rhs; })
115 .def_property_readonly_static("version", [](py::object /*self*/) { return DAPHNEEthFrame::version; })
116 .def_property_readonly_static("s_bits_per_adc", [](py::object /*self*/) {
118 })
119 .def_property_readonly_static("s_bits_per_word", [](py::object /*self*/) {
121 })
122 .def_property_readonly_static("s_num_adcs", [](py::object /*self*/) { return DAPHNEEthFrame::s_num_adcs; })
123 .def_property_readonly_static("s_num_adc_words", [](py::object /*self*/) {
125 })
126 .def_property_readonly_static("s_expected_bytes", [](py::object /*self*/) {
128 })
129 .def_static("sizeof", []() { return sizeof(DAPHNEEthFrame); })
130 .def("get_bytes", [](DAPHNEEthFrame* fr) -> py::bytes {
131 return py::bytes(reinterpret_cast<char*>(fr), sizeof(DAPHNEEthFrame)); // NOLINT reinterpret_cast
132 });
133} // NOLINT (defensible use of "overly long" function)
134
135// NOLINTEND(build/unsigned)
136
137} // namespace dunedaq::fddetdataformats::python
void register_daphneeth(py::module &m)
Definition daphneeth.cpp:21
DAQEthHeader is a versioned and unified structure for every FE electronics.
Struct for accessing raw DAPHNE eth frames.
void set_adc(int i, uint16_t val)
Set the ith ADC value in the frame to val.
void set_timestamp(const uint64_t new_timestamp)
Set the starting 64-bit timestamp of the frame.
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) const
Get the ith ADC value in the frame.