Line data Source code
1 : /**
2 : * @file wib.cpp Python bindings for the WIBFrame 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/WIBFrame.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_wib(py::module& m)
20 : {
21 :
22 0 : py::class_<WIBFrame>(m, "WIBFrame", py::buffer_protocol())
23 0 : .def(py::init())
24 0 : .def(py::init([](py::capsule capsule) {
25 0 : auto wfp = *static_cast<WIBFrame*>(capsule.get_pointer());
26 0 : return wfp;
27 : }))
28 0 : .def(py::init([](py::bytes bytes) {
29 0 : py::buffer_info info(py::buffer(bytes).request());
30 0 : auto wfp = *static_cast<WIBFrame*>(info.ptr);
31 0 : return wfp;
32 0 : }))
33 0 : .def("get_wib_header",
34 0 : static_cast<const WIBHeader* (WIBFrame::*)() const>(&WIBFrame::get_wib_header),
35 0 : py::return_value_policy::reference_internal)
36 0 : .def("get_coldata_header", &WIBFrame::get_coldata_header, py::return_value_policy::reference_internal)
37 0 : .def("get_block", &WIBFrame::get_block, py::return_value_policy::reference_internal)
38 0 : .def("get_channel",
39 0 : static_cast<uint16_t (WIBFrame::*)(const uint8_t, const uint8_t, const uint8_t) const>(&WIBFrame::get_channel))
40 0 : .def("get_channel", static_cast<uint16_t (WIBFrame::*)(const uint8_t, const uint8_t) const>(&WIBFrame::get_channel))
41 0 : .def("get_channel", static_cast<uint16_t (WIBFrame::*)(const uint8_t) const>(&WIBFrame::get_channel))
42 0 : .def("set_channel", static_cast<void (WIBFrame::*)(const uint8_t, const uint16_t)>(&WIBFrame::set_channel))
43 0 : .def("get_timestamp", &WIBFrame::get_timestamp)
44 0 : .def_static("sizeof", []() { return sizeof(WIBFrame); })
45 0 : .def("get_bytes",
46 0 : [](WIBFrame* fr) -> py::bytes { return py::bytes(reinterpret_cast<char*>(fr), sizeof(WIBFrame)); });
47 :
48 0 : py::class_<WIBHeader>(m, "WIBHeader")
49 0 : .def_property_readonly("sof", [](WIBHeader& self) -> uint32_t { return self.sof; })
50 0 : .def_property_readonly("version", [](WIBHeader& self) -> uint32_t { return self.version; })
51 0 : .def_property_readonly("fiber_no", [](WIBHeader& self) -> uint32_t { return self.fiber_no; })
52 0 : .def_property_readonly("crate_no", [](WIBHeader& self) -> uint32_t { return self.crate_no; })
53 0 : .def_property_readonly("slot_no", [](WIBHeader& self) -> uint32_t { return self.slot_no; })
54 0 : .def_property_readonly("mm", [](WIBHeader& self) -> uint32_t { return self.mm; })
55 0 : .def_property_readonly("oos", [](WIBHeader& self) -> uint32_t { return self.oos; })
56 0 : .def_property_readonly("mm", [](WIBHeader& self) -> uint32_t { return self.mm; })
57 0 : .def_property_readonly("wib_errors", [](WIBHeader& self) -> uint32_t { return self.wib_errors; })
58 0 : .def("get_timestamp", &WIBHeader::get_timestamp)
59 0 : .def("get_wib_counter", &WIBHeader::get_wib_counter);
60 0 : py::class_<ColdataHeader>(m, "ColdataHeader")
61 0 : .def_property_readonly("s1_error", [](ColdataHeader& self) -> uint32_t { return self.s1_error; })
62 0 : .def_property_readonly("s2_error", [](ColdataHeader& self) -> uint32_t { return self.s2_error; })
63 0 : .def_property_readonly("coldata_convert_count",
64 0 : [](ColdataHeader& self) -> uint32_t { return self.coldata_convert_count; })
65 0 : .def_property_readonly("error_register", [](ColdataHeader& self) -> uint32_t { return self.error_register; })
66 0 : .def_property_readonly("hdr_1", [](ColdataHeader& self) -> uint32_t { return self.hdr_1; })
67 0 : .def_property_readonly("hdr_3", [](ColdataHeader& self) -> uint32_t { return self.hdr_3; })
68 0 : .def_property_readonly("hdr_2", [](ColdataHeader& self) -> uint32_t { return self.hdr_2; })
69 0 : .def_property_readonly("hdr_4", [](ColdataHeader& self) -> uint32_t { return self.hdr_4; })
70 0 : .def_property_readonly("hdr_5", [](ColdataHeader& self) -> uint32_t { return self.hdr_5; })
71 0 : .def_property_readonly("hdr_7", [](ColdataHeader& self) -> uint32_t { return self.hdr_7; })
72 0 : .def_property_readonly("hdr_6", [](ColdataHeader& self) -> uint32_t { return self.hdr_6; })
73 0 : .def_property_readonly("hdr_8", [](ColdataHeader& self) -> uint32_t { return self.hdr_8; })
74 0 : .def("get_checksum_a", &ColdataHeader::get_checksum_a)
75 0 : .def("get_checksum_b", &ColdataHeader::get_checksum_b)
76 0 : .def("get_hdr", &ColdataHeader::get_hdr);
77 :
78 0 : py::class_<ColdataSegment>(m, "ColdataSegment").def("get_channel", &ColdataSegment::get_channel);
79 0 : py::class_<ColdataBlock>(m, "ColdataBlock").def("get_channel", &ColdataBlock::get_channel);
80 0 : }
81 :
82 : } // namespace dunedaq::fddetdataformats::python
|