CMS 3D CMS Logo

DTCELinkId.h
Go to the documentation of this file.
1 #ifndef CondFormats_Phase2TrackerDTC_DTCELinkId_h
2 #define CondFormats_Phase2TrackerDTC_DTCELinkId_h
3 
4 // -*- C++ -*-
5 //
6 // Package: CondFormats/Phase2TrackerDTC
7 // Class: DTCELinkId
8 //
16 //
17 // Original Author: Luigi Calligaris, SPRACE, Sao Paulo, BR
18 // Created : Wed, 27 Feb 2019 21:41:13 GMT
19 //
20 //
21 
23 
24 #include <cstdint>
25 #include <functional>
26 #include <limits>
27 
28 class DTCELinkId {
29 public:
30  DTCELinkId() noexcept;
31  DTCELinkId(DTCELinkId const&) noexcept;
32  DTCELinkId(DTCELinkId&&) noexcept;
33  DTCELinkId& operator=(DTCELinkId const&) noexcept;
34  DTCELinkId& operator=(DTCELinkId&&) noexcept;
35  ~DTCELinkId() noexcept;
36 
37  // Constructs a DTCELinkId addressed by (dtc_id, gbtlink_id, elink_id)
38  DTCELinkId(uint16_t, uint8_t, uint8_t) noexcept;
39 
40  inline auto elink_id() const noexcept { return elink_id_; }
41  inline auto gbtlink_id() const noexcept { return gbtlink_id_; }
42  inline auto dtc_id() const noexcept { return dtc_id_; }
43 
44 private:
45  // In order to keep the payload small, we use the C standard integers, optimizing them for size.
46  // The lpGBT has at most 7 ePorts, therefore they can be addressed by an 8-bit number.
47  // The DTC should host at most 72 GBT links, therefore an 8-bit number should be enough to address it.
48  // The C++ memory alignment and padding rules impose that this class will have at least 32 bits size,
49  // i.e. 8+8+8 bits and 8+8+16 would be the same, so we choose the latter.
50  uint8_t elink_id_;
51  uint8_t gbtlink_id_;
52  uint16_t dtc_id_;
53 
55 };
56 
57 namespace std {
58  template <>
59  struct hash<DTCELinkId> {
60  size_t operator()(const DTCELinkId& k) const noexcept {
61  // With
62  constexpr const size_t shift_gbtlink_id = numeric_limits<decltype(k.elink_id())>::max() + 1u;
63  constexpr const size_t shift_dtc_id = (numeric_limits<decltype(k.gbtlink_id())>::max() + 1u) * shift_gbtlink_id;
64 
65  return k.elink_id() + k.gbtlink_id() * shift_gbtlink_id + k.dtc_id() * shift_dtc_id;
66  }
67  };
68 } // namespace std
69 
70 inline bool operator<(DTCELinkId const& lhs, DTCELinkId const& rhs) {
71  return lhs.dtc_id() < rhs.dtc_id() || (lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() < rhs.gbtlink_id()) ||
72  (lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() == rhs.gbtlink_id() && lhs.elink_id() < rhs.elink_id());
73 }
74 inline bool operator>(DTCELinkId const& lhs, DTCELinkId const& rhs) {
75  return lhs.dtc_id() > rhs.dtc_id() || (lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() > rhs.gbtlink_id()) ||
76  (lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() == rhs.gbtlink_id() && lhs.elink_id() > rhs.elink_id());
77 }
78 inline bool operator==(DTCELinkId const& lhs, DTCELinkId const& rhs) {
79  return lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() == rhs.gbtlink_id() && lhs.elink_id() == rhs.elink_id();
80 }
81 inline bool operator!=(DTCELinkId const& lhs, DTCELinkId const& rhs) {
82  return lhs.dtc_id() != rhs.dtc_id() || lhs.gbtlink_id() != rhs.gbtlink_id() || lhs.elink_id() != rhs.elink_id();
83 }
84 
85 #endif // end DataFormats_Phase2TrackerDTC_DTCELinkId_h
DTCELinkId::~DTCELinkId
~DTCELinkId() noexcept
Definition: DTCELinkId.cc:34
std::hash< DTCELinkId >::operator()
size_t operator()(const DTCELinkId &k) const noexcept
Definition: DTCELinkId.h:60
DTCELinkId::elink_id
auto elink_id() const noexcept
Definition: DTCELinkId.h:40
DTCELinkId
Definition: DTCELinkId.h:28
DTCELinkId::elink_id_
uint8_t elink_id_
Definition: DTCELinkId.h:50
cond::hash
Definition: Time.h:19
operator==
bool operator==(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:78
COND_SERIALIZABLE
#define COND_SERIALIZABLE
Definition: Serializable.h:39
DTCELinkId::dtc_id
auto dtc_id() const noexcept
Definition: DTCELinkId.h:42
operator>
bool operator>(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:74
watchdog.const
const
Definition: watchdog.py:83
DTCELinkId::gbtlink_id_
uint8_t gbtlink_id_
Definition: DTCELinkId.h:51
DTCELinkId::DTCELinkId
DTCELinkId() noexcept
Definition: DTCELinkId.cc:7
dqmdumpme.k
k
Definition: dqmdumpme.py:60
operator!=
bool operator!=(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:81
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Serializable.h
std
Definition: JetResolutionObject.h:76
DTCELinkId::gbtlink_id
auto gbtlink_id() const noexcept
Definition: DTCELinkId.h:41
DTCELinkId::operator=
DTCELinkId & operator=(DTCELinkId const &) noexcept
Definition: DTCELinkId.cc:18
operator<
bool operator<(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:70
DTCELinkId::dtc_id_
uint16_t dtc_id_
Definition: DTCELinkId.h:52