DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SourceID.hpp
Go to the documentation of this file.
1
8
9#ifndef DAQDATAFORMATS_INCLUDE_DAQDATAFORMATS_SOURCEID_HPP_
10#define DAQDATAFORMATS_INCLUDE_DAQDATAFORMATS_SOURCEID_HPP_
11
12#include <cassert>
13#include <cstddef>
14#include <cstdint>
15#include <iomanip>
16#include <istream>
17#include <limits>
18#include <ostream>
19#include <sstream>
20#include <string>
21#include <tuple>
22
24
32{
33
34 using Version_t = uint16_t; // NOLINT(build/unsigned)
35 using Subsystem_t = uint16_t; // NOLINT(build/unsigned)
36 using ID_t = uint32_t; // NOLINT(build/unsigned)
37
47
48 // Taking SourceID as the direct successor of GeoID which had version 1
49 static constexpr Version_t s_source_id_version = 2;
50
51 static constexpr ID_t s_invalid_id = std::numeric_limits<ID_t>::max();
52
54
57
60
61 SourceID() = default;
62
63 SourceID(const Subsystem& subsystem_arg, const ID_t& id_arg)
64 : subsystem(subsystem_arg)
65 , id(id_arg)
66 {
67 }
68
69 std::string to_string() const
70 {
71 std::ostringstream ostr;
72 ostr << subsystem_to_string(subsystem) << "_0x" << std::hex << std::setfill('0') << std::setw(2 * sizeof(id)) << id;
73 return ostr.str();
74 }
75
76 bool is_in_valid_state() const noexcept { return subsystem != Subsystem::kUnknown && id != s_invalid_id; }
77
79 bool operator<(const SourceID& other) const noexcept;
80 bool operator!=(const SourceID& other) const noexcept;
81 bool operator==(const SourceID& other) const noexcept;
82
83 static std::string subsystem_to_string(const Subsystem& type);
84 static Subsystem string_to_subsystem(const std::string& typestring);
85};
86
87inline bool
88SourceID::operator<(const SourceID& other) const noexcept
89{
90 return std::tuple(subsystem, id) < std::tuple(other.subsystem, other.id);
91}
92
93} // namespace dunedaq::daqdataformats
94
95#include "detail/SourceID.hxx"
96
97#endif // DAQDATAFORMATS_INCLUDE_DAQDATAFORMATS_SOURCEID_HPP_
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
bool operator<(const SourceID &other) const noexcept
Comparison operators to allow SourceID to be used in std::map.
Definition SourceID.hpp:88
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
Subsystem
The Subsystem enum describes the kind of source we're dealing with.
Definition SourceID.hpp:40
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
bool operator==(const SourceID &other) const noexcept
Definition SourceID.hxx:57
SourceID(const Subsystem &subsystem_arg, const ID_t &id_arg)
Definition SourceID.hpp:63
bool operator!=(const SourceID &other) const noexcept
Definition SourceID.hxx:51