Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/EcalMonitorClient/interface/DQWorkerClient.h"
0002 
0003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0004 #include "DQM/EcalCommon/interface/StatusManager.h"
0005 #include "DQM/EcalCommon/interface/MESetChannel.h"
0006 #include "DQM/EcalCommon/interface/MESetMulti.h"
0007 #include "DQM/EcalCommon/interface/MESetUtils.h"
0008 
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0013 
0014 #include <sstream>
0015 
0016 namespace ecaldqm {
0017   DQWorkerClient::DQWorkerClient()
0018       : DQWorker(), sources_(), qualitySummaries_(), hasLumiPlots_(false), statusManager_(nullptr) {}
0019 
0020   /*static*/
0021   void DQWorkerClient::fillDescriptions(edm::ParameterSetDescription& _desc) {
0022     DQWorker::fillDescriptions(_desc);
0023     _desc.addWildcardUntracked<std::vector<std::string> >("*");
0024 
0025     edm::ParameterSetDescription sourceParameters;
0026     edm::ParameterSetDescription sourceNodeParameters;
0027     fillMESetDescriptions(sourceNodeParameters);
0028     sourceParameters.addNode(
0029         edm::ParameterWildcard<edm::ParameterSetDescription>("*", edm::RequireZeroOrMore, false, sourceNodeParameters));
0030     _desc.addUntracked("sources", sourceParameters);
0031   }
0032 
0033   void DQWorkerClient::setME(edm::ParameterSet const& _ps) {
0034     DQWorker::setME(_ps);
0035 
0036     // Flags the Client ME to run as lumibased:
0037     // In offline mode will save the ME client at the end of the LS
0038     // See: EcalDQMonitorClient::dqmEndLuminosityBlock
0039     for (auto& mItr : MEs_) {
0040       if (mItr.second->getLumiFlag()) {
0041         hasLumiPlots_ = true;
0042         break;
0043       }
0044     }
0045   }
0046 
0047   void DQWorkerClient::setSource(edm::ParameterSet const& _params) {
0048     std::vector<std::string> const& sourceNames(_params.getParameterNames());
0049 
0050     for (unsigned iS(0); iS < sourceNames.size(); iS++) {
0051       std::string name(sourceNames[iS]);
0052       edm::ParameterSet const& params(_params.getUntrackedParameterSet(name));
0053 
0054       if (onlineMode_ && params.getUntrackedParameter<bool>("online"))
0055         continue;
0056 
0057       sources_.insert(name, createMESet(params));
0058     }
0059 
0060     if (verbosity_ > 1) {
0061       std::stringstream ss;
0062       ss << name_ << ": Using ";
0063       for (MESetCollection::const_iterator sItr(sources_.begin()); sItr != sources_.end(); ++sItr)
0064         ss << sItr->first << " ";
0065       ss << "as sources";
0066       edm::LogInfo("EcalDQM") << ss.str();
0067     }
0068   }
0069 
0070   void DQWorkerClient::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) {
0071 // MESetChannel class removed until concurrency issue is finalized
0072 #if 0
0073     for(MESetCollection::iterator sItr(sources_.begin()); sItr != sources_.end(); ++sItr){
0074       if(!sItr->second->getLumiFlag()) continue;
0075       MESetChannel const* channel(dynamic_cast<MESetChannel const*>(sItr->second));
0076       if(channel) channel->checkDirectory();
0077     }
0078 #endif
0079   }
0080 
0081   void DQWorkerClient::bookMEs(DQMStore::IBooker& _ibooker) {
0082     DQWorker::bookMEs(_ibooker);
0083     resetMEs();
0084   }
0085 
0086   void DQWorkerClient::releaseMEs() {
0087     DQWorker::releaseMEs();
0088     releaseSource();
0089   }
0090 
0091   void DQWorkerClient::releaseSource() {
0092     for (MESetCollection::iterator sItr(sources_.begin()); sItr != sources_.end(); ++sItr)
0093       sItr->second->clear();
0094   }
0095 
0096   bool DQWorkerClient::retrieveSource(DQMStore::IGetter& _igetter, ProcessType _type) {
0097     std::string failedPath;
0098     for (MESetCollection::iterator sItr(sources_.begin()); sItr != sources_.end(); ++sItr) {
0099       if (!onlineMode_ && _type == kLumi && !sItr->second->getLumiFlag())
0100         continue;
0101       if (verbosity_ > 1)
0102         edm::LogInfo("EcalDQM") << name_ << ": Retrieving source " << sItr->first;
0103       if (!sItr->second->retrieve(GetElectronicsMap(), _igetter, &failedPath)) {
0104         if (verbosity_ > 1)
0105           edm::LogWarning("EcalDQM") << name_ << ": Could not find source " << sItr->first << "@" << failedPath;
0106         return false;
0107       }
0108     }
0109 
0110     return true;
0111   }
0112 
0113   void DQWorkerClient::resetMEs() {
0114     for (auto& mItr : MEs_) {
0115       MESet* meset(mItr.second.get());
0116 
0117       // Protects Trend-type Client MEs from being reset at the end of the LS
0118       // See: EcalDQMonitorClient::runWorkers
0119       if (meset->getBinType() == ecaldqm::binning::kTrend)
0120         continue;
0121 
0122       if (qualitySummaries_.find(mItr.first) != qualitySummaries_.end()) {
0123         MESetMulti* multi(dynamic_cast<MESetMulti*>(meset));
0124         if (multi) {
0125           for (unsigned iS(0); iS < multi->getMultiplicity(); ++iS) {
0126             multi->use(iS);
0127             if (multi->getKind() == MonitorElement::Kind::TH2F) {
0128               multi->resetAll(-1.);
0129               multi->reset(GetElectronicsMap(), kUnknown);
0130             } else
0131               multi->reset(GetElectronicsMap(), -1.);
0132           }
0133         } else {
0134           if (meset->getKind() == MonitorElement::Kind::TH2F) {
0135             meset->resetAll(-1.);
0136             meset->reset(GetElectronicsMap(), kUnknown);
0137           } else
0138             meset->reset(GetElectronicsMap(), -1.);
0139         }
0140       } else
0141         meset->reset(GetElectronicsMap());
0142     }
0143   }
0144 
0145   void DQWorkerClient::resetPerLumi() {
0146     for (auto const& meset : MEs_) {
0147       int i = 0;
0148       while (auto me = meset.second->getME(i)) {
0149         if (me->getLumiFlag()) {
0150           // reset per-lumi histograms in offline harvesting so that they only show
0151           // data of the current lumisection.
0152           me->Reset();
0153         }
0154         i++;
0155       }
0156     }
0157   }
0158 
0159   void DQWorkerClient::towerAverage_(MESet& _target, MESet const& _source, float _threshold) {
0160     bool isQuality(_threshold > 0.);
0161 
0162     MESet::iterator tEnd(_target.end(GetElectronicsMap()));
0163     for (MESet::iterator tItr(_target.beginChannel(GetElectronicsMap())); tItr != tEnd;
0164          tItr.toNextChannel(GetElectronicsMap())) {
0165       DetId towerId(tItr->getId());
0166 
0167       std::vector<DetId> cryIds;
0168       if (towerId.subdetId() == EcalTriggerTower)
0169         cryIds = GetTrigTowerMap()->constituentsOf(EcalTrigTowerDetId(towerId));
0170       else {
0171         cryIds = scConstituents(EcalScDetId(towerId));
0172       }
0173 
0174       if (cryIds.empty())
0175         return;
0176 
0177       float mean(0.);
0178       float nValid(0.);
0179       bool masked(false);
0180       for (unsigned iId(0); iId < cryIds.size(); ++iId) {
0181         float content(_source.getBinContent(getEcalDQMSetupObjects(), cryIds[iId]));
0182         if (isQuality) {
0183           if (content < 0. || content == 2.)
0184             continue;
0185           if (content == 5.)
0186             masked = true;
0187           else {
0188             nValid += 1;
0189             if (content > 2.) {
0190               masked = true;
0191               mean += content - 3.;
0192             } else
0193               mean += content;
0194           }
0195         } else {
0196           mean += content;
0197           nValid += 1.;
0198         }
0199       }
0200 
0201       if (isQuality) {
0202         if (nValid < 1.)
0203           tItr->setBinContent(masked ? 5. : 2.);
0204         else {
0205           mean /= nValid;
0206           if (mean < _threshold)
0207             tItr->setBinContent(masked ? 3. : 0.);
0208           else
0209             tItr->setBinContent(masked ? 4. : 1.);
0210         }
0211       } else
0212         tItr->setBinContent(nValid < 1. ? 0. : mean / nValid);
0213     }
0214   }
0215 
0216 }  // namespace ecaldqm