Line data Source code
1 : /**
2 : * @file sourceid.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/SourceID.hpp"
10 :
11 : #include <pybind11/operators.h>
12 : #include <pybind11/pybind11.h>
13 : #include <pybind11/stl.h>
14 :
15 : #include <sstream>
16 :
17 : namespace py = pybind11;
18 :
19 : namespace dunedaq::daqdataformats::python {
20 :
21 : void
22 0 : register_sourceid(py::module& m)
23 : {
24 :
25 0 : py::class_<SourceID> py_sourceid(m, "SourceID");
26 0 : py_sourceid.def(py::init()).def(py::init<const SourceID::Subsystem&, const SourceID::ID_t&>());
27 0 : py_sourceid.def(py::self < py::self)
28 0 : .def(py::self == py::self)
29 0 : .def(py::self != py::self)
30 0 : .def("__hash__",
31 0 : [](const SourceID& self) {
32 0 : return py::hash(py::make_tuple(static_cast<uint32_t>(self.subsystem), self.id)); // NOLINT(build/unsigned)
33 : })
34 0 : .def_property_readonly_static(
35 0 : "s_source_id_version", [](const py::object&) -> SourceID::Version_t { return SourceID::s_source_id_version; })
36 0 : .def_property_readonly_static("s_invalid_id",
37 0 : [](const py::object&) -> SourceID::ID_t { return SourceID::s_invalid_id; })
38 0 : .def("__str__",
39 0 : [](const SourceID& gid) {
40 0 : std::ostringstream oss;
41 0 : oss << gid;
42 0 : return oss.str();
43 0 : })
44 0 : .def("__repr__", [](const SourceID& gid) {
45 0 : std::ostringstream oss;
46 0 : oss << "<daqdataformats::SourceID " << gid << ">";
47 0 : return oss.str();
48 0 : });
49 :
50 0 : py::enum_<SourceID::Subsystem>(py_sourceid, "Subsystem")
51 0 : .value("kUnknown", SourceID::Subsystem::kUnknown)
52 0 : .value("kDetectorReadout", SourceID::Subsystem::kDetectorReadout)
53 0 : .value("kHwSignalsInterface", SourceID::Subsystem::kHwSignalsInterface)
54 0 : .value("kTrigger", SourceID::Subsystem::kTrigger)
55 0 : .value("kTRBuilder", SourceID::Subsystem::kTRBuilder)
56 0 : .export_values();
57 :
58 0 : py_sourceid.def_readwrite("version", &SourceID::version)
59 0 : .def_readwrite("subsystem", &SourceID::subsystem)
60 0 : .def_readwrite("id", &SourceID::id);
61 :
62 0 : py_sourceid.def("subsystem_to_string", &SourceID::subsystem_to_string)
63 0 : .def("string_to_subsystem", &SourceID::string_to_subsystem)
64 0 : .def("to_string", &SourceID::to_string)
65 0 : .def("is_in_valid_state", &SourceID::is_in_valid_state);
66 0 : }
67 :
68 : } // namespace dunedaq::daqdataformats::python
|