DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
daphneethstream.cpp
Go to the documentation of this file.
1
8
10
11#include <pybind11/pybind11.h>
12#include <pybind11/stl.h>
13
14namespace py = pybind11;
15
17
18// NOLINTBEGIN(build/unsigned)
19
20void
22{
23
24 py::class_<DAPHNEEthStreamFrame::ChannelWord>(m, "DAPHNEEthStreamChannelWord")
25 .def_property(
26 "tbd",
27 [](DAPHNEEthStreamFrame::ChannelWord& self) -> uint64_t { return self.tbd; },
28 [](DAPHNEEthStreamFrame::ChannelWord& self, uint64_t tbd) { self.tbd = tbd; })
29 .def_property(
30 "version",
31 [](DAPHNEEthStreamFrame::ChannelWord& self) -> uint64_t { return self.version; },
32 [](DAPHNEEthStreamFrame::ChannelWord& self, uint64_t version) { self.version = version; })
33 .def_property(
34 "channel",
35 [](DAPHNEEthStreamFrame::ChannelWord& self) -> uint64_t { return self.channel; },
36 [](DAPHNEEthStreamFrame::ChannelWord& self, uint64_t channel) { self.channel = channel; });
37
38 py::class_<DAPHNEEthStreamFrame::Header>(m, "DAPHNEEthStreamHeader")
39 .def_property(
40 "channel_words",
41 [](DAPHNEEthStreamFrame::Header& self) -> py::list {
42 py::list result;
43 for (int i = 0; i < 4; i++) {
44 result.append(self.channel_words[i]);
45 }
46 return result;
47 },
48 [](DAPHNEEthStreamFrame::Header& self, py::list channel_words) {
49 for (int i = 0; i < 4 && i < static_cast<int>(len(channel_words)); i++) {
50 self.channel_words[i] = channel_words[i].cast<DAPHNEEthStreamFrame::ChannelWord>();
51 }
52 });
53
54 py::class_<DAPHNEEthStreamFrame>(m, "DAPHNEEthStreamFrame", py::buffer_protocol())
55 .def(py::init())
56 .def(py::init([](py::capsule capsule) {
57 auto wfp = *static_cast<DAPHNEEthStreamFrame*>(capsule.get_pointer());
58 return wfp;
59 }))
60 .def(py::init([](py::bytes bytes) {
61 py::buffer_info info(py::buffer(bytes).request());
62 auto wfp = *static_cast<DAPHNEEthStreamFrame*>(info.ptr);
63 return wfp;
64 }))
65 .def(
66 "get_daqheader",
67 [](DAPHNEEthStreamFrame& self) -> const detdataformats::DAQEthHeader& { return self.daq_header; },
68 py::return_value_policy::reference_internal)
69 .def(
70 "get_daphneheader",
71 [](DAPHNEEthStreamFrame& self) -> const DAPHNEEthStreamFrame::Header& { return self.header; },
72 py::return_value_policy::reference_internal)
73 .def(
74 "get_header",
75 [](DAPHNEEthStreamFrame& self) -> const DAPHNEEthStreamFrame::Header& { return self.header; },
76 py::return_value_policy::reference_internal)
77 .def("get_adc", &DAPHNEEthStreamFrame::get_adc)
78 .def("set_adc", &DAPHNEEthStreamFrame::set_adc)
79 .def("get_timestamp", &DAPHNEEthStreamFrame::get_timestamp)
80 .def("set_timestamp", &DAPHNEEthStreamFrame::set_timestamp)
81 .def("get_channel", &DAPHNEEthStreamFrame::get_channel)
82 .def("set_channel", &DAPHNEEthStreamFrame::set_channel)
83 .def("get_channel0", &DAPHNEEthStreamFrame::get_channel0)
84 .def("get_channel1", &DAPHNEEthStreamFrame::get_channel1)
85 .def("get_channel2", &DAPHNEEthStreamFrame::get_channel2)
86 .def("get_channel3", &DAPHNEEthStreamFrame::get_channel3)
87 .def_static("sizeof", []() { return sizeof(DAPHNEEthStreamFrame); })
88 .def("get_bytes", [](DAPHNEEthStreamFrame* fr) -> py::bytes {
89 return py::bytes(reinterpret_cast<char*>(fr), sizeof(DAPHNEEthStreamFrame)); // NOLINT reinterpret_cast
90 });
91}
92
93// NOLINTEND(build/unsigned)
94
95} // namespace dunedaq::fddetdataformats::python
Class for accessing raw DAPHNE eth stream frames, as used in ProtoDUNE-II.
uint8_t get_channel1() const
Get the channel 1 from the DAPHNE Stream frame header.
void set_timestamp(const uint64_t new_timestamp)
Set the starting 64-bit timestamp of the frame.
uint8_t get_channel0() const
Get the channel 0 from the DAPHNE Stream frame header.
void set_adc(uint i_channel, uint i_adc, uint16_t val)
Set the i_adc-th ADC value of i_channel-th channel in the frame to val.
uint16_t get_adc(uint i_adc, uint i_channel) const
Get the i_adc-th ADC value of i_channel-th channel in the frame.
uint8_t get_channel3() const
Get the channel 3 from the DAPHNE Stream frame header.
uint8_t get_channel2() const
Get the channel 2 from the DAPHNE Stream frame header.
uint8_t get_channel(const uint i_channel) const
Get the channel identifier of the frame.
void set_channel(const uint i_channel, const uint8_t new_channel_val)
Set the channel identifier of the frame.
uint64_t get_timestamp() const
Get the starting 64-bit timestamp of the frame.
void register_daphneethstream(py::module &m)
DAQEthHeader is a versioned and unified structure for every FE electronics.