File indexing completed on 2022-06-06 07:38:17
0001 #ifndef CondFormats_GEMObjects_GEMChMap_h
0002 #define CondFormats_GEMObjects_GEMChMap_h
0003
0004 #include "CondFormats/Serialization/interface/Serializable.h"
0005 #include "DataFormats/MuonDetId/interface/GEMDetId.h"
0006 #include <map>
0007 #include <string>
0008 #include <vector>
0009 #include <algorithm>
0010
0011 class GEMChMap {
0012 public:
0013 struct sectorEC {
0014 unsigned int fedId;
0015 uint8_t amcNum;
0016 bool operator==(const sectorEC& r) const {
0017 if (fedId == r.fedId) {
0018 return amcNum == r.amcNum;
0019 } else {
0020 return false;
0021 }
0022 }
0023
0024 COND_SERIALIZABLE;
0025 };
0026
0027 struct chamEC {
0028 unsigned int fedId;
0029 uint8_t amcNum;
0030 uint16_t gebId;
0031 bool operator<(const chamEC& r) const {
0032 if (fedId == r.fedId) {
0033 if (amcNum == r.amcNum) {
0034 return gebId < r.gebId;
0035 } else {
0036 return amcNum < r.amcNum;
0037 }
0038 } else {
0039 return fedId < r.fedId;
0040 }
0041 }
0042
0043 COND_SERIALIZABLE;
0044 };
0045
0046 struct chamDC {
0047 uint32_t detId;
0048 int chamberType;
0049 bool operator<(const chamDC& r) const { return detId < r.detId; }
0050
0051 COND_SERIALIZABLE;
0052 };
0053
0054 struct vfatEC {
0055 int chamberType;
0056 uint16_t vfatAdd;
0057 bool operator<(const vfatEC& r) const {
0058 if (vfatAdd == r.vfatAdd) {
0059 return chamberType < r.chamberType;
0060 } else {
0061 return vfatAdd < r.vfatAdd;
0062 }
0063 }
0064
0065 COND_SERIALIZABLE;
0066 };
0067
0068 struct channelNum {
0069 int chamberType;
0070 int vfatAdd;
0071 int chNum;
0072 bool operator<(const channelNum& c) const {
0073 if (chamberType == c.chamberType) {
0074 if (vfatAdd == c.vfatAdd) {
0075 return chNum < c.chNum;
0076 } else {
0077 return vfatAdd < c.vfatAdd;
0078 }
0079 } else {
0080 return chamberType < c.chamberType;
0081 }
0082 }
0083
0084 COND_SERIALIZABLE;
0085 };
0086
0087 struct stripNum {
0088 int chamberType;
0089 int iEta;
0090 int stNum;
0091 bool operator<(const stripNum& s) const {
0092 if (chamberType == s.chamberType) {
0093 if (iEta == s.iEta) {
0094 return stNum < s.stNum;
0095 } else {
0096 return iEta < s.iEta;
0097 }
0098 } else {
0099 return chamberType < s.chamberType;
0100 }
0101 }
0102
0103 COND_SERIALIZABLE;
0104 };
0105
0106 GEMChMap();
0107
0108 explicit GEMChMap(const std::string& version);
0109
0110 ~GEMChMap();
0111
0112 const std::string& version() const;
0113 void setDummy();
0114
0115 std::map<chamEC, chamDC> chamberMap() { return chamberMap_; };
0116
0117 bool isValidAMC(unsigned int fedId, uint8_t amcNum) const {
0118 return std::find(amcVec_.begin(), amcVec_.end(), sectorEC({fedId, amcNum})) != amcVec_.end();
0119 }
0120
0121 bool isValidChamber(unsigned int fedId, uint8_t amcNum, uint16_t gebId) const {
0122 return chamberMap_.find({fedId, amcNum, gebId}) != chamberMap_.end();
0123 }
0124
0125 bool isValidVFAT(int chamberType, uint16_t vfatAdd) const {
0126 return chamIEtas_.find({chamberType, vfatAdd}) != chamIEtas_.end();
0127 }
0128
0129 bool isValidStrip(int chamberType, int iEta, int strip) const {
0130 return stChMap_.find({chamberType, iEta, strip}) != stChMap_.end();
0131 }
0132
0133 void add(sectorEC e) { amcVec_.push_back(e); }
0134
0135 const chamDC& chamberPos(unsigned int fedId, uint8_t amcNum, uint16_t gebId) const {
0136 return chamberMap_.at({fedId, amcNum, gebId});
0137 }
0138 void add(chamEC e, chamDC d) { chamberMap_[e] = d; }
0139
0140 const std::vector<uint16_t> getVfats(const int type) const { return chamVfats_.at(type); }
0141 void add(int type, uint16_t d) {
0142 if (std::find(chamVfats_[type].begin(), chamVfats_[type].end(), d) == chamVfats_[type].end())
0143 chamVfats_[type].push_back(d);
0144 }
0145
0146 const std::vector<int> getIEtas(int chamberType, uint16_t vfatAdd) const {
0147 return chamIEtas_.at({chamberType, vfatAdd});
0148 }
0149 void add(vfatEC d, int iEta) {
0150 if (std::find(chamIEtas_[d].begin(), chamIEtas_[d].end(), iEta) == chamIEtas_[d].end())
0151 chamIEtas_[d].push_back(iEta);
0152 }
0153
0154 const channelNum& getChannel(int chamberType, int iEta, int strip) const {
0155 return stChMap_.at({chamberType, iEta, strip});
0156 }
0157 const stripNum& getStrip(int chamberType, int vfatAdd, int channel) const {
0158 return chStMap_.at({chamberType, vfatAdd, channel});
0159 }
0160
0161 void add(channelNum c, stripNum s) { chStMap_[c] = s; }
0162 void add(stripNum s, channelNum c) { stChMap_[s] = c; }
0163
0164 private:
0165 std::string theVersion;
0166
0167 std::vector<sectorEC> amcVec_;
0168
0169
0170 std::map<chamEC, chamDC> chamberMap_;
0171
0172 std::map<int, std::vector<uint16_t>> chamVfats_;
0173 std::map<vfatEC, std::vector<int>> chamIEtas_;
0174
0175 std::map<channelNum, stripNum> chStMap_;
0176 std::map<stripNum, channelNum> stChMap_;
0177
0178 COND_SERIALIZABLE;
0179
0180 public:
0181
0182 static const int chipIdMask_ = 0xfff;
0183 static const int maxGEBs_ = 24;
0184 static const int maxGEB1_ = 12;
0185 static const int maxGEB2_ = 12;
0186 static const int maxAMCs_ = 15;
0187 static const int maxVFatGE0_ = 12;
0188 static const int maxVFatGE11_ = 3;
0189 static const int maxVFatGE21_ = 6;
0190 static const int maxiEtaIdGE0_ = 8;
0191 static const int maxiEtaIdGE11_ = 8;
0192 static const int maxiEtaIdGE21_ = 16;
0193 static const int maxChan_ = 128;
0194 };
0195 #endif