CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
35  constexpr HcalElectronicsId() : hcalElectronicsId_{0xffffffffu} {}
37  constexpr HcalElectronicsId(uint32_t id) : hcalElectronicsId_{id} {}
39  constexpr HcalElectronicsId(int fiberChan, int fiberIndex, int spigot, int dccid)
40  : hcalElectronicsId_((uint32_t)((fiberChan & 0x3) | (((fiberIndex - 1) & 0x7) << 2) | ((spigot & 0xF) << 5) |
41  ((dccid & 0x1F) << 9))) {}
43  constexpr HcalElectronicsId(int slbChan, int slbSite, int spigot, int dccid, int crate, int slot, int tb)
45  (uint32_t)((slbChan & 0x3) | (((slbSite)&0x7) << 2) | ((spigot & 0xF) << 5) | ((dccid & 0x1F) << 9))) {
46  hcalElectronicsId_ |= ((tb & 0x1) << 19) | ((slot & 0x1f) << 14) | ((crate & 0x3f) << 20);
47  hcalElectronicsId_ |= 0x02000000;
48  }
50  constexpr HcalElectronicsId(int crate, int slot, int fiber, int fc, bool isTrigger)
51  : hcalElectronicsId_((int)((fc & 0xF) | (((fiber)&0x1F) << 4) | ((slot & 0xF) << 9) | ((crate & 0x3F) << 13))) {
52  if (isTrigger)
53  hcalElectronicsId_ |= 0x02000000;
54  hcalElectronicsId_ |= 0x04000000;
55  }
56 
57  constexpr uint32_t operator()() { return hcalElectronicsId_; }
58 
59  constexpr uint32_t rawId() const { return hcalElectronicsId_; }
60 
61  constexpr bool isVMEid() const { return (hcalElectronicsId_ & 0x04000000) == 0; }
62  constexpr bool isUTCAid() const { return (hcalElectronicsId_ & 0x04000000) != 0; }
63  constexpr bool isTriggerChainId() const { return (hcalElectronicsId_ & 0x02000000) != 0; }
64 
66  constexpr void setHTR(int crate, int slot, int tb) {
67  if (isUTCAid())
68  return; // cannot do this for uTCA
69  hcalElectronicsId_ &= 0x3FFF; // keep the readout chain info
70  hcalElectronicsId_ |= ((tb & 0x1) << 19) | ((slot & 0x1f) << 14) | ((crate & 0x3f) << 20);
71  }
72 
74  constexpr int subtype() const { return (isUTCAid()) ? ((hcalElectronicsId_ >> 21) & 0x1F) : (-1); }
76  constexpr int fiberChanId() const { return (isVMEid()) ? (hcalElectronicsId_ & 0x3) : (hcalElectronicsId_ & 0xF); }
78  constexpr int fiberIndex() const {
79  return (isVMEid()) ? (((hcalElectronicsId_ >> 2) & 0x7) + 1) : ((hcalElectronicsId_ >> 4) & 0x1F);
80  }
82  constexpr int slbChannelIndex() const { return hcalElectronicsId_ & 0x3; }
84  constexpr int slbSiteNumber() const { return ((hcalElectronicsId_ >> 2) & 0x7); }
85 
87  constexpr int htrChanId() const { return isVMEid() ? ((fiberChanId() + 1) + ((fiberIndex() - 1) * 3)) : (0); }
88 
91 
93  constexpr int spigot() const { return (isVMEid()) ? ((hcalElectronicsId_ >> 5) & 0xF) : slot(); }
95  constexpr int dccid() const { return (isVMEid()) ? ((hcalElectronicsId_ >> 9) & 0x1F) : crateId(); }
97  constexpr int htrSlot() const { return slot(); }
99  constexpr int slot() const {
100  return (isVMEid()) ? ((hcalElectronicsId_ >> 14) & 0x1F) : ((hcalElectronicsId_ >> 9) & 0xF);
101  }
103  constexpr int htrTopBottom() const { return (isVMEid()) ? ((hcalElectronicsId_ >> 19) & 0x1) : (-1); }
105  constexpr int readoutVMECrateId() const { return crateId(); }
107  constexpr int crateId() const {
108  return (isVMEid()) ? ((hcalElectronicsId_ >> 20) & 0x1F) : ((hcalElectronicsId_ >> 13) & 0x3F);
109  }
111  constexpr int linearIndex() const {
112  return (isVMEid()) ? ((hcalElectronicsId_)&0x3FFF) : ((hcalElectronicsId_)&0x7FFFF);
113  }
114 
115  static const int maxLinearIndex = 0x7FFFF; //
116  static const int maxDCCId = 31;
117 
119  constexpr int operator==(const HcalElectronicsId& id) const { return id.hcalElectronicsId_ == hcalElectronicsId_; }
121  constexpr int operator!=(const HcalElectronicsId& id) const { return id.hcalElectronicsId_ != hcalElectronicsId_; }
123  constexpr int operator<(const HcalElectronicsId& id) const { return hcalElectronicsId_ < id.hcalElectronicsId_; }
124 
125 private:
127 };
128 
129 std::ostream& operator<<(std::ostream&, const HcalElectronicsId&);
130 
131 #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
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
constexpr HcalElectronicsId(int crate, int slot, int fiber, int fc, bool isTrigger)
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)
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.