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:
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 int32_t subtype() const {
75  return (isUTCAid()) ? static_cast<int32_t>((hcalElectronicsId_ >> 21) & 0x1F) : (-1);
76  }
78  constexpr int32_t fiberChanId() const {
79  return (isVMEid()) ? static_cast<int32_t>(hcalElectronicsId_ & 0x3) : (hcalElectronicsId_ & 0xF);
80  }
82  constexpr int32_t fiberIndex() const {
83  return (isVMEid()) ? (((hcalElectronicsId_ >> 2) & 0x7) + 1) : ((hcalElectronicsId_ >> 4) & 0x1F);
84  }
86  constexpr int32_t slbChannelIndex() const { return hcalElectronicsId_ & 0x3; }
88  constexpr int32_t slbSiteNumber() const { return ((hcalElectronicsId_ >> 2) & 0x7); }
89 
91  constexpr int32_t htrChanId() const { return isVMEid() ? ((fiberChanId() + 1) + ((fiberIndex() - 1) * 3)) : (0); }
92 
95 
97  constexpr int32_t spigot() const { return (isVMEid()) ? ((hcalElectronicsId_ >> 5) & 0xF) : slot(); }
99  constexpr int32_t dccid() const { return (isVMEid()) ? ((hcalElectronicsId_ >> 9) & 0x1F) : crateId(); }
101  constexpr int32_t htrSlot() const { return slot(); }
103  constexpr int32_t slot() const {
104  return (isVMEid()) ? ((hcalElectronicsId_ >> 14) & 0x1F) : ((hcalElectronicsId_ >> 9) & 0xF);
105  }
107  constexpr int32_t htrTopBottom() const {
108  return (isVMEid()) ? static_cast<int32_t>((hcalElectronicsId_ >> 19) & 0x1) : (-1);
109  }
111  constexpr int32_t readoutVMECrateId() const { return crateId(); }
113  constexpr int32_t crateId() const {
114  return (isVMEid()) ? ((hcalElectronicsId_ >> 20) & 0x1F) : ((hcalElectronicsId_ >> 13) & 0x3F);
115  }
117  constexpr int32_t linearIndex() const {
118  return (isVMEid()) ? ((hcalElectronicsId_) & 0x3FFF) : ((hcalElectronicsId_) & 0x7FFFF);
119  }
120 
121  static const int maxLinearIndex = 0x7FFFF; //
122  static const int maxDCCId = 31;
123 
125  constexpr int operator==(const HcalElectronicsId& id) const { return id.hcalElectronicsId_ == hcalElectronicsId_; }
127  constexpr int operator!=(const HcalElectronicsId& id) const { return id.hcalElectronicsId_ != hcalElectronicsId_; }
129  constexpr int operator<(const HcalElectronicsId& id) const { return hcalElectronicsId_ < id.hcalElectronicsId_; }
130 
131 private:
133 };
134 
135 std::ostream& operator<<(std::ostream&, const HcalElectronicsId&);
136 
137 #endif
constexpr HcalElectronicsId(int slbChan, int slbSite, int spigot, int dccid, int crate, int slot, int tb)
constexpr void setHTR(int crate, int slot, int tb)
constexpr int operator!=(const HcalElectronicsId &id) const
constexpr int32_t htrSlot() const
get the htr slot
constexpr uint32_t operator()()
constexpr int32_t htrTopBottom() const
get the htr top/bottom (1=top/0=bottom), valid for VME
static int slbChan(const HcalTriggerPrimitiveSample &theSample)
constexpr bool isVMEid() const
constexpr HcalElectronicsId(int crate, int slot, int fiber, int fc, bool isTrigger)
constexpr HcalElectronicsId()
constexpr HcalElectronicsId(uint32_t id)
constexpr int32_t linearIndex() const
get a fast, compact, unique index for linear lookups
constexpr int32_t readoutVMECrateId() const
get the readout VME crate number
constexpr int32_t fiberChanId() const
get the fiber channel id (which of channels on a fiber)
constexpr int32_t spigot() const
get the spigot (input number on DCC, AMC card number for uTCA)
constexpr HcalElectronicsId(int fiberChan, int fiberIndex, int spigot, int dccid)
constexpr int32_t slbSiteNumber() const
get the SLB site number (valid only for VME trigger-chain ids)
constexpr int32_t subtype() const
get subtype for this channel (valid for uTCA only)
constexpr int operator<(const HcalElectronicsId &id) const
Compare the id to another id for use in a map.
constexpr bool isUTCAid() const
constexpr int32_t fiberIndex() const
get the fiber index. For VME 1-8 (which of eight fibers carried by a spigot), for uTCA fibers are zer...
constexpr int32_t htrChanId() const
get the HTR channel id (1-24)
std::ostream & operator<<(std::ostream &, const HcalElectronicsId &)
constexpr uint32_t rawId() const
static const int maxDCCId
constexpr int operator==(const HcalElectronicsId &id) const
constexpr bool isTriggerChainId() const
constexpr int32_t slbChannelIndex() const
get the SLB channel index (valid only for VME trigger-chain ids)
static const int maxLinearIndex
std::string slbChannelCode() const
get the HTR-wide slb channel code (letter plus number)
constexpr int32_t slot() const
get the htr or uHTR slot
Readout chain identification for Hcal.
constexpr int32_t dccid() const
get the (Hcal local) DCC id for VME, crate number for uTCA
constexpr int32_t crateId() const
get the readout VME crate number