CMS 3D CMS Logo

HcalElectronicsId.h
Go to the documentation of this file.
1 #ifndef DATAFORMATS_HCALDETID_HCALELECTRONICSID_H
2 #define DATAFORMATS_HCALDETID_HCALELECTRONICSID_H 1
3 
4 #include <string>
5 #include <ostream>
6 #include <cstdint>
7 
33 public:
36  : hcalElectronicsId_{0xffffffffu}
37  {}
40  : hcalElectronicsId_{id}
41  {}
43  constexpr HcalElectronicsId(int fiberChan, int fiberIndex, int spigot, int dccid)
44  : hcalElectronicsId_((uint32_t)((fiberChan&0x3) | (((fiberIndex-1)&0x7)<<2) |
45  ((spigot&0xF)<<5) | ((dccid&0x1F)<<9)))
46  {}
48  constexpr HcalElectronicsId(int slbChan, int slbSite, int spigot,
49  int dccid, int crate, int slot, int tb)
50  : hcalElectronicsId_((uint32_t)((slbChan&0x3) | (((slbSite)&0x7)<<2) |
51  ((spigot&0xF)<<5) | ((dccid&0x1F)<<9))) {
52  hcalElectronicsId_|=((tb&0x1)<<19) | ((slot&0x1f)<<14) | ((crate&0x3f)<<20);
53  hcalElectronicsId_|=0x02000000;
54  }
56  constexpr HcalElectronicsId(int crate, int slot, int fiber, int fc, bool isTrigger)
57  : hcalElectronicsId_((int)((fc&0xF) | (((fiber)&0x1F)<<4) |
58  ((slot&0xF)<<9) | ((crate&0x3F)<<13))) {
59  if (isTrigger) hcalElectronicsId_|=0x02000000;
60  hcalElectronicsId_|=0x04000000;
61  }
62 
63  constexpr uint32_t operator()() { return hcalElectronicsId_; }
64 
65  constexpr uint32_t rawId() const { return hcalElectronicsId_; }
66 
67  constexpr bool isVMEid() const { return (hcalElectronicsId_&0x04000000)==0; }
68  constexpr bool isUTCAid() const { return (hcalElectronicsId_&0x04000000)!=0; }
69  constexpr bool isTriggerChainId() const { return (hcalElectronicsId_&0x02000000)!=0; }
70 
72  constexpr void setHTR(int crate, int slot, int tb) {
73  if (isUTCAid()) return; // cannot do this for uTCA
74  hcalElectronicsId_&=0x3FFF; // keep the readout chain info
75  hcalElectronicsId_|=((tb&0x1)<<19) | ((slot&0x1f)<<14) | ((crate&0x3f)<<20);
76  }
77 
79  constexpr int subtype() const { return (isUTCAid())?((hcalElectronicsId_>>21)&0x1F):(-1); }
81  constexpr int fiberChanId() const { return (isVMEid())?(hcalElectronicsId_&0x3):(hcalElectronicsId_&0xF); }
83  constexpr int fiberIndex() const { return (isVMEid())?(((hcalElectronicsId_>>2)&0x7)+1):((hcalElectronicsId_>>4)&0x1F); }
85  constexpr int slbChannelIndex() const { return hcalElectronicsId_&0x3; }
87  constexpr int slbSiteNumber() const { return ((hcalElectronicsId_>>2)&0x7); }
88 
90  constexpr int htrChanId() const { return isVMEid()?((fiberChanId()+1)+((fiberIndex()-1)*3)):(0); }
91 
94 
96  constexpr int spigot() const { return (isVMEid())?((hcalElectronicsId_>>5)&0xF):slot(); }
98  constexpr int dccid() const { return (isVMEid())?((hcalElectronicsId_>>9)&0x1F):crateId(); }
100  constexpr int htrSlot() const { return slot(); }
102  constexpr int slot() const { return (isVMEid())?((hcalElectronicsId_>>14)&0x1F):((hcalElectronicsId_>>9)&0xF); }
104  constexpr int htrTopBottom() const { return (isVMEid())?((hcalElectronicsId_>>19)&0x1):(-1); }
106  constexpr int readoutVMECrateId() const { return crateId(); }
108  constexpr int crateId() const { return (isVMEid())?((hcalElectronicsId_>>20)&0x1F):((hcalElectronicsId_>>13)&0x3F); }
110  constexpr int linearIndex() const { return (isVMEid())?((hcalElectronicsId_)&0x3FFF):((hcalElectronicsId_)&0x7FFFF); }
111 
112  static const int maxLinearIndex = 0x7FFFF; //
113  static const int maxDCCId = 31;
114 
116  constexpr int operator==(const HcalElectronicsId& id) const { return id.hcalElectronicsId_==hcalElectronicsId_; }
118  constexpr int operator!=(const HcalElectronicsId& id) const { return id.hcalElectronicsId_!=hcalElectronicsId_; }
120  constexpr int operator<(const HcalElectronicsId& id) const { return hcalElectronicsId_<id.hcalElectronicsId_; }
121 
122 private:
124 };
125 
126 std::ostream& operator<<(std::ostream&,const HcalElectronicsId&);
127 
128 
129 #endif
constexpr HcalElectronicsId(int slbChan, int slbSite, int spigot, int dccid, int crate, int slot, int tb)
constexpr uint32_t rawId() const
constexpr void setHTR(int crate, int slot, int tb)
constexpr int operator<(const HcalElectronicsId &id) const
Compare the id to another id for use in a map.
constexpr uint32_t operator()()
constexpr int slbChannelIndex() const
get the SLB channel index (valid only for VME trigger-chain ids)
static int slbChan(const HcalTriggerPrimitiveSample &theSample)
constexpr int dccid() const
get the (Hcal local) DCC id for VME, crate number for uTCA
constexpr HcalElectronicsId(int crate, int slot, int fiber, int fc, bool isTrigger)
#define constexpr
constexpr HcalElectronicsId()
constexpr HcalElectronicsId(uint32_t id)
constexpr bool isUTCAid() const
constexpr int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom), valid for VME
constexpr int linearIndex() const
get a fast, compact, unique index for linear lookups
constexpr bool isVMEid() const
std::string slbChannelCode() const
get the HTR-wide slb channel code (letter plus number)
constexpr HcalElectronicsId(int fiberChan, int fiberIndex, int spigot, int dccid)
constexpr int htrSlot() const
get the htr slot
constexpr int readoutVMECrateId() const
get the readout VME crate number
constexpr int operator==(const HcalElectronicsId &id) const
constexpr int spigot() const
get the spigot (input number on DCC, AMC card number for uTCA)
constexpr int crateId() const
get the readout VME crate number
constexpr int fiberIndex() const
get the fiber index. For VME 1-8 (which of eight fibers carried by a spigot), for uTCA fibers are zer...
constexpr int subtype() const
get subtype for this channel (valid for uTCA only)
std::ostream & operator<<(std::ostream &, const HcalElectronicsId &)
static const int maxDCCId
constexpr int slot() const
get the htr or uHTR slot
static const int maxLinearIndex
constexpr int operator!=(const HcalElectronicsId &id) const
constexpr int htrChanId() const
get the HTR channel id (1-24)
constexpr int slbSiteNumber() const
get the SLB site number (valid only for VME trigger-chain ids)
constexpr bool isTriggerChainId() const
constexpr int fiberChanId() const
get the fiber channel id (which of channels on a fiber)
Readout chain identification for Hcal.