Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:10:10

0001 #include "DQM/HcalCommon/interface/ElectronicsMap.h"
0002 #include <iomanip>
0003 
0004 namespace hcaldqm {
0005   namespace electronicsmap {
0006     void ElectronicsMap::initialize(HcalElectronicsMap const *emap, ElectronicsMapType etype /*=fHcalElectronicsMap*/) {
0007       _etype = etype;
0008       _emap = emap;
0009       //    if we actually use a HashMap then
0010       if (_etype != fHcalElectronicsMap) {
0011         if (_etype == fD2EHashMap) {
0012           std::vector<HcalElectronicsId> eids = emap->allElectronicsIdPrecision();
0013           for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
0014             HcalGenericDetId did = HcalGenericDetId(_emap->lookup(*it));
0015             EMapType::iterator dit = _ids.find(did.rawId());
0016             if (dit != _ids.end())
0017               continue;
0018             //                      if (!did.isHcalDetId())
0019             //                          continue;
0020 
0021             _ids.insert(std::make_pair(did.rawId(), it->rawId()));
0022           }
0023         } else if (_etype == fT2EHashMap) {
0024           //    HcalTrigTowerDetId -> HcalElectronicsId
0025           std::vector<HcalTrigTowerDetId> tids = emap->allTriggerId();
0026           for (std::vector<HcalTrigTowerDetId>::const_iterator it = tids.begin(); it != tids.end(); ++it) {
0027             HcalElectronicsId eid = _emap->lookupTrigger(*it);
0028             uint32_t hash = it->rawId();
0029             EMapType::iterator eit = _ids.find(hash);
0030             if (eit != _ids.end())
0031               continue;
0032 
0033             _ids.insert(std::make_pair(hash, eid.rawId()));
0034           }
0035         } else if (_etype == fE2DHashMap) {
0036           //    HcalElectronicId -> HcalDetId hash map
0037           std::vector<HcalElectronicsId> eids = emap->allElectronicsIdPrecision();
0038           for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
0039             HcalGenericDetId did = HcalGenericDetId(_emap->lookup(*it));
0040             uint32_t hash = it->rawId();
0041             EMapType::iterator eit = _ids.find(hash);
0042             if (eit != _ids.end())
0043               continue;
0044 
0045             //  note, we have EChannel hashing here
0046             _ids.insert(std::make_pair(hash, did.rawId()));
0047           }
0048         } else if (_etype == fE2THashMap) {
0049           //    HcalElectronicId -> HcalDetId hash map
0050           std::vector<HcalElectronicsId> eids = emap->allElectronicsIdTrigger();
0051           for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
0052             HcalTrigTowerDetId tid = HcalTrigTowerDetId(_emap->lookupTrigger(*it));
0053             EMapType::iterator eit = _ids.find(it->rawId());
0054             if (eit != _ids.end())
0055               continue;
0056 
0057             //  eid.rawId() -> tid.rawId()
0058             _ids.insert(std::make_pair(it->rawId(), tid.rawId()));
0059           }
0060         }
0061       }
0062     }
0063 
0064     void ElectronicsMap::initialize(HcalElectronicsMap const *emap,
0065                                     ElectronicsMapType etype,
0066                                     filter::HashFilter const &filter) {
0067       _etype = etype;
0068       _emap = emap;
0069 
0070       //    note this initialization has iteration over electronics not
0071       //    detector.
0072       //    Filtering is done on Electronics id - possible to have
0073       //    several electronics ids to 1 detid - not vice versa
0074       if (_etype != fHcalElectronicsMap) {
0075         if (_etype == fD2EHashMap) {
0076           std::vector<HcalElectronicsId> eids = emap->allElectronicsIdPrecision();
0077           for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
0078             HcalGenericDetId did = HcalGenericDetId(_emap->lookup(*it));
0079             if (filter.filter(*it))
0080               continue;
0081             //  skip those that are not detid or calib ids
0082             //                      if (!did.isHcalDetId())
0083             //                          continue;
0084 
0085             _ids.insert(std::make_pair(did.rawId(), it->rawId()));
0086           }
0087         } else if (_etype == fT2EHashMap) {
0088           std::vector<HcalElectronicsId> eids = emap->allElectronicsIdTrigger();
0089           for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
0090             if (filter.filter(*it))
0091               continue;
0092             HcalTrigTowerDetId tid = emap->lookupTrigger(*it);
0093             _ids.insert(std::make_pair(tid.rawId(), it->rawId()));
0094           }
0095         } else if (_etype == fE2DHashMap) {
0096           std::vector<HcalElectronicsId> eids = emap->allElectronicsIdPrecision();
0097           for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
0098             HcalGenericDetId did = HcalGenericDetId(_emap->lookup(*it));
0099             uint32_t hash = hashfunctions::hash_EChannel(*it);
0100             if (filter.filter(*it))
0101               continue;
0102             //  skip those that are not detid or calib ids
0103             //                      if (!did.isHcalDetId())
0104             //                          continue;
0105 
0106             //  note: use EChannel hashing here!
0107             _ids.insert(std::make_pair(hash, did.rawId()));
0108           }
0109         } else if (_etype == fE2THashMap) {
0110           std::vector<HcalElectronicsId> eids = emap->allElectronicsIdTrigger();
0111           for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
0112             if (filter.filter(*it))
0113               continue;
0114             HcalTrigTowerDetId tid = emap->lookupTrigger(*it);
0115             _ids.insert(std::make_pair(it->rawId(), tid.rawId()));
0116           }
0117         }
0118       }
0119     }
0120 
0121     //  3 funcs below are only for 1->1 mappings
0122     uint32_t ElectronicsMap::lookup(DetId const &id) {
0123       uint32_t hash = id.rawId();
0124       if (_etype == fHcalElectronicsMap)
0125         return _emap->lookup(id).rawId();
0126       else {
0127         EMapType::iterator it = _ids.find(hash);
0128         return it == _ids.end() ? 0 : it->second;
0129       }
0130       return 0;
0131     }
0132 
0133     uint32_t ElectronicsMap::lookup(HcalDetId const &id) {
0134       // Turn the HcalDetId into a HcalGenericDetId to avoid newForm
0135       uint32_t hash = (id.oldFormat() ? id.otherForm() : id.rawId());
0136       HcalGenericDetId gdid(hash);
0137       if (_etype == fHcalElectronicsMap)
0138         return _emap->lookup(gdid).rawId();
0139       else {
0140         EMapType::iterator it = _ids.find(hash);
0141         return it == _ids.end() ? 0 : it->second;
0142       }
0143       return 0;
0144     }
0145 
0146     uint32_t ElectronicsMap::lookup(HcalElectronicsId const &id) {
0147       uint32_t hash = id.rawId();
0148       if (_etype == fHcalElectronicsMap)
0149         return _emap->lookup(id).rawId();
0150       else {
0151         EMapType::iterator it = _ids.find(hash);
0152         return it == _ids.end() ? 0 : it->second;
0153       }
0154       return 0;
0155     }
0156 
0157     void ElectronicsMap::print() {
0158       std::cout << "Electronics HashMap Type=" << _etype << std::endl;
0159       for (auto const &v : _ids) {
0160         std::cout << std::hex << v.first << "  " << v.second << std::dec << std::endl;
0161       }
0162     }
0163   }  // namespace electronicsmap
0164 }  // namespace hcaldqm