From cf348feb9ac01263a2165c0b54c9805ec7f8e6d7 Mon Sep 17 00:00:00 2001 From: Marino Missiroli Date: Sat, 6 May 2023 14:30:30 +0200 Subject: [PATCH] do not throw exception in Trigger{Bx,Rates}Monitor if L1-uGT results are unavailable --- DQM/HLTEvF/plugins/TriggerBxMonitor.cc | 45 ++++++++++++++--------- DQM/HLTEvF/plugins/TriggerRatesMonitor.cc | 38 ++++++++++++------- DQM/HLTEvF/test/testTriggerMonitors.sh | 6 +-- 3 files changed, 54 insertions(+), 35 deletions(-) diff --git a/DQM/HLTEvF/plugins/TriggerBxMonitor.cc b/DQM/HLTEvF/plugins/TriggerBxMonitor.cc index 82096793b59d0..f1b456cbc836c 100644 --- a/DQM/HLTEvF/plugins/TriggerBxMonitor.cc +++ b/DQM/HLTEvF/plugins/TriggerBxMonitor.cc @@ -100,9 +100,10 @@ class TriggerBxMonitor : public DQMGlobalEDAnalyzer { }; // module configuration - const edm::ESGetToken m_l1tMenuToken; - const edm::EDGetTokenT m_l1t_results; - const edm::EDGetTokenT m_hlt_results; + const edm::ESGetToken m_l1tMenu_token; + const edm::InputTag m_l1t_results_inputTag; + const edm::EDGetTokenT m_l1t_results_token; + const edm::EDGetTokenT m_hlt_results_token; const std::string m_dqm_path; const bool m_make_1d_plots; const bool m_make_2d_plots; @@ -125,13 +126,14 @@ void TriggerBxMonitor::fillDescriptions(edm::ConfigurationDescriptions& descript TriggerBxMonitor::TriggerBxMonitor(edm::ParameterSet const& config) : // module configuration - m_l1tMenuToken{esConsumes()}, - m_l1t_results(consumes(config.getUntrackedParameter("l1tResults"))), - m_hlt_results(consumes(config.getUntrackedParameter("hltResults"))), - m_dqm_path(config.getUntrackedParameter("dqmPath")), - m_make_1d_plots(config.getUntrackedParameter("make1DPlots")), - m_make_2d_plots(config.getUntrackedParameter("make2DPlots")), - m_ls_range(config.getUntrackedParameter("lsRange")) {} + m_l1tMenu_token{esConsumes()}, + m_l1t_results_inputTag{config.getUntrackedParameter("l1tResults")}, + m_l1t_results_token{consumes(m_l1t_results_inputTag)}, + m_hlt_results_token{consumes(config.getUntrackedParameter("hltResults"))}, + m_dqm_path{config.getUntrackedParameter("dqmPath")}, + m_make_1d_plots{config.getUntrackedParameter("make1DPlots")}, + m_make_2d_plots{config.getUntrackedParameter("make2DPlots")}, + m_ls_range{config.getUntrackedParameter("lsRange")} {} void TriggerBxMonitor::dqmBeginRun(edm::Run const& run, edm::EventSetup const& setup, @@ -159,7 +161,7 @@ void TriggerBxMonitor::dqmBeginRun(edm::Run const& run, // initialise the HLTConfigProvider bool changed = true; edm::EDConsumerBase::Labels labels; - labelsForToken(m_hlt_results, labels); + labelsForToken(m_hlt_results_token, labels); if (histograms.hltConfig.init(run, setup, labels.process, changed)) { if (m_make_1d_plots) { histograms.hlt_bx.clear(); @@ -228,7 +230,7 @@ void TriggerBxMonitor::bookHistograms(DQMStore::IBooker& booker, // book the individual histograms for the L1 triggers that are included in the L1 menu booker.setCurrentFolder(m_dqm_path + "/L1T"); - auto const& l1tMenu = setup.getData(m_l1tMenuToken); + auto const& l1tMenu = setup.getData(m_l1tMenu_token); for (auto const& keyval : l1tMenu.getAlgorithmMap()) { unsigned int bit = keyval.second.getIndex(); std::string const& name = fmt::sprintf("%s (bit %d)", keyval.first, bit); @@ -295,10 +297,18 @@ void TriggerBxMonitor::dqmAnalyze(edm::Event const& event, // monitor the bx distribution for the L1 triggers { - auto const& bxvector = event.get(m_l1t_results); - if (not bxvector.isEmpty(0)) { - auto const& results = bxvector.at(0, 0); - for (unsigned int i = 0; i < GlobalAlgBlk::maxPhysicsTriggers; ++i) + auto const& algBlkBxVecHandle = event.getHandle(m_l1t_results_token); + if (not algBlkBxVecHandle.isValid()) { + edm::LogError("TriggerBxMonitor") + << "L1 trigger results with label [" << m_l1t_results_inputTag.encode() + << "] not present or invalid. MonitorElements of L1T results not filled for this event."; + } else if (algBlkBxVecHandle->isEmpty(0)) { + edm::LogError("TriggerBxMonitor") + << "L1 trigger results with label [" << m_l1t_results_inputTag.encode() + << "] empty for BX=0. MonitorElements of L1T results not filled for this event."; + } else { + auto const& results = algBlkBxVecHandle->at(0, 0); + for (unsigned int i = 0; i < GlobalAlgBlk::maxPhysicsTriggers; ++i) { if (results.getAlgoDecisionFinal(i)) { if (m_make_1d_plots and histograms.l1t_bx.at(i)) histograms.l1t_bx[i]->Fill(bx); @@ -306,12 +316,13 @@ void TriggerBxMonitor::dqmAnalyze(edm::Event const& event, histograms.l1t_bx_2d[i]->Fill(bx, ls); histograms.l1t_bx_all->Fill(bx, i); } + } } } // monitor the bx distribution for the HLT triggers if (histograms.hltConfig.inited()) { - auto const& hltResults = event.get(m_hlt_results); + auto const& hltResults = event.get(m_hlt_results_token); for (unsigned int i = 0; i < hltResults.size(); ++i) { if (hltResults.at(i).accept()) { if (m_make_1d_plots and histograms.hlt_bx.at(i)) diff --git a/DQM/HLTEvF/plugins/TriggerRatesMonitor.cc b/DQM/HLTEvF/plugins/TriggerRatesMonitor.cc index e0ab981bfd6a9..ccb77f916582b 100644 --- a/DQM/HLTEvF/plugins/TriggerRatesMonitor.cc +++ b/DQM/HLTEvF/plugins/TriggerRatesMonitor.cc @@ -131,9 +131,10 @@ class TriggerRatesMonitor : public DQMGlobalEDAnalyzer { }; // module configuration - const edm::ESGetToken m_l1tMenuToken; - const edm::EDGetTokenT m_l1t_results; - const edm::EDGetTokenT m_hlt_results; + const edm::ESGetToken m_l1tMenu_token; + const edm::InputTag m_l1t_results_inputTag; + const edm::EDGetTokenT m_l1t_results_token; + const edm::EDGetTokenT m_hlt_results_token; const std::string m_dqm_path; const uint32_t m_lumisections_range; }; @@ -152,11 +153,12 @@ void TriggerRatesMonitor::fillDescriptions(edm::ConfigurationDescriptions &descr TriggerRatesMonitor::TriggerRatesMonitor(edm::ParameterSet const &config) : // module configuration - m_l1tMenuToken{esConsumes()}, - m_l1t_results(consumes(config.getUntrackedParameter("l1tResults"))), - m_hlt_results(consumes(config.getUntrackedParameter("hltResults"))), - m_dqm_path(config.getUntrackedParameter("dqmPath")), - m_lumisections_range(config.getUntrackedParameter("lumisectionRange")) {} + m_l1tMenu_token{esConsumes()}, + m_l1t_results_inputTag{config.getUntrackedParameter("l1tResults")}, + m_l1t_results_token{consumes(m_l1t_results_inputTag)}, + m_hlt_results_token{consumes(config.getUntrackedParameter("hltResults"))}, + m_dqm_path{config.getUntrackedParameter("dqmPath")}, + m_lumisections_range{config.getUntrackedParameter("lumisectionRange")} {} void TriggerRatesMonitor::dqmBeginRun(edm::Run const &run, edm::EventSetup const &setup, @@ -171,7 +173,7 @@ void TriggerRatesMonitor::dqmBeginRun(edm::Run const &run, // initialise the HLTConfigProvider bool changed = true; edm::EDConsumerBase::Labels labels; - labelsForToken(m_hlt_results, labels); + labelsForToken(m_hlt_results_token, labels); if (histograms.hltConfig.init(run, setup, labels.process, changed)) { // number of trigger paths in labels.process auto const nTriggers = histograms.hltConfig.size(); @@ -257,7 +259,7 @@ void TriggerRatesMonitor::bookHistograms(DQMStore::IBooker &booker, // book the rate histograms for the L1T triggers that are included in the L1T menu booker.setCurrentFolder(m_dqm_path + "/L1T"); - auto const &l1tMenu = setup.getData(m_l1tMenuToken); + auto const &l1tMenu = setup.getData(m_l1tMenu_token); for (auto const &keyval : l1tMenu.getAlgorithmMap()) { unsigned int const bit = keyval.second.getIndex(); if (bit >= histograms.l1t_counts.size()) { @@ -357,9 +359,17 @@ void TriggerRatesMonitor::dqmAnalyze(edm::Event const &event, histograms.tcds_counts[event.experimentType()]->Fill(lumisection); // monitor the rates of L1T triggers - auto const &bxvector = event.get(m_l1t_results); - if (not bxvector.isEmpty(0)) { - auto const &results = bxvector.at(0, 0); + auto const &algBlkBxVecHandle = event.getHandle(m_l1t_results_token); + if (not algBlkBxVecHandle.isValid()) { + edm::LogError("TriggerRatesMonitor") + << "L1 trigger results with label [" << m_l1t_results_inputTag.encode() + << "] not present or invalid. MonitorElements of L1T results not filled for this event."; + } else if (algBlkBxVecHandle->isEmpty(0)) { + edm::LogError("TriggerRatesMonitor") + << "L1 trigger results with label [" << m_l1t_results_inputTag.encode() + << "] empty for BX=0. MonitorElements of L1T results not filled for this event."; + } else { + auto const &results = algBlkBxVecHandle->at(0, 0); for (unsigned int i = 0; i < GlobalAlgBlk::maxPhysicsTriggers; ++i) if (results.getAlgoDecisionFinal(i)) if (histograms.l1t_counts[i]) @@ -368,7 +378,7 @@ void TriggerRatesMonitor::dqmAnalyze(edm::Event const &event, // monitor the rates of HLT triggers, datasets and streams if (histograms.hltConfig.inited()) { - auto const &hltResults = event.get(m_hlt_results); + auto const &hltResults = event.get(m_hlt_results_token); if (hltResults.size() != histograms.hltIndices.size()) { edm::LogError("TriggerRatesMonitor") << "This should never happen: the number of HLT paths has changed since the beginning of the run" diff --git a/DQM/HLTEvF/test/testTriggerMonitors.sh b/DQM/HLTEvF/test/testTriggerMonitors.sh index 507d445c664fc..7cb566490a1a2 100755 --- a/DQM/HLTEvF/test/testTriggerMonitors.sh +++ b/DQM/HLTEvF/test/testTriggerMonitors.sh @@ -7,10 +7,8 @@ function die { } # run test job -TESTDIR="${LOCALTOP}"/src/DQM/HLTEvF/test - -cmsRun "${TESTDIR}"/testTriggerMonitors_dqm_cfg.py \ +cmsRun "${SCRAM_TEST_PATH}"/testTriggerMonitors_dqm_cfg.py \ || die "Failure running testTriggerMonitors_dqm_cfg.py" $? -cmsRun "${TESTDIR}"/testTriggerMonitors_harvesting_cfg.py \ +cmsRun "${SCRAM_TEST_PATH}"/testTriggerMonitors_harvesting_cfg.py \ || die "Failure running testTriggerMonitors_harvesting_cfg.py" $?