Line data Source code
1 : /**
2 : * @file daphneethstream.cpp Python bindings for the DAPHNEEthStreamFrame 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/DAPHNEEthStreamFrame.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_daphneethstream(py::module& m)
22 : {
23 :
24 0 : py::class_<DAPHNEEthStreamFrame::ChannelWord>(m, "DAPHNEEthStreamChannelWord")
25 0 : .def_property(
26 : "tbd",
27 0 : [](DAPHNEEthStreamFrame::ChannelWord& self) -> uint64_t { return self.tbd; },
28 0 : [](DAPHNEEthStreamFrame::ChannelWord& self, uint64_t tbd) { self.tbd = tbd; })
29 0 : .def_property(
30 : "version",
31 0 : [](DAPHNEEthStreamFrame::ChannelWord& self) -> uint64_t { return self.version; },
32 0 : [](DAPHNEEthStreamFrame::ChannelWord& self, uint64_t version) { self.version = version; })
33 0 : .def_property(
34 : "channel",
35 0 : [](DAPHNEEthStreamFrame::ChannelWord& self) -> uint64_t { return self.channel; },
36 0 : [](DAPHNEEthStreamFrame::ChannelWord& self, uint64_t channel) { self.channel = channel; });
37 :
38 0 : py::class_<DAPHNEEthStreamFrame::Header>(m, "DAPHNEEthStreamHeader")
39 0 : .def_property(
40 : "channel_words",
41 0 : [](DAPHNEEthStreamFrame::Header& self) -> py::list {
42 0 : py::list result;
43 0 : for (int i = 0; i < 4; i++) {
44 0 : result.append(self.channel_words[i]);
45 : }
46 0 : return result;
47 0 : },
48 0 : [](DAPHNEEthStreamFrame::Header& self, py::list channel_words) {
49 0 : for (int i = 0; i < 4 && i < static_cast<int>(len(channel_words)); i++) {
50 0 : self.channel_words[i] = channel_words[i].cast<DAPHNEEthStreamFrame::ChannelWord>();
51 : }
52 0 : });
53 :
54 0 : py::class_<DAPHNEEthStreamFrame>(m, "DAPHNEEthStreamFrame", py::buffer_protocol())
55 0 : .def(py::init())
56 0 : .def(py::init([](py::capsule capsule) {
57 0 : auto wfp = *static_cast<DAPHNEEthStreamFrame*>(capsule.get_pointer());
58 0 : return wfp;
59 : }))
60 0 : .def(py::init([](py::bytes bytes) {
61 0 : py::buffer_info info(py::buffer(bytes).request());
62 0 : auto wfp = *static_cast<DAPHNEEthStreamFrame*>(info.ptr);
63 0 : return wfp;
64 0 : }))
65 0 : .def(
66 : "get_daqheader",
67 0 : [](DAPHNEEthStreamFrame& self) -> const detdataformats::DAQEthHeader& { return self.daq_header; },
68 0 : py::return_value_policy::reference_internal)
69 0 : .def(
70 : "get_daphneheader",
71 0 : [](DAPHNEEthStreamFrame& self) -> const DAPHNEEthStreamFrame::Header& { return self.header; },
72 0 : py::return_value_policy::reference_internal)
73 0 : .def(
74 : "get_header",
75 0 : [](DAPHNEEthStreamFrame& self) -> const DAPHNEEthStreamFrame::Header& { return self.header; },
76 0 : py::return_value_policy::reference_internal)
77 0 : .def("get_adc", &DAPHNEEthStreamFrame::get_adc)
78 0 : .def("set_adc", &DAPHNEEthStreamFrame::set_adc)
79 0 : .def("get_timestamp", &DAPHNEEthStreamFrame::get_timestamp)
80 0 : .def("set_timestamp", &DAPHNEEthStreamFrame::set_timestamp)
81 0 : .def("get_channel", &DAPHNEEthStreamFrame::get_channel)
82 0 : .def("set_channel", &DAPHNEEthStreamFrame::set_channel)
83 0 : .def("get_channel0", &DAPHNEEthStreamFrame::get_channel0)
84 0 : .def("get_channel1", &DAPHNEEthStreamFrame::get_channel1)
85 0 : .def("get_channel2", &DAPHNEEthStreamFrame::get_channel2)
86 0 : .def("get_channel3", &DAPHNEEthStreamFrame::get_channel3)
87 0 : .def_static("sizeof", []() { return sizeof(DAPHNEEthStreamFrame); })
88 0 : .def("get_bytes", [](DAPHNEEthStreamFrame* fr) -> py::bytes {
89 0 : return py::bytes(reinterpret_cast<char*>(fr), sizeof(DAPHNEEthStreamFrame)); // NOLINT reinterpret_cast
90 : });
91 0 : }
92 :
93 : // NOLINTEND(build/unsigned)
94 :
95 : } // namespace dunedaq::fddetdataformats::python
|