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 
22 #include <cstdint>
23 #include <limits>
24 
26 
27 class DTCELinkId {
28 public:
35 
36  // Constructs a DTCELinkId addressed by (dtc_id, gbtlink_id, elink_id)
37  DTCELinkId(uint16_t, uint8_t, uint8_t) noexcept;
38 
39  inline auto elink_id() const noexcept { return elink_id_; }
40  inline auto gbtlink_id() const noexcept { return gbtlink_id_; }
41  inline auto dtc_id() const noexcept { return dtc_id_; }
42 
43 private:
44  // In order to keep the payload small, we use the C standard integers, optimizing them for size.
45  // The lpGBT has at most 7 ePorts, therefore they can be addressed by an 8-bit number.
46  // The DTC should host at most 72 GBT links, therefore an 8-bit number should be enough to address it.
47  // The C++ memory alignment and padding rules impose that this class will have at least 32 bits size,
48  // i.e. 8+8+8 bits and 8+8+16 would be the same, so we choose the latter.
49  uint8_t elink_id_;
50  uint8_t gbtlink_id_;
51  uint16_t dtc_id_;
52 
54 };
55 
56 namespace std {
57  template <>
58  struct hash<DTCELinkId> {
59  size_t operator()(const DTCELinkId& k) const noexcept {
60  // With
61  constexpr const size_t shift_gbtlink_id = numeric_limits<decltype(k.elink_id())>::max() + 1u;
62  constexpr const size_t shift_dtc_id = (numeric_limits<decltype(k.gbtlink_id())>::max() + 1u) * shift_gbtlink_id;
63 
64  return k.elink_id() + k.gbtlink_id() * shift_gbtlink_id + k.dtc_id() * shift_dtc_id;
65  }
66  };
67 } // namespace std
68 
69 inline bool operator<(DTCELinkId const& lhs, DTCELinkId const& rhs) {
70  return lhs.dtc_id() < rhs.dtc_id() || (lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() < rhs.gbtlink_id()) ||
71  (lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() == rhs.gbtlink_id() && lhs.elink_id() < rhs.elink_id());
72 }
73 inline bool operator>(DTCELinkId const& lhs, DTCELinkId const& rhs) {
74  return lhs.dtc_id() > rhs.dtc_id() || (lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() > rhs.gbtlink_id()) ||
75  (lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() == rhs.gbtlink_id() && lhs.elink_id() > rhs.elink_id());
76 }
77 inline bool operator==(DTCELinkId const& lhs, DTCELinkId const& rhs) {
78  return lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() == rhs.gbtlink_id() && lhs.elink_id() == rhs.elink_id();
79 }
80 inline bool operator!=(DTCELinkId const& lhs, DTCELinkId const& rhs) {
81  return lhs.dtc_id() != rhs.dtc_id() || lhs.gbtlink_id() != rhs.gbtlink_id() || lhs.elink_id() != rhs.elink_id();
82 }
83 
84 #endif // end DataFormats_Phase2TrackerDTC_DTCELinkId_h
auto gbtlink_id() const noexcept
Definition: DTCELinkId.h:40
bool operator==(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:77
bool operator>(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:73
size_t operator()(const DTCELinkId &k) const noexcept
Definition: DTCELinkId.h:59
~DTCELinkId() noexcept
Definition: DTCELinkId.cc:34
DTCELinkId & operator=(DTCELinkId const &) noexcept
Definition: DTCELinkId.cc:18
auto dtc_id() const noexcept
Definition: DTCELinkId.h:41
uint8_t elink_id_
Definition: DTCELinkId.h:49
uint16_t dtc_id_
Definition: DTCELinkId.h:51
#define noexcept
bool operator!=(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:80
uint8_t gbtlink_id_
Definition: DTCELinkId.h:50
#define COND_SERIALIZABLE
Definition: Serializable.h:38
bool operator<(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:69
DTCELinkId() noexcept
Definition: DTCELinkId.cc:7
auto elink_id() const noexcept
Definition: DTCELinkId.h:39
#define constexpr