Skip to content

Commit

Permalink
do not throw exception in Trigger{Bx,Rates}Monitor if L1-uGT results …
Browse files Browse the repository at this point in the history
…are unavailable
  • Loading branch information
missirol committed May 6, 2023
1 parent 21ff8f0 commit cf348fe
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 35 deletions.
45 changes: 28 additions & 17 deletions DQM/HLTEvF/plugins/TriggerBxMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ class TriggerBxMonitor : public DQMGlobalEDAnalyzer<RunBasedHistograms> {
};

// module configuration
const edm::ESGetToken<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd> m_l1tMenuToken;
const edm::EDGetTokenT<GlobalAlgBlkBxCollection> m_l1t_results;
const edm::EDGetTokenT<edm::TriggerResults> m_hlt_results;
const edm::ESGetToken<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd> m_l1tMenu_token;
const edm::InputTag m_l1t_results_inputTag;
const edm::EDGetTokenT<GlobalAlgBlkBxCollection> m_l1t_results_token;
const edm::EDGetTokenT<edm::TriggerResults> m_hlt_results_token;
const std::string m_dqm_path;
const bool m_make_1d_plots;
const bool m_make_2d_plots;
Expand All @@ -125,13 +126,14 @@ void TriggerBxMonitor::fillDescriptions(edm::ConfigurationDescriptions& descript

TriggerBxMonitor::TriggerBxMonitor(edm::ParameterSet const& config)
: // module configuration
m_l1tMenuToken{esConsumes<edm::Transition::BeginRun>()},
m_l1t_results(consumes<GlobalAlgBlkBxCollection>(config.getUntrackedParameter<edm::InputTag>("l1tResults"))),
m_hlt_results(consumes<edm::TriggerResults>(config.getUntrackedParameter<edm::InputTag>("hltResults"))),
m_dqm_path(config.getUntrackedParameter<std::string>("dqmPath")),
m_make_1d_plots(config.getUntrackedParameter<bool>("make1DPlots")),
m_make_2d_plots(config.getUntrackedParameter<bool>("make2DPlots")),
m_ls_range(config.getUntrackedParameter<uint32_t>("lsRange")) {}
m_l1tMenu_token{esConsumes<edm::Transition::BeginRun>()},
m_l1t_results_inputTag{config.getUntrackedParameter<edm::InputTag>("l1tResults")},
m_l1t_results_token{consumes(m_l1t_results_inputTag)},
m_hlt_results_token{consumes(config.getUntrackedParameter<edm::InputTag>("hltResults"))},
m_dqm_path{config.getUntrackedParameter<std::string>("dqmPath")},
m_make_1d_plots{config.getUntrackedParameter<bool>("make1DPlots")},
m_make_2d_plots{config.getUntrackedParameter<bool>("make2DPlots")},
m_ls_range{config.getUntrackedParameter<uint32_t>("lsRange")} {}

void TriggerBxMonitor::dqmBeginRun(edm::Run const& run,
edm::EventSetup const& setup,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -295,23 +297,32 @@ 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);
if (m_make_2d_plots and histograms.l1t_bx_2d.at(i))
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))
Expand Down
38 changes: 24 additions & 14 deletions DQM/HLTEvF/plugins/TriggerRatesMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ class TriggerRatesMonitor : public DQMGlobalEDAnalyzer<RunBasedHistograms> {
};

// module configuration
const edm::ESGetToken<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd> m_l1tMenuToken;
const edm::EDGetTokenT<GlobalAlgBlkBxCollection> m_l1t_results;
const edm::EDGetTokenT<edm::TriggerResults> m_hlt_results;
const edm::ESGetToken<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd> m_l1tMenu_token;
const edm::InputTag m_l1t_results_inputTag;
const edm::EDGetTokenT<GlobalAlgBlkBxCollection> m_l1t_results_token;
const edm::EDGetTokenT<edm::TriggerResults> m_hlt_results_token;
const std::string m_dqm_path;
const uint32_t m_lumisections_range;
};
Expand All @@ -152,11 +153,12 @@ void TriggerRatesMonitor::fillDescriptions(edm::ConfigurationDescriptions &descr

TriggerRatesMonitor::TriggerRatesMonitor(edm::ParameterSet const &config)
: // module configuration
m_l1tMenuToken{esConsumes<edm::Transition::BeginRun>()},
m_l1t_results(consumes<GlobalAlgBlkBxCollection>(config.getUntrackedParameter<edm::InputTag>("l1tResults"))),
m_hlt_results(consumes<edm::TriggerResults>(config.getUntrackedParameter<edm::InputTag>("hltResults"))),
m_dqm_path(config.getUntrackedParameter<std::string>("dqmPath")),
m_lumisections_range(config.getUntrackedParameter<uint32_t>("lumisectionRange")) {}
m_l1tMenu_token{esConsumes<edm::Transition::BeginRun>()},
m_l1t_results_inputTag{config.getUntrackedParameter<edm::InputTag>("l1tResults")},
m_l1t_results_token{consumes(m_l1t_results_inputTag)},
m_hlt_results_token{consumes(config.getUntrackedParameter<edm::InputTag>("hltResults"))},
m_dqm_path{config.getUntrackedParameter<std::string>("dqmPath")},
m_lumisections_range{config.getUntrackedParameter<uint32_t>("lumisectionRange")} {}

void TriggerRatesMonitor::dqmBeginRun(edm::Run const &run,
edm::EventSetup const &setup,
Expand All @@ -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();
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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])
Expand All @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions DQM/HLTEvF/test/testTriggerMonitors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" $?

0 comments on commit cf348fe

Please sign in to comment.