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::daqdataformats::python {
21 :
22 : void
23 0 : register_timeslice(py::module& m)
24 : {
25 0 : py::class_<TimeSliceHeader>(m, "TimeSliceHeader")
26 0 : .def_property_readonly_static("s_timeslice_header_marker",
27 0 : [](const TimeSliceHeader& self) -> uint32_t { // NOLINT(build/unsigned)
28 : return self.s_timeslice_header_marker;
29 : })
30 0 : .def_property_readonly_static("s_timeslice_header_version",
31 0 : [](const TimeSliceHeader& self) -> uint32_t { // NOLINT(build/unsigned)
32 : return self.s_timeslice_header_version;
33 : })
34 0 : .def_property_readonly("timeslice_header_marker",
35 0 : [](const TimeSliceHeader& self) -> uint32_t { // NOLINT(build/unsigned)
36 0 : return self.timeslice_header_marker;
37 : })
38 0 : .def_property_readonly(
39 0 : "version", [](const TimeSliceHeader& self) -> uint32_t { return self.version; }) // NOLINT(build/unsigned)
40 0 : .def_property_readonly("timeslice_number",
41 0 : [](const TimeSliceHeader& self) -> timeslice_number_t { return self.timeslice_number; })
42 :
43 0 : .def_property_readonly("run_number", [](const TimeSliceHeader& self) -> run_number_t { return self.run_number; });
44 :
45 0 : py::class_<TimeSlice> py_timeslice(m, "TimeSlice", pybind11::buffer_protocol());
46 0 : py_timeslice.def(py::init<TimeSliceHeader const&>())
47 0 : .def(py::init<timeslice_number_t, run_number_t>())
48 0 : .def(
49 0 : "get_header", [](TimeSlice& self) { return self.get_header(); }, py::return_value_policy::reference_internal)
50 : // .def("set_header", &TimeSlice::set_header)
51 0 : .def(
52 : "get_fragments_ref",
53 0 : [](TimeSlice& self) {
54 0 : auto fragments = py::list();
55 0 : for (auto& fragment : self.get_fragments_ref()) {
56 0 : auto py_fragment = py::cast(*fragment, py::return_value_policy::reference);
57 0 : fragments.append(py_fragment);
58 0 : }
59 0 : return fragments;
60 0 : },
61 0 : py::return_value_policy::reference_internal)
62 0 : .def("get_total_size_bytes", &TimeSlice::get_total_size_bytes)
63 0 : .def("get_sum_of_fragment_payload_sizes", &TimeSlice::get_sum_of_fragment_payload_sizes);
64 0 : } // NOLINT
65 :
66 : } // namespace dunedaq::daqdataformats::python
|