Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:33

0001 #ifndef CondFormats_Phase2TrackerDTC_DTCELinkId_h
0002 #define CondFormats_Phase2TrackerDTC_DTCELinkId_h
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:    CondFormats/Phase2TrackerDTC
0007 // Class:      DTCELinkId
0008 //
0009 /**\class DTCELinkId DTCELinkId.cc CondFormats/Phase2TrackerDTC/src/DTCELinkId.cc
0010 
0011 Description: DTCELinkId identifies a specific eLink in the interface of a specific GBT link instance in the firmware of a specific DTC of the tracker back-end.
0012 
0013 Implementation:
0014         [Notes on implementation]
0015 */
0016 //
0017 // Original Author:  Luigi Calligaris, SPRACE, Sao Paulo, BR
0018 // Created        :  Wed, 27 Feb 2019 21:41:13 GMT
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   // Constructs a DTCELinkId addressed by (dtc_id, gbtlink_id, elink_id)
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   // In order to keep the payload small, we use the C standard integers, optimizing them for size.
0046   // The lpGBT has at most 7 ePorts, therefore they can be addressed by an 8-bit number.
0047   // The DTC should host at most 72 GBT links, therefore an 8-bit number should be enough to address it.
0048   // The C++ memory alignment and padding rules impose that this class will have at least 32 bits size,
0049   // i.e. 8+8+8 bits and 8+8+16 would be the same, so we choose the latter.
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       // With
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 }  // namespace std
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  // end DataFormats_Phase2TrackerDTC_DTCELinkId_h