Line data Source code
1 : /**
2 : * @file wibeth.cpp Python bindings for the WIBEthFrame 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/WIBEthFrame.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 : void
19 0 : register_wibeth(py::module& m)
20 : {
21 :
22 :
23 0 : py::class_<WIBEthFrame::WIBEthHeader>(m, "WIBEthHeader")
24 0 : .def_property("channel",
25 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.channel;},
26 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t channel) {self.channel = channel;}
27 : )
28 0 : .def_property("version",
29 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.version;},
30 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t version) {self.version = version;}
31 : )
32 : // .def_property("reserved",
33 : // [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.reserved;},
34 : // [](WIBEthFrame::WIBEthHeader& self, uint32_t reserved) {self.reserved = reserved;}
35 : // )
36 0 : .def_property("cd",
37 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.cd;},
38 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t cd) {self.version = cd;}
39 : )
40 0 : .def_property("context",
41 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.context;},
42 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t context) {self.version = context;}
43 : )
44 0 : .def_property("ready",
45 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.ready;},
46 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t ready) {self.ready = ready;}
47 : )
48 0 : .def_property("calibration",
49 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.calibration;},
50 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t calibration) {self.calibration = calibration;}
51 : )
52 0 : .def_property("pulser",
53 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.pulser;},
54 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t pulser) {self.pulser = pulser;}
55 : )
56 0 : .def_property("femb_sync",
57 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.femb_sync;},
58 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t femb_sync) {self.femb_sync = femb_sync;}
59 : )
60 0 : .def_property("wib_sync",
61 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.wib_sync;},
62 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t wib_sync) {self.wib_sync = wib_sync;}
63 : )
64 0 : .def_property("lol",
65 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.lol;},
66 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t lol) {self.lol = lol;}
67 : )
68 0 : .def_property("link_valid",
69 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.link_valid;},
70 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t link_valid) {self.link_valid = link_valid;}
71 : )
72 0 : .def_property("crc_err",
73 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.crc_err;},
74 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t crc_err) {self.crc_err = crc_err;}
75 : )
76 0 : .def_property("colddata_timestamp_1",
77 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.colddata_timestamp_1;},
78 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t colddata_timestamp_1) {self.lol = colddata_timestamp_1;}
79 : )
80 0 : .def_property("colddata_timestamp_0",
81 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint32_t {return self.colddata_timestamp_0;},
82 0 : [](WIBEthFrame::WIBEthHeader& self, uint32_t colddata_timestamp_0) {self.colddata_timestamp_0 = colddata_timestamp_0;}
83 : )
84 0 : .def_property("extra_data",
85 0 : [](WIBEthFrame::WIBEthHeader& self) -> uint64_t {return self.extra_data;},
86 0 : [](WIBEthFrame::WIBEthHeader& self, uint64_t extra_data) {self.extra_data = extra_data;}
87 : )
88 : ;
89 :
90 0 : py::class_<WIBEthFrame>(m, "WIBEthFrame", py::buffer_protocol())
91 0 : .def(py::init())
92 0 : .def(py::init([](py::capsule capsule) {
93 0 : auto wfp = *static_cast<WIBEthFrame*>(capsule.get_pointer());
94 0 : return wfp;
95 : } ))
96 0 : .def(py::init([](py::bytes bytes){
97 0 : py::buffer_info info(py::buffer(bytes).request());
98 0 : auto wfp = *static_cast<WIBEthFrame*>(info.ptr);
99 0 : return wfp;
100 0 : }))
101 0 : .def("get_daqheader", [](WIBEthFrame& self) -> const detdataformats::DAQEthHeader& {return self.daq_header;}, py::return_value_policy::reference_internal)
102 0 : .def("get_wibheader", [](WIBEthFrame& self) -> const WIBEthFrame::WIBEthHeader& {return self.header;}, py::return_value_policy::reference_internal)
103 0 : .def("get_adc", &WIBEthFrame::get_adc)
104 0 : .def("set_adc", &WIBEthFrame::set_adc)
105 0 : .def("get_timestamp", &WIBEthFrame::get_timestamp)
106 0 : .def("set_timestamp", &WIBEthFrame::set_timestamp)
107 0 : .def("get_channel", &WIBEthFrame::get_channel)
108 0 : .def("set_channel", &WIBEthFrame::set_channel)
109 0 : .def_static("sizeof", [](){ return sizeof(WIBEthFrame); })
110 0 : .def("get_bytes",
111 0 : [](WIBEthFrame* fr) -> py::bytes {
112 0 : return py::bytes(reinterpret_cast<char*>(fr), sizeof(WIBEthFrame));
113 : })
114 : ;
115 0 : }
116 :
117 : } // namespace dunedaq::fddetdataformats::python
|