From 0d941009d4d45d7e38e0f39a01f4d81a2309c4bc Mon Sep 17 00:00:00 2001 From: Marino Missiroli Date: Wed, 4 Jan 2023 16:37:48 +0100 Subject: [PATCH 1/4] added unit test for HLTFiltersDQMonitor plugin --- DQMOffline/Trigger/test/BuildFile.xml | 3 + DQMOffline/Trigger/test/harvesting_cfg.py | 54 +++++++++ DQMOffline/Trigger/test/readme.md | 30 +++++ .../Trigger/test/testHLTFiltersDQMonitor.sh | 13 +++ .../test/testHLTFiltersDQMonitor_cfg.py | 105 ++++++++++++++++++ 5 files changed, 205 insertions(+) create mode 100644 DQMOffline/Trigger/test/harvesting_cfg.py create mode 100644 DQMOffline/Trigger/test/readme.md create mode 100755 DQMOffline/Trigger/test/testHLTFiltersDQMonitor.sh create mode 100644 DQMOffline/Trigger/test/testHLTFiltersDQMonitor_cfg.py diff --git a/DQMOffline/Trigger/test/BuildFile.xml b/DQMOffline/Trigger/test/BuildFile.xml index ce6faa9a25b79..931645fb71875 100644 --- a/DQMOffline/Trigger/test/BuildFile.xml +++ b/DQMOffline/Trigger/test/BuildFile.xml @@ -2,3 +2,6 @@ + + + diff --git a/DQMOffline/Trigger/test/harvesting_cfg.py b/DQMOffline/Trigger/test/harvesting_cfg.py new file mode 100644 index 0000000000000..c8fcfea1f0599 --- /dev/null +++ b/DQMOffline/Trigger/test/harvesting_cfg.py @@ -0,0 +1,54 @@ +import FWCore.ParameterSet.Config as cms + +## CLI parser +import argparse +import sys + +parser = argparse.ArgumentParser( + prog = 'cmsRun '+sys.argv[0]+' --', + description = 'Configuration file to run the DQMFileSaver on DQMIO input files.', + formatter_class = argparse.ArgumentDefaultsHelpFormatter +) + +parser.add_argument('-t', '--nThreads', type = int, help = 'Number of threads', + default = 4) + +parser.add_argument('-s', '--nStreams', type = int, help = 'Number of EDM streams', + default = 0) + +parser.add_argument('-i', '--inputFiles', nargs = '+', help = 'List of DQMIO input files', + default = ['file:DQMIO.root']) + +argv = sys.argv[:] +if '--' in argv: + argv.remove('--') +args, unknown = parser.parse_known_args(argv) + +# Process +process = cms.Process('HARVESTING') + +process.options.numberOfThreads = args.nThreads +process.options.numberOfStreams = args.nStreams +process.options.numberOfConcurrentLuminosityBlocks = 1 + +# Source (DQM input) +process.source = cms.Source('DQMRootSource', + fileNames = cms.untracked.vstring(args.inputFiles) +) + +# DQMStore (Service) +process.load('DQMServices.Core.DQMStore_cfi') + +# MessageLogger (Service) +process.load('FWCore.MessageLogger.MessageLogger_cfi') + +# Output module (file in ROOT format) +from DQMServices.Components.DQMFileSaver_cfi import dqmSaver as _dqmSaver +process.dqmSaver = _dqmSaver.clone( + workflow = '/DQMOffline/Trigger/'+process.name_() +) + +# EndPath +process.endp = cms.EndPath( + process.dqmSaver +) diff --git a/DQMOffline/Trigger/test/readme.md b/DQMOffline/Trigger/test/readme.md new file mode 100644 index 0000000000000..0e62f7793ee2f --- /dev/null +++ b/DQMOffline/Trigger/test/readme.md @@ -0,0 +1,30 @@ +Unit test: `testHLTFiltersDQMonitor` +------------------------------------ + +Test of the DQM plugin `HLTFiltersDQMonitor`. + + - To run the test via `scram` + ```sh + scram build runtests_testHLTFiltersDQMonitor + ``` + + - To run the test without `scram` + ```sh + LOCALTOP="${CMSSW_BASE}" "${CMSSW_BASE}"/src/DQMOffline/Trigger/test/testHLTFiltersDQMonitor.sh + ``` + + - To show info on command-line arguments of `testHLTFiltersDQMonitor_cfg.py` + ```sh + python3 "${CMSSW_BASE}"/src/DQMOffline/Trigger/test/testHLTFiltersDQMonitor_cfg.py -h + ``` + + - To execute cmsRun with `testHLTFiltersDQMonitor_cfg.py` (example) + ```sh + cmsRun "${CMSSW_BASE}"/src/DQMOffline/Trigger/test/testHLTFiltersDQMonitor_cfg.py -- -t 4 -s 0 -o tmp.root -n 100 + ``` + + - To create a bare ROOT file from the DQMIO output of `testHLTFiltersDQMonitor_cfg.py`, + run the harvesting step as follows + ```sh + cmsRun "${CMSSW_BASE}"/src/DQMOffline/Trigger/test/harvesting_cfg.py -- -i file:tmp.root + ``` diff --git a/DQMOffline/Trigger/test/testHLTFiltersDQMonitor.sh b/DQMOffline/Trigger/test/testHLTFiltersDQMonitor.sh new file mode 100755 index 0000000000000..5f5748f633138 --- /dev/null +++ b/DQMOffline/Trigger/test/testHLTFiltersDQMonitor.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Pass in name and status +function die { + printf "\n%s: status %s\n" "$1" "$2" + exit $2 +} + +# run test job +TESTDIR="${LOCALTOP}"/src/DQMOffline/Trigger/test + +cmsRun "${TESTDIR}"/testHLTFiltersDQMonitor_cfg.py -- -t 1 -n 128 \ + || die "Failure running testHLTFiltersDQMonitor_cfg.py" $? diff --git a/DQMOffline/Trigger/test/testHLTFiltersDQMonitor_cfg.py b/DQMOffline/Trigger/test/testHLTFiltersDQMonitor_cfg.py new file mode 100644 index 0000000000000..8b360ffc9b145 --- /dev/null +++ b/DQMOffline/Trigger/test/testHLTFiltersDQMonitor_cfg.py @@ -0,0 +1,105 @@ +import FWCore.ParameterSet.Config as cms + +## CLI parser +import argparse +import sys + +parser = argparse.ArgumentParser( + prog = 'cmsRun '+sys.argv[0]+' --', + description = 'Configuration file to test of the HLTFiltersDQMonitor plugin.', + formatter_class = argparse.ArgumentDefaultsHelpFormatter +) + +parser.add_argument('-t', '--nThreads', type = int, help = 'Number of threads', + default = 4) + +parser.add_argument('-s', '--nStreams', type = int, help = 'Number of EDM streams', + default = 0) + +parser.add_argument('-i', '--inputFiles', nargs = '+', help = 'List of EDM input files', + default = ['/store/relval/CMSSW_12_6_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/125X_mcRun3_2022_realistic_v3-v1/2580000/2d96539c-b321-401f-b7b2-51884a5d421f.root']) + +parser.add_argument('-n', '--maxEvents', type = int, help = 'Number of input events', + default = 100) + +parser.add_argument('-o', '--outputFile', type = str, help = 'Path to output file in DQMIO format', + default = 'DQMIO.root') + +parser.add_argument('--wantSummary', action = 'store_true', help = 'Value of process.options.wantSummary', + default = False) + +parser.add_argument('-d', '--debugMode', action = 'store_true', help = 'Enable debug info (requires recompiling first with \'USER_CXXFLAGS="-DEDM_ML_DEBUG" scram b\')', + default = False) + +argv = sys.argv[:] +if '--' in argv: + argv.remove('--') +args, unknown = parser.parse_known_args(argv) + +## Process +process = cms.Process('TEST') + +process.options.numberOfThreads = args.nThreads +process.options.numberOfStreams = args.nStreams +process.options.wantSummary = args.wantSummary +process.maxEvents.input = args.maxEvents + +## Source +process.source = cms.Source('PoolSource', + fileNames = cms.untracked.vstring(args.inputFiles), + inputCommands = cms.untracked.vstring( + 'drop *', + 'keep edmTriggerResults_*_*_*', + 'keep triggerTriggerEvent_*_*_*', + 'keep triggerTriggerEventWithRefs_*_*_*' + ) +) + +## MessageLogger (Service) +process.load('FWCore.MessageLogger.MessageLogger_cfi') +process.MessageLogger.cerr.FwkReport.reportEvery = 1 # only report every Nth event start +process.MessageLogger.cerr.FwkReport.limit = -1 # max number of reported messages (all if -1) +process.MessageLogger.cerr.enableStatistics = False # enable "MessageLogger Summary" message + +## DQMStore (Service) +process.load('DQMServices.Core.DQMStore_cfi') + +## FastTimerService (Service) +from HLTrigger.Timer.FastTimerService_cfi import FastTimerService as _FastTimerService +process.FastTimerService = _FastTimerService.clone( + enableDQM = False, + printEventSummary = False, + printJobSummary = True, + printRunSummary = False, + writeJSONSummary = False +) +process.MessageLogger.FastReport = dict() + +## EventData Modules +from DQMOffline.Trigger.hltFiltersDQMonitor_cfi import hltFiltersDQMonitor as _hltFiltersDQMonitor +process.dqmHLTFiltersDQMonitor = _hltFiltersDQMonitor.clone( + folderName = 'HLT/Filters', + efficPlotNamePrefix = 'effic_', + triggerResults = 'TriggerResults::HLT', + triggerSummaryAOD = 'hltTriggerSummaryAOD::HLT', + triggerSummaryRAW = 'hltTriggerSummaryRAW::HLT' +) +process.MessageLogger.HLTFiltersDQMonitor = dict() +if args.debugMode: + process.MessageLogger.cerr.threshold = 'DEBUG' + process.MessageLogger.debugModules = ['dqmHLTFiltersDQMonitor'] + +## Output Modules +process.dqmOutput = cms.OutputModule('DQMRootOutputModule', + fileName = cms.untracked.string(args.outputFile) +) + +## Path +process.testPath = cms.Path( + process.dqmHLTFiltersDQMonitor +) + +## EndPath +process.testEndPath = cms.EndPath( + process.dqmOutput +) From 259186be424717f7d4877bda7899f6ef93cd45c8 Mon Sep 17 00:00:00 2001 From: Marino Missiroli Date: Wed, 4 Jan 2023 16:39:06 +0100 Subject: [PATCH 2/4] removed access to bare ROOT objects in HLTFiltersDQMonitor --- .../Trigger/plugins/HLTFiltersDQMonitor.cc | 141 +++++++++++------- .../Trigger/test/testHLTFiltersDQMonitor.sh | 2 +- 2 files changed, 90 insertions(+), 53 deletions(-) diff --git a/DQMOffline/Trigger/plugins/HLTFiltersDQMonitor.cc b/DQMOffline/Trigger/plugins/HLTFiltersDQMonitor.cc index 0fd32999bdd50..1f46b29f8377f 100644 --- a/DQMOffline/Trigger/plugins/HLTFiltersDQMonitor.cc +++ b/DQMOffline/Trigger/plugins/HLTFiltersDQMonitor.cc @@ -16,7 +16,7 @@ #include #include -#include +#include #include class HLTFiltersDQMonitor : public DQMEDAnalyzer { @@ -42,8 +42,11 @@ class HLTFiltersDQMonitor : public DQMEDAnalyzer { bool skipRun_; MonitorElement* meMenu_; - std::map meDatasetMap_; - std::map mePathMap_; + std::unordered_map meDatasetMap_; + std::unordered_map mePathMap_; + + // map of bin-label-keyword -> bin-index in ME + std::unordered_map binIndexMap_; edm::EDGetTokenT triggerResultsToken_; edm::EDGetTokenT triggerSummaryTokenAOD_; @@ -132,6 +135,9 @@ void HLTFiltersDQMonitor::bookHistograms(DQMStore::IBooker& iBooker, return; } + // clear map of bin-label-keyword -> bin-index in ME + binIndexMap_.clear(); + iBooker.setCurrentFolder(folderName_); iBooker.bookString("HLTMenu", hltConfigProvider_.tableName().c_str()); @@ -152,11 +158,15 @@ void HLTFiltersDQMonitor::bookHistograms(DQMStore::IBooker& iBooker, triggerNames.size(), -0.1, 1.1, - ""); - if (meMenu_ and meMenu_->getTProfile() and meMenu_->getTProfile()->GetXaxis()) { - for (size_t idx = 0; idx < triggerNames.size(); ++idx) { - meMenu_->getTProfile()->GetXaxis()->SetBinLabel(idx + 1, triggerNames.at(idx).c_str()); - } + "", + [&triggerNames](TProfile* tprof) { + for (size_t idx = 0; idx < triggerNames.size(); ++idx) { + tprof->GetXaxis()->SetBinLabel(idx + 1, triggerNames[idx].c_str()); + } + }); + + for (size_t idx = 0; idx < triggerNames.size(); ++idx) { + binIndexMap_[triggerNames[idx]] = idx + 1; } LogTrace("") << "[HLTFiltersDQMonitor::bookHistograms] HLTConfigProvider::size() = " << hltConfigProvider_.size() @@ -173,19 +183,32 @@ void HLTFiltersDQMonitor::bookHistograms(DQMStore::IBooker& iBooker, LogTrace("") << "[HLTFiltersDQMonitor::bookHistograms] Dataset = \"" << idset << "\""; const std::string meDatasetName(efficPlotNamePrefix_ + idset); meDatasetMap_[meDatasetName] = iBooker.bookProfile( - meDatasetName.c_str(), meDatasetName.c_str(), dsetPathNames.size(), 0., dsetPathNames.size(), -0.1, 1.1, ""); - TProfile* meDatasetTProf(nullptr); - if (meDatasetMap_.at(meDatasetName)) { - meDatasetTProf = meDatasetMap_.at(meDatasetName)->getTProfile(); - } + meDatasetName.c_str(), + meDatasetName.c_str(), + dsetPathNames.size(), + 0., + dsetPathNames.size(), + -0.1, + 1.1, + "", + [&dsetPathNames, &triggerNames](TProfile* tprof) { + for (size_t idxPath = 0; idxPath < dsetPathNames.size(); ++idxPath) { + auto const& iPathName = dsetPathNames[idxPath]; + if (std::find(triggerNames.begin(), triggerNames.end(), iPathName) == triggerNames.end()) { + continue; + } + tprof->GetXaxis()->SetBinLabel(idxPath + 1, iPathName.c_str()); + } + }); + for (size_t idxPath = 0; idxPath < dsetPathNames.size(); ++idxPath) { - auto const& iPathName(dsetPathNames.at(idxPath)); + auto const& iPathName = dsetPathNames[idxPath]; if (std::find(triggerNames.begin(), triggerNames.end(), iPathName) == triggerNames.end()) { continue; } - if (meDatasetTProf and meDatasetTProf->GetXaxis()) { - meDatasetTProf->GetXaxis()->SetBinLabel(idxPath + 1, iPathName.c_str()); - } + + binIndexMap_[idset + "." + iPathName] = idxPath + 1; + if (this->skipPathMonitorElement(iPathName)) { continue; } @@ -221,22 +244,24 @@ void HLTFiltersDQMonitor::bookHistograms(DQMStore::IBooker& iBooker, } const std::string mePathName(efficPlotNamePrefix_ + idset + "_" + iPathName); - mePathMap_[mePathName] = iBooker.bookProfile(mePathName.c_str(), - iPathName.c_str(), - mePath_binLabels.size(), - 0., - mePath_binLabels.size(), - -0.1, - 1.1, - ""); - - if (mePathMap_.at(mePathName)) { - auto* const mePathTProf(mePathMap_.at(mePathName)->getTProfile()); - if (mePathTProf and mePathTProf->GetXaxis()) { - for (size_t iMod = 0; iMod < mePath_binLabels.size(); ++iMod) { - mePathTProf->GetXaxis()->SetBinLabel(iMod + 1, mePath_binLabels.at(iMod).c_str()); - } - } + + mePathMap_[mePathName] = + iBooker.bookProfile(mePathName.c_str(), + iPathName.c_str(), + mePath_binLabels.size(), + 0., + mePath_binLabels.size(), + -0.1, + 1.1, + "", + [&mePath_binLabels](TProfile* tprof) { + for (size_t iMod = 0; iMod < mePath_binLabels.size(); ++iMod) { + tprof->GetXaxis()->SetBinLabel(iMod + 1, mePath_binLabels[iMod].c_str()); + } + }); + + for (size_t iMod = 0; iMod < mePath_binLabels.size(); ++iMod) { + binIndexMap_[idset + "." + iPathName + "." + mePath_binLabels[iMod]] = iMod + 1; } } } @@ -262,7 +287,7 @@ void HLTFiltersDQMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu } // fill MonitorElement: HLT-Menu (bin: path) - if (meMenu_ and meMenu_->getTProfile() and meMenu_->getTProfile()->GetXaxis()) { + if (meMenu_) { auto const& triggerNames(hltConfigProvider_.triggerNames()); for (auto const& iPathName : triggerNames) { const uint pathIndex(hltConfigProvider_.triggerIndex(iPathName)); @@ -273,10 +298,13 @@ void HLTFiltersDQMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu << ") -> plugin will not fill bin associated to this path in HLT-Menu MonitorElement"; continue; } - auto const pathAccept(triggerResults->accept(pathIndex)); - auto* const axis(meMenu_->getTProfile()->GetXaxis()); - auto const ibin(axis->FindBin(iPathName.c_str())); - if ((0 < ibin) and (ibin <= axis->GetNbins())) { + if (binIndexMap_.find(iPathName) == binIndexMap_.end()) { + throw cms::Exception("HLTFiltersDQMonitorInvalidBinLabel") + << "invalid key for bin-index map (name of Path in HLT-menu ME): \"" << iPathName << "\""; + } + auto const ibin = binIndexMap_[iPathName]; + auto const pathAccept = triggerResults->accept(pathIndex); + if ((0 < ibin) and (ibin <= size_t(meMenu_->getNbinsX()))) { meMenu_->Fill(ibin - 0.5, pathAccept); } } @@ -311,10 +339,10 @@ void HLTFiltersDQMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu // loop over PrimaryDatasets in Stream for (auto const& idset : dsets) { LogTrace("") << "[HLTFiltersDQMonitor::analyze] Dataset = \"" << idset << "\""; - TProfile* meDatasetTProf(nullptr); + MonitorElement* meDatasetProf(nullptr); const std::string meDatasetName(efficPlotNamePrefix_ + idset); if (meDatasetMap_.find(meDatasetName) != meDatasetMap_.end()) { - meDatasetTProf = meDatasetMap_.at(meDatasetName)->getTProfile(); + meDatasetProf = meDatasetMap_[meDatasetName]; } auto const& dsetPathNames(hltConfigProvider_.datasetContent(idset)); // loop over Paths in PrimaryDataset @@ -332,20 +360,23 @@ void HLTFiltersDQMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu << "Path = \"" << iPathName << "\", HLTConfigProvider::triggerIndex(\"" << iPathName << "\") = " << pathIndex << ", Accept = " << pathAccept; // fill MonitorElement: PrimaryDataset (bin: path) - if (meDatasetTProf and meDatasetTProf->GetXaxis()) { - auto* const axis(meDatasetTProf->GetXaxis()); - auto const ibin(axis->FindBin(iPathName.c_str())); - if ((0 < ibin) and (ibin <= axis->GetNbins())) { - meDatasetTProf->Fill(ibin - 0.5, pathAccept); + if (meDatasetProf) { + auto const ibinKey = idset + "." + iPathName; + if (binIndexMap_.find(ibinKey) == binIndexMap_.end()) { + throw cms::Exception("HLTFiltersDQMonitorInvalidBinLabel") + << "invalid key for bin-index map (name of Path in Dataset ME): \"" << ibinKey << "\""; + } + auto const ibin = binIndexMap_[ibinKey]; + if (0 < ibin and ibin <= size_t(meDatasetProf->getNbinsX())) { + meDatasetProf->Fill(ibin - 0.5, pathAccept); } } // fill MonitorElement: Path (bin: filter) auto const mePathName(efficPlotNamePrefix_ + idset + "_" + iPathName); if (mePathMap_.find(mePathName) != mePathMap_.end()) { - auto* const mePathTProf(mePathMap_.at(mePathName)->getTProfile()); - if (mePathTProf) { - auto* const axis(mePathTProf->GetXaxis()); - if (axis) { + auto* const mePathProf(mePathMap_[mePathName]); + if (true) { + if (true) { unsigned indexLastFilterPathModules(triggerResults->index(pathIndex) + 1); LogTrace("") << "[HLTFiltersDQMonitor::analyze] " << "indexLastFilterPathModules = " << indexLastFilterPathModules; @@ -408,9 +439,15 @@ void HLTFiltersDQMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu << moduleLabel << "\", HLTConfigProvider::moduleIndex(" << pathIndex << ", \"" << moduleLabel << "\") = " << slotModule << ", filterAccept = " << filterAccept << ", previousFilterAccept = " << previousFilterAccept; - auto const ibin(axis->FindBin(moduleLabel.c_str())); - if ((0 < ibin) and (ibin <= axis->GetNbins())) { - mePathTProf->Fill(ibin - 0.5, filterAccept); + + auto const ibinKey = idset + "." + iPathName + "." + moduleLabel; + if (binIndexMap_.find(ibinKey) == binIndexMap_.end()) { + throw cms::Exception("HLTFiltersDQMonitorInvalidBinLabel") + << "invalid key for bin-index map (name of Module in Path ME): \"" << ibinKey << "\""; + } + auto const ibin = binIndexMap_[ibinKey]; + if (0 < ibin and ibin <= size_t(mePathProf->getNbinsX())) { + mePathProf->Fill(ibin - 0.5, filterAccept); } previousFilterAccept = filterAccept; } diff --git a/DQMOffline/Trigger/test/testHLTFiltersDQMonitor.sh b/DQMOffline/Trigger/test/testHLTFiltersDQMonitor.sh index 5f5748f633138..1315ea893c9c0 100755 --- a/DQMOffline/Trigger/test/testHLTFiltersDQMonitor.sh +++ b/DQMOffline/Trigger/test/testHLTFiltersDQMonitor.sh @@ -9,5 +9,5 @@ function die { # run test job TESTDIR="${LOCALTOP}"/src/DQMOffline/Trigger/test -cmsRun "${TESTDIR}"/testHLTFiltersDQMonitor_cfg.py -- -t 1 -n 128 \ +cmsRun "${TESTDIR}"/testHLTFiltersDQMonitor_cfg.py -- -t 4 -n 128 \ || die "Failure running testHLTFiltersDQMonitor_cfg.py" $? From c33e51f0bc73f018e56c62b6edeab643eb710c7d Mon Sep 17 00:00:00 2001 From: Marino Missiroli Date: Wed, 4 Jan 2023 16:52:08 +0100 Subject: [PATCH 3/4] renaming of cfi and parameters of HLTFiltersDQMonitor --- DQMOffline/Trigger/plugins/BuildFile.xml | 39 +- .../Trigger/plugins/HLTFiltersDQMonitor.cc | 653 ++++++++++-------- .../Trigger/python/DQMOffline_Trigger_cff.py | 18 +- .../python/DQMOffline_Trigger_cosmics_cff.py | 9 +- .../Trigger/python/HLT_DQM_Offline_cff.py | 8 +- .../fv_dqmoffline_sourceclient-file_cfg.py | 4 +- .../test/testHLTFiltersDQMonitor_cfg.py | 8 +- .../Trigger/test/triggerSequenceTest_cfg.py | 4 +- .../Trigger/test/trigger_dqmoffline_cfg.py | 4 +- ...rigger_dqmoffline_sourceclient-file_cfg.py | 2 +- ...dqmoffline_sourceclient_relval-file_cfg.py | 2 +- .../test/trigger_dqmoffline_step2_cfg.py | 4 +- 12 files changed, 403 insertions(+), 352 deletions(-) diff --git a/DQMOffline/Trigger/plugins/BuildFile.xml b/DQMOffline/Trigger/plugins/BuildFile.xml index 25abaa9e8463f..4fe2dd3f1cf14 100644 --- a/DQMOffline/Trigger/plugins/BuildFile.xml +++ b/DQMOffline/Trigger/plugins/BuildFile.xml @@ -1,27 +1,30 @@ - - - + + + + + + + + + + + - - - - - - - - - - - - + - + + + + + + + - - + + diff --git a/DQMOffline/Trigger/plugins/HLTFiltersDQMonitor.cc b/DQMOffline/Trigger/plugins/HLTFiltersDQMonitor.cc index 1f46b29f8377f..0fa4b85c5b2ea 100644 --- a/DQMOffline/Trigger/plugins/HLTFiltersDQMonitor.cc +++ b/DQMOffline/Trigger/plugins/HLTFiltersDQMonitor.cc @@ -1,42 +1,42 @@ -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/ServiceRegistry/interface/Service.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -#include "DQMServices/Core/interface/DQMStore.h" #include "DQMServices/Core/interface/DQMEDAnalyzer.h" - +#include "DQMServices/Core/interface/DQMStore.h" #include "DataFormats/Common/interface/TriggerResults.h" #include "DataFormats/HLTReco/interface/TriggerEvent.h" #include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h" - +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "FWCore/Utilities/interface/Exception.h" #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h" +#include #include -#include #include -#include +#include class HLTFiltersDQMonitor : public DQMEDAnalyzer { public: - explicit HLTFiltersDQMonitor(const edm::ParameterSet&); + explicit HLTFiltersDQMonitor(edm::ParameterSet const&); ~HLTFiltersDQMonitor() override = default; + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: void dqmBeginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) override; void bookHistograms(DQMStore::IBooker&, edm::Run const& iRun, edm::EventSetup const& iSetup) override; - void analyze(const edm::Event&, const edm::EventSetup&) override; + void analyze(edm::Event const&, edm::EventSetup const&) override; - bool skipStreamByName(const std::string& streamName) const; - bool skipPathMonitorElement(const std::string& pathName) const; - bool skipModuleByEDMType(const std::string& moduleEDMType) const; - bool skipModuleByType(const std::string& moduleType) const; + bool skipStreamByName(std::string const& streamName) const; + bool skipPathMonitorElement(std::string const& pathName) const; + bool skipModuleByEDMType(std::string const& moduleEDMType) const; + bool skipModuleByType(std::string const& moduleType) const; - const std::string folderName_; - const std::string efficPlotNamePrefix_; + std::string const folderName_; + std::string const efficPlotNamePrefix_; std::string processName_; bool initFailed_; bool skipRun_; @@ -45,12 +45,12 @@ class HLTFiltersDQMonitor : public DQMEDAnalyzer { std::unordered_map meDatasetMap_; std::unordered_map mePathMap_; - // map of bin-label-keyword -> bin-index in ME + // map of bin-label-keyword -> bin-index in MonitorElement std::unordered_map binIndexMap_; edm::EDGetTokenT triggerResultsToken_; - edm::EDGetTokenT triggerSummaryTokenAOD_; - edm::EDGetTokenT triggerSummaryTokenRAW_; + edm::EDGetTokenT triggerEventToken_; + edm::EDGetTokenT triggerEventWithRefsToken_; HLTConfigProvider hltConfigProvider_; }; @@ -62,11 +62,12 @@ HLTFiltersDQMonitor::HLTFiltersDQMonitor(const edm::ParameterSet& iConfig) initFailed_(false), skipRun_(false), meMenu_(nullptr) { - auto const triggerResultsInputTag(iConfig.getParameter("triggerResults")); + auto const& triggerResultsInputTag = iConfig.getParameter("triggerResults"); if (triggerResultsInputTag.process().empty()) { - edm::LogError("Input") << "process not specified in HLT TriggerResults InputTag \"" - << triggerResultsInputTag.encode() << "\" -> plugin will not produce DQM outputs"; + edm::LogError("HLTFiltersDQMonitor") << "process not specified in HLT TriggerResults InputTag \"" + << triggerResultsInputTag.encode() + << "\" -> plugin will not produce DQM outputs"; initFailed_ = true; return; } else { @@ -74,31 +75,32 @@ HLTFiltersDQMonitor::HLTFiltersDQMonitor(const edm::ParameterSet& iConfig) triggerResultsToken_ = consumes(triggerResultsInputTag); - auto triggerSummaryAODInputTag(iConfig.getParameter("triggerSummaryAOD")); - if (triggerSummaryAODInputTag.process().empty()) { - triggerSummaryAODInputTag = - edm::InputTag(triggerSummaryAODInputTag.label(), triggerSummaryAODInputTag.instance(), processName_); - } else if (triggerSummaryAODInputTag.process() != processName_) { - edm::LogWarning("Input") << "edm::TriggerResults process name '" << processName_ - << "' differs from trigger::TriggerEvent process name '" - << triggerSummaryAODInputTag.process() << "' -> plugin will not produce DQM outputs"; + auto triggerEventInputTag = iConfig.getParameter("triggerEvent"); + if (triggerEventInputTag.process().empty()) { + triggerEventInputTag = edm::InputTag(triggerEventInputTag.label(), triggerEventInputTag.instance(), processName_); + } else if (triggerEventInputTag.process() != processName_) { + edm::LogWarning("HLTFiltersDQMonitor") + << "edm::TriggerResults process name '" << processName_ + << "' differs from trigger::TriggerEvent process name '" << triggerEventInputTag.process() + << "' -> plugin will not produce DQM outputs"; initFailed_ = true; return; } - triggerSummaryTokenAOD_ = consumes(triggerSummaryAODInputTag); - - auto triggerSummaryRAWInputTag(iConfig.getParameter("triggerSummaryRAW")); - if (triggerSummaryRAWInputTag.process().empty()) { - triggerSummaryRAWInputTag = - edm::InputTag(triggerSummaryRAWInputTag.label(), triggerSummaryRAWInputTag.instance(), processName_); - } else if (triggerSummaryRAWInputTag.process() != processName_) { - edm::LogWarning("Input") << "edm::TriggerResults process name '" << processName_ - << "' differs from trigger::TriggerEventWithRefs process name '" - << triggerSummaryRAWInputTag.process() << "' -> plugin will not produce DQM outputs"; + triggerEventToken_ = consumes(triggerEventInputTag); + + auto triggerEventWithRefsInputTag = iConfig.getParameter("triggerEventWithRefs"); + if (triggerEventWithRefsInputTag.process().empty()) { + triggerEventWithRefsInputTag = + edm::InputTag(triggerEventWithRefsInputTag.label(), triggerEventWithRefsInputTag.instance(), processName_); + } else if (triggerEventWithRefsInputTag.process() != processName_) { + edm::LogWarning("HLTFiltersDQMonitor") + << "edm::TriggerResults process name '" << processName_ + << "' differs from trigger::TriggerEventWithRefs process name '" << triggerEventWithRefsInputTag.process() + << "' -> plugin will not produce DQM outputs"; initFailed_ = true; return; } - triggerSummaryTokenRAW_ = mayConsume(triggerSummaryRAWInputTag); + triggerEventWithRefsToken_ = mayConsume(triggerEventWithRefsInputTag); } } @@ -107,22 +109,24 @@ void HLTFiltersDQMonitor::dqmBeginRun(edm::Run const& iRun, edm::EventSetup cons return; } - LogTrace("") + LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor] " << "----------------------------------------------------------------------------------------------------"; - LogTrace("") << "[HLTFiltersDQMonitor::dqmBeginRun] Run = " << iRun.id(); + LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::dqmBeginRun] Run = " << iRun.id(); // reset data members holding information from the previous run skipRun_ = false; - bool hltChanged(true); + bool hltChanged = true; if (hltConfigProvider_.init(iRun, iSetup, processName_, hltChanged)) { - LogTrace("") << "[HLTFiltersDQMonitor::dqmBeginRun] HLTConfigProvider initialized [processName() = " - << hltConfigProvider_.processName() << ", tableName() = " << hltConfigProvider_.tableName() - << ", size() = " << hltConfigProvider_.size() << "]"; + LogTrace("HLTFiltersDQMonitor") + << "[HLTFiltersDQMonitor::dqmBeginRun] HLTConfigProvider initialized [processName() = " + << hltConfigProvider_.processName() << ", tableName() = " << hltConfigProvider_.tableName() + << ", size() = " << hltConfigProvider_.size() << "]"; } else { - edm::LogError("Input") << "initialization of HLTConfigProvider failed for Run=" << iRun.id() << " (process=\"" - << processName_ << "\") -> plugin will not produce DQM outputs for this run"; + edm::LogError("HLTFiltersDQMonitor") << "initialization of HLTConfigProvider failed for Run=" << iRun.id() + << " (process=\"" << processName_ + << "\") -> plugin will not produce DQM outputs for this run"; skipRun_ = true; return; } @@ -135,21 +139,21 @@ void HLTFiltersDQMonitor::bookHistograms(DQMStore::IBooker& iBooker, return; } - // clear map of bin-label-keyword -> bin-index in ME + // clear map of bin-label-keyword -> bin-index in MonitorElement binIndexMap_.clear(); iBooker.setCurrentFolder(folderName_); iBooker.bookString("HLTMenu", hltConfigProvider_.tableName().c_str()); - auto hltMenuName(hltConfigProvider_.tableName()); + auto hltMenuName = hltConfigProvider_.tableName(); std::replace(hltMenuName.begin(), hltMenuName.end(), '/', '_'); - std::replace(hltMenuName.begin(), hltMenuName.end(), '.', '_'); + std::replace(hltMenuName.begin(), hltMenuName.end(), '.', 'p'); while (hltMenuName.front() == '_') { hltMenuName.erase(0, 1); } - auto const& triggerNames(hltConfigProvider_.triggerNames()); + auto const& triggerNames = hltConfigProvider_.triggerNames(); meMenu_ = iBooker.bookProfile(efficPlotNamePrefix_ + hltMenuName, "Path Efficiency", @@ -169,100 +173,108 @@ void HLTFiltersDQMonitor::bookHistograms(DQMStore::IBooker& iBooker, binIndexMap_[triggerNames[idx]] = idx + 1; } - LogTrace("") << "[HLTFiltersDQMonitor::bookHistograms] HLTConfigProvider::size() = " << hltConfigProvider_.size() - << ", HLTConfigProvider::triggerNames().size() = " << triggerNames.size(); + LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::bookHistograms] HLTConfigProvider::size() = " + << hltConfigProvider_.size() + << ", HLTConfigProvider::triggerNames().size() = " << triggerNames.size(); for (auto const& istream : hltConfigProvider_.streamNames()) { - LogTrace("") << "[HLTFiltersDQMonitor::bookHistograms] Stream = \"" << istream << "\""; - - if (not this->skipStreamByName(istream)) { - auto const& dsets(hltConfigProvider_.streamContent(istream)); - for (auto const& idset : dsets) { - const std::vector& dsetPathNames = hltConfigProvider_.datasetContent(idset); - iBooker.setCurrentFolder(folderName_ + "/" + idset); - LogTrace("") << "[HLTFiltersDQMonitor::bookHistograms] Dataset = \"" << idset << "\""; - const std::string meDatasetName(efficPlotNamePrefix_ + idset); - meDatasetMap_[meDatasetName] = iBooker.bookProfile( - meDatasetName.c_str(), - meDatasetName.c_str(), - dsetPathNames.size(), - 0., - dsetPathNames.size(), - -0.1, - 1.1, - "", - [&dsetPathNames, &triggerNames](TProfile* tprof) { - for (size_t idxPath = 0; idxPath < dsetPathNames.size(); ++idxPath) { - auto const& iPathName = dsetPathNames[idxPath]; - if (std::find(triggerNames.begin(), triggerNames.end(), iPathName) == triggerNames.end()) { - continue; - } - tprof->GetXaxis()->SetBinLabel(idxPath + 1, iPathName.c_str()); + LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::bookHistograms] Stream = \"" << istream << "\""; + + if (this->skipStreamByName(istream)) { + continue; + } + + auto const& dsets = hltConfigProvider_.streamContent(istream); + for (auto const& idset : dsets) { + iBooker.setCurrentFolder(folderName_ + "/" + idset); + LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::bookHistograms] Dataset = \"" << idset << "\""; + auto const& dsetPathNames = hltConfigProvider_.datasetContent(idset); + auto const meDatasetName = efficPlotNamePrefix_ + idset; + meDatasetMap_[meDatasetName] = iBooker.bookProfile( + meDatasetName.c_str(), + meDatasetName.c_str(), + dsetPathNames.size(), + 0., + dsetPathNames.size(), + -0.1, + 1.1, + "", + [&dsetPathNames, &triggerNames](TProfile* tprof) { + for (size_t idxPath = 0; idxPath < dsetPathNames.size(); ++idxPath) { + auto const& iPathName = dsetPathNames[idxPath]; + if (std::find(triggerNames.begin(), triggerNames.end(), iPathName) == triggerNames.end()) { + continue; } - }); + tprof->GetXaxis()->SetBinLabel(idxPath + 1, iPathName.c_str()); + } + }); + for (size_t idxPath = 0; idxPath < dsetPathNames.size(); ++idxPath) { + auto const& iPathName = dsetPathNames[idxPath]; + if (std::find(triggerNames.begin(), triggerNames.end(), iPathName) == triggerNames.end()) { + continue; + } + binIndexMap_[idset + "." + iPathName] = idxPath + 1; - for (size_t idxPath = 0; idxPath < dsetPathNames.size(); ++idxPath) { - auto const& iPathName = dsetPathNames[idxPath]; - if (std::find(triggerNames.begin(), triggerNames.end(), iPathName) == triggerNames.end()) { - continue; - } + if (this->skipPathMonitorElement(iPathName)) { + continue; + } - binIndexMap_[idset + "." + iPathName] = idxPath + 1; + LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::bookHistograms] Path = \"" << iPathName << "\""; + + auto const& moduleLabels = hltConfigProvider_.moduleLabels(iPathName); + std::vector mePath_binLabels; + mePath_binLabels.reserve(moduleLabels.size()); + for (size_t iMod = 0; iMod < moduleLabels.size(); ++iMod) { + auto const& moduleLabel = moduleLabels[iMod]; + + bool skipModule = false; + if (this->skipModuleByEDMType(hltConfigProvider_.moduleEDMType(moduleLabel)) or + this->skipModuleByType(hltConfigProvider_.moduleType(moduleLabel))) { + skipModule = true; + } else if (std::find(mePath_binLabels.begin(), mePath_binLabels.end(), moduleLabel) != + mePath_binLabels.end()) { + LogDebug("HLTFiltersDQMonitor") + << "module \"" << moduleLabel << "\" included multiple times in Path \"" << iPathName << "\"" + << "-> only 1 bin labelled \"" << moduleLabel << "\" will be created in the MonitorElement of the Path"; + skipModule = true; + } - if (this->skipPathMonitorElement(iPathName)) { + if (skipModule) { + LogTrace("HLTFiltersDQMonitor") + << "[HLTFiltersDQMonitor::bookHistograms] [-] Module = \"" << moduleLabel << "\""; continue; } - LogTrace("") << "[HLTFiltersDQMonitor::bookHistograms] Path = \"" << iPathName << "\""; + mePath_binLabels.emplace_back(moduleLabel); - auto const& moduleLabels(hltConfigProvider_.moduleLabels(iPathName)); - std::vector mePath_binLabels; - mePath_binLabels.reserve(moduleLabels.size()); - for (size_t iMod = 0; iMod < moduleLabels.size(); ++iMod) { - auto const& moduleLabel(moduleLabels.at(iMod)); - if (this->skipModuleByEDMType(hltConfigProvider_.moduleEDMType(moduleLabel)) or - this->skipModuleByType(hltConfigProvider_.moduleType(moduleLabel))) { - LogTrace("") << "[HLTFiltersDQMonitor::bookHistograms] [-] Module = \"" << moduleLabel << "\""; - continue; - } - LogTrace("") << "[HLTFiltersDQMonitor::bookHistograms] [bin=" << mePath_binLabels.size() + 1 - << "] Module = \"" << moduleLabel << "\""; - - if (std::find(mePath_binLabels.begin(), mePath_binLabels.end(), moduleLabel) != mePath_binLabels.end()) { - edm::LogInfo("Input") << "module \"" << moduleLabel << "\" included multiple times in path \"" - << iPathName << "\"" - << "-> only 1 bin labelled \"" << moduleLabel - << "\" will be created in the DQM MonitorElement of the path"; - continue; - } + LogTrace("HLTFiltersDQMonitor") + << "[HLTFiltersDQMonitor::bookHistograms] [bin=" << mePath_binLabels.size() << "] Module = \"" + << moduleLabel << "\""; + } - mePath_binLabels.emplace_back(moduleLabel); - } + if (mePath_binLabels.empty()) { + continue; + } - if (mePath_binLabels.empty()) { - continue; - } + auto const mePathName = efficPlotNamePrefix_ + idset + "_" + iPathName; - const std::string mePathName(efficPlotNamePrefix_ + idset + "_" + iPathName); - - mePathMap_[mePathName] = - iBooker.bookProfile(mePathName.c_str(), - iPathName.c_str(), - mePath_binLabels.size(), - 0., - mePath_binLabels.size(), - -0.1, - 1.1, - "", - [&mePath_binLabels](TProfile* tprof) { - for (size_t iMod = 0; iMod < mePath_binLabels.size(); ++iMod) { - tprof->GetXaxis()->SetBinLabel(iMod + 1, mePath_binLabels[iMod].c_str()); - } - }); - - for (size_t iMod = 0; iMod < mePath_binLabels.size(); ++iMod) { - binIndexMap_[idset + "." + iPathName + "." + mePath_binLabels[iMod]] = iMod + 1; - } + mePathMap_[mePathName] = + iBooker.bookProfile(mePathName.c_str(), + iPathName.c_str(), + mePath_binLabels.size(), + 0., + mePath_binLabels.size(), + -0.1, + 1.1, + "", + [&mePath_binLabels](TProfile* tprof) { + for (size_t iMod = 0; iMod < mePath_binLabels.size(); ++iMod) { + tprof->GetXaxis()->SetBinLabel(iMod + 1, mePath_binLabels[iMod].c_str()); + } + }); + + for (size_t iMod = 0; iMod < mePath_binLabels.size(); ++iMod) { + binIndexMap_[idset + "." + iPathName + "." + mePath_binLabels[iMod]] = iMod + 1; } } } @@ -274,221 +286,256 @@ void HLTFiltersDQMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu return; } - LogTrace("") << "[HLTFiltersDQMonitor::analyze] --------------------------------------------------------"; - LogTrace("") << "[HLTFiltersDQMonitor::analyze] Run = " << iEvent.id().run() - << ", LuminosityBlock = " << iEvent.id().luminosityBlock() << ", Event = " << iEvent.id().event(); + LogTrace("HLTFiltersDQMonitor") + << "[HLTFiltersDQMonitor::analyze] --------------------------------------------------------"; + LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze] Run = " << iEvent.id().run() + << ", LuminosityBlock = " << iEvent.id().luminosityBlock() + << ", Event = " << iEvent.id().event(); - auto const& triggerResults(iEvent.getHandle(triggerResultsToken_)); + auto const& triggerResults = iEvent.getHandle(triggerResultsToken_); if (not triggerResults.isValid()) { - edm::LogWarning("Input") << "invalid handle to edm::TriggerResults (InputTag: \"triggerResults\")" - << " -> plugin will not fill DQM outputs for this event"; + edm::EDConsumerBase::Labels labels; + labelsForToken(triggerResultsToken_, labels); + edm::LogWarning("HLTFiltersDQMonitor") + << "invalid handle to edm::TriggerResults (InputTag: \"" << labels.module << ":" << labels.productInstance + << ":" << labels.process << "\") -> plugin will not fill DQM outputs for this event"; return; } - // fill MonitorElement: HLT-Menu (bin: path) - if (meMenu_) { - auto const& triggerNames(hltConfigProvider_.triggerNames()); - for (auto const& iPathName : triggerNames) { - const uint pathIndex(hltConfigProvider_.triggerIndex(iPathName)); - if (pathIndex >= triggerResults->size()) { - edm::LogError("Logic") << "[HLTFiltersDQMonitor::analyze] " - << "index associated to path \"" << iPathName << "\" (" << pathIndex - << ") is inconsistent with triggerResults::size() (" << triggerResults->size() - << ") -> plugin will not fill bin associated to this path in HLT-Menu MonitorElement"; - continue; - } - if (binIndexMap_.find(iPathName) == binIndexMap_.end()) { - throw cms::Exception("HLTFiltersDQMonitorInvalidBinLabel") - << "invalid key for bin-index map (name of Path in HLT-menu ME): \"" << iPathName << "\""; - } - auto const ibin = binIndexMap_[iPathName]; + // fill MonitorElement: HLT-Menu (bin: Path) + auto const& triggerNames = hltConfigProvider_.triggerNames(); + for (auto const& iPathName : triggerNames) { + unsigned int const pathIndex = hltConfigProvider_.triggerIndex(iPathName); + if (pathIndex >= triggerResults->size()) { + edm::LogError("HLTFiltersDQMonitor") + << "[HLTFiltersDQMonitor::analyze] " + << "index associated to Path \"" << iPathName << "\" (" << pathIndex + << ") is inconsistent with triggerResults::size() (" << triggerResults->size() + << ") -> plugin will not fill bin associated to this Path in HLT-Menu MonitorElement"; + continue; + } + + if (binIndexMap_.find(iPathName) == binIndexMap_.end()) { + throw cms::Exception("HLTFiltersDQMonitorInvalidBinLabel") + << "invalid key for bin-index map (name of Path bin in MonitorElement of HLT Menu): \"" << iPathName << "\""; + } + auto const ibin = binIndexMap_[iPathName]; + if ((0 < ibin) and (ibin <= size_t(meMenu_->getNbinsX()))) { auto const pathAccept = triggerResults->accept(pathIndex); - if ((0 < ibin) and (ibin <= size_t(meMenu_->getNbinsX()))) { - meMenu_->Fill(ibin - 0.5, pathAccept); - } + meMenu_->Fill(ibin - 0.5, pathAccept); + } else { + edm::LogError("HLTFiltersDQMonitor") << "out-of-range bin index of Path \"" << iPathName + << "\" in MonitorElement of HLT Menu (MonitorElement not filled): bin_key=\"" + << iPathName << "\", bin_index=" << ibin; } } - auto const& triggerEventAOD(iEvent.getHandle(triggerSummaryTokenAOD_)); - edm::Handle triggerEventRAW; - - bool useTriggerEventAOD(true); - if (not triggerEventAOD.isValid()) { - useTriggerEventAOD = false; - edm::LogInfo("Input") << "invalid handle to trigger::TriggerEvent (InputTag: \"triggerSummaryAOD\")," - << " will attempt to access trigger::TriggerEventWithRefs (InputTag: \"triggerSummaryRAW\")"; - - triggerEventRAW = iEvent.getHandle(triggerSummaryTokenRAW_); - if (not triggerEventRAW.isValid()) { - edm::LogWarning("Input") << "invalid handle to trigger::TriggerEventWithRefs (InputTag: \"triggerSummaryRAW\")" - << " -> plugin will not fill DQM outputs for this event"; + auto const& triggerEventHandle = iEvent.getHandle(triggerEventToken_); + edm::Handle triggerEventWithRefs; + + bool useTriggerEvent = true; + if (not triggerEventHandle.isValid()) { + useTriggerEvent = false; + + edm::EDConsumerBase::Labels triggerEventLabels; + labelsForToken(triggerEventToken_, triggerEventLabels); + + edm::EDConsumerBase::Labels triggerEventWithRefsLabels; + labelsForToken(triggerEventWithRefsToken_, triggerEventWithRefsLabels); + + edm::LogInfo("HLTFiltersDQMonitor") << "invalid handle to trigger::TriggerEvent (InputTag: \"" + << triggerEventLabels.module << ":" << triggerEventLabels.productInstance << ":" + << triggerEventLabels.process + << "\"), will attempt to access trigger::TriggerEventWithRefs (InputTag:\"" + << triggerEventWithRefsLabels.module << ":" + << triggerEventWithRefsLabels.productInstance << ":" + << triggerEventWithRefsLabels.process << "\")"; + + triggerEventWithRefs = iEvent.getHandle(triggerEventWithRefsToken_); + if (not triggerEventWithRefs.isValid()) { + edm::LogWarning("HLTFiltersDQMonitor") + << "invalid handle to trigger::TriggerEventWithRefs (InputTag: \"" << triggerEventWithRefsLabels.module << ":" + << triggerEventWithRefsLabels.productInstance << ":" << triggerEventWithRefsLabels.process + << "\") -> plugin will not fill DQM outputs for this event"; return; } } - auto const triggerEventSize(useTriggerEventAOD ? triggerEventAOD->sizeFilters() : triggerEventRAW->size()); - LogTrace("") << "[HLTFiltersDQMonitor::analyze] useTriggerEventAOD = " << useTriggerEventAOD - << ", triggerEventSize = " << triggerEventSize; + auto const triggerEventSize = useTriggerEvent ? triggerEventHandle->sizeFilters() : triggerEventWithRefs->size(); + LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze] useTriggerEvent = " << useTriggerEvent + << ", triggerEventSize = " << triggerEventSize; // fill MonitorElements for PrimaryDatasets and Paths // loop over Streams for (auto const& istream : hltConfigProvider_.streamNames()) { - LogTrace("") << "[HLTFiltersDQMonitor::analyze] Stream = \"" << istream << "\""; - auto const& dsets(hltConfigProvider_.streamContent(istream)); + LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze] Stream = \"" << istream << "\""; + // loop over PrimaryDatasets in Stream + auto const& dsets = hltConfigProvider_.streamContent(istream); for (auto const& idset : dsets) { - LogTrace("") << "[HLTFiltersDQMonitor::analyze] Dataset = \"" << idset << "\""; - MonitorElement* meDatasetProf(nullptr); - const std::string meDatasetName(efficPlotNamePrefix_ + idset); - if (meDatasetMap_.find(meDatasetName) != meDatasetMap_.end()) { - meDatasetProf = meDatasetMap_[meDatasetName]; + LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze] Dataset = \"" << idset << "\""; + + // consider only Datasets with a MonitorElement (see bookHistograms) + auto const meDatasetName = efficPlotNamePrefix_ + idset; + if (meDatasetMap_.find(meDatasetName) == meDatasetMap_.end()) { + LogDebug("HLTFiltersDQMonitor") << "No MonitorElement associated to Dataset \"" << idset << "\" in Stream \"" + << istream << "\" (will be ignored)"; + continue; } - auto const& dsetPathNames(hltConfigProvider_.datasetContent(idset)); + MonitorElement* const meDatasetProf = meDatasetMap_[meDatasetName]; + // loop over Paths in PrimaryDataset + auto const& dsetPathNames = hltConfigProvider_.datasetContent(idset); for (auto const& iPathName : dsetPathNames) { - const uint pathIndex(hltConfigProvider_.triggerIndex(iPathName)); + unsigned int const pathIndex = hltConfigProvider_.triggerIndex(iPathName); if (pathIndex >= triggerResults->size()) { - edm::LogError("Logic") << "[HLTFiltersDQMonitor::analyze] " - << "index associated to path \"" << iPathName << "\" (" << pathIndex - << ") is inconsistent with triggerResults::size() (" << triggerResults->size() - << ") -> plugin will not fill DQM info related to this path"; + edm::LogError("HLTFiltersDQMonitor") + << "[HLTFiltersDQMonitor::analyze] " + << "index associated to Path \"" << iPathName << "\" (" << pathIndex + << ") is inconsistent with triggerResults::size() (" << triggerResults->size() + << ") -> plugin will not fill DQM info related to this Path"; + continue; + } + auto const pathAccept = triggerResults->accept(pathIndex); + LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze] " + << "Path = \"" << iPathName << "\", HLTConfigProvider::triggerIndex(\"" + << iPathName << "\") = " << pathIndex << ", Accept = " << pathAccept; + + // fill MonitorElement: PrimaryDataset (bin: Path) + auto const ibinKey = idset + "." + iPathName; + if (binIndexMap_.find(ibinKey) == binIndexMap_.end()) { + throw cms::Exception("HLTFiltersDQMonitorInvalidBinLabel") + << "invalid key for bin-index map (name of Path bin in MonitorElement of Dataset): \"" << ibinKey << "\""; + } + auto const ibin = binIndexMap_[ibinKey]; + if (0 < ibin and ibin <= size_t(meDatasetProf->getNbinsX())) { + meDatasetProf->Fill(ibin - 0.5, pathAccept); + } else { + edm::LogError("HLTFiltersDQMonitor") + << "out-of-range bin index of Path \"" << iPathName << "\" in MonitorElement of Dataset \"" << idset + << "\" (MonitorElement not filled): bin_key=\"" << ibinKey << "\", bin_index=" << ibin; + } + + // fill MonitorElement: Path (bin: filter) + auto const mePathName = efficPlotNamePrefix_ + idset + "_" + iPathName; + + // consider only Paths with a MonitorElement + if (mePathMap_.find(mePathName) == mePathMap_.end()) { + LogDebug("HLTFiltersDQMonitor") << "No MonitorElement associated to Path \"" << iPathName + << "\" in Dataset \"" << idset << "\" (will be ignored)"; + continue; + } + + MonitorElement* const mePathProf = mePathMap_[mePathName]; + + unsigned int indexLastFilterInPath = triggerResults->index(pathIndex) + 1; + LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze] " + << "indexLastFilterInPath = " << indexLastFilterInPath; + // identify module corresponding to last filter executed in the Path + while (indexLastFilterInPath > 0) { + --indexLastFilterInPath; + auto const& labelLastFilterInPath = hltConfigProvider_.moduleLabel(pathIndex, indexLastFilterInPath); + auto const labelLastFilterInPathTag = edm::InputTag(labelLastFilterInPath, "", processName_); + unsigned int const indexLastFilterInTriggerEvent = + useTriggerEvent ? triggerEventHandle->filterIndex(labelLastFilterInPathTag) + : triggerEventWithRefs->filterIndex(labelLastFilterInPathTag); + LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze] " + << "indexLastFilterInPath = " << indexLastFilterInPath + << ", labelLastFilterInPath = " << labelLastFilterInPath + << ", indexLastFilterInTriggerEvent = " << indexLastFilterInTriggerEvent + << " (triggerEventSize = " << triggerEventSize << ")"; + if (indexLastFilterInTriggerEvent < triggerEventSize) { + if (this->skipModuleByType(hltConfigProvider_.moduleType(labelLastFilterInPath))) { + continue; + } + break; + } + } + // number of modules in the path + unsigned int const nModulesInPath = hltConfigProvider_.size(pathIndex); + LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze] " + << "-> selected indexLastFilterInPath = " << indexLastFilterInPath + << " (HLTConfigProvider::size(" << pathIndex << ") = " << nModulesInPath << ")"; + if (indexLastFilterInPath >= nModulesInPath) { + edm::LogError("HLTFiltersDQMonitor") + << " selected index (" << indexLastFilterInPath << ") for last filter of path \"" << iPathName + << "\" is inconsistent with number of modules in the Path (" << nModulesInPath << ")"; continue; } - auto const pathAccept(triggerResults->accept(pathIndex)); - LogTrace("") << "[HLTFiltersDQMonitor::analyze] " - << "Path = \"" << iPathName << "\", HLTConfigProvider::triggerIndex(\"" << iPathName - << "\") = " << pathIndex << ", Accept = " << pathAccept; - // fill MonitorElement: PrimaryDataset (bin: path) - if (meDatasetProf) { - auto const ibinKey = idset + "." + iPathName; + // store decision of previous filter + bool previousFilterAccept(true); + for (size_t modIdx = 0; modIdx < nModulesInPath; ++modIdx) { + // each filter-bin is filled, with a 0 or 1, only when all previous filters in the Path have passed + if (not previousFilterAccept) { + break; + } + // consider only selected EDFilter modules + auto const& moduleLabel = hltConfigProvider_.moduleLabel(pathIndex, modIdx); + if (this->skipModuleByEDMType(hltConfigProvider_.moduleEDMType(moduleLabel)) or + this->skipModuleByType(hltConfigProvider_.moduleType(moduleLabel))) { + continue; + } + // index of module in this Path [0,nModulesInPath) + unsigned int const slotModule = hltConfigProvider_.moduleIndex(pathIndex, moduleLabel); + bool filterAccept = false; + if (slotModule < indexLastFilterInPath) { + filterAccept = true; + } else if (slotModule == indexLastFilterInPath) { + filterAccept = pathAccept; + } + LogTrace("HLTFiltersDQMonitor") + << "[HLTFiltersDQMonitor::analyze] " + << "HLTConfigProvider::moduleLabel(" << pathIndex << ", " << modIdx << ") = \"" << moduleLabel + << "\", HLTConfigProvider::moduleIndex(" << pathIndex << ", \"" << moduleLabel << "\") = " << slotModule + << ", filterAccept = " << filterAccept << ", previousFilterAccept = " << previousFilterAccept; + + auto const ibinKey = idset + "." + iPathName + "." + moduleLabel; if (binIndexMap_.find(ibinKey) == binIndexMap_.end()) { throw cms::Exception("HLTFiltersDQMonitorInvalidBinLabel") - << "invalid key for bin-index map (name of Path in Dataset ME): \"" << ibinKey << "\""; + << "invalid key for bin-index map (name of Module bin in MonitorElement of Path): \"" << ibinKey + << "\""; } auto const ibin = binIndexMap_[ibinKey]; - if (0 < ibin and ibin <= size_t(meDatasetProf->getNbinsX())) { - meDatasetProf->Fill(ibin - 0.5, pathAccept); - } - } - // fill MonitorElement: Path (bin: filter) - auto const mePathName(efficPlotNamePrefix_ + idset + "_" + iPathName); - if (mePathMap_.find(mePathName) != mePathMap_.end()) { - auto* const mePathProf(mePathMap_[mePathName]); - if (true) { - if (true) { - unsigned indexLastFilterPathModules(triggerResults->index(pathIndex) + 1); - LogTrace("") << "[HLTFiltersDQMonitor::analyze] " - << "indexLastFilterPathModules = " << indexLastFilterPathModules; - // identify module corresponding to last filter executed in the path - while (indexLastFilterPathModules > 0) { - --indexLastFilterPathModules; - const std::string& labelLastFilterPathModules( - hltConfigProvider_.moduleLabel(pathIndex, indexLastFilterPathModules)); - const uint indexLastFilterFilters = - useTriggerEventAOD - ? triggerEventAOD->filterIndex(edm::InputTag(labelLastFilterPathModules, "", processName_)) - : triggerEventRAW->filterIndex(edm::InputTag(labelLastFilterPathModules, "", processName_)); - LogTrace("") << "[HLTFiltersDQMonitor::analyze] " - << "indexLastFilterPathModules = " << indexLastFilterPathModules - << ", labelLastFilterPathModules = " << labelLastFilterPathModules - << ", indexLastFilterFilters = " << indexLastFilterFilters - << " (triggerEventSize = " << triggerEventSize << ")"; - if (indexLastFilterFilters < triggerEventSize) { - if (this->skipModuleByType(hltConfigProvider_.moduleType(labelLastFilterPathModules))) { - continue; - } - break; - } - } - // number of modules in the path - const unsigned sizeModulesPath(hltConfigProvider_.size(pathIndex)); - LogTrace("") << "[HLTFiltersDQMonitor::analyze] " - << "-> selected indexLastFilterPathModules = " << indexLastFilterPathModules - << " (HLTConfigProvider::size(" << pathIndex << ") = " << sizeModulesPath << ")"; - if (indexLastFilterPathModules >= sizeModulesPath) { - edm::LogError("Logic") << " selected index (" << indexLastFilterPathModules - << ") for last filter of path \"" << iPathName - << "\" is inconsistent with number of modules in the path (" << sizeModulesPath - << ")"; - continue; - } - // store decision of previous filter - bool previousFilterAccept(true); - for (size_t modIdx = 0; modIdx < sizeModulesPath; ++modIdx) { - // each filter-bin is filled, with a 0 or 1, only when all previous filters in the path have passed - if (not previousFilterAccept) { - break; - } - // consider only selected EDFilter modules - auto const& moduleLabel(hltConfigProvider_.moduleLabel(pathIndex, modIdx)); - if (this->skipModuleByEDMType(hltConfigProvider_.moduleEDMType(moduleLabel)) or - this->skipModuleByType(hltConfigProvider_.moduleType(moduleLabel))) { - continue; - } - // index of the module in the path [0,sizeModulesPath) - const unsigned slotModule(hltConfigProvider_.moduleIndex(pathIndex, moduleLabel)); - bool filterAccept(false); - if (slotModule < indexLastFilterPathModules) { - filterAccept = true; - } else if (slotModule == indexLastFilterPathModules) { - filterAccept = pathAccept; - } - LogTrace("") << "[HLTFiltersDQMonitor::analyze] " - << "HLTConfigProvider::moduleLabel(" << pathIndex << ", " << modIdx << ") = \"" - << moduleLabel << "\", HLTConfigProvider::moduleIndex(" << pathIndex << ", \"" - << moduleLabel << "\") = " << slotModule << ", filterAccept = " << filterAccept - << ", previousFilterAccept = " << previousFilterAccept; - - auto const ibinKey = idset + "." + iPathName + "." + moduleLabel; - if (binIndexMap_.find(ibinKey) == binIndexMap_.end()) { - throw cms::Exception("HLTFiltersDQMonitorInvalidBinLabel") - << "invalid key for bin-index map (name of Module in Path ME): \"" << ibinKey << "\""; - } - auto const ibin = binIndexMap_[ibinKey]; - if (0 < ibin and ibin <= size_t(mePathProf->getNbinsX())) { - mePathProf->Fill(ibin - 0.5, filterAccept); - } - previousFilterAccept = filterAccept; - } - } + if (0 < ibin and ibin <= size_t(mePathProf->getNbinsX())) { + mePathProf->Fill(ibin - 0.5, filterAccept); + } else { + edm::LogError("HLTFiltersDQMonitor") + << "out-of-range bin index of Module \"" << moduleLabel + << "\" in MonitorElement of Path \"iPathName\" in Dataset \"" << idset + << "\" (MonitorElement not filled): bin_key=\"" << ibinKey << "\", bin_index=" << ibin; } + previousFilterAccept = filterAccept; } } } } } -bool HLTFiltersDQMonitor::skipStreamByName(const std::string& streamName) const { - if ((streamName.find("Physics") != std::string::npos) || (streamName.find("Scouting") != std::string::npos) || - (streamName.find("Parking") != std::string::npos) || (streamName == "A")) { - return false; - } - return true; +bool HLTFiltersDQMonitor::skipStreamByName(std::string const& streamName) const { + return ((streamName.find("Physics") == std::string::npos) and (streamName.find("Scouting") == std::string::npos) and + (streamName.find("Parking") == std::string::npos) and (streamName != "A")); } -bool HLTFiltersDQMonitor::skipPathMonitorElement(const std::string& pathName) const { - if ((pathName.find("HLT_") == std::string::npos) || (pathName.find("HLT_Physics") != std::string::npos) || - (pathName.find("HLT_Random") != std::string::npos)) { - return true; - } - return false; +bool HLTFiltersDQMonitor::skipPathMonitorElement(std::string const& pathName) const { + return ((pathName.find("HLT_") == std::string::npos) or (pathName.find("HLT_Physics") != std::string::npos) or + (pathName.find("HLT_Random") != std::string::npos)); } -bool HLTFiltersDQMonitor::skipModuleByEDMType(const std::string& moduleEDMType) const { +bool HLTFiltersDQMonitor::skipModuleByEDMType(std::string const& moduleEDMType) const { return (moduleEDMType != "EDFilter"); } -bool HLTFiltersDQMonitor::skipModuleByType(const std::string& moduleType) const { return (moduleType == "HLTBool"); } +bool HLTFiltersDQMonitor::skipModuleByType(std::string const& moduleType) const { return (moduleType == "HLTBool"); } void HLTFiltersDQMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add("folderName", "HLT/Filters"); desc.add("efficPlotNamePrefix", "effic_"); desc.add("triggerResults", edm::InputTag("TriggerResults::HLT")); - desc.add("triggerSummaryAOD", edm::InputTag("hltTriggerSummaryAOD::HLT")); - desc.add("triggerSummaryRAW", edm::InputTag("hltTriggerSummaryRAW::HLT")); - descriptions.add("hltFiltersDQMonitor", desc); + desc.add("triggerEvent", edm::InputTag("hltTriggerSummaryAOD::HLT")); + desc.add("triggerEventWithRefs", edm::InputTag("hltTriggerSummaryRAW::HLT")); + descriptions.add("dqmHLTFiltersDQMonitor", desc); } DEFINE_FWK_MODULE(HLTFiltersDQMonitor); diff --git a/DQMOffline/Trigger/python/DQMOffline_Trigger_cff.py b/DQMOffline/Trigger/python/DQMOffline_Trigger_cff.py index 4db1eeac77bc8..0d4a2b40475b7 100644 --- a/DQMOffline/Trigger/python/DQMOffline_Trigger_cff.py +++ b/DQMOffline/Trigger/python/DQMOffline_Trigger_cff.py @@ -4,13 +4,13 @@ from DQM.HLTEvF.HLTObjectsMonitor_cfi import * # monitoring of efficiencies of HLT paths and filters -from DQMOffline.Trigger.hltFiltersDQMonitor_cfi import * -hltFiltersDQM = hltFiltersDQMonitor.clone( - folderName = 'HLT/Filters', - efficPlotNamePrefix = 'effic_', - triggerResults = 'TriggerResults::HLT', - triggerSummaryAOD = 'hltTriggerSummaryAOD::HLT', - triggerSummaryRAW = 'hltTriggerSummaryRAW::HLT', +from DQMOffline.Trigger.dqmHLTFiltersDQMonitor_cfi import dqmHLTFiltersDQMonitor as _dqmHLTFiltersDQMonitor +dqmHLTFiltersDQMonitor = _dqmHLTFiltersDQMonitor.clone( + folderName = 'HLT/Filters', + efficPlotNamePrefix = 'effic_', + triggerResults = 'TriggerResults::HLT', + triggerEvent = 'hltTriggerSummaryAOD::HLT', + triggerEventWithRefs = 'hltTriggerSummaryRAW::HLT' ) # Lumi @@ -121,7 +121,7 @@ ## ADD here sequences/modules which rely ONLY on collections stored in the AOD format offlineHLTSourceOnAOD = cms.Sequence( dqmEnvHLT - * hltFiltersDQM + * dqmHLTFiltersDQMonitor * lumiMonitorHLTsequence * muonFullOfflineDQM * HLTTauDQMOffline @@ -145,7 +145,7 @@ ## w/ the RECO step on-the-fly (to be added to offlineHLTSourceOnAOD which should run anyhow) offlineHLTSourceWithRECO = cms.Sequence( - hltFiltersDQM + dqmHLTFiltersDQMonitor * egHLTOffDQMSource ## NEEDED in VALIDATION, not really in MONITORING * egHLTOffDQMSource_HEP17 ## NEEDED in VALIDATION, not really in MONITORING * jetMETHLTOfflineAnalyzer diff --git a/DQMOffline/Trigger/python/DQMOffline_Trigger_cosmics_cff.py b/DQMOffline/Trigger/python/DQMOffline_Trigger_cosmics_cff.py index 35ed1de61bcc1..2c4898f836aac 100644 --- a/DQMOffline/Trigger/python/DQMOffline_Trigger_cosmics_cff.py +++ b/DQMOffline/Trigger/python/DQMOffline_Trigger_cosmics_cff.py @@ -33,7 +33,7 @@ #onlineHLTSource = cms.Sequence(EcalPi0Mon*EcalPhiSymMon*hltMonMuBits*dqmEnvHLTOnline) # HLT Offline ----------------------------------- -from DQMOffline.Trigger.hltFiltersDQMonitor_cfi import * +from DQMOffline.Trigger.dqmHLTFiltersDQMonitor_cfi import * # EGamma from DQMOffline.Trigger.EgHLTOfflineSource_cfi import * @@ -51,8 +51,9 @@ dqmEnvHLT= DQMServices.Components.DQMEnvironment_cfi.dqmEnv.clone( subSystemFolder = 'HLT' ) + offlineHLTSource = cms.Sequence( - hltFiltersDQMonitor * + dqmHLTFiltersDQMonitor * egHLTOffDQMSource * hltMuonOfflineAnalyzers * HLTTauDQMOffline * @@ -60,5 +61,5 @@ dqmEnvHLT ) -#triggerCosmicOfflineDQMSource = cms.Sequence(onlineHLTSource*offlineHLTSource) -triggerCosmicOfflineDQMSource = cms.Sequence(offlineHLTSource) +#triggerCosmicOfflineDQMSource = cms.Sequence(onlineHLTSource*offlineHLTSource) +triggerCosmicOfflineDQMSource = cms.Sequence(offlineHLTSource) diff --git a/DQMOffline/Trigger/python/HLT_DQM_Offline_cff.py b/DQMOffline/Trigger/python/HLT_DQM_Offline_cff.py index 749ad18606eba..ced6a88a33ba9 100644 --- a/DQMOffline/Trigger/python/HLT_DQM_Offline_cff.py +++ b/DQMOffline/Trigger/python/HLT_DQM_Offline_cff.py @@ -1,9 +1,9 @@ import FWCore.ParameterSet.Config as cms -from DQMOffline.Trigger.hltFiltersDQMonitor_cfi import * -hltFiltersDQMonitor.triggerSummaryAOD = 'hltTriggerSummaryAOD::HLT' -hltFiltersDQMonitor.triggerResults = 'TriggerResults::HLT' +from DQMOffline.Trigger.dqmHLTFiltersDQMonitor_cfi import * +dqmHLTFiltersDQMonitor.triggerEvent = 'hltTriggerSummaryAOD::HLT' +dqmHLTFiltersDQMonitor.triggerResults = 'TriggerResults::HLT' from DQMOffline.Trigger.HLTEventInfoClient_cfi import * -hltDqmOffline = cms.Sequence(hltFiltersDQMonitor*hltEventInfoClient) +hltDqmOffline = cms.Sequence( dqmHLTFiltersDQMonitor * hltEventInfoClient ) diff --git a/DQMOffline/Trigger/test/fv_dqmoffline_sourceclient-file_cfg.py b/DQMOffline/Trigger/test/fv_dqmoffline_sourceclient-file_cfg.py index 936a4283a89ce..7f3b973cd38a5 100644 --- a/DQMOffline/Trigger/test/fv_dqmoffline_sourceclient-file_cfg.py +++ b/DQMOffline/Trigger/test/fv_dqmoffline_sourceclient-file_cfg.py @@ -54,12 +54,12 @@ ############################### -# Only hltFiltersDQMonitor +# Only dqmHLTFiltersDQMonitor # ############################## # # Offline -process.pHLT = cms.Path(process.hltFiltersDQMonitor) +process.pHLT = cms.Path(process.dqmHLTFiltersDQMonitor) diff --git a/DQMOffline/Trigger/test/testHLTFiltersDQMonitor_cfg.py b/DQMOffline/Trigger/test/testHLTFiltersDQMonitor_cfg.py index 8b360ffc9b145..ab8404895ebfa 100644 --- a/DQMOffline/Trigger/test/testHLTFiltersDQMonitor_cfg.py +++ b/DQMOffline/Trigger/test/testHLTFiltersDQMonitor_cfg.py @@ -76,13 +76,13 @@ process.MessageLogger.FastReport = dict() ## EventData Modules -from DQMOffline.Trigger.hltFiltersDQMonitor_cfi import hltFiltersDQMonitor as _hltFiltersDQMonitor -process.dqmHLTFiltersDQMonitor = _hltFiltersDQMonitor.clone( +from DQMOffline.Trigger.dqmHLTFiltersDQMonitor_cfi import dqmHLTFiltersDQMonitor as _dqmHLTFiltersDQMonitor +process.dqmHLTFiltersDQMonitor = _dqmHLTFiltersDQMonitor.clone( folderName = 'HLT/Filters', efficPlotNamePrefix = 'effic_', triggerResults = 'TriggerResults::HLT', - triggerSummaryAOD = 'hltTriggerSummaryAOD::HLT', - triggerSummaryRAW = 'hltTriggerSummaryRAW::HLT' + triggerEvent = 'hltTriggerSummaryAOD::HLT', + triggerEventWithRefs = 'hltTriggerSummaryRAW::HLT' ) process.MessageLogger.HLTFiltersDQMonitor = dict() if args.debugMode: diff --git a/DQMOffline/Trigger/test/triggerSequenceTest_cfg.py b/DQMOffline/Trigger/test/triggerSequenceTest_cfg.py index 804b311118495..8517a4c4adbca 100644 --- a/DQMOffline/Trigger/test/triggerSequenceTest_cfg.py +++ b/DQMOffline/Trigger/test/triggerSequenceTest_cfg.py @@ -61,7 +61,7 @@ ) -process.p = cms.EndPath(process.hltFiltersDQMonitor) +process.p = cms.EndPath(process.dqmHLTFiltersDQMonitor) process.pp = cms.Path(process.dqmEnv+process.dqmSaver) process.DQMStore.verbose = 0 @@ -92,7 +92,7 @@ # # # copy stdout to a file # process.MessageLogger.detailedInfo = process.MessageLogger.cout -# process.MessageLogger.debugModules = ['hltFiltersDQMonitor'] +# process.MessageLogger.debugModules = ['dqmHLTFiltersDQMonitor'] # process.MessageLogger.critical = cms.untracked.PSet( # threshold = cms.untracked.string('ERROR'), # #threshold = cms.untracked.string('INFO'), diff --git a/DQMOffline/Trigger/test/trigger_dqmoffline_cfg.py b/DQMOffline/Trigger/test/trigger_dqmoffline_cfg.py index f3a5a7f57adc5..b08610eb8d61b 100644 --- a/DQMOffline/Trigger/test/trigger_dqmoffline_cfg.py +++ b/DQMOffline/Trigger/test/trigger_dqmoffline_cfg.py @@ -107,7 +107,7 @@ critical = cms.untracked.PSet( threshold = cms.untracked.string('ERROR') ), - debugModules = cms.untracked.vstring('hltFiltersDQMonitor'), + debugModules = cms.untracked.vstring('dqmHLTFiltersDQMonitor'), cout = cms.untracked.PSet( threshold = cms.untracked.string('WARNING'), WARNING = cms.untracked.PSet( @@ -132,7 +132,7 @@ process.allPath = cms.Path( process.triggerCosmicOfflineDQMSource * process.triggerOfflineDQMClient * process.hltOfflineDQMClient * process.dqmStoreStats ) #process.allPath = cms.Path( process.triggerCosmicOfflineDQMSource*process.hltOfflineDQMClient) #process.allPath = cms.Path( process.DQMOfflineCosmics) -#process.psource = cms.Path(process.hltFiltersDQMonitor) +#process.psource = cms.Path(process.dqmHLTFiltersDQMonitor) process.p = cms.EndPath(process.dqmSaver) process.DQMStore.verbose = 0 diff --git a/DQMOffline/Trigger/test/trigger_dqmoffline_sourceclient-file_cfg.py b/DQMOffline/Trigger/test/trigger_dqmoffline_sourceclient-file_cfg.py index a11a077afec0d..d0ce7f87a51d0 100644 --- a/DQMOffline/Trigger/test/trigger_dqmoffline_sourceclient-file_cfg.py +++ b/DQMOffline/Trigger/test/trigger_dqmoffline_sourceclient-file_cfg.py @@ -64,7 +64,7 @@ 'cout') ) -process.psource = cms.Path(process.hltFiltersDQMonitor) +process.psource = cms.Path(process.dqmHLTFiltersDQMonitor) process.p = cms.EndPath(process.dqmSaver) process.DQMStore.verbose = 0 process.DQM.collectorHost = '' diff --git a/DQMOffline/Trigger/test/trigger_dqmoffline_sourceclient_relval-file_cfg.py b/DQMOffline/Trigger/test/trigger_dqmoffline_sourceclient_relval-file_cfg.py index 0b3b996c36dfd..9e5d6d6136072 100644 --- a/DQMOffline/Trigger/test/trigger_dqmoffline_sourceclient_relval-file_cfg.py +++ b/DQMOffline/Trigger/test/trigger_dqmoffline_sourceclient_relval-file_cfg.py @@ -72,7 +72,7 @@ 'cout') ) -process.psource = cms.Path(process.hltFiltersDQMonitor) +process.psource = cms.Path(process.dqmHLTFiltersDQMonitor) process.p = cms.EndPath(process.dqmSaver) process.DQMStore.verbose = 0 process.DQM.collectorHost = '' diff --git a/DQMOffline/Trigger/test/trigger_dqmoffline_step2_cfg.py b/DQMOffline/Trigger/test/trigger_dqmoffline_step2_cfg.py index f2c2a8a65fd79..74bc26f68e1cb 100644 --- a/DQMOffline/Trigger/test/trigger_dqmoffline_step2_cfg.py +++ b/DQMOffline/Trigger/test/trigger_dqmoffline_step2_cfg.py @@ -55,7 +55,7 @@ # critical = cms.untracked.PSet( # threshold = cms.untracked.string('ERROR') # ), -# debugModules = cms.untracked.vstring('hltFiltersDQMonitor'), +# debugModules = cms.untracked.vstring('dqmHLTFiltersDQMonitor'), ##debugModules = cms.untracked.vstring('*'), # cout = cms.untracked.PSet( # threshold = cms.untracked.string('WARNING'), @@ -73,7 +73,7 @@ process.triggerOfflineDQMSource.remove(process.l1tcsctf) process.AllPath = cms.Path(process.triggerOfflineDQMSource * process.MEtoEDMConverter) -#process.AllPath = cms.Path(process.hltFiltersDQMonitor * process.MEtoEDMConverter) +#process.AllPath = cms.Path(process.dqmHLTFiltersDQMonitor * process.MEtoEDMConverter) process.outpath = cms.EndPath(process.EDM) From a6fe90eccaf3c0eb78dbe391a71a85a0184c1002 Mon Sep 17 00:00:00 2001 From: Marino Missiroli Date: Wed, 4 Jan 2023 18:54:05 +0100 Subject: [PATCH 4/4] avoid extra map searches in HLTFiltersDQMonitor --- .../Trigger/plugins/HLTFiltersDQMonitor.cc | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/DQMOffline/Trigger/plugins/HLTFiltersDQMonitor.cc b/DQMOffline/Trigger/plugins/HLTFiltersDQMonitor.cc index 0fa4b85c5b2ea..9b6072a607c7b 100644 --- a/DQMOffline/Trigger/plugins/HLTFiltersDQMonitor.cc +++ b/DQMOffline/Trigger/plugins/HLTFiltersDQMonitor.cc @@ -316,11 +316,12 @@ void HLTFiltersDQMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu continue; } - if (binIndexMap_.find(iPathName) == binIndexMap_.end()) { + auto const foundBin = binIndexMap_.find(iPathName); + if (foundBin == binIndexMap_.end()) { throw cms::Exception("HLTFiltersDQMonitorInvalidBinLabel") << "invalid key for bin-index map (name of Path bin in MonitorElement of HLT Menu): \"" << iPathName << "\""; } - auto const ibin = binIndexMap_[iPathName]; + auto const ibin = foundBin->second; if ((0 < ibin) and (ibin <= size_t(meMenu_->getNbinsX()))) { auto const pathAccept = triggerResults->accept(pathIndex); meMenu_->Fill(ibin - 0.5, pathAccept); @@ -378,12 +379,13 @@ void HLTFiltersDQMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu // consider only Datasets with a MonitorElement (see bookHistograms) auto const meDatasetName = efficPlotNamePrefix_ + idset; - if (meDatasetMap_.find(meDatasetName) == meDatasetMap_.end()) { + auto const meDatasetMapFindIt = meDatasetMap_.find(meDatasetName); + if (meDatasetMapFindIt == meDatasetMap_.end()) { LogDebug("HLTFiltersDQMonitor") << "No MonitorElement associated to Dataset \"" << idset << "\" in Stream \"" << istream << "\" (will be ignored)"; continue; } - MonitorElement* const meDatasetProf = meDatasetMap_[meDatasetName]; + MonitorElement* const meDatasetProf = meDatasetMapFindIt->second; // loop over Paths in PrimaryDataset auto const& dsetPathNames = hltConfigProvider_.datasetContent(idset); @@ -404,11 +406,12 @@ void HLTFiltersDQMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu // fill MonitorElement: PrimaryDataset (bin: Path) auto const ibinKey = idset + "." + iPathName; - if (binIndexMap_.find(ibinKey) == binIndexMap_.end()) { + auto const foundBin = binIndexMap_.find(ibinKey); + if (foundBin == binIndexMap_.end()) { throw cms::Exception("HLTFiltersDQMonitorInvalidBinLabel") << "invalid key for bin-index map (name of Path bin in MonitorElement of Dataset): \"" << ibinKey << "\""; } - auto const ibin = binIndexMap_[ibinKey]; + auto const ibin = foundBin->second; if (0 < ibin and ibin <= size_t(meDatasetProf->getNbinsX())) { meDatasetProf->Fill(ibin - 0.5, pathAccept); } else { @@ -421,13 +424,13 @@ void HLTFiltersDQMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu auto const mePathName = efficPlotNamePrefix_ + idset + "_" + iPathName; // consider only Paths with a MonitorElement - if (mePathMap_.find(mePathName) == mePathMap_.end()) { + auto const mePathMapFindIt = mePathMap_.find(mePathName); + if (mePathMapFindIt == mePathMap_.end()) { LogDebug("HLTFiltersDQMonitor") << "No MonitorElement associated to Path \"" << iPathName << "\" in Dataset \"" << idset << "\" (will be ignored)"; continue; } - - MonitorElement* const mePathProf = mePathMap_[mePathName]; + MonitorElement* const mePathProf = mePathMapFindIt->second; unsigned int indexLastFilterInPath = triggerResults->index(pathIndex) + 1; LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze] " @@ -491,12 +494,13 @@ void HLTFiltersDQMonitor::analyze(const edm::Event& iEvent, const edm::EventSetu << ", filterAccept = " << filterAccept << ", previousFilterAccept = " << previousFilterAccept; auto const ibinKey = idset + "." + iPathName + "." + moduleLabel; - if (binIndexMap_.find(ibinKey) == binIndexMap_.end()) { + auto const foundBin = binIndexMap_.find(ibinKey); + if (foundBin == binIndexMap_.end()) { throw cms::Exception("HLTFiltersDQMonitorInvalidBinLabel") << "invalid key for bin-index map (name of Module bin in MonitorElement of Path): \"" << ibinKey << "\""; } - auto const ibin = binIndexMap_[ibinKey]; + auto const ibin = foundBin->second; if (0 < ibin and ibin <= size_t(mePathProf->getNbinsX())) { mePathProf->Fill(ibin - 0.5, filterAccept); } else {