Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-27 06:44:03

0001 #include "DQM/EcalMonitorClient/interface/EcalDQMonitorClient.h"
0002 
0003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0004 
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
0009 
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0012 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0013 #include "FWCore/ParameterSet/interface/FileInPath.h"
0014 
0015 #include "FWCore/ServiceRegistry/interface/Service.h"
0016 
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 
0019 #include <ctime>
0020 #include <fstream>
0021 
0022 EcalDQMonitorClient::EcalDQMonitorClient(edm::ParameterSet const& _ps)
0023     : DQMEDHarvester(),
0024       ecaldqm::EcalDQMonitor(_ps),
0025       iEvt_(0),
0026       cStHndl(esConsumes<edm::Transition::BeginRun>()),
0027       tStHndl(esConsumes<edm::Transition::BeginRun>()),
0028       statusManager_() {
0029   edm::ConsumesCollector collector(consumesCollector());
0030   executeOnWorkers_(
0031       [this, &collector](ecaldqm::DQWorker* worker) {
0032         ecaldqm::DQWorkerClient* client(dynamic_cast<ecaldqm::DQWorkerClient*>(worker));
0033         if (!client)
0034           throw cms::Exception("InvalidConfiguration") << "Non-client DQWorker " << worker->getName() << " passed";
0035         client->setStatusManager(this->statusManager_);
0036         client->setTokens(collector);
0037         worker->setTokens(collector);
0038       },
0039       "initialization");
0040 
0041   // This is no longer used since run 2
0042   //
0043   //if (_ps.existsAs<edm::FileInPath>("PNMaskFile", false)) {
0044   //  std::ifstream maskFile(_ps.getUntrackedParameter<edm::FileInPath>("PNMaskFile").fullPath());
0045   //  if (maskFile.is_open())
0046   //    statusManager_.readFromStream(maskFile);
0047   //}
0048 }
0049 
0050 EcalDQMonitorClient::~EcalDQMonitorClient() {}
0051 
0052 /*static*/
0053 void EcalDQMonitorClient::fillDescriptions(edm::ConfigurationDescriptions& _descs) {
0054   edm::ParameterSetDescription desc;
0055   ecaldqm::EcalDQMonitor::fillDescriptions(desc);
0056 
0057   edm::ParameterSetDescription clientParameters;
0058   ecaldqm::DQWorkerClient::fillDescriptions(clientParameters);
0059   edm::ParameterSetDescription allWorkers;
0060   allWorkers.addNode(
0061       edm::ParameterWildcard<edm::ParameterSetDescription>("*", edm::RequireZeroOrMore, false, clientParameters));
0062   desc.addUntracked("workerParameters", allWorkers);
0063 
0064   desc.addOptionalUntracked<edm::FileInPath>("PNMaskFile");
0065 
0066   _descs.addDefault(desc);
0067 }
0068 
0069 void EcalDQMonitorClient::beginRun(edm::Run const& _run, edm::EventSetup const& _es) {
0070   executeOnWorkers_([&_es](ecaldqm::DQWorker* worker) { worker->setSetupObjects(_es); },
0071                     "ecaldqmGetSetupObjects",
0072                     "Getting EventSetup Objects");
0073 
0074   if (_es.find(edm::eventsetup::EventSetupRecordKey::makeKey<EcalDQMChannelStatusRcd>()) &&
0075       _es.find(edm::eventsetup::EventSetupRecordKey::makeKey<EcalDQMTowerStatusRcd>())) {
0076     const EcalDQMChannelStatus* ChStatus = &_es.getData(cStHndl);
0077     const EcalDQMTowerStatus* TStatus = &_es.getData(tStHndl);
0078 
0079     statusManager_.readFromObj(*ChStatus, *TStatus);
0080   }
0081 
0082   ecaldqmBeginRun(_run, _es);
0083 }
0084 
0085 void EcalDQMonitorClient::endRun(edm::Run const& _run, edm::EventSetup const& _es) { ecaldqmEndRun(_run, _es); }
0086 
0087 void EcalDQMonitorClient::dqmEndLuminosityBlock(DQMStore::IBooker& _ibooker,
0088                                                 DQMStore::IGetter& _igetter,
0089                                                 edm::LuminosityBlock const& _lumi,
0090                                                 edm::EventSetup const& _es) {
0091   executeOnWorkers_(
0092       [&_ibooker](ecaldqm::DQWorker* worker) {
0093         ecaldqm::DQWorkerClient* client(static_cast<ecaldqm::DQWorkerClient*>(worker));
0094         if (!client->onlineMode() && !client->runsOn(ecaldqm::DQWorkerClient::kLumi))
0095           return;
0096         client->bookMEs(_ibooker);
0097       },
0098       "bookMEs",
0099       "Booking MEs");
0100 
0101   ecaldqmEndLuminosityBlock(_lumi, _es);
0102 
0103   runWorkers(_igetter, ecaldqm::DQWorkerClient::kLumi);
0104 
0105   executeOnWorkers_(
0106       [](ecaldqm::DQWorker* worker) {
0107         ecaldqm::DQWorkerClient* client(static_cast<ecaldqm::DQWorkerClient*>(worker));
0108         client->resetPerLumi();
0109       },
0110       "dqmEndLuminosityBlock",
0111       "Reset per-lumi MEs");
0112 }
0113 
0114 void EcalDQMonitorClient::dqmEndJob(DQMStore::IBooker& _ibooker, DQMStore::IGetter& _igetter) {
0115   executeOnWorkers_(
0116       [&_ibooker](ecaldqm::DQWorker* worker) {
0117         if (!worker->checkElectronicsMap(false))  // to avoid crashes on empty runs
0118           return;
0119         worker->bookMEs(_ibooker);  // worker returns if already booked
0120       },
0121       "bookMEs",
0122       "Booking MEs");
0123 
0124   runWorkers(_igetter, ecaldqm::DQWorkerClient::kJob);
0125 
0126   executeOnWorkers_([](ecaldqm::DQWorker* worker) { worker->releaseMEs(); }, "releaseMEs", "releasing histograms");
0127 }
0128 
0129 void EcalDQMonitorClient::runWorkers(DQMStore::IGetter& _igetter, ecaldqm::DQWorkerClient::ProcessType _type) {
0130   if (verbosity_ > 0)
0131     edm::LogInfo("EcalDQM") << moduleName_ << ": Starting worker modules..";
0132 
0133   executeOnWorkers_(
0134       [&_igetter, &_type](ecaldqm::DQWorker* worker) {
0135         if (!worker->checkElectronicsMap(false))  // to avoid crashes on empty runs
0136           return;
0137         ecaldqm::DQWorkerClient* client(static_cast<ecaldqm::DQWorkerClient*>(worker));
0138         if (!client->onlineMode() && !client->runsOn(_type))
0139           return;
0140         client->releaseSource();
0141         client->resetMEs();
0142         if (!client->retrieveSource(_igetter, _type))
0143           return;
0144         if (client->onlineMode())
0145           client->setTime(time(nullptr));
0146         client->producePlots(_type);
0147       },
0148       "retrieveAndRun",
0149       "producing plots");
0150 
0151   if (verbosity_ > 0)
0152     edm::LogInfo("EcalDQM") << " done." << std::endl;
0153 }
0154 
0155 DEFINE_FWK_MODULE(EcalDQMonitorClient);