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) {
65 self.trigger_sample_value = trigger_sample_value;
66 })
67 .def_property(
68 "threshold",
69 [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.threshold; },
70 [](DAPHNEEthFrame::Header& self, uint32_t threshold) { self.threshold = threshold; })
71 .def_property(
72 "baseline",
73 [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.baseline; },
74 [](DAPHNEEthFrame::Header& self, uint32_t baseline) { self.baseline = baseline; })
75 .def_property_readonly_static("s_expected_bytes",
76 [](py::object /*self*/) { return DAPHNEEthFrame::Header::s_expected_bytes; });
77
78 py::class_<DAPHNEEthFrame>(m, "DAPHNEEthFrame", py::buffer_protocol())
79 .def(py::init())
80 .def(py::init([](py::capsule capsule) {
81 auto wfp = *static_cast<DAPHNEEthFrame*>(capsule.get_pointer());
82 return wfp;
83 }))
84 .def(py::init([](py::bytes bytes) {
85 py::buffer_info info(py::buffer(bytes).request());
86 auto wfp = *static_cast<DAPHNEEthFrame*>(info.ptr);
87 return wfp;
88 }))
89 .def(
90 "get_daqheader",
91 [](DAPHNEEthFrame& self) -> const detdataformats::DAQEthHeader& { return self.daq_header; },
92 py::return_value_policy::reference_internal)
93 .def(
94 "get_daphneheader",
95 [](DAPHNEEthFrame& self) -> const DAPHNEEthFrame::Header& { return self.header; },
96 py::return_value_policy::reference_internal)
97 .def(
98 "get_header",
99 [](DAPHNEEthFrame& self) -> const DAPHNEEthFrame::Header& { return self.header; },
100 py::return_value_policy::reference_internal)
101 .def_property_readonly(
102 "daq_header",
103 [](DAPHNEEthFrame& self) -> detdataformats::DAQEthHeader& { return self.daq_header; },
104 py::return_value_policy::reference_internal)
105 .def_property_readonly(
106 "header",
107 [](DAPHNEEthFrame& self) -> DAPHNEEthFrame::Header& { return self.header; },
108 py::return_value_policy::reference_internal)
109 .def("get_adc", &DAPHNEEthFrame::get_adc)
110 .def("set_adc", &DAPHNEEthFrame::set_adc)
111 .def("get_timestamp", &DAPHNEEthFrame::get_timestamp)
112 .def("set_timestamp", &DAPHNEEthFrame::set_timestamp)
113 .def("get_channel", &DAPHNEEthFrame::get_channel)
114 .def("set_channel", &DAPHNEEthFrame::set_channel)
115 .def("__lt__", [](const DAPHNEEthFrame& lhs, const DAPHNEEthFrame& rhs) { return lhs < rhs; })
116 .def_property_readonly_static("version", [](py::object /*self*/) { return DAPHNEEthFrame::version; })
117 .def_property_readonly_static("s_bits_per_adc", [](py::object /*self*/) { return DAPHNEEthFrame::s_bits_per_adc; })
118 .def_property_readonly_static("s_bits_per_word",
119 [](py::object /*self*/) { return DAPHNEEthFrame::s_bits_per_word; })
120 .def_property_readonly_static("s_num_adcs", [](py::object /*self*/) { return DAPHNEEthFrame::s_num_adcs; })
121 .def_property_readonly_static("s_num_adc_words",
122 [](py::object /*self*/) { return DAPHNEEthFrame::s_num_adc_words; })
123 .def_property_readonly_static("s_expected_bytes",
124 [](py::object /*self*/) { return DAPHNEEthFrame::s_expected_bytes; })
125 .def_static("sizeof", []() { return sizeof(DAPHNEEthFrame); })
126 .def("get_bytes", [](DAPHNEEthFrame* fr) -> py::bytes {
127 return py::bytes(reinterpret_cast<char*>(fr), sizeof(DAPHNEEthFrame)); // NOLINT reinterpret_cast
128 });
129} // NOLINT (defensible use of "overly long" function)
130
131// NOLINTEND(build/unsigned)
132
133} // 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.