DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
sourceid.cpp
Go to the documentation of this file.
1
8
10
11#include <pybind11/operators.h>
12#include <pybind11/pybind11.h>
13#include <pybind11/stl.h>
14
15#include <sstream>
16
17namespace py = pybind11;
18
20
21void
22register_sourceid(py::module& m)
23{
24
25 py::class_<SourceID> py_sourceid(m, "SourceID");
26 py_sourceid.def(py::init()).def(py::init<const SourceID::Subsystem&, const SourceID::ID_t&>());
27 py_sourceid.def(py::self < py::self)
28 .def(py::self == py::self)
29 .def(py::self != py::self)
30 .def("__hash__",
31 [](const SourceID& self) {
32 return py::hash(py::make_tuple(static_cast<uint32_t>(self.subsystem), self.id)); // NOLINT(build/unsigned)
33 })
34 .def_property_readonly_static(
35 "s_source_id_version", [](const py::object&) -> SourceID::Version_t { return SourceID::s_source_id_version; })
36 .def_property_readonly_static("s_invalid_id",
37 [](const py::object&) -> SourceID::ID_t { return SourceID::s_invalid_id; })
38 .def("__str__",
39 [](const SourceID& gid) {
40 std::ostringstream oss;
41 oss << gid;
42 return oss.str();
43 })
44 .def("__repr__", [](const SourceID& gid) {
45 std::ostringstream oss;
46 oss << "<daqdataformats::SourceID " << gid << ">";
47 return oss.str();
48 });
49
50 py::enum_<SourceID::Subsystem>(py_sourceid, "Subsystem")
51 .value("kUnknown", SourceID::Subsystem::kUnknown)
52 .value("kDetectorReadout", SourceID::Subsystem::kDetectorReadout)
53 .value("kHwSignalsInterface", SourceID::Subsystem::kHwSignalsInterface)
54 .value("kTrigger", SourceID::Subsystem::kTrigger)
55 .value("kTRBuilder", SourceID::Subsystem::kTRBuilder)
56 .export_values();
57
58 py_sourceid.def_readwrite("version", &SourceID::version)
59 .def_readwrite("subsystem", &SourceID::subsystem)
60 .def_readwrite("id", &SourceID::id);
61
62 py_sourceid.def("subsystem_to_string", &SourceID::subsystem_to_string)
63 .def("string_to_subsystem", &SourceID::string_to_subsystem)
64 .def("to_string", &SourceID::to_string)
65 .def("is_in_valid_state", &SourceID::is_in_valid_state);
66}
67
68} // namespace dunedaq::daqdataformats::python
void register_sourceid(py::module &)
Definition sourceid.cpp:22
SourceID is a generalized representation of the source of a piece of data in the DAQ....
Definition SourceID.hpp:32
static constexpr Version_t s_source_id_version
Definition SourceID.hpp:49
Subsystem subsystem
The general subsystem of the source of the data.
Definition SourceID.hpp:56
static std::string subsystem_to_string(const Subsystem &type)
Definition SourceID.hxx:63
static Subsystem string_to_subsystem(const std::string &typestring)
Definition SourceID.hxx:81
std::string to_string() const
Definition SourceID.hpp:69
static constexpr ID_t s_invalid_id
Definition SourceID.hpp:51
bool is_in_valid_state() const noexcept
Definition SourceID.hpp:76
ID_t id
Unique identifier of the source of the data.
Definition SourceID.hpp:59