File indexing completed on 2024-04-06 12:02:33
0001 #ifndef CondFormats_Phase2TrackerDTC_DTCELinkId_h
0002 #define CondFormats_Phase2TrackerDTC_DTCELinkId_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include "CondFormats/Serialization/interface/Serializable.h"
0023
0024 #include <cstdint>
0025 #include <functional>
0026 #include <limits>
0027
0028 class DTCELinkId {
0029 public:
0030 DTCELinkId() noexcept;
0031 DTCELinkId(DTCELinkId const&) noexcept;
0032 DTCELinkId(DTCELinkId&&) noexcept;
0033 DTCELinkId& operator=(DTCELinkId const&) noexcept;
0034 DTCELinkId& operator=(DTCELinkId&&) noexcept;
0035 ~DTCELinkId() noexcept;
0036
0037
0038 DTCELinkId(uint16_t, uint8_t, uint8_t) noexcept;
0039
0040 inline auto elink_id() const noexcept { return elink_id_; }
0041 inline auto gbtlink_id() const noexcept { return gbtlink_id_; }
0042 inline auto dtc_id() const noexcept { return dtc_id_; }
0043
0044 private:
0045
0046
0047
0048
0049
0050 uint8_t elink_id_;
0051 uint8_t gbtlink_id_;
0052 uint16_t dtc_id_;
0053
0054 COND_SERIALIZABLE;
0055 };
0056
0057 namespace std {
0058 template <>
0059 struct hash<DTCELinkId> {
0060 size_t operator()(const DTCELinkId& k) const noexcept {
0061
0062 constexpr const size_t shift_gbtlink_id = numeric_limits<decltype(k.elink_id())>::max() + 1u;
0063 constexpr const size_t shift_dtc_id = (numeric_limits<decltype(k.gbtlink_id())>::max() + 1u) * shift_gbtlink_id;
0064
0065 return k.elink_id() + k.gbtlink_id() * shift_gbtlink_id + k.dtc_id() * shift_dtc_id;
0066 }
0067 };
0068 }
0069
0070 inline bool operator<(DTCELinkId const& lhs, DTCELinkId const& rhs) {
0071 return lhs.dtc_id() < rhs.dtc_id() || (lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() < rhs.gbtlink_id()) ||
0072 (lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() == rhs.gbtlink_id() && lhs.elink_id() < rhs.elink_id());
0073 }
0074 inline bool operator>(DTCELinkId const& lhs, DTCELinkId const& rhs) {
0075 return lhs.dtc_id() > rhs.dtc_id() || (lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() > rhs.gbtlink_id()) ||
0076 (lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() == rhs.gbtlink_id() && lhs.elink_id() > rhs.elink_id());
0077 }
0078 inline bool operator==(DTCELinkId const& lhs, DTCELinkId const& rhs) {
0079 return lhs.dtc_id() == rhs.dtc_id() && lhs.gbtlink_id() == rhs.gbtlink_id() && lhs.elink_id() == rhs.elink_id();
0080 }
0081 inline bool operator!=(DTCELinkId const& lhs, DTCELinkId const& rhs) {
0082 return lhs.dtc_id() != rhs.dtc_id() || lhs.gbtlink_id() != rhs.gbtlink_id() || lhs.elink_id() != rhs.elink_id();
0083 }
0084
0085 #endif