Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:35

0001 #ifndef DATAFORMATS_HCALDETID_HCALELECTRONICSID_H
0002 #define DATAFORMATS_HCALDETID_HCALELECTRONICSID_H 1
0003 
0004 #include <string>
0005 #include <ostream>
0006 #include <cstdint>
0007 
0008 /** \brief Readout chain identification for Hcal
0009 
0010     [31:27] Unused (so far)
0011     [26] VME (0), uTCA (1)
0012 
0013     For VME Electronics:
0014     [25]    Trigger-chain id flag
0015     [24:20] Readout Crate Id
0016     [19] HTR FPGA selector [t/b]
0017     [18:14] HTR Slot
0018     [13:9]  DCC id
0019     [8:5]   Spigot
0020     [4:2]   FiberIndex or SLB site
0021     [1:0]   FiberChanId or SLB channel
0022 
0023     For uTCA Electronics:
0024 
0025      [25]    Is Trigger Id
0026      [18:13] Readout Crate Id
0027      [12:9] Slot
0028      [8:4]   Fiber
0029      [3:0]   FiberChanId
0030 
0031  */
0032 class HcalElectronicsId {
0033 public:
0034   /** Default constructor -- invalid value */
0035   constexpr HcalElectronicsId() : hcalElectronicsId_{0xffffffffu} {}
0036   /** from raw */
0037   constexpr HcalElectronicsId(uint32_t id) : hcalElectronicsId_{id} {}
0038   /** VME Constructor from fiberchan,fiber index,spigot,dccid */
0039   constexpr HcalElectronicsId(int fiberChan, int fiberIndex, int spigot, int dccid)
0040       : hcalElectronicsId_((uint32_t)((fiberChan & 0x3) | (((fiberIndex - 1) & 0x7) << 2) | ((spigot & 0xF) << 5) |
0041                                       ((dccid & 0x1F) << 9))) {}
0042   /** VME Constructor from slb channel,slb site,spigot,dccid */
0043   constexpr HcalElectronicsId(int slbChan, int slbSite, int spigot, int dccid, int crate, int slot, int tb)
0044       : hcalElectronicsId_(
0045             (uint32_t)((slbChan & 0x3) | (((slbSite)&0x7) << 2) | ((spigot & 0xF) << 5) | ((dccid & 0x1F) << 9))) {
0046     hcalElectronicsId_ |= ((tb & 0x1) << 19) | ((slot & 0x1f) << 14) | ((crate & 0x3f) << 20);
0047     hcalElectronicsId_ |= 0x02000000;
0048   }
0049   /** uTCA constructor */
0050   constexpr HcalElectronicsId(int crate, int slot, int fiber, int fc, bool isTrigger)
0051       : hcalElectronicsId_((int)((fc & 0xF) | (((fiber)&0x1F) << 4) | ((slot & 0xF) << 9) | ((crate & 0x3F) << 13))) {
0052     if (isTrigger)
0053       hcalElectronicsId_ |= 0x02000000;
0054     hcalElectronicsId_ |= 0x04000000;
0055   }
0056 
0057   constexpr uint32_t operator()() { return hcalElectronicsId_; }
0058 
0059   constexpr uint32_t rawId() const { return hcalElectronicsId_; }
0060 
0061   constexpr bool isVMEid() const { return (hcalElectronicsId_ & 0x04000000) == 0; }
0062   constexpr bool isUTCAid() const { return (hcalElectronicsId_ & 0x04000000) != 0; }
0063   constexpr bool isTriggerChainId() const { return (hcalElectronicsId_ & 0x02000000) != 0; }
0064 
0065   /** Set the VME htr-related information 1=top, 0=bottom*/
0066   constexpr void setHTR(int crate, int slot, int tb) {
0067     if (isUTCAid())
0068       return;                      // cannot do this for uTCA
0069     hcalElectronicsId_ &= 0x3FFF;  // keep the readout chain info
0070     hcalElectronicsId_ |= ((tb & 0x1) << 19) | ((slot & 0x1f) << 14) | ((crate & 0x3f) << 20);
0071   }
0072 
0073   /// get subtype for this channel (valid for uTCA only)
0074   constexpr int subtype() const { return (isUTCAid()) ? ((hcalElectronicsId_ >> 21) & 0x1F) : (-1); }
0075   /// get the fiber channel id (which of channels on a fiber)
0076   constexpr int fiberChanId() const { return (isVMEid()) ? (hcalElectronicsId_ & 0x3) : (hcalElectronicsId_ & 0xF); }
0077   /// get the fiber index.  For VME 1-8 (which of eight fibers carried by a spigot), for uTCA fibers are zero-based
0078   constexpr int fiberIndex() const {
0079     return (isVMEid()) ? (((hcalElectronicsId_ >> 2) & 0x7) + 1) : ((hcalElectronicsId_ >> 4) & 0x1F);
0080   }
0081   /// get the SLB channel index  (valid only for VME trigger-chain ids)
0082   constexpr int slbChannelIndex() const { return hcalElectronicsId_ & 0x3; }
0083   /// get the SLB site number (valid only for VME trigger-chain ids)
0084   constexpr int slbSiteNumber() const { return ((hcalElectronicsId_ >> 2) & 0x7); }
0085 
0086   /// get the HTR channel id (1-24)
0087   constexpr int htrChanId() const { return isVMEid() ? ((fiberChanId() + 1) + ((fiberIndex() - 1) * 3)) : (0); }
0088 
0089   /// get the HTR-wide slb channel code (letter plus number)
0090   std::string slbChannelCode() const;
0091 
0092   /// get the spigot (input number on DCC, AMC card number for uTCA)
0093   constexpr int spigot() const { return (isVMEid()) ? ((hcalElectronicsId_ >> 5) & 0xF) : slot(); }
0094   /// get the (Hcal local) DCC id for VME, crate number for uTCA
0095   constexpr int dccid() const { return (isVMEid()) ? ((hcalElectronicsId_ >> 9) & 0x1F) : crateId(); }
0096   /// get the htr slot
0097   constexpr int htrSlot() const { return slot(); }
0098   /// get the htr or uHTR slot
0099   constexpr int slot() const {
0100     return (isVMEid()) ? ((hcalElectronicsId_ >> 14) & 0x1F) : ((hcalElectronicsId_ >> 9) & 0xF);
0101   }
0102   /// get the htr top/bottom (1=top/0=bottom), valid for VME
0103   constexpr int htrTopBottom() const { return (isVMEid()) ? ((hcalElectronicsId_ >> 19) & 0x1) : (-1); }
0104   /// get the readout VME crate number
0105   constexpr int readoutVMECrateId() const { return crateId(); }
0106   /// get the readout VME crate number
0107   constexpr int crateId() const {
0108     return (isVMEid()) ? ((hcalElectronicsId_ >> 20) & 0x1F) : ((hcalElectronicsId_ >> 13) & 0x3F);
0109   }
0110   /// get a fast, compact, unique index for linear lookups
0111   constexpr int linearIndex() const {
0112     return (isVMEid()) ? ((hcalElectronicsId_)&0x3FFF) : ((hcalElectronicsId_)&0x7FFFF);
0113   }
0114 
0115   static const int maxLinearIndex = 0x7FFFF;  //
0116   static const int maxDCCId = 31;
0117 
0118   /** Equality operator */
0119   constexpr int operator==(const HcalElectronicsId& id) const { return id.hcalElectronicsId_ == hcalElectronicsId_; }
0120   /** Non-Equality operator */
0121   constexpr int operator!=(const HcalElectronicsId& id) const { return id.hcalElectronicsId_ != hcalElectronicsId_; }
0122   /// Compare the id to another id for use in a map
0123   constexpr int operator<(const HcalElectronicsId& id) const { return hcalElectronicsId_ < id.hcalElectronicsId_; }
0124 
0125 private:
0126   uint32_t hcalElectronicsId_;
0127 };
0128 
0129 std::ostream& operator<<(std::ostream&, const HcalElectronicsId&);
0130 
0131 #endif