DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
time_slice.cpp
Go to the documentation of this file.
1
8
11
12#include <pybind11/pybind11.h>
13#include <pybind11/stl.h>
14
15#include <memory>
16#include <sstream>
17#include <vector>
18
19namespace py = pybind11;
20
22
23void
24register_timeslice(py::module& m)
25{
26 py::class_<TimeSliceHeader>(m, "TimeSliceHeader")
27 .def(py::init<>())
28 .def_property_readonly_static("s_timeslice_header_marker",
29 [](const py::object&) -> uint32_t { // NOLINT(build/unsigned)
31 })
32 .def_property_readonly_static("s_timeslice_header_version",
33 [](const py::object&) -> uint32_t { // NOLINT(build/unsigned)
35 })
36 .def_property_readonly("timeslice_header_marker",
37 [](const TimeSliceHeader& self) -> uint32_t { // NOLINT(build/unsigned)
38 return self.timeslice_header_marker;
39 })
40 .def_property_readonly(
41 "version", [](const TimeSliceHeader& self) -> uint32_t { return self.version; }) // NOLINT(build/unsigned)
42 .def_property_readonly("timeslice_number",
43 [](const TimeSliceHeader& self) -> timeslice_number_t { return self.timeslice_number; })
44 .def_property_readonly("run_number", [](const TimeSliceHeader& self) -> run_number_t { return self.run_number; })
45 .def_property_readonly("element_id", [](const TimeSliceHeader& self) -> SourceID { return self.element_id; })
46 .def("__str__",
47 [](const TimeSliceHeader& hdr) {
48 std::ostringstream oss;
49 oss << hdr;
50 return oss.str();
51 })
52 .def("__repr__", [](const TimeSliceHeader& hdr) {
53 std::ostringstream oss;
54 oss << "<daqdataformats::TimeSliceHeader " << hdr << ">";
55 return oss.str();
56 });
57
58 py::class_<TimeSlice> py_timeslice(m, "TimeSlice", pybind11::buffer_protocol());
59 py_timeslice.def(py::init<TimeSliceHeader const&>())
60 .def(py::init<timeslice_number_t, run_number_t>())
61 .def(
62 "get_header", [](TimeSlice& self) { return self.get_header(); }, py::return_value_policy::reference_internal)
63 // .def("set_header", &TimeSlice::set_header)
64 .def(
65 "get_fragments_ref",
66 [](TimeSlice& self) {
67 auto fragments = py::list();
68 for (auto& fragment : self.get_fragments_ref()) {
69 auto py_fragment = py::cast(*fragment, py::return_value_policy::reference);
70 fragments.append(py_fragment);
71 }
72 return fragments;
73 },
74 py::return_value_policy::reference_internal)
75 .def("get_total_size_bytes", &TimeSlice::get_total_size_bytes)
76 .def("get_sum_of_fragment_payload_sizes", &TimeSlice::get_sum_of_fragment_payload_sizes);
77} // NOLINT
78
79} // namespace dunedaq::daqdataformats::python
C++ Representation of a DUNE TimeSlice, consisting of a TimeSliceHeader object and a vector of pointe...
Definition TimeSlice.hpp:27
size_t get_total_size_bytes() const
Get size of timeslice from underlying TimeSliceHeader and Fragments.
Definition TimeSlice.hpp:78
size_t get_sum_of_fragment_payload_sizes() const
Get the sum of the fragment payload sizes.
Definition TimeSlice.hpp:91
void register_timeslice(py::module &)
uint64_t timeslice_number_t
Definition Types.hpp:40
SourceID is a generalized representation of the source of a piece of data in the DAQ....
Definition SourceID.hpp:32
Data fields associated with a TimeSliceHeader.
static constexpr uint32_t s_timeslice_header_marker
Marker bytes to identify a TimeSliceHeader entry in a raw data stream.
static constexpr uint32_t s_timeslice_header_version
timeslice_number_t timeslice_number
Slice number of this TimeSlice within the stream.