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", static_cast<const WIBHeader* (WIBFrame::*)() const >(&WIBFrame::get_wib_header), py::return_value_policy::reference_internal)
34 0 : .def("get_coldata_header", &WIBFrame::get_coldata_header, py::return_value_policy::reference_internal)
35 0 : .def("get_block", &WIBFrame::get_block, py::return_value_policy::reference_internal)
36 0 : .def("get_channel", static_cast<uint16_t (WIBFrame::*)(const uint8_t, const uint8_t, const uint8_t) const>(&WIBFrame::get_channel))
37 0 : .def("get_channel", static_cast<uint16_t (WIBFrame::*)(const uint8_t, const uint8_t) const>(&WIBFrame::get_channel))
38 0 : .def("get_channel", static_cast<uint16_t (WIBFrame::*)(const uint8_t) const>(&WIBFrame::get_channel))
39 0 : .def("set_channel", static_cast<void (WIBFrame::*)(const uint8_t, const uint16_t)>(&WIBFrame::set_channel))
40 0 : .def("get_timestamp", &WIBFrame::get_timestamp)
41 0 : .def_static("sizeof", [](){ return sizeof(WIBFrame); })
42 0 : .def("get_bytes",
43 0 : [](WIBFrame* fr) -> py::bytes {
44 0 : return py::bytes(reinterpret_cast<char*>(fr), sizeof(WIBFrame));
45 : }
46 : )
47 : ;
48 :
49 0 : py::class_<WIBHeader>(m, "WIBHeader")
50 0 : .def_property_readonly("sof", [](WIBHeader& self) -> uint32_t {return self.sof;})
51 0 : .def_property_readonly("version", [](WIBHeader& self) -> uint32_t {return self.version;})
52 0 : .def_property_readonly("fiber_no", [](WIBHeader& self) -> uint32_t {return self.fiber_no;})
53 0 : .def_property_readonly("crate_no", [](WIBHeader& self) -> uint32_t {return self.crate_no;})
54 0 : .def_property_readonly("slot_no", [](WIBHeader& self) -> uint32_t {return self.slot_no;})
55 0 : .def_property_readonly("mm", [](WIBHeader& self) -> uint32_t {return self.mm;})
56 0 : .def_property_readonly("oos", [](WIBHeader& self) -> uint32_t {return self.oos;})
57 0 : .def_property_readonly("mm", [](WIBHeader& self) -> uint32_t {return self.mm;})
58 0 : .def_property_readonly("wib_errors", [](WIBHeader& self) -> uint32_t {return self.wib_errors;})
59 0 : .def("get_timestamp", &WIBHeader::get_timestamp)
60 0 : .def("get_wib_counter", &WIBHeader::get_wib_counter)
61 : ;
62 0 : py::class_<ColdataHeader>(m, "ColdataHeader")
63 0 : .def_property_readonly("s1_error", [](ColdataHeader& self) -> uint32_t {return self.s1_error;})
64 0 : .def_property_readonly("s2_error", [](ColdataHeader& self) -> uint32_t {return self.s2_error;})
65 0 : .def_property_readonly("coldata_convert_count", [](ColdataHeader& self) -> uint32_t {return self.coldata_convert_count;})
66 0 : .def_property_readonly("error_register", [](ColdataHeader& self) -> uint32_t {return self.error_register;})
67 0 : .def_property_readonly("hdr_1", [](ColdataHeader& self) -> uint32_t {return self.hdr_1;})
68 0 : .def_property_readonly("hdr_3", [](ColdataHeader& self) -> uint32_t {return self.hdr_3;})
69 0 : .def_property_readonly("hdr_2", [](ColdataHeader& self) -> uint32_t {return self.hdr_2;})
70 0 : .def_property_readonly("hdr_4", [](ColdataHeader& self) -> uint32_t {return self.hdr_4;})
71 0 : .def_property_readonly("hdr_5", [](ColdataHeader& self) -> uint32_t {return self.hdr_5;})
72 0 : .def_property_readonly("hdr_7", [](ColdataHeader& self) -> uint32_t {return self.hdr_7;})
73 0 : .def_property_readonly("hdr_6", [](ColdataHeader& self) -> uint32_t {return self.hdr_6;})
74 0 : .def_property_readonly("hdr_8", [](ColdataHeader& self) -> uint32_t {return self.hdr_8;})
75 0 : .def("get_checksum_a", &ColdataHeader::get_checksum_a)
76 0 : .def("get_checksum_b", &ColdataHeader::get_checksum_b)
77 0 : .def("get_hdr", &ColdataHeader::get_hdr)
78 : ;
79 :
80 0 : py::class_<ColdataSegment>(m, "ColdataSegment")
81 0 : .def("get_channel", &ColdataSegment::get_channel)
82 : ;
83 0 : py::class_<ColdataBlock>(m, "ColdataBlock")
84 0 : .def("get_channel", &ColdataBlock::get_channel)
85 : ;
86 :
87 0 : }
88 :
89 : } // namespace dunedaq::fddetdataformats::python
|