Line data Source code
1 : /**
2 : * @file wibeth.cpp Python bindings for the DAPHNEEthFrame 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/DAPHNEEthFrame.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 : // NOLINTBEGIN(build/unsigned)
19 :
20 : void
21 0 : register_daphneeth(py::module& m)
22 : {
23 :
24 0 : 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 0 : .def_property(
30 : "w1",
31 0 : [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.w1; },
32 0 : [](DAPHNEEthFrame::Header& self, uint32_t w1) { self.w1 = w1; })
33 0 : .def_property(
34 : "w2",
35 0 : [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.w2; },
36 0 : [](DAPHNEEthFrame::Header& self, uint32_t w2) { self.w2 = w2; })
37 0 : .def_property(
38 : "w3",
39 0 : [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.w3; },
40 0 : [](DAPHNEEthFrame::Header& self, uint32_t w3) { self.w3 = w3; })
41 0 : .def_property(
42 : "w4",
43 0 : [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.w4; },
44 0 : [](DAPHNEEthFrame::Header& self, uint32_t w4) { self.w4 = w4; })
45 0 : .def_property(
46 : "w5",
47 0 : [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.w5; },
48 0 : [](DAPHNEEthFrame::Header& self, uint32_t w5) { self.w5 = w5; })
49 0 : .def_property(
50 : "w6",
51 0 : [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.w6; },
52 0 : [](DAPHNEEthFrame::Header& self, uint32_t w6) { self.w6 = w6; })
53 0 : .def_property(
54 : "channel",
55 0 : [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.channel; },
56 0 : [](DAPHNEEthFrame::Header& self, uint32_t channel) { self.channel = channel; })
57 0 : .def_property(
58 : "version",
59 0 : [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.version; },
60 0 : [](DAPHNEEthFrame::Header& self, uint32_t version) { self.version = version; })
61 0 : .def_property(
62 : "trigger_sample_value",
63 0 : [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.trig_sample; },
64 0 : [](DAPHNEEthFrame::Header& self, uint32_t trig_sample) { self.trig_sample = trig_sample; })
65 0 : .def_property(
66 : "threshold",
67 0 : [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.threshold; },
68 0 : [](DAPHNEEthFrame::Header& self, uint32_t threshold) { self.threshold = threshold; })
69 0 : .def_property(
70 : "baseline",
71 0 : [](DAPHNEEthFrame::Header& self) -> uint32_t { return self.baseline; },
72 0 : [](DAPHNEEthFrame::Header& self, uint32_t baseline) { self.baseline = baseline; });
73 :
74 0 : py::class_<DAPHNEEthFrame>(m, "DAPHNEEthFrame", py::buffer_protocol())
75 0 : .def(py::init())
76 0 : .def(py::init([](py::capsule capsule) {
77 0 : auto wfp = *static_cast<DAPHNEEthFrame*>(capsule.get_pointer());
78 0 : return wfp;
79 : }))
80 0 : .def(py::init([](py::bytes bytes) {
81 0 : py::buffer_info info(py::buffer(bytes).request());
82 0 : auto wfp = *static_cast<DAPHNEEthFrame*>(info.ptr);
83 0 : return wfp;
84 0 : }))
85 0 : .def(
86 : "get_daqheader",
87 0 : [](DAPHNEEthFrame& self) -> const detdataformats::DAQEthHeader& { return self.daq_header; },
88 0 : py::return_value_policy::reference_internal)
89 0 : .def(
90 : "get_daphneheader",
91 0 : [](DAPHNEEthFrame& self) -> const DAPHNEEthFrame::Header& { return self.header; },
92 0 : py::return_value_policy::reference_internal)
93 0 : .def(
94 : "get_header",
95 0 : [](DAPHNEEthFrame& self) -> const DAPHNEEthFrame::Header& { return self.header; },
96 0 : py::return_value_policy::reference_internal)
97 0 : .def("get_adc", &DAPHNEEthFrame::get_adc)
98 0 : .def("set_adc", &DAPHNEEthFrame::set_adc)
99 0 : .def("get_timestamp", &DAPHNEEthFrame::get_timestamp)
100 0 : .def("set_timestamp", &DAPHNEEthFrame::set_timestamp)
101 0 : .def("get_channel", &DAPHNEEthFrame::get_channel)
102 0 : .def("set_channel", &DAPHNEEthFrame::set_channel)
103 0 : .def_static("sizeof", []() { return sizeof(DAPHNEEthFrame); })
104 0 : .def("get_bytes", [](DAPHNEEthFrame* fr) -> py::bytes {
105 0 : return py::bytes(reinterpret_cast<char*>(fr), sizeof(DAPHNEEthFrame)); // NOLINT reinterpret_cast
106 : });
107 0 : }
108 :
109 : // NOLINTEND(build/unsigned)
110 :
111 : } // namespace dunedaq::fddetdataformats::python
|