Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:31

0001 #include "DQM/HcalCommon/interface/Utilities.h"
0002 #include <utility>
0003 
0004 namespace hcaldqm {
0005   using namespace constants;
0006   namespace utilities {
0007     /*
0008  *  Useful Detector Functions. For Fast Detector Validity Check
0009  */
0010     std::pair<uint16_t, uint16_t> fed2crate(int fed) {
0011       //  uTCA Crate is split in half
0012       uint16_t slot = 0;
0013       if (fed <= FED_VME_MAX) {
0014         slot = fed % 2 == 0 ? SLOT_uTCA_MIN : SLOT_uTCA_MIN + 6;
0015       } else if ((fed >= 1100 && fed <= 1117) || (fed >= 1140 && fed <= 1148)) {
0016         slot = fed >= 1140 ? SLOT_uTCA_MIN + 8 : fed % 2 == 0 ? SLOT_uTCA_MIN : SLOT_uTCA_MIN + 4;
0017       } else {
0018         slot = fed % 2 == 0 ? SLOT_uTCA_MIN : SLOT_uTCA_MIN + 6;
0019       }
0020       std::pair<uint16_t, uint16_t> crate_slot = std::make_pair<uint16_t, uint16_t>(0, 0);
0021       auto it_fed2crate = constants::fed2crate_map.find(fed);
0022       if (it_fed2crate != constants::fed2crate_map.end()) {
0023         crate_slot =
0024             std::make_pair<uint16_t const, uint16_t const>((uint16_t const)it_fed2crate->second, (uint16_t const)slot);
0025       }
0026       return crate_slot;
0027     }
0028 
0029     uint16_t crate2fed(int crate, int slot) {
0030       //     for the details see Constants.h
0031       int fed = 0;
0032       auto it_crate2fed = constants::crate2fed_map.find(crate);
0033       if (it_crate2fed != constants::crate2fed_map.end()) {
0034         fed = it_crate2fed->second;
0035         if (fed <= FED_VME_MAX && fed > 0) {
0036           if (slot > 10 && (std::find(constants::crateListVME.begin(), constants::crateListVME.end(), crate) !=
0037                             constants::crateListVME.end())) {
0038             ++fed;
0039           }
0040         } else {
0041           if (crate == 22 || crate == 29 || crate == 32 || crate == 23 || crate == 27 || crate == 26 ||
0042               crate == 38) {  // needed to handle dual fed readout for HF and HO
0043             if (slot > 6 && (std::find(constants::crateListuTCA.begin(), constants::crateListuTCA.end(), crate) !=
0044                              constants::crateListuTCA.end())) {
0045               ++fed;  // hard coded mid slot FED numbering
0046             }
0047           } else {  // needed to handle  3-FED readout for HBHE
0048             if (slot > 8 && (std::find(constants::crateListuTCA.begin(), constants::crateListuTCA.end(), crate) !=
0049                              constants::crateListuTCA.end())) {
0050               fed = (fed + 1100) / 2 + 40;  // hard coded right slot FED numbering, no better way
0051             } else if (slot > 4 &&
0052                        (std::find(constants::crateListuTCA.begin(), constants::crateListuTCA.end(), crate) !=
0053                         constants::crateListuTCA.end())) {
0054               ++fed;  // hard coded mid slot FED numbering
0055             }
0056           }
0057         }
0058       }
0059       return fed;
0060     }
0061 
0062     uint32_t hash(HcalDetId const &did) { return did.rawId(); }
0063     uint32_t hash(HcalElectronicsId const &eid) { return eid.rawId(); }
0064     uint32_t hash(HcalTrigTowerDetId const &tid) { return tid.rawId(); }
0065 
0066     std::vector<int> getCrateList(HcalElectronicsMap const *emap) {
0067       std::vector<int> vCrates;
0068       std::vector<HcalElectronicsId> vids = emap->allElectronicsIdPrecision();
0069       for (std::vector<HcalElectronicsId>::const_iterator it = vids.begin(); it != vids.end(); ++it) {
0070         HcalElectronicsId eid = HcalElectronicsId(it->rawId());
0071         int crate = eid.crateId();
0072         if (std::find(vCrates.begin(), vCrates.end(), crate) == vCrates.end()) {
0073           vCrates.push_back(crate);
0074         }
0075       }
0076       std::sort(vCrates.begin(), vCrates.end());
0077       return vCrates;
0078     }
0079 
0080     std::map<int, uint32_t> getCrateHashMap(HcalElectronicsMap const *emap) {
0081       std::map<int, uint32_t> crateHashMap;
0082       std::vector<HcalElectronicsId> vids = emap->allElectronicsIdPrecision();
0083       for (std::vector<HcalElectronicsId>::const_iterator it = vids.begin(); it != vids.end(); ++it) {
0084         HcalElectronicsId eid = HcalElectronicsId(it->rawId());
0085         int this_crate = eid.crateId();
0086         uint32_t this_hash =
0087             (eid.isVMEid()
0088                  ? utilities::hash(HcalElectronicsId(FIBERCH_MIN, FIBER_VME_MIN, eid.spigot(), eid.dccid()))
0089                  : utilities::hash(HcalElectronicsId(eid.crateId(), eid.slot(), FIBER_uTCA_MIN1, FIBERCH_MIN, false)));
0090         if (crateHashMap.find(this_crate) == crateHashMap.end()) {
0091           crateHashMap[this_crate] = this_hash;
0092         }
0093       }
0094       return crateHashMap;
0095     }
0096 
0097     std::vector<int> getFEDList(HcalElectronicsMap const *emap) {
0098       std::vector<int> vfeds;
0099       std::vector<HcalElectronicsId> vids = emap->allElectronicsIdPrecision();
0100       for (std::vector<HcalElectronicsId>::const_iterator it = vids.begin(); it != vids.end(); ++it) {
0101         int fed = it->isVMEid() ? it->dccid() + FED_VME_MIN : crate2fed(it->crateId(), it->slot());
0102         uint32_t n = 0;
0103         for (std::vector<int>::const_iterator jt = vfeds.begin(); jt != vfeds.end(); ++jt)
0104           if (fed == *jt)
0105             break;
0106           else
0107             n++;
0108         if (n == vfeds.size())
0109           vfeds.push_back(fed);
0110       }
0111 
0112       std::sort(vfeds.begin(), vfeds.end());
0113       return vfeds;
0114     }
0115     std::vector<int> getFEDVMEList(HcalElectronicsMap const *emap) {
0116       std::vector<int> vfeds;
0117       std::vector<HcalElectronicsId> vids = emap->allElectronicsIdPrecision();
0118       for (std::vector<HcalElectronicsId>::const_iterator it = vids.begin(); it != vids.end(); ++it) {
0119         if (!it->isVMEid())
0120           continue;
0121         int fed = it->isVMEid() ? it->dccid() + FED_VME_MIN : crate2fed(it->crateId(), it->slot());
0122         uint32_t n = 0;
0123         for (std::vector<int>::const_iterator jt = vfeds.begin(); jt != vfeds.end(); ++jt)
0124           if (fed == *jt)
0125             break;
0126           else
0127             n++;
0128         if (n == vfeds.size())
0129           vfeds.push_back(fed);
0130       }
0131 
0132       std::sort(vfeds.begin(), vfeds.end());
0133       return vfeds;
0134     }
0135     std::vector<int> getFEDuTCAList(HcalElectronicsMap const *emap) {
0136       std::vector<int> vfeds;
0137       std::vector<HcalElectronicsId> vids = emap->allElectronicsIdPrecision();
0138       for (std::vector<HcalElectronicsId>::const_iterator it = vids.begin(); it != vids.end(); ++it) {
0139         if (it->isVMEid())
0140           continue;
0141         int fed = it->isVMEid() ? it->dccid() + FED_VME_MIN : crate2fed(it->crateId(), it->slot());
0142         uint32_t n = 0;
0143         for (std::vector<int>::const_iterator jt = vfeds.begin(); jt != vfeds.end(); ++jt)
0144           if (fed == *jt)
0145             break;
0146           else
0147             n++;
0148         if (n == vfeds.size())
0149           vfeds.push_back(fed);
0150       }
0151 
0152       std::sort(vfeds.begin(), vfeds.end());
0153       return vfeds;
0154     }
0155 
0156     bool isFEDHBHE(HcalElectronicsId const &eid) {
0157       if (eid.isVMEid()) {
0158         return false;
0159       } else {
0160         int fed = crate2fed(eid.crateId(), eid.slot());
0161         if ((fed >= 1100 && fed < 1118) || (fed >= 1140 && fed <= 1148))
0162           return true;
0163         else
0164           return false;
0165       }
0166 
0167       return false;
0168     }
0169 
0170     bool isFEDHF(HcalElectronicsId const &eid) {
0171       if (eid.isVMEid())
0172         return false;
0173       int fed = crate2fed(eid.crateId(), eid.slot());
0174       if (fed >= 1118 && fed <= 1123)
0175         return true;
0176       else
0177         return false;
0178 
0179       return false;
0180     }
0181 
0182     bool isFEDHO(HcalElectronicsId const &eid) {
0183       if (eid.isVMEid())
0184         return false;
0185       int fed = crate2fed(eid.crateId(), eid.slot());
0186       if (fed >= 1124 && fed <= 1135)
0187         return true;
0188       else
0189         return false;
0190 
0191       return false;
0192     }
0193 
0194     /*
0195  *  Orbit Gap Related
0196  */
0197     std::string ogtype2string(OrbitGapType type) {
0198       switch (type) {
0199         case tNull:
0200           return "Null";
0201         case tPhysics:
0202           return "Physics";
0203         case tPedestal:
0204           return "Pedestal";
0205         case tLED:
0206           return "LED";
0207         case tHFRaddam:
0208           return "HFRaddam";
0209         case tHBHEHPD:
0210           return "HBHEHPD";
0211         case tHO:
0212           return "HO";
0213         case tHF:
0214           return "HF";
0215         case tZDC:
0216           return "ZDC";
0217         case tHEPMega:
0218           return "HEPMegatile";
0219         case tHEMMega:
0220           return "HEMMegatile";
0221         case tHBPMega:
0222           return "HBPMegatile";
0223         case tHBMMega:
0224           return "HBMMegatile";
0225         case tCRF:
0226           return "CRF";
0227         case tCalib:
0228           return "Calib";
0229         case tSafe:
0230           return "Safe";
0231         case tSiPMPMT:
0232           return "SiPM-PMT";
0233         case tMegatile:
0234           return "Megatile";
0235         case tUnknown:
0236           return "Unknown";
0237         default:
0238           return "Null";
0239       }
0240     }
0241 
0242     int getRBX(uint32_t iphi) { return (((iphi + 2) % 72) + 4 - 1) / 4; }
0243 
0244   }  // namespace utilities
0245 }  // namespace hcaldqm