Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-25 06:38:15

0001 #include "DQM/HcalCommon/interface/DQHarvester.h"
0002 #include "FWCore/Framework/interface/Run.h"
0003 
0004 namespace hcaldqm {
0005   using namespace constants;
0006 
0007   DQHarvester::DQHarvester(edm::ParameterSet const &ps)
0008       : DQModule(ps),
0009         hcalDbServiceToken_(esConsumes<HcalDbService, HcalDbRecord, edm::Transition::BeginRun>()),
0010         runInfoToken_(esConsumes<RunInfo, RunInfoRcd, edm::Transition::BeginRun>()),
0011         hcalChannelQualityToken_(
0012             esConsumes<HcalChannelQuality, HcalChannelQualityRcd, edm::Transition::BeginLuminosityBlock>(
0013                 edm::ESInputTag("", "withTopo"))) {}
0014 
0015   void DQHarvester::beginRun(edm::Run const &r, edm::EventSetup const &es) {
0016     if (_ptype == fLocal)
0017       if (r.runAuxiliary().run() == 1)
0018         return;
0019 
0020     //      TEMPORARY FIX
0021     if (_ptype != fOffline) {  // hidefed2crate
0022       _vhashFEDs.clear();
0023       _vcdaqEids.clear();
0024     }
0025 
0026     //  - get the Hcal Electronics Map
0027     //  - collect all the FED numbers and FED's rawIds
0028     edm::ESHandle<HcalDbService> dbs = es.getHandle(hcalDbServiceToken_);
0029     _emap = dbs->getHcalMapping();
0030 
0031     if (_ptype != fOffline) {  // hidefed2crate
0032       _vFEDs = utilities::getFEDList(_emap);
0033       for (std::vector<int>::const_iterator it = _vFEDs.begin(); it != _vFEDs.end(); ++it) {
0034         //
0035         //  FIXME
0036         //  until there exists a map of FED2Crate and Crate2FED,
0037         //  all the unknown Crates will be mapped to 0...
0038         //
0039         if (*it == 0) {
0040           _vhashFEDs.push_back(HcalElectronicsId(0, SLOT_uTCA_MIN, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0041           continue;
0042         }
0043 
0044         if (*it > FED_VME_MAX) {
0045           std::pair<uint16_t, uint16_t> cspair = utilities::fed2crate(*it);
0046           _vhashFEDs.push_back(
0047               HcalElectronicsId(cspair.first, cspair.second, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0048         } else
0049           _vhashFEDs.push_back(HcalElectronicsId(FIBERCH_MIN, FIBER_VME_MIN, SPIGOT_MIN, (*it) - FED_VME_MIN).rawId());
0050       }
0051 
0052       //    get the FEDs registered at cDAQ
0053       if (auto runInfoRec = es.tryToGet<RunInfoRcd>()) {
0054         const RunInfo &runInfo = es.getData(runInfoToken_);
0055         std::vector<int> vfeds = runInfo.m_fed_in;
0056         for (std::vector<int>::const_iterator it = vfeds.begin(); it != vfeds.end(); ++it) {
0057           if (*it >= constants::FED_VME_MIN && *it <= FED_VME_MAX)
0058             _vcdaqEids.push_back(
0059                 HcalElectronicsId(constants::FIBERCH_MIN, constants::FIBER_VME_MIN, SPIGOT_MIN, (*it) - FED_VME_MIN)
0060                     .rawId());
0061           else if (*it >= constants::FED_uTCA_MIN && *it <= FEDNumbering::MAXHCALuTCAFEDID) {
0062             std::pair<uint16_t, uint16_t> cspair = utilities::fed2crate(*it);
0063             _vcdaqEids.push_back(
0064                 HcalElectronicsId(cspair.first, cspair.second, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0065           }
0066         }
0067       }
0068     } else {
0069       _vCrates = utilities::getCrateList(_emap);
0070       std::map<int, uint32_t> crateHashMap = utilities::getCrateHashMap(_emap);
0071       for (auto &it_crate : _vCrates) {
0072         _vhashCrates.push_back(crateHashMap[it_crate]);
0073       }
0074     }
0075 
0076     // Initialize channel quality masks, but do not load (changed for 10_4_X,
0077     // moving to LS granularity)
0078     _xQuality.initialize(hashfunctions::fDChannel);
0079   }
0080 
0081   void DQHarvester::dqmBeginLuminosityBlock(DQMStore::IBooker &ib,
0082                                             DQMStore::IGetter &ig,
0083                                             edm::LuminosityBlock const &lb,
0084                                             edm::EventSetup const &es) {
0085     //  get the Hcal Channels Quality for channels that are not 0
0086     const HcalChannelQuality *cq = &es.getData(hcalChannelQualityToken_);
0087     std::vector<DetId> detids = cq->getAllChannels();
0088     for (std::vector<DetId>::const_iterator it = detids.begin(); it != detids.end(); ++it) {
0089       if (HcalGenericDetId(*it).genericSubdet() == HcalGenericDetId::HcalGenUnknown)
0090         continue;
0091 
0092       if (HcalGenericDetId(*it).isHcalDetId()) {
0093         HcalDetId did(*it);
0094         uint32_t mask = (cq->getValues(did))->getValue();
0095         if (mask != 0)
0096           _xQuality.push(did, mask);
0097       }
0098     }
0099   }
0100 
0101   void DQHarvester::dqmEndLuminosityBlock(DQMStore::IBooker &ib,
0102                                           DQMStore::IGetter &ig,
0103                                           edm::LuminosityBlock const &lb,
0104                                           edm::EventSetup const &es) {
0105     //  should be the same - just in case!
0106     _currentLS = lb.luminosityBlock();
0107     _totalLS++;
0108     _dqmEndLuminosityBlock(ib, ig, lb, es);
0109   }
0110   void DQHarvester::dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) { _dqmEndJob(ib, ig); }
0111 }  // namespace hcaldqm