Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-12-06 03:45:40

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 {
0050       if (detId == r.detId) {
0051         return chamberType < r.chamberType;
0052       } else {
0053         return detId < r.detId;
0054       }
0055     }
0056 
0057     COND_SERIALIZABLE;
0058   };
0059 
0060   struct vfatEC {
0061     int chamberType;
0062     uint16_t vfatAdd;
0063     bool operator<(const vfatEC& r) const {
0064       if (vfatAdd == r.vfatAdd) {
0065         return chamberType < r.chamberType;
0066       } else {
0067         return vfatAdd < r.vfatAdd;
0068       }
0069     }
0070 
0071     COND_SERIALIZABLE;
0072   };
0073 
0074   struct channelNum {
0075     int chamberType;
0076     int vfatAdd;
0077     int chNum;
0078     bool operator<(const channelNum& c) const {
0079       if (chamberType == c.chamberType) {
0080         if (vfatAdd == c.vfatAdd) {
0081           return chNum < c.chNum;
0082         } else {
0083           return vfatAdd < c.vfatAdd;
0084         }
0085       } else {
0086         return chamberType < c.chamberType;
0087       }
0088     }
0089 
0090     COND_SERIALIZABLE;
0091   };
0092 
0093   struct stripNum {
0094     int chamberType;
0095     int iEta;
0096     int stNum;
0097     bool operator<(const stripNum& s) const {
0098       if (chamberType == s.chamberType) {
0099         if (iEta == s.iEta) {
0100           return stNum < s.stNum;
0101         } else {
0102           return iEta < s.iEta;
0103         }
0104       } else {
0105         return chamberType < s.chamberType;
0106       }
0107     }
0108 
0109     COND_SERIALIZABLE;
0110   };
0111 
0112   GEMChMap();
0113 
0114   explicit GEMChMap(const std::string& version);
0115 
0116   ~GEMChMap();
0117 
0118   const std::string& version() const;
0119   void setDummy();
0120 
0121   std::map<chamEC, chamDC> chamberMap() { return chamberMap_; };
0122 
0123   bool isValidAMC(unsigned int fedId, uint8_t amcNum) const {
0124     return std::find(amcVec_.begin(), amcVec_.end(), sectorEC({fedId, amcNum})) != amcVec_.end();
0125   }
0126 
0127   bool isValidChamber(unsigned int fedId, uint8_t amcNum, uint16_t gebId) const {
0128     return chamberMap_.find({fedId, amcNum, gebId}) != chamberMap_.end();
0129   }
0130 
0131   bool isValidVFAT(int chamberType, uint16_t vfatAdd) const {
0132     return chamIEtas_.find({chamberType, vfatAdd}) != chamIEtas_.end();
0133   }
0134 
0135   bool isValidStrip(int chamberType, int iEta, int strip) const {
0136     return stChMap_.find({chamberType, iEta, strip}) != stChMap_.end();
0137   }
0138 
0139   void add(sectorEC e) { amcVec_.push_back(e); }
0140 
0141   const chamDC& chamberPos(unsigned int fedId, uint8_t amcNum, uint16_t gebId) const {
0142     return chamberMap_.at({fedId, amcNum, gebId});
0143   }
0144   void add(chamEC e, chamDC d) { chamberMap_[e] = d; }
0145 
0146   const std::vector<uint16_t> getVfats(const int type) const { return chamVfats_.at(type); }
0147   void add(int type, uint16_t d) {
0148     if (std::find(chamVfats_[type].begin(), chamVfats_[type].end(), d) == chamVfats_[type].end())
0149       chamVfats_[type].push_back(d);
0150   }
0151 
0152   const std::vector<int> getIEtas(int chamberType, uint16_t vfatAdd) const {
0153     return chamIEtas_.at({chamberType, vfatAdd});
0154   }
0155   void add(vfatEC d, int iEta) {
0156     if (std::find(chamIEtas_[d].begin(), chamIEtas_[d].end(), iEta) == chamIEtas_[d].end())
0157       chamIEtas_[d].push_back(iEta);
0158   }
0159 
0160   const channelNum& getChannel(int chamberType, int iEta, int strip) const {
0161     return stChMap_.at({chamberType, iEta, strip});
0162   }
0163   const stripNum& getStrip(int chamberType, int vfatAdd, int channel) const {
0164     return chStMap_.at({chamberType, vfatAdd, channel});
0165   }
0166 
0167   void add(channelNum c, stripNum s) { chStMap_[c] = s; }
0168   void add(stripNum s, channelNum c) { stChMap_[s] = c; }
0169 
0170 private:
0171   std::string theVersion;
0172 
0173   std::vector<sectorEC> amcVec_;
0174 
0175   // electronics map to GEMDetId chamber
0176   std::map<chamEC, chamDC> chamberMap_;
0177 
0178   std::map<int, std::vector<uint16_t>> chamVfats_;
0179   std::map<vfatEC, std::vector<int>> chamIEtas_;
0180 
0181   std::map<channelNum, stripNum> chStMap_;
0182   std::map<stripNum, channelNum> stChMap_;
0183 
0184   COND_SERIALIZABLE;
0185 
0186 public:
0187   // size of ID bits
0188   static const int chipIdMask_ = 0xfff;  // chipId mask for 12 bits
0189   static const int maxGEBs_ = 24;        // 5 bits for GEB id
0190   static const int maxGEB1_ = 12;        // 5 bits for GEB id
0191   static const int maxGEB2_ = 12;        // 5 bits for GEB id
0192   static const int maxAMCs_ = 15;        // 4 bits for AMC no.
0193   static const int maxVFatGE0_ = 12;     // vFat per eta partition, not known yet for ME0
0194   static const int maxVFatGE11_ = 3;     // vFat per eta partition in GE11
0195   static const int maxVFatGE21_ = 6;     // vFat per eta partition in GE21
0196   static const int maxiEtaIdGE0_ = 8;    // no. eta partitions for GE0
0197   static const int maxiEtaIdGE11_ = 8;   // no. eta partitions for GE11
0198   static const int maxiEtaIdGE21_ = 16;  // no. eta partitions for GE21
0199   static const int maxChan_ = 128;       // channels per vFat
0200 };
0201 #endif  // GEMChMap_H