Line data Source code
1 : /**
2 : * @file timeslice.cpp
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 "daqdataformats/TimeSlice.hpp"
10 : #include "daqdataformats/TimeSliceHeader.hpp"
11 :
12 : #include <pybind11/pybind11.h>
13 : #include <pybind11/stl.h>
14 :
15 : #include <memory>
16 : #include <vector>
17 :
18 : namespace py = pybind11;
19 :
20 : namespace dunedaq {
21 : namespace daqdataformats {
22 : namespace python {
23 :
24 : void
25 0 : register_timeslice(py::module& m)
26 : {
27 0 : py::class_<TimeSliceHeader>(m, "TimeSliceHeader")
28 0 : .def_property_readonly_static("s_timeslice_header_marker",
29 0 : [](const TimeSliceHeader& self) -> uint32_t { // NOLINT(build/unsigned)
30 0 : return self.s_timeslice_header_marker;
31 : })
32 0 : .def_property_readonly_static("s_timeslice_header_version",
33 0 : [](const TimeSliceHeader& self) -> uint32_t { // NOLINT(build/unsigned)
34 0 : return self.s_timeslice_header_version;
35 : })
36 0 : .def_property_readonly("timeslice_header_marker",
37 0 : [](const TimeSliceHeader& self) -> uint32_t { // NOLINT(build/unsigned)
38 0 : return self.timeslice_header_marker;
39 : })
40 0 : .def_property_readonly(
41 0 : "version", [](const TimeSliceHeader& self) -> uint32_t { return self.version; }) // NOLINT(build/unsigned)
42 0 : .def_property_readonly("timeslice_number",
43 0 : [](const TimeSliceHeader& self) -> timeslice_number_t { return self.timeslice_number; })
44 :
45 0 : .def_property_readonly("run_number", [](const TimeSliceHeader& self) -> run_number_t { return self.run_number; });
46 :
47 0 : py::class_<TimeSlice> py_timeslice(m, "TimeSlice", pybind11::buffer_protocol());
48 0 : py_timeslice.def(py::init<TimeSliceHeader const&>())
49 0 : .def(py::init<timeslice_number_t, run_number_t>())
50 0 : .def(
51 0 : "get_header", [](TimeSlice& self) { return self.get_header(); }, py::return_value_policy::reference_internal)
52 : // .def("set_header", &TimeSlice::set_header)
53 0 : .def(
54 : "get_fragments_ref",
55 0 : [](TimeSlice& self) {
56 0 : auto fragments = py::list();
57 0 : for (auto& fragment : self.get_fragments_ref()) {
58 0 : auto py_fragment = py::cast(*fragment, py::return_value_policy::reference);
59 0 : fragments.append(py_fragment);
60 0 : }
61 0 : return fragments;
62 0 : },
63 0 : py::return_value_policy::reference_internal)
64 0 : .def("get_total_size_bytes", &TimeSlice::get_total_size_bytes)
65 0 : .def("get_sum_of_fragment_payload_sizes", &TimeSlice::get_sum_of_fragment_payload_sizes);
66 0 : } // NOLINT
67 :
68 : } // namespace python
69 : } // namespace daqdataformats
70 : } // namespace dunedaq
|