File indexing completed on 2024-04-06 12:04:17
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
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 class HcalElectronicsId {
0033 public:
0034
0035 constexpr HcalElectronicsId() : hcalElectronicsId_{0xffffffffu} {}
0036
0037 constexpr HcalElectronicsId(uint32_t id) : hcalElectronicsId_{id} {}
0038
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
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
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
0066 constexpr void setHTR(int crate, int slot, int tb) {
0067 if (isUTCAid())
0068 return;
0069 hcalElectronicsId_ &= 0x3FFF;
0070 hcalElectronicsId_ |= ((tb & 0x1) << 19) | ((slot & 0x1f) << 14) | ((crate & 0x3f) << 20);
0071 }
0072
0073
0074 constexpr int32_t subtype() const {
0075 return (isUTCAid()) ? static_cast<int32_t>((hcalElectronicsId_ >> 21) & 0x1F) : (-1);
0076 }
0077
0078 constexpr int32_t fiberChanId() const {
0079 return (isVMEid()) ? static_cast<int32_t>(hcalElectronicsId_ & 0x3) : (hcalElectronicsId_ & 0xF);
0080 }
0081
0082 constexpr int32_t fiberIndex() const {
0083 return (isVMEid()) ? (((hcalElectronicsId_ >> 2) & 0x7) + 1) : ((hcalElectronicsId_ >> 4) & 0x1F);
0084 }
0085
0086 constexpr int32_t slbChannelIndex() const { return hcalElectronicsId_ & 0x3; }
0087
0088 constexpr int32_t slbSiteNumber() const { return ((hcalElectronicsId_ >> 2) & 0x7); }
0089
0090
0091 constexpr int32_t htrChanId() const { return isVMEid() ? ((fiberChanId() + 1) + ((fiberIndex() - 1) * 3)) : (0); }
0092
0093
0094 std::string slbChannelCode() const;
0095
0096
0097 constexpr int32_t spigot() const { return (isVMEid()) ? ((hcalElectronicsId_ >> 5) & 0xF) : slot(); }
0098
0099 constexpr int32_t dccid() const { return (isVMEid()) ? ((hcalElectronicsId_ >> 9) & 0x1F) : crateId(); }
0100
0101 constexpr int32_t htrSlot() const { return slot(); }
0102
0103 constexpr int32_t slot() const {
0104 return (isVMEid()) ? ((hcalElectronicsId_ >> 14) & 0x1F) : ((hcalElectronicsId_ >> 9) & 0xF);
0105 }
0106
0107 constexpr int32_t htrTopBottom() const {
0108 return (isVMEid()) ? static_cast<int32_t>((hcalElectronicsId_ >> 19) & 0x1) : (-1);
0109 }
0110
0111 constexpr int32_t readoutVMECrateId() const { return crateId(); }
0112
0113 constexpr int32_t crateId() const {
0114 return (isVMEid()) ? ((hcalElectronicsId_ >> 20) & 0x1F) : ((hcalElectronicsId_ >> 13) & 0x3F);
0115 }
0116
0117 constexpr int32_t linearIndex() const {
0118 return (isVMEid()) ? ((hcalElectronicsId_) & 0x3FFF) : ((hcalElectronicsId_) & 0x7FFFF);
0119 }
0120
0121 static const int maxLinearIndex = 0x7FFFF;
0122 static const int maxDCCId = 31;
0123
0124
0125 constexpr int operator==(const HcalElectronicsId& id) const { return id.hcalElectronicsId_ == hcalElectronicsId_; }
0126
0127 constexpr int operator!=(const HcalElectronicsId& id) const { return id.hcalElectronicsId_ != hcalElectronicsId_; }
0128
0129 constexpr int operator<(const HcalElectronicsId& id) const { return hcalElectronicsId_ < id.hcalElectronicsId_; }
0130
0131 private:
0132 uint32_t hcalElectronicsId_;
0133 };
0134
0135 std::ostream& operator<<(std::ostream&, const HcalElectronicsId&);
0136
0137 #endif