Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/HcalCommon/interface/DQTask.h"
0002 
0003 #include "FWCore/Utilities/interface/ESInputTag.h"
0004 #include "FWCore/Utilities/interface/Transition.h"
0005 
0006 namespace hcaldqm {
0007   using namespace constants;
0008   DQTask::DQTask(edm::ParameterSet const &ps)
0009       : DQModule(ps),
0010         _cEvsTotal(_name, "EventsTotal"),
0011         _cEvsPerLS(_name, "EventsPerLS"),
0012         _cRunKeyVal(_name, "RunKeyValue"),
0013         _cRunKeyName(_name, "RunKeyName"),
0014         _cProcessingTypeName(_name, "ProcessingType"),
0015         _procLSs(0),
0016         hcalDbServiceToken_(esConsumes<HcalDbService, HcalDbRecord, edm::Transition::BeginRun>()),
0017         runInfoToken_(esConsumes<RunInfo, RunInfoRcd, edm::Transition::BeginRun>()),
0018         hcalChannelQualityToken_(
0019             esConsumes<HcalChannelQuality, HcalChannelQualityRcd, edm::Transition::BeginLuminosityBlock>(
0020                 edm::ESInputTag("", "withTopo"))) {
0021     //  tags and Tokens
0022     _tagRaw = ps.getUntrackedParameter<edm::InputTag>("tagRaw", edm::InputTag("rawDataCollector"));
0023     _tokRaw = consumes<FEDRawDataCollection>(_tagRaw);
0024   }
0025 
0026   void DQTask::fillPSetDescription(edm::ParameterSetDescription &desc) {
0027     //from class inheritance
0028     hcaldqm::DQModule::fillPSetDescription(desc);
0029 
0030     desc.addUntracked<edm::InputTag>("tagRaw", edm::InputTag("rawDataCollector"));
0031   }
0032 
0033   /*
0034  *  By design, all the sources will ahve this function inherited and will
0035  *  never override.
0036  */
0037   void DQTask::analyze(edm::Event const &e, edm::EventSetup const &es) {
0038     this->_resetMonitors(fEvent);
0039     _logger.debug(_name + " processing");
0040     if (!this->_isApplicable(e))
0041       return;
0042 
0043     _evsTotal++;
0044     _cEvsTotal.fill(_evsTotal);
0045 
0046     auto lumiCache = luminosityBlockCache(e.getLuminosityBlock().index());
0047     lumiCache->EvtCntLS++;
0048     _evsPerLS = lumiCache->EvtCntLS;
0049     _cEvsPerLS.fill(_evsPerLS);
0050 
0051     this->_process(e, es);
0052   }
0053 
0054   void DQTask::bookHistograms(DQMStore::IBooker &ib, edm::Run const &r, edm::EventSetup const &es) {
0055     //  initialize some containers to be used by all modules
0056     _xQuality.initialize(hashfunctions::fDChannel);
0057 
0058     //  get the run info FEDs - FEDs registered at cDAQ
0059     //  and determine if there are any HCAL FEDs in.
0060     //  push them as ElectronicsIds into the vector
0061     if (auto runInfoRec = es.tryToGet<RunInfoRcd>()) {
0062       const RunInfo &runInfo = es.getData(runInfoToken_);
0063       std::vector<int> vfeds = runInfo.m_fed_in;
0064       for (std::vector<int>::const_iterator it = vfeds.begin(); it != vfeds.end(); ++it) {
0065         if (*it >= constants::FED_VME_MIN && *it <= FED_VME_MAX)
0066           _vcdaqEids.push_back(
0067               HcalElectronicsId(constants::FIBERCH_MIN, constants::FIBER_VME_MIN, SPIGOT_MIN, (*it) - FED_VME_MIN)
0068                   .rawId());
0069         else if (*it >= constants::FED_uTCA_MIN && *it <= FEDNumbering::MAXHCALuTCAFEDID) {
0070           std::pair<uint16_t, uint16_t> cspair = utilities::fed2crate(*it);
0071           _vcdaqEids.push_back(
0072               HcalElectronicsId(cspair.first, cspair.second, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0073         }
0074       }
0075     }
0076 
0077     //  book some base guys
0078     _cEvsTotal.book(ib, _subsystem);
0079     _cEvsPerLS.book(ib, _subsystem);
0080     _cRunKeyVal.book(ib, _subsystem);
0081     _cRunKeyName.book(ib, _subsystem);
0082     _cProcessingTypeName.book(ib, _subsystem);
0083 
0084     //  fill what you can now
0085     _cRunKeyVal.fill(_runkeyVal);
0086     _cRunKeyName.fill(_runkeyName);
0087     _cProcessingTypeName.fill(pTypeNames[_ptype]);
0088 
0089     // Load conditions and emap
0090     _dbService = es.getHandle(hcalDbServiceToken_);
0091     _emap = _dbService->getHcalMapping();
0092   }
0093 
0094   void DQTask::dqmBeginRun(edm::Run const &, edm::EventSetup const &) {
0095     this->_resetMonitors(fEvent);
0096     this->_resetMonitors(f1LS);
0097     this->_resetMonitors(f10LS);
0098     this->_resetMonitors(f50LS);
0099     this->_resetMonitors(f100LS);
0100   }
0101 
0102   std::shared_ptr<hcaldqm::Cache> DQTask::globalBeginLuminosityBlock(edm::LuminosityBlock const &lb,
0103                                                                      edm::EventSetup const &es) const {
0104     auto d = std::make_shared<hcaldqm::Cache>();
0105     d->currentLS = lb.luminosityBlock();
0106     d->EvtCntLS = 0;
0107 
0108     /*   //// these resets were not useful anymore
0109     this->_resetMonitors(f1LS);
0110     if (_procLSs % 10 == 0)
0111       this->_resetMonitors(f10LS);
0112     if (_procLSs % 50 == 0)
0113       this->_resetMonitors(f50LS);
0114     if (_procLSs % 100 == 0)
0115       this->_resetMonitors(f100LS);
0116 */
0117 
0118     //  get the Channel Quality Status for all the channels
0119     d->xQuality.initialize(hashfunctions::fDChannel);
0120     d->xQuality.reset();
0121     const HcalChannelQuality &cq = es.getData(hcalChannelQualityToken_);
0122     std::vector<DetId> detids = cq.getAllChannels();
0123     for (std::vector<DetId>::const_iterator it = detids.begin(); it != detids.end(); ++it) {
0124       //    if unknown skip
0125       if (HcalGenericDetId(*it).genericSubdet() == HcalGenericDetId::HcalGenUnknown)
0126         continue;
0127 
0128       if (HcalGenericDetId(*it).isHcalDetId()) {
0129         HcalDetId did(*it);
0130         uint32_t mask = (cq.getValues(did))->getValue();
0131         if (mask != 0) {
0132           d->xQuality.push(did, mask);
0133         }
0134       }
0135     }
0136     return d;
0137   }
0138 
0139   void DQTask::globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) { _procLSs++; }
0140 
0141   void DQTask::_resetMonitors(UpdateFreq uf) {
0142     //  reset per event
0143     switch (uf) {
0144       case fEvent:
0145         break;
0146       case f1LS:
0147         _evsPerLS = 0;
0148         break;
0149       case f10LS:
0150         break;
0151       case f50LS:
0152         break;
0153       case f100LS:
0154         break;
0155       default:
0156         break;
0157     }
0158   }
0159 
0160   int DQTask::_getCalibType(edm::Event const &e) {
0161     int calibType = 0;
0162 
0163     edm::Handle<FEDRawDataCollection> craw;
0164     if (!e.getByToken(_tokRaw, craw))
0165       _logger.dqmthrow("Collection FEDRawDataCollection isn't available " + _tagRaw.label() + " " + _tagRaw.instance());
0166 
0167     int badFEDs = 0;
0168     std::vector<int> types(8, 0);
0169     for (int i = FED_VME_MIN; i <= FED_VME_MAX; i++) {
0170       FEDRawData const &fd = craw->FEDData(i);
0171       if (fd.size() < 24) {
0172         badFEDs++;
0173         continue;
0174       }
0175       int cval = (int)((HcalDCCHeader const *)(fd.data()))->getCalibType();
0176       if (cval > 7)
0177         _logger.warn("Unexpected Calib Type in FED " + std::to_string(i));
0178       types[cval]++;
0179     }
0180     for (int i = FED_uTCA_MIN; i <= FED_uTCA_MAX; i++) {
0181       FEDRawData const &fd = craw->FEDData(i);
0182       if (fd.size() < 24) {
0183         badFEDs++;
0184         continue;
0185       }
0186       int cval = (int)((HcalDCCHeader const *)(fd.data()))->getCalibType();
0187       if (cval > 7)
0188         _logger.warn("Unexpected Calib Type in FED " + std::to_string(i));
0189       types[cval]++;
0190     }
0191 
0192     int max = 0;
0193     for (unsigned int ic = 0; ic < 8; ic++) {
0194       if (types[ic] > max) {
0195         max = types[ic];
0196         calibType = ic;
0197       }
0198     }
0199     if (max != (FED_VME_NUM + (FED_uTCA_MAX - FED_uTCA_MIN + 1) - badFEDs))
0200       _logger.warn("Conflicting Calibration Types found. Assigning " + std::to_string(calibType));
0201 
0202     return calibType;
0203   }
0204 }  // namespace hcaldqm