diff --git a/Alignment/OfflineValidation/plugins/EopElecTreeWriter.cc b/Alignment/OfflineValidation/plugins/EopElecTreeWriter.cc index 67ff870c9ed5e..8a1b742ef4835 100644 --- a/Alignment/OfflineValidation/plugins/EopElecTreeWriter.cc +++ b/Alignment/OfflineValidation/plugins/EopElecTreeWriter.cc @@ -83,7 +83,7 @@ struct EopTriggerType { bool fired; - int prescale; + double prescale; int index; EopTriggerType() { @@ -411,7 +411,7 @@ void EopElecTreeWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& const unsigned int prescaleSize = hltConfig_.prescaleSize(); for (unsigned int ps = 0; ps < prescaleSize; ps++) { - const unsigned int prescaleValue = hltConfig_.prescaleValue(ps, triggerName); + auto const prescaleValue = hltConfig_.prescaleValue(ps, triggerName); if (prescaleValue != 1) { myTrigger.prescale = prescaleValue; } diff --git a/Calibration/HcalCalibAlgos/test/GammaJetAnalysis.cc b/Calibration/HcalCalibAlgos/test/GammaJetAnalysis.cc index 90845b38e06d3..554afc738f60c 100644 --- a/Calibration/HcalCalibAlgos/test/GammaJetAnalysis.cc +++ b/Calibration/HcalCalibAlgos/test/GammaJetAnalysis.cc @@ -245,9 +245,9 @@ class GammaJetAnalysis : public edm::one::EDAnalyzer photonTrigFired_; - std::vector photonTrigPrescale_; + std::vector photonTrigPrescale_; std::vector jetTrigFired_; - std::vector jetTrigPrescale_; + std::vector jetTrigPrescale_; // Event info int runNumber_, lumiBlock_, eventNumber_; @@ -782,8 +782,8 @@ void GammaJetAnalysis::analyze(const edm::Event& iEvent, const edm::EventSetup& photonTrigPrescale_.push_back(-1); else { // for triggers with two L1 seeds this fails - std::pair prescaleVals = - hltPrescaleProvider_.prescaleValues(iEvent, evSetup, evTrigNames.triggerName(id)); + auto const prescaleVals = + hltPrescaleProvider_.prescaleValues(iEvent, evSetup, evTrigNames.triggerName(id)); photonTrigPrescale_.push_back(prescaleVals.first * prescaleVals.second); } } @@ -799,8 +799,8 @@ void GammaJetAnalysis::analyze(const edm::Event& iEvent, const edm::EventSetup& if (fired) jetTrigFlag = true; jetTrigFired_.push_back(fired); - std::pair prescaleVals = - hltPrescaleProvider_.prescaleValues(iEvent, evSetup, evTrigNames.triggerName(id)); + auto const prescaleVals = + hltPrescaleProvider_.prescaleValues(iEvent, evSetup, evTrigNames.triggerName(id)); jetTrigPrescale_.push_back(prescaleVals.first * prescaleVals.second); } } diff --git a/Calibration/IsolatedParticles/plugins/IsoTrig.cc b/Calibration/IsolatedParticles/plugins/IsoTrig.cc index 9bc9a7e3cbd7d..c4f467db60b1f 100644 --- a/Calibration/IsolatedParticles/plugins/IsoTrig.cc +++ b/Calibration/IsolatedParticles/plugins/IsoTrig.cc @@ -18,6 +18,7 @@ // system include files #include +#include // Root objects #include "TROOT.h" @@ -198,8 +199,8 @@ class IsoTrig : public edm::one::EDAnalyzer trigList_; - std::map> trigPreList_; + std::unordered_map trigList_; + std::unordered_map> trigPreList_; bool changed_; double pLimits_[6]; edm::Service fs_; @@ -263,7 +264,8 @@ class IsoTrig : public edm::one::EDAnalyzer vec_[3]; }; @@ -660,7 +662,8 @@ void IsoTrig::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) { const std::vector &triggerNames_ = triggerNames.triggerNames(); if (verbosity_ % 10 > 1) edm::LogVerbatim("IsoTrack") << "number of HLTs " << triggerNames_.size(); - int hlt(-1), preL1(-1), preHLT(-1), prescale(-1); + double preL1(-1), preHLT(-1), prescale(-1); + int hlt(-1); for (unsigned int i = 0; i < triggerResults->size(); i++) { unsigned int triggerindx = hltConfig.triggerIndex(triggerNames_[i]); const std::vector &moduleLabels(hltConfig.moduleLabels(triggerindx)); @@ -680,7 +683,7 @@ void IsoTrig::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) { edm::Handle L1cands; iEvent.getByToken(tok_l1cand_, L1cands); - const std::pair prescales(hltPrescaleProvider_.prescaleValues(iEvent, iSetup, triggerNames_[i])); + auto const prescales = hltPrescaleProvider_.prescaleValues(iEvent, iSetup, triggerNames_[i]); preL1 = prescales.first; preHLT = prescales.second; prescale = preL1 * preHLT; @@ -692,8 +695,8 @@ void IsoTrig::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) { if (trigList_.find(RunNo) != trigList_.end()) { trigList_[RunNo] += 1; } else { - trigList_.insert(std::pair(RunNo, 1)); - trigPreList_.insert(std::pair>(RunNo, prescales)); + trigList_.insert({RunNo, 1}); + trigPreList_.insert({RunNo, prescales}); } //loop over all trigger filters in event (i.e. filters passed) for (unsigned int ifilter = 0; ifilter < triggerEvent.sizeFilters(); ++ifilter) { @@ -1174,27 +1177,24 @@ void IsoTrig::beginJob() { // ------------ method called once each job just after ending the event loop ------------ void IsoTrig::endJob() { - unsigned int preL1, preHLT; - std::map::iterator itr; - std::map>::iterator itrPre; edm::LogWarning("IsoTrack") << trigNames_.size() << "Triggers were run. RunNo vs HLT accepts for"; for (unsigned int i = 0; i < trigNames_.size(); ++i) edm::LogWarning("IsoTrack") << "[" << i << "]: " << trigNames_[i]; unsigned int n = maxRunNo_ - minRunNo_ + 1; - g_Pre = fs_->make("h_PrevsRN", "PreScale Vs Run Number", n, minRunNo_, maxRunNo_); - g_PreL1 = fs_->make("h_PreL1vsRN", "L1 PreScale Vs Run Number", n, minRunNo_, maxRunNo_); - g_PreHLT = fs_->make("h_PreHLTvsRN", "HLT PreScale Vs Run Number", n, minRunNo_, maxRunNo_); + g_Pre = fs_->make("h_PrevsRN", "PreScale Vs Run Number", n, minRunNo_, maxRunNo_); + g_PreL1 = fs_->make("h_PreL1vsRN", "L1 PreScale Vs Run Number", n, minRunNo_, maxRunNo_); + g_PreHLT = fs_->make("h_PreHLTvsRN", "HLT PreScale Vs Run Number", n, minRunNo_, maxRunNo_); g_Accepts = fs_->make("h_HLTAcceptsvsRN", "HLT Accepts Vs Run Number", n, minRunNo_, maxRunNo_); - for (itr = trigList_.begin(), itrPre = trigPreList_.begin(); itr != trigList_.end(); itr++, itrPre++) { - preL1 = (itrPre->second).first; - preHLT = (itrPre->second).second; - edm::LogVerbatim("IsoTrack") << itr->first << " " << itr->second << " " << itrPre->first << " " << preL1 << " " - << preHLT; - g_Accepts->Fill(itr->first, itr->second); - g_PreL1->Fill(itr->first, preL1); - g_PreHLT->Fill(itr->first, preHLT); - g_Pre->Fill(itr->first, preL1 * preHLT); + for (auto const &[runNum, nAccept] : trigList_) { + auto const &triggerPrescales = trigPreList_[runNum]; + auto const preL1 = triggerPrescales.first; + auto const preHLT = triggerPrescales.second; + edm::LogVerbatim("IsoTrack") << runNum << " " << nAccept << " " << preL1 << " " << preHLT; + g_Accepts->Fill(runNum, nAccept); + g_PreL1->Fill(runNum, preL1); + g_PreHLT->Fill(runNum, preHLT); + g_Pre->Fill(runNum, preL1 * preHLT); } } diff --git a/CommonTools/TriggerUtils/interface/PrescaleWeightProvider.h b/CommonTools/TriggerUtils/interface/PrescaleWeightProvider.h index 3b8773ff6057c..7abad1fd180d5 100644 --- a/CommonTools/TriggerUtils/interface/PrescaleWeightProvider.h +++ b/CommonTools/TriggerUtils/interface/PrescaleWeightProvider.h @@ -6,7 +6,7 @@ // Package: CommonTools/TriggerUtils // Class: PrescaleWeightProvider // -/** +/* \class PrescaleWeightProvider PrescaleWeightProvider.h "CommonTools/TriggerUtils/interface/PrescaleWeightProvider.h" \brief @@ -14,13 +14,13 @@ HLT and L1 prescales. The weight is equal to the lowest combined (L1*HLT) prescale of the selected paths - \author Aram Avetisyan */ #include #include #include +#include #include "DataFormats/Common/interface/Handle.h" @@ -28,6 +28,7 @@ #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/Framework/interface/ConsumesCollector.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/EDGetToken.h" #include "FWCore/Utilities/interface/InputTag.h" @@ -72,8 +73,10 @@ class PrescaleWeightProvider { // to be called from the ED module's beginRun() method void initRun(const edm::Run& run, const edm::EventSetup& setup); + // to be called from the ED module's event loop method - int prescaleWeight(const edm::Event& event, const edm::EventSetup& setup); + template + T prescaleWeight(const edm::Event& event, const edm::EventSetup& setup); private: PrescaleWeightProvider(const edm::ParameterSet& config, edm::ConsumesCollector& iC); @@ -90,4 +93,113 @@ PrescaleWeightProvider::PrescaleWeightProvider(const edm::ParameterSet& config, : PrescaleWeightProvider(config, iC) { hltPrescaleProvider_ = std::make_unique(config, iC, module); } -#endif + +template +T PrescaleWeightProvider::prescaleWeight(const edm::Event& event, const edm::EventSetup& setup) { + static_assert(std::is_same_v or std::is_same_v, + "\n\tPlease use prescaleWeight or prescaleWeight" + "\n\t(other types for HLT prescales are not supported anymore by PrescaleWeightProvider"); + if (!init_) + return 1; + + // L1 + L1GtUtils const& l1GtUtils = hltPrescaleProvider_->l1GtUtils(); + + // HLT + HLTConfigProvider const& hltConfig = hltPrescaleProvider_->hltConfigProvider(); + + edm::Handle triggerResults; + event.getByToken(triggerResultsToken_, triggerResults); + if (!triggerResults.isValid()) { + if (verbosity_ > 0) + edm::LogError("PrescaleWeightProvider::prescaleWeight") + << "TriggerResults product not found for InputTag \"" << triggerResultsTag_.encode() << "\""; + return 1; + } + + const int SENTINEL(-1); + int weight(SENTINEL); + + for (unsigned ui = 0; ui < hltPaths_.size(); ui++) { + const std::string hltPath(hltPaths_.at(ui)); + unsigned hltIndex(hltConfig.triggerIndex(hltPath)); + if (hltIndex == hltConfig.size()) { + if (verbosity_ > 0) + edm::LogError("PrescaleWeightProvider::prescaleWeight") << "HLT path \"" << hltPath << "\" does not exist"; + continue; + } + if (!triggerResults->accept(hltIndex)) + continue; + + const std::vector >& level1Seeds = hltConfig.hltL1GTSeeds(hltPath); + if (level1Seeds.size() != 1) { + if (verbosity_ > 0) + edm::LogError("PrescaleWeightProvider::prescaleWeight") + << "HLT path \"" << hltPath << "\" provides too many L1 seeds"; + return 1; + } + parseL1Seeds(level1Seeds.at(0).second); + if (l1SeedPaths_.empty()) { + if (verbosity_ > 0) + edm::LogWarning("PrescaleWeightProvider::prescaleWeight") + << "Failed to parse L1 seeds for HLT path \"" << hltPath << "\""; + continue; + } + + int l1Prescale(SENTINEL); + for (unsigned uj = 0; uj < l1SeedPaths_.size(); uj++) { + int l1TempPrescale(SENTINEL); + int errorCode(0); + if (level1Seeds.at(0).first) { // technical triggers + unsigned techBit(atoi(l1SeedPaths_.at(uj).c_str())); + const std::string techName(*(triggerMenuLite_->gtTechTrigName(techBit, errorCode))); + if (errorCode != 0) + continue; + if (!l1GtUtils.decision(event, techName, errorCode)) + continue; + if (errorCode != 0) + continue; + l1TempPrescale = l1GtUtils.prescaleFactor(event, techName, errorCode); + if (errorCode != 0) + continue; + } else { // algorithmic triggers + if (!l1GtUtils.decision(event, l1SeedPaths_.at(uj), errorCode)) + continue; + if (errorCode != 0) + continue; + l1TempPrescale = l1GtUtils.prescaleFactor(event, l1SeedPaths_.at(uj), errorCode); + if (errorCode != 0) + continue; + } + if (l1TempPrescale > 0) { + if (l1Prescale == SENTINEL || l1Prescale > l1TempPrescale) + l1Prescale = l1TempPrescale; + } + } + if (l1Prescale == SENTINEL) { + if (verbosity_ > 0) + edm::LogError("PrescaleWeightProvider::prescaleWeight") + << "Unable to find the L1 prescale for HLT path \"" << hltPath << "\""; + continue; + } + + auto const prescale = l1Prescale * hltPrescaleProvider_->prescaleValue(event, setup, hltPath); + + if (prescale > 0) { + if (weight == SENTINEL || weight > prescale) { + weight = prescale; + } + } + } + + if (weight == SENTINEL) { + if (verbosity_ > 0) + edm::LogWarning("PrescaleWeightProvider::prescaleWeight") + << "No valid weight for any requested HLT path, returning default weight of 1"; + return 1; + } + + return weight; +} + +#endif // CommonTools_TriggerUtils_PrescaleWeightProvider_h diff --git a/CommonTools/TriggerUtils/plugins/CandidateTriggerObjectProducer.cc b/CommonTools/TriggerUtils/plugins/CandidateTriggerObjectProducer.cc index 611945665931a..7a6665fa39c6e 100644 --- a/CommonTools/TriggerUtils/plugins/CandidateTriggerObjectProducer.cc +++ b/CommonTools/TriggerUtils/plugins/CandidateTriggerObjectProducer.cc @@ -88,8 +88,8 @@ void CandidateTriggerObjectProducer::produce(edm::Event& iEvent, const edm::Even //matching with regexp filter name. More than 1 matching filter is allowed if (TString(*iHLT).Contains(TRegexp(TString(triggerName_)))) { triggerInMenu[*iHLT] = true; - const std::pair prescales(hltPrescaleProvider_.prescaleValues(iEvent, iSetup, *iHLT)); - if (prescales.first * prescales.second == 1) + auto const prescales = hltPrescaleProvider_.prescaleValues(iEvent, iSetup, *iHLT); + if (prescales.first == 1 and prescales.second == 1) triggerUnprescaled[*iHLT] = true; } } diff --git a/CommonTools/TriggerUtils/src/PrescaleWeightProvider.cc b/CommonTools/TriggerUtils/src/PrescaleWeightProvider.cc index 3b1352a610621..f75403aec0930 100644 --- a/CommonTools/TriggerUtils/src/PrescaleWeightProvider.cc +++ b/CommonTools/TriggerUtils/src/PrescaleWeightProvider.cc @@ -11,7 +11,6 @@ #include "DataFormats/Common/interface/TriggerResults.h" #include "DataFormats/L1GlobalTrigger/interface/L1GtTriggerMenuLite.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Utilities/interface/BranchType.h" @@ -94,109 +93,6 @@ void PrescaleWeightProvider::initRun(const edm::Run& run, const edm::EventSetup& } } -int PrescaleWeightProvider::prescaleWeight(const edm::Event& event, const edm::EventSetup& setup) { - if (!init_) - return 1; - - // L1 - L1GtUtils const& l1GtUtils = hltPrescaleProvider_->l1GtUtils(); - - // HLT - HLTConfigProvider const& hltConfig = hltPrescaleProvider_->hltConfigProvider(); - - edm::Handle triggerResults; - event.getByToken(triggerResultsToken_, triggerResults); - if (!triggerResults.isValid()) { - if (verbosity_ > 0) - edm::LogError("PrescaleWeightProvider::prescaleWeight") - << "TriggerResults product not found for InputTag \"" << triggerResultsTag_.encode() << "\""; - return 1; - } - - const int SENTINEL(-1); - int weight(SENTINEL); - - for (unsigned ui = 0; ui < hltPaths_.size(); ui++) { - const std::string hltPath(hltPaths_.at(ui)); - unsigned hltIndex(hltConfig.triggerIndex(hltPath)); - if (hltIndex == hltConfig.size()) { - if (verbosity_ > 0) - edm::LogError("PrescaleWeightProvider::prescaleWeight") << "HLT path \"" << hltPath << "\" does not exist"; - continue; - } - if (!triggerResults->accept(hltIndex)) - continue; - - const std::vector >& level1Seeds = hltConfig.hltL1GTSeeds(hltPath); - if (level1Seeds.size() != 1) { - if (verbosity_ > 0) - edm::LogError("PrescaleWeightProvider::prescaleWeight") - << "HLT path \"" << hltPath << "\" provides too many L1 seeds"; - return 1; - } - parseL1Seeds(level1Seeds.at(0).second); - if (l1SeedPaths_.empty()) { - if (verbosity_ > 0) - edm::LogWarning("PrescaleWeightProvider::prescaleWeight") - << "Failed to parse L1 seeds for HLT path \"" << hltPath << "\""; - continue; - } - - int l1Prescale(SENTINEL); - for (unsigned uj = 0; uj < l1SeedPaths_.size(); uj++) { - int l1TempPrescale(SENTINEL); - int errorCode(0); - if (level1Seeds.at(0).first) { // technical triggers - unsigned techBit(atoi(l1SeedPaths_.at(uj).c_str())); - const std::string techName(*(triggerMenuLite_->gtTechTrigName(techBit, errorCode))); - if (errorCode != 0) - continue; - if (!l1GtUtils.decision(event, techName, errorCode)) - continue; - if (errorCode != 0) - continue; - l1TempPrescale = l1GtUtils.prescaleFactor(event, techName, errorCode); - if (errorCode != 0) - continue; - } else { // algorithmic triggers - if (!l1GtUtils.decision(event, l1SeedPaths_.at(uj), errorCode)) - continue; - if (errorCode != 0) - continue; - l1TempPrescale = l1GtUtils.prescaleFactor(event, l1SeedPaths_.at(uj), errorCode); - if (errorCode != 0) - continue; - } - if (l1TempPrescale > 0) { - if (l1Prescale == SENTINEL || l1Prescale > l1TempPrescale) - l1Prescale = l1TempPrescale; - } - } - if (l1Prescale == SENTINEL) { - if (verbosity_ > 0) - edm::LogError("PrescaleWeightProvider::prescaleWeight") - << "Unable to find the L1 prescale for HLT path \"" << hltPath << "\""; - continue; - } - - int hltPrescale(hltPrescaleProvider_->prescaleValue(event, setup, hltPath)); - - if (hltPrescale * l1Prescale > 0) { - if (weight == SENTINEL || weight > hltPrescale * l1Prescale) { - weight = hltPrescale * l1Prescale; - } - } - } - - if (weight == SENTINEL) { - if (verbosity_ > 0) - edm::LogWarning("PrescaleWeightProvider::prescaleWeight") - << "No valid weight for any requested HLT path, returning default weight of 1"; - return 1; - } - return weight; -} - void PrescaleWeightProvider::parseL1Seeds(const std::string& l1Seeds) { l1SeedPaths_.clear(); std::stringstream ss(l1Seeds); diff --git a/DPGAnalysis/Skims/interface/TriggerMatchProducer.h b/DPGAnalysis/Skims/interface/TriggerMatchProducer.h index 1d7f62ffa77a2..043112e6b2d63 100644 --- a/DPGAnalysis/Skims/interface/TriggerMatchProducer.h +++ b/DPGAnalysis/Skims/interface/TriggerMatchProducer.h @@ -139,7 +139,7 @@ void TriggerMatchProducer::produce(edm::Event& event, const edm::EventSe if (TString(*iHLT).Contains(TRegexp(hltTag_))) { triggerInMenu[*iHLT] = true; - if (hltPrescaleProvider_.prescaleValue(event, eventSetup, *iHLT) == 1) + if (hltPrescaleProvider_.prescaleValue(event, eventSetup, *iHLT) == 1) triggerUnprescaled[*iHLT] = true; } } diff --git a/DQM/Physics/src/EwkMuLumiMonitorDQM.cc b/DQM/Physics/src/EwkMuLumiMonitorDQM.cc index a2f73820ed250..995d23beb23cb 100644 --- a/DQM/Physics/src/EwkMuLumiMonitorDQM.cc +++ b/DQM/Physics/src/EwkMuLumiMonitorDQM.cc @@ -235,11 +235,8 @@ void EwkMuLumiMonitorDQM::analyze(const Event& ev, const EventSetup&) { bool prescaled = false; const unsigned int prescaleSize = hltConfigProvider_.prescaleSize(); for (unsigned int ps = 0; ps < prescaleSize; ps++) { - const unsigned int prescaleValue = hltConfigProvider_.prescaleValue(ps, trig); - if (prescaleValue != 1) + if (hltConfigProvider_.prescaleValue(ps, trig) != 1) prescaled = true; - // std::cout<< " prescaleValue[" << ps << "] =" << prescaleValue - //< theSame_den; std::vector theSame_num; - //retrieving HLT prescale - PrescaleHLT_den = (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath)).second; - PrescaleHLT_num = (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath1)).second; + // object holding L1T (double) and HLT (uint) prescales + auto const prescales_den = hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath); + auto const prescales_num = hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath1); + // retrieving HLT prescale + auto PrescaleHLT_den = prescales_den.second; + auto PrescaleHLT_num = prescales_num.second; if (PrescaleHLT_den > 0 && PrescaleHLT_num > 0) - HLTP = PrescaleHLT_num / std::__gcd(PrescaleHLT_num, PrescaleHLT_den); + HLTP = PrescaleHLT_num / std::min(PrescaleHLT_num, PrescaleHLT_den); //retrieving L1 prescale //Checking if we have the same l1 seeds in den and num @@ -1376,18 +1377,16 @@ double BPHMonitor::Prescale(const std::string hltpath1, //and some of them can be also switched off //check if for each den l1 there is the same l1 seed in num - if (!(hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath)).first.empty()) { - for (size_t iSeed = 0; iSeed < (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath)).first.size(); - ++iSeed) { - std::string l1_den = (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath)).first.at(iSeed).first; - int l1_denp = (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath)).first.at(iSeed).second; + if (not prescales_den.first.empty()) { + for (size_t iSeed = 0; iSeed < prescales_den.first.size(); ++iSeed) { + auto l1_den = prescales_den.first.at(iSeed).first; + auto l1_denp = prescales_den.first.at(iSeed).second; if (l1_denp < 1) continue; flag = false; - for (size_t iSeed1 = 0; iSeed1 < (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath1)).first.size(); - ++iSeed1) { - std::string l1_num = (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath1)).first.at(iSeed1).first; - int l1_nump = (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath1)).first.at(iSeed1).second; + for (size_t iSeed1 = 0; iSeed1 < prescales_num.first.size(); ++iSeed1) { + auto l1_num = prescales_num.first.at(iSeed1).first; + auto l1_nump = prescales_num.first.at(iSeed1).second; if (l1_num == l1_den && l1_nump >= 1) //the same seed { flag = true; @@ -1398,18 +1397,16 @@ double BPHMonitor::Prescale(const std::string hltpath1, } } //check if for each num l1 there is the same l1 seed in den - if (!(hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath1)).first.empty()) { - for (size_t iSeed = 0; iSeed < (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath1)).first.size(); - ++iSeed) { - std::string l1_num = (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath1)).first.at(iSeed).first; - int l1_nump = (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath1)).first.at(iSeed).second; + if (not prescales_num.first.empty()) { + for (size_t iSeed = 0; iSeed < prescales_num.first.size(); ++iSeed) { + auto l1_num = prescales_num.first.at(iSeed).first; + auto l1_nump = prescales_num.first.at(iSeed).second; if (l1_nump < 1) continue; flag = false; - for (size_t iSeed1 = 0; iSeed1 < (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath)).first.size(); - ++iSeed1) { - std::string l1_den = (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath)).first.at(iSeed1).first; - int l1_denp = (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath)).first.at(iSeed1).second; + for (size_t iSeed1 = 0; iSeed1 < prescales_den.first.size(); ++iSeed1) { + auto l1_den = prescales_den.first.at(iSeed1).first; + auto l1_denp = prescales_den.first.at(iSeed1).second; if (l1_den == l1_num && l1_denp >= 1) //the same seed { flag = true; @@ -1433,11 +1430,10 @@ double BPHMonitor::Prescale(const std::string hltpath1, if (flag && (theSame_num.size() == theSame_den.size())) { L1P = 1; //den and num have the same set of l1 seeds } else { - if (!(hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath1)).first.empty()) { + if (not prescales_num.first.empty()) { Prescale_num = 1; - for (size_t iSeed = 0; iSeed < (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath1)).first.size(); - ++iSeed) { - int l1 = (hltPrescale_->prescaleValuesInDetail(iEvent, iSetup, hltpath1)).first.at(iSeed).second; + for (size_t iSeed = 0; iSeed < prescales_num.first.size(); ++iSeed) { + auto l1 = prescales_num.first.at(iSeed).second; if (l1 < 1) continue; if (l1 == 1) { diff --git a/DataFormats/PatCandidates/interface/PackedTriggerPrescales.h b/DataFormats/PatCandidates/interface/PackedTriggerPrescales.h index 6ab787115f150..35f72640f07e5 100644 --- a/DataFormats/PatCandidates/interface/PackedTriggerPrescales.h +++ b/DataFormats/PatCandidates/interface/PackedTriggerPrescales.h @@ -1,8 +1,11 @@ -#ifndef _DataFormats_PatCandidates_PackedTriggerPrescales_H_ -#define _DataFormats_PatCandidates_PackedTriggerPrescales_H_ +#ifndef DataFormats_PatCandidates_PackedTriggerPrescales_h +#define DataFormats_PatCandidates_PackedTriggerPrescales_h + +#include +#include -#include "DataFormats/Common/interface/TriggerResults.h" #include "FWCore/Common/interface/TriggerNames.h" +#include "DataFormats/Common/interface/TriggerResults.h" #include "DataFormats/Common/interface/Ref.h" namespace pat { @@ -11,12 +14,19 @@ namespace pat { public: PackedTriggerPrescales() : triggerNames_(nullptr) {} PackedTriggerPrescales(const edm::Handle &handle); - ~PackedTriggerPrescales() {} + ~PackedTriggerPrescales() = default; + + // get prescale by index + // method templated to force correct choice of output type + // (as part of deprecating integer types for trigger prescales) + template + T getPrescaleForIndex(int index) const; - // get prescale by index. - int getPrescaleForIndex(int index) const; // get prescale by name or name prefix (if setTriggerNames was called) - int getPrescaleForName(const std::string &name, bool prefixOnly = false) const; + // method templated to force correct choice of output type + // (as part of deprecating integer types for trigger prescales) + template + T getPrescaleForName(const std::string &name, bool prefixOnly = false) const; // return the TriggerResults associated with this const edm::TriggerResults &triggerResults() const { return *edm::getProduct(triggerResults_); } @@ -26,14 +36,51 @@ namespace pat { void setTriggerNames(const edm::TriggerNames &names) { triggerNames_ = &names; } // set that the trigger of given index has a given prescale - void addPrescaledTrigger(int index, int prescale); + void addPrescaledTrigger(int index, double prescale); protected: - std::vector prescaleValues_; + std::vector prescaleValues_; edm::RefCore triggerResults_; const edm::TriggerNames *triggerNames_; }; + template + T PackedTriggerPrescales::getPrescaleForIndex(int index) const { + static_assert(std::is_same_v, + "\n\n\tPlease use getPrescaleForIndex " + "(other types for trigger prescales are not supported anymore by PackedTriggerPrescales)"); + if (unsigned(index) >= triggerResults().size()) + throw cms::Exception("InvalidReference", "Index out of bounds"); + return prescaleValues_[index]; + } + + template + T PackedTriggerPrescales::getPrescaleForName(const std::string &name, bool prefixOnly) const { + static_assert(std::is_same_v, + "\n\n\tPlease use getPrescaleForName " + "(other types for trigger prescales are not supported anymore by PackedTriggerPrescales)"); + if (triggerNames_ == nullptr) + throw cms::Exception("LogicError", "getPrescaleForName called without having called setTriggerNames first"); + if (prefixOnly) { + auto const &names = triggerNames_->triggerNames(); + if (name.empty()) + throw cms::Exception("EmptyName", + "getPrescaleForName called with invalid arguments (name is empty, prefixOnly=true"); + size_t siz = name.length() - 1; + while (siz > 0 && (name[siz] == '*' || name[siz] == '\0')) + siz--; + for (unsigned int i = 0, n = names.size(); i < n; ++i) { + if (strncmp(name.c_str(), names[i].c_str(), siz) == 0) { + return getPrescaleForIndex(i); + } + } + throw cms::Exception("InvalidReference", "Index out of bounds"); + } else { + int index = triggerNames_->triggerIndex(name); + return getPrescaleForIndex(index); + } + } + } // namespace pat -#endif +#endif // DataFormats_PatCandidates_PackedTriggerPrescales_h diff --git a/DataFormats/PatCandidates/interface/TriggerPath.h b/DataFormats/PatCandidates/interface/TriggerPath.h index d04226ec6946f..2a85dc49682e9 100644 --- a/DataFormats/PatCandidates/interface/TriggerPath.h +++ b/DataFormats/PatCandidates/interface/TriggerPath.h @@ -7,7 +7,7 @@ // Class: pat::TriggerPath // // -/** +/* \class pat::TriggerPath TriggerPath.h "DataFormats/PatCandidates/interface/TriggerPath.h" \brief Analysis-level HLTrigger path class @@ -20,6 +20,7 @@ #include #include +#include #include "DataFormats/Common/interface/Ref.h" #include "DataFormats/Common/interface/RefProd.h" @@ -41,7 +42,7 @@ namespace pat { /// Path index in trigger table unsigned index_; /// Pre-scale - unsigned prescale_; + double prescale_; /// Was path run? bool run_; /// Did path succeed? @@ -76,7 +77,7 @@ namespace pat { /// Constructor from values TriggerPath(const std::string& name, unsigned index, - unsigned prescale, + double prescale, bool run, bool accept, bool error, @@ -84,7 +85,7 @@ namespace pat { unsigned l3Filters = 0); /// Destructor - virtual ~TriggerPath(){}; + virtual ~TriggerPath() = default; /// Methods @@ -93,7 +94,7 @@ namespace pat { /// Set the path index void setIndex(unsigned index) { index_ = index; }; /// Set the path pre-scale - void setPrescale(unsigned prescale) { prescale_ = prescale; }; + void setPrescale(double prescale) { prescale_ = prescale; }; /// Set the run flag void setRun(bool run) { run_ = run; }; /// Set the success flag @@ -116,7 +117,13 @@ namespace pat { /// Get the path index unsigned index() const { return index_; }; /// Get the path pre-scale - unsigned prescale() const { return prescale_; }; + template + T prescale() const { + static_assert(std::is_same_v, + "\n\tPlease use prescale" + "\n\t(other types for prescales are not supported anymore by pat::TriggerPath"); + return prescale_; + }; /// Get the run flag bool wasRun() const { return run_; }; /// Get the success flag diff --git a/DataFormats/PatCandidates/src/PackedTriggerPrescales.cc b/DataFormats/PatCandidates/src/PackedTriggerPrescales.cc index f78a940ae1e1c..070af058a105b 100644 --- a/DataFormats/PatCandidates/src/PackedTriggerPrescales.cc +++ b/DataFormats/PatCandidates/src/PackedTriggerPrescales.cc @@ -1,39 +1,12 @@ #include "DataFormats/PatCandidates/interface/PackedTriggerPrescales.h" #include "DataFormats/Common/interface/RefProd.h" -#include pat::PackedTriggerPrescales::PackedTriggerPrescales(const edm::Handle &handle) : prescaleValues_(), triggerResults_(edm::RefProd(handle).refCore()), triggerNames_(nullptr) { prescaleValues_.resize(handle->size(), 0); } -int pat::PackedTriggerPrescales::getPrescaleForIndex(int index) const { - if (unsigned(index) >= triggerResults().size()) - throw cms::Exception("InvalidReference", "Index out of bounds"); - return prescaleValues_[index]; -} - -int pat::PackedTriggerPrescales::getPrescaleForName(const std::string &name, bool prefixOnly) const { - if (triggerNames_ == nullptr) - throw cms::Exception("LogicError", "getPrescaleForName called without having called setTriggerNames first"); - if (prefixOnly) { - const std::vector &names = triggerNames_->triggerNames(); - size_t siz = name.length() - 1; - while (siz > 0 && (name[siz] == '*' || name[siz] == '\0')) - siz--; - for (unsigned int i = 0, n = names.size(); i < n; ++i) { - if (strncmp(name.c_str(), names[i].c_str(), siz) == 0) { - return getPrescaleForIndex(i); - } - } - throw cms::Exception("InvalidReference", "Index out of bounds"); - } else { - int index = triggerNames_->triggerIndex(name); - return getPrescaleForIndex(index); - } -} - -void pat::PackedTriggerPrescales::addPrescaledTrigger(int index, int prescale) { +void pat::PackedTriggerPrescales::addPrescaledTrigger(int index, double prescale) { if (unsigned(index) >= triggerResults().size()) throw cms::Exception("InvalidReference", "Index out of bounds"); prescaleValues_[index] = prescale; diff --git a/DataFormats/PatCandidates/src/TriggerPath.cc b/DataFormats/PatCandidates/src/TriggerPath.cc index df2c7a0b321ef..a46c3a7e692cc 100644 --- a/DataFormats/PatCandidates/src/TriggerPath.cc +++ b/DataFormats/PatCandidates/src/TriggerPath.cc @@ -1,35 +1,30 @@ -// -// - #include "DataFormats/PatCandidates/interface/TriggerPath.h" -using namespace pat; - // Constructors and Destructor // Default constructor -TriggerPath::TriggerPath() +pat::TriggerPath::TriggerPath() : name_(), index_(), prescale_(), run_(), accept_(), error_(), lastActiveFilterSlot_(), l3Filters_(0) { modules_.clear(); filterIndices_.clear(); } // Constructor from path name only -TriggerPath::TriggerPath(const std::string& name) +pat::TriggerPath::TriggerPath(const std::string& name) : name_(name), index_(), prescale_(), run_(), accept_(), error_(), lastActiveFilterSlot_(), l3Filters_(0) { modules_.clear(); filterIndices_.clear(); } // Constructor from values -TriggerPath::TriggerPath(const std::string& name, - unsigned index, - unsigned prescale, - bool run, - bool accept, - bool error, - unsigned lastActiveFilterSlot, - unsigned l3Filters) +pat::TriggerPath::TriggerPath(const std::string& name, + unsigned index, + double prescale, + bool run, + bool accept, + bool error, + unsigned lastActiveFilterSlot, + unsigned l3Filters) : name_(name), index_(index), prescale_(prescale), @@ -45,14 +40,14 @@ TriggerPath::TriggerPath(const std::string& name, // Methods // Get the index of a certain module -int TriggerPath::indexModule(const std::string& name) const { +int pat::TriggerPath::indexModule(const std::string& name) const { if (modules_.begin() == modules_.end()) return -1; return (std::find(modules_.begin(), modules_.end(), name) - modules_.begin()); } // Get names of all L1 seeds with a certain decision -std::vector TriggerPath::l1Seeds(const bool decision) const { +std::vector pat::TriggerPath::l1Seeds(const bool decision) const { std::vector seeds; for (L1SeedCollection::const_iterator iSeed = l1Seeds().begin(); iSeed != l1Seeds().end(); ++iSeed) { if (iSeed->first == decision) diff --git a/DataFormats/PatCandidates/src/classes_def_trigger.xml b/DataFormats/PatCandidates/src/classes_def_trigger.xml index 851e382fad62b..d6ccc0be3df01 100644 --- a/DataFormats/PatCandidates/src/classes_def_trigger.xml +++ b/DataFormats/PatCandidates/src/classes_def_trigger.xml @@ -58,7 +58,8 @@ - + + @@ -103,7 +104,8 @@ - + + diff --git a/HLTrigger/HLTanalyzers/plugins/HLTInfo.cc b/HLTrigger/HLTanalyzers/plugins/HLTInfo.cc index 487d0f46f5066..bf962a62be69b 100644 --- a/HLTrigger/HLTanalyzers/plugins/HLTInfo.cc +++ b/HLTrigger/HLTanalyzers/plugins/HLTInfo.cc @@ -60,7 +60,7 @@ void HLTInfo::setup(const edm::ParameterSet& pSet, TTree* HltTree) { HltEvtCnt = 0; const int kMaxTrigFlag = 10000; trigflag = new int[kMaxTrigFlag]; - trigPrescl = new int[kMaxTrigFlag]; + trigPrescl = new double[kMaxTrigFlag]; L1EvtCnt = 0; const int kMaxL1Flag = 10000; @@ -136,8 +136,7 @@ void HLTInfo::analyze(const edm::Handle& hltresults, const std::string& trigName = triggerNames.triggerName(itrig); bool accept = hltresults->accept(itrig); - //trigPrescl[itrig] = hltConfig_.prescaleValue(iEvent, eventSetup, trigName); - trigPrescl[itrig] = hltPrescaleProvider_->prescaleValue(iEvent, eventSetup, trigName); + trigPrescl[itrig] = hltPrescaleProvider_->prescaleValue(iEvent, eventSetup, trigName); if (accept) { trigflag[itrig] = 1; diff --git a/HLTrigger/HLTanalyzers/plugins/HLTInfo.h b/HLTrigger/HLTanalyzers/plugins/HLTInfo.h index 7868a0fb05307..953dbe88be21a 100644 --- a/HLTrigger/HLTanalyzers/plugins/HLTInfo.h +++ b/HLTrigger/HLTanalyzers/plugins/HLTInfo.h @@ -80,7 +80,8 @@ class HLTInfo { int L1EvtCnt, HltEvtCnt, nhltpart; int *trigflag, *l1flag, *l1flag5Bx, *l1techflag; - int *trigPrescl, *l1Prescl, *l1techPrescl; + double* trigPrescl; + int *l1Prescl, *l1techPrescl; TString* algoBitToName; TString* techBitToName; diff --git a/HLTrigger/HLTcore/interface/HLTConfigData.h b/HLTrigger/HLTcore/interface/HLTConfigData.h index 3d26ff3751bfc..e359ec30c8684 100644 --- a/HLTrigger/HLTcore/interface/HLTConfigData.h +++ b/HLTrigger/HLTcore/interface/HLTConfigData.h @@ -1,5 +1,5 @@ -#ifndef HLTcore_HLTConfigData_h -#define HLTcore_HLTConfigData_h +#ifndef HLTrigger_HLTcore_HLTConfigData_h +#define HLTrigger_HLTcore_HLTConfigData_h /** \class HLTConfigData * @@ -11,12 +11,14 @@ * */ -#include "DataFormats/HLTReco/interface/HLTPrescaleTable.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "DataFormats/HLTReco/interface/HLTPrescaleTable.h" +#include "HLTrigger/HLTcore/interface/FractionalPrescale.h" #include #include #include +#include // // class declaration @@ -91,15 +93,15 @@ class HLTConfigData { /// HLTLevel1GTSeed module /// HLTLevel1GTSeed modules for all trigger paths - const std::vector > >& hltL1GTSeeds() const; + const std::vector>>& hltL1GTSeeds() const; /// HLTLevel1GTSeed modules for trigger path with name - const std::vector >& hltL1GTSeeds(const std::string& trigger) const; + const std::vector>& hltL1GTSeeds(const std::string& trigger) const; /// HLTLevel1GTSeed modules for trigger path with index i - const std::vector >& hltL1GTSeeds(unsigned int trigger) const; + const std::vector>& hltL1GTSeeds(unsigned int trigger) const; /// HLTL1TSeed module /// HLTL1TSeed modules for all trigger paths - const std::vector >& hltL1TSeeds() const; + const std::vector>& hltL1TSeeds() const; /// HLTL1TSeed modules for trigger path with name const std::vector& hltL1TSeeds(const std::string& trigger) const; /// HLTL1TSeed modules for trigger path with index i @@ -113,7 +115,7 @@ class HLTConfigData { /// index of stream with name unsigned int streamIndex(const std::string& stream) const; /// names of datasets for all streams - const std::vector >& streamContents() const; + const std::vector>& streamContents() const; /// names of datasets in stream with index i const std::vector& streamContent(unsigned int stream) const; /// names of datasets in stream with name @@ -127,7 +129,7 @@ class HLTConfigData { /// index of dataset with name unsigned int datasetIndex(const std::string& dataset) const; /// names of trigger paths for all datasets - const std::vector >& datasetContents() const; + const std::vector>& datasetContents() const; /// names of trigger paths in dataset with index i const std::vector& datasetContent(unsigned int dataset) const; /// names of trigger paths in dataset with name @@ -137,10 +139,13 @@ class HLTConfigData { /// Number of HLT prescale sets unsigned int prescaleSize() const; /// HLT prescale value in specific prescale set for a specific trigger path - unsigned int prescaleValue(unsigned int set, const std::string& trigger) const; - /// low-level data member access + template + T prescaleValue(unsigned int set, const std::string& trigger) const; + /// labels of HLT prescale columns const std::vector& prescaleLabels() const; - const std::map >& prescaleTable() const; + /// map of HLT prescales by trigger-path name (key=path, value=prescales) + template + std::map> const& prescaleTable() const; /// technical: id() function needed for use with ThreadSafeRegistry edm::ParameterSetID id() const; @@ -152,24 +157,49 @@ class HLTConfigData { std::string globalTag_; std::string tableName_; std::vector triggerNames_; - std::vector > moduleLabels_; - std::vector > saveTagsModules_; + std::vector> moduleLabels_; + std::vector> saveTagsModules_; std::map triggerIndex_; - std::vector > moduleIndex_; + std::vector> moduleIndex_; unsigned int l1tType_; - std::vector > > hltL1GTSeeds_; - std::vector > hltL1TSeeds_; + std::vector>> hltL1GTSeeds_; + std::vector> hltL1TSeeds_; std::vector streamNames_; std::map streamIndex_; - std::vector > streamContents_; + std::vector> streamContents_; std::vector datasetNames_; std::map datasetIndex_; - std::vector > datasetContents_; + std::vector> datasetContents_; trigger::HLTPrescaleTable hltPrescaleTable_; + std::map> hltPrescaleTableValuesDouble_; + std::map> hltPrescaleTableValuesFractional_; }; -#endif + +template +T HLTConfigData::prescaleValue(unsigned int set, const std::string& trigger) const { + static_assert(std::is_same_v or std::is_same_v, + "\n\tPlease use prescaleValue or prescaleValue" + "\n\t(other types for HLT prescales are not supported anymore by HLTConfigData)"); + return hltPrescaleTable_.prescale(set, trigger); +} + +template +std::map> const& HLTConfigData::prescaleTable() const { + static_assert(std::is_same_v or std::is_same_v, + "\n\tPlease use prescaleTable or prescaleTable" + "\n\t(other types for HLT prescales are not supported anymore by HLTConfigData)"); + return hltPrescaleTable_.table(); +} + +template <> +std::map> const& HLTConfigData::prescaleTable() const; + +template <> +std::map> const& HLTConfigData::prescaleTable() const; + +#endif // HLTrigger_HLTcore_HLTConfigData_h diff --git a/HLTrigger/HLTcore/interface/HLTConfigProvider.h b/HLTrigger/HLTcore/interface/HLTConfigProvider.h index fdd303a278146..0359136e9508d 100644 --- a/HLTrigger/HLTcore/interface/HLTConfigProvider.h +++ b/HLTrigger/HLTcore/interface/HLTConfigProvider.h @@ -21,6 +21,7 @@ #include #include #include +#include // // class declaration @@ -120,21 +121,21 @@ class HLTConfigProvider { /// HLTLevel1GTSeed module /// HLTLevel1GTSeed modules for all trigger paths - const std::vector > >& hltL1GTSeeds() const { + const std::vector>>& hltL1GTSeeds() const { return hltConfigData_->hltL1GTSeeds(); } /// HLTLevel1GTSeed modules for trigger path with name - const std::vector >& hltL1GTSeeds(const std::string& trigger) const { + const std::vector>& hltL1GTSeeds(const std::string& trigger) const { return hltConfigData_->hltL1GTSeeds(trigger); } /// HLTLevel1GTSeed modules for trigger path with index i - const std::vector >& hltL1GTSeeds(unsigned int trigger) const { + const std::vector>& hltL1GTSeeds(unsigned int trigger) const { return hltConfigData_->hltL1GTSeeds(trigger); } /// HLTL1TSeed module /// HLTL1TSeed modules for all trigger paths - const std::vector >& hltL1TSeeds() const { return hltConfigData_->hltL1TSeeds(); } + const std::vector>& hltL1TSeeds() const { return hltConfigData_->hltL1TSeeds(); } /// HLTL1TSeed modules for trigger path with name const std::vector& hltL1TSeeds(const std::string& trigger) const { return hltConfigData_->hltL1TSeeds(trigger); @@ -152,7 +153,7 @@ class HLTConfigProvider { /// index of stream with name unsigned int streamIndex(const std::string& stream) const { return hltConfigData_->streamIndex(stream); } /// names of datasets for all streams - const std::vector >& streamContents() const { return hltConfigData_->streamContents(); } + const std::vector>& streamContents() const { return hltConfigData_->streamContents(); } /// names of datasets in stream with index i const std::vector& streamContent(unsigned int stream) const { return hltConfigData_->streamContent(stream); @@ -170,7 +171,7 @@ class HLTConfigProvider { /// index of dataset with name unsigned int datasetIndex(const std::string& dataset) const { return hltConfigData_->datasetIndex(dataset); } /// names of trigger paths for all datasets - const std::vector >& datasetContents() const { return hltConfigData_->datasetContents(); } + const std::vector>& datasetContents() const { return hltConfigData_->datasetContents(); } /// names of trigger paths in dataset with index i const std::vector& datasetContent(unsigned int dataset) const { return hltConfigData_->datasetContent(dataset); @@ -186,18 +187,21 @@ class HLTConfigProvider { /// HLT prescale value in specific prescale set for a specific trigger path template T prescaleValue(unsigned int set, const std::string& trigger) const { - //limit to only 4 allowed types - static_assert(std::is_same_v or std::is_same_v or std::is_same_v or - std::is_same_v, - "Please use prescaleValue, prescaleValue, prescaleValue, or " - "prescaleValue,\n note int and unsigned int will be depreated soon"); - return hltConfigData_->prescaleValue(set, trigger); + static_assert(std::is_same_v or std::is_same_v, + "\n\tPlease use prescaleValue or prescaleValue" + "\n\t(other types for HLT prescales are not supported anymore by HLTConfigProvider)"); + return hltConfigData_->prescaleValue(set, trigger); } /// low-level data member access const std::vector& prescaleLabels() const { return hltConfigData_->prescaleLabels(); } - const std::map >& prescaleTable() const { - return hltConfigData_->prescaleTable(); + + template + std::map> const& prescaleTable() const { + static_assert(std::is_same_v or std::is_same_v, + "\n\tPlease use prescaleTable or prescaleTable" + "\n\t(other types for HLT prescales are not supported anymore by HLTConfigProvider)"); + return hltConfigData_->prescaleTable(); } /// regexp processing diff --git a/HLTrigger/HLTcore/interface/HLTPrescaleProvider.h b/HLTrigger/HLTcore/interface/HLTPrescaleProvider.h index 48d6b9a63c1bd..9fa6c7702ea64 100644 --- a/HLTrigger/HLTcore/interface/HLTPrescaleProvider.h +++ b/HLTrigger/HLTcore/interface/HLTPrescaleProvider.h @@ -1,11 +1,10 @@ -#ifndef HLTcore_HLTPrescaleProvider_h -#define HLTcore_HLTPrescaleProvider_h +#ifndef HLTrigger_HLTcore_HLTPrescaleProvider_h +#define HLTrigger_HLTcore_HLTPrescaleProvider_h /** \class HLTPrescaleProvider * - * - * This class provides access routines to get hold of the HLT Configuration - * + * This class provides access routines to get hold of the HLT Configuration, + * as well as the prescales of Level-1 and High-Level triggers. * * \author Martin Grunewald * @@ -26,6 +25,7 @@ #include #include #include +#include namespace edm { class ConsumesCollector; @@ -80,10 +80,10 @@ class HLTPrescaleProvider { // In case of a complex Boolean expression as L1 seed template - std::pair >, THLT> prescaleValuesInDetail(const edm::Event& iEvent, - const edm::EventSetup& iSetup, - const std::string& trigger) { - std::pair >, THLT> retval; + std::pair>, THLT> prescaleValuesInDetail(const edm::Event& iEvent, + const edm::EventSetup& iSetup, + const std::string& trigger) { + std::pair>, THLT> retval; for (auto& entry : getL1PrescaleValueInDetail(iEvent, iSetup, trigger)) { retval.first.emplace_back(std::move(entry.first), convertL1PS(entry.second)); } @@ -103,19 +103,32 @@ class HLTPrescaleProvider { private: void checkL1GtUtils() const; void checkL1TGlobalUtil() const; + template T convertL1PS(double val) const { + static_assert(std::is_same_v or std::is_same_v, + "\n\n\tPlease use convertL1PS or convertL1PS" + " (other types for L1T prescales are not supported anymore by HLTPrescaleProvider)" + "\n\tconvertL1PS is used inside prescaleValues and prescaleValuesInDetail," + " so it might be necessary to specify template arguments for those calls," + "\n\te.g. prescaleValues" + " (the 1st argument applies to L1T prescales, the 2nd to HLT prescales)\n"); return T(val); } double getL1PrescaleValue(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger); - std::vector > getL1PrescaleValueInDetail(const edm::Event& iEvent, - const edm::EventSetup& iSetup, - const std::string& trigger); + + std::vector> getL1PrescaleValueInDetail(const edm::Event& iEvent, + const edm::EventSetup& iSetup, + const std::string& trigger); + static constexpr int kL1PrescaleDenominator_ = 100; + HLTConfigProvider hltConfigProvider_; + std::unique_ptr l1GtUtils_; std::unique_ptr l1tGlobalUtil_; + unsigned char count_[5] = {0, 0, 0, 0, 0}; bool inited_ = false; }; @@ -135,11 +148,6 @@ HLTPrescaleProvider::HLTPrescaleProvider(edm::ParameterSet const& pset, edm::Con } template <> -FractionalPrescale HLTPrescaleProvider::convertL1PS(double val) const; - -template <> -unsigned int HLTPrescaleProvider::prescaleValue(const edm::Event& iEvent, - const edm::EventSetup& iSetup, - const std::string& trigger); +FractionalPrescale HLTPrescaleProvider::convertL1PS(double val) const; -#endif +#endif // HLTrigger_HLTcore_HLTPrescaleProvider_h diff --git a/HLTrigger/HLTcore/plugins/HLTEventAnalyzerAOD.cc b/HLTrigger/HLTcore/plugins/HLTEventAnalyzerAOD.cc index bfc7505459056..638f469df58aa 100644 --- a/HLTrigger/HLTcore/plugins/HLTEventAnalyzerAOD.cc +++ b/HLTrigger/HLTcore/plugins/HLTEventAnalyzerAOD.cc @@ -151,12 +151,11 @@ void HLTEventAnalyzerAOD::analyzeTrigger(const edm::Event& iEvent, return; } - const std::pair prescales(hltPrescaleProvider_.prescaleValues(iEvent, iSetup, triggerName)); + auto const prescales = hltPrescaleProvider_.prescaleValues(iEvent, iSetup, triggerName); LogVerbatim("HLTEventAnalyzerAOD") << "HLTEventAnalyzerAOD::analyzeTrigger: path " << triggerName << " [" << triggerIndex << "] " << "prescales L1T,HLT: " << prescales.first << "," << prescales.second << endl; - const std::pair >, int> prescalesInDetail( - hltPrescaleProvider_.prescaleValuesInDetail(iEvent, iSetup, triggerName)); + auto const prescalesInDetail = hltPrescaleProvider_.prescaleValuesInDetail(iEvent, iSetup, triggerName); std::ostringstream message; for (unsigned int i = 0; i < prescalesInDetail.first.size(); ++i) { message << " " << i << ":" << prescalesInDetail.first[i].first << "/" << prescalesInDetail.first[i].second; diff --git a/HLTrigger/HLTcore/plugins/HLTPrescaleExample.cc b/HLTrigger/HLTcore/plugins/HLTPrescaleExample.cc index 508016066f039..d951a96e349fa 100644 --- a/HLTrigger/HLTcore/plugins/HLTPrescaleExample.cc +++ b/HLTrigger/HLTcore/plugins/HLTPrescaleExample.cc @@ -1,10 +1,11 @@ +#include #include "FWCore/Framework/interface/one/EDAnalyzer.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "HLTrigger/HLTcore/interface/HLTPrescaleProvider.h" -#include class HLTPrescaleExample : public edm::one::EDAnalyzer { public: @@ -18,8 +19,8 @@ class HLTPrescaleExample : public edm::one::EDAnalyzer { private: HLTPrescaleProvider hltPSProvider_; - std::string hltProcess_; - std::string hltPath_; + std::string const hltProcess_; + std::string const hltPath_; }; HLTPrescaleExample::HLTPrescaleExample(edm::ParameterSet const& iPSet) @@ -33,39 +34,34 @@ void HLTPrescaleExample::beginRun(edm::Run const& iRun, edm::EventSetup const& i } void HLTPrescaleExample::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) { - auto hltPSDouble = hltPSProvider_.prescaleValue(iEvent, iSetup, hltPath_); - auto hltPSInt = hltPSProvider_.prescaleValue(iEvent, iSetup, hltPath_); - auto hltPSUInt = hltPSProvider_.prescaleValue(iEvent, iSetup, hltPath_); - auto hltPSFrac = hltPSProvider_.prescaleValue(iEvent, iSetup, hltPath_); + auto const hltPSDouble = hltPSProvider_.prescaleValue(iEvent, iSetup, hltPath_); + auto const hltPSFrac = hltPSProvider_.prescaleValue(iEvent, iSetup, hltPath_); - auto l1HLTPSDouble = hltPSProvider_.prescaleValues(iEvent, iSetup, hltPath_); - auto l1HLTPSInt = hltPSProvider_.prescaleValues(iEvent, iSetup, hltPath_); - auto l1HLTPSFrac = hltPSProvider_.prescaleValues(iEvent, iSetup, hltPath_); - auto l1HLTPSDoubleFrac = hltPSProvider_.prescaleValues(iEvent, iSetup, hltPath_); + auto const l1HLTPSDouble = hltPSProvider_.prescaleValues(iEvent, iSetup, hltPath_); + auto const l1HLTPSFrac = hltPSProvider_.prescaleValues(iEvent, iSetup, hltPath_); + auto const l1HLTPSDoubleFrac = hltPSProvider_.prescaleValues(iEvent, iSetup, hltPath_); - auto l1HLTDetailPSDouble = hltPSProvider_.prescaleValuesInDetail(iEvent, iSetup, hltPath_); - auto l1HLTDetailPSInt = hltPSProvider_.prescaleValuesInDetail(iEvent, iSetup, hltPath_); - auto l1HLTDetailPSFrac = hltPSProvider_.prescaleValuesInDetail(iEvent, iSetup, hltPath_); + auto const l1HLTDetailPSDouble = hltPSProvider_.prescaleValuesInDetail(iEvent, iSetup, hltPath_); + auto const l1HLTDetailPSFrac = hltPSProvider_.prescaleValuesInDetail(iEvent, iSetup, hltPath_); - std::cout << "---------Begin Event--------" << std::endl; - std::cout << "hltDouble " << hltPSDouble << " hltInt " << hltPSInt << " hltPSUInt " << hltPSUInt << " hltFrac " - << hltPSFrac << std::endl; + edm::LogPrint log(""); - std::cout << " l1HLTDouble " << l1HLTPSDouble.first << " " << l1HLTPSDouble.second << " l1HLTInt " << l1HLTPSInt.first - << " " << l1HLTPSInt.second << " l1HLTFrac " << l1HLTPSFrac.first << " " << l1HLTPSFrac.second - << " l1HLTDoubleFrac " << l1HLTPSDoubleFrac.first << " " << l1HLTPSDoubleFrac.second << std::endl; - auto printL1HLTDetail = [](const std::string& text, const auto& val, std::ostream& out) { - out << text; + log << "---------Begin Event--------\n"; + log << "hltDouble " << hltPSDouble << " hltFrac " << hltPSFrac << "\n"; + log << " l1HLTDouble " << l1HLTPSDouble.first << " " << l1HLTPSDouble.second << " l1HLTFrac " << l1HLTPSFrac.first + << " " << l1HLTPSFrac.second << " l1HLTDoubleFrac " << l1HLTPSDoubleFrac.first << " " << l1HLTPSDoubleFrac.second + << "\n"; + auto printL1HLTDetail = [&log](const std::string& text, const auto& val) { + log << text; for (const auto& entry : val.first) { - out << entry.first << ":" << entry.second << " "; + log << entry.first << ":" << entry.second << " "; } - out << " HLT : " << val.second << std::endl; + log << " HLT : " << val.second << "\n"; }; - printL1HLTDetail("l1HLTDetailDouble ", l1HLTDetailPSDouble, std::cout); - printL1HLTDetail("l1HLTDetailInt ", l1HLTDetailPSInt, std::cout); - printL1HLTDetail("l1HLTDetailFrac ", l1HLTDetailPSFrac, std::cout); - std::cout << "---------End Event--------" << std::endl << std::endl; + printL1HLTDetail("l1HLTDetailDouble ", l1HLTDetailPSDouble); + printL1HLTDetail("l1HLTDetailFrac ", l1HLTDetailPSFrac); + log << "---------End Event--------\n\n"; } DEFINE_FWK_MODULE(HLTPrescaleExample); diff --git a/HLTrigger/HLTcore/src/HLTConfigData.cc b/HLTrigger/HLTcore/src/HLTConfigData.cc index 657abc6fd7803..81cd648bafbb7 100644 --- a/HLTrigger/HLTcore/src/HLTConfigData.cc +++ b/HLTrigger/HLTcore/src/HLTConfigData.cc @@ -10,8 +10,8 @@ #include "HLTrigger/HLTcore/interface/HLTConfigData.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/path_configuration.h" +#include "FWCore/Utilities/interface/transform.h" -#include #include //Using this function with the 'const static within s_dummyPSet' @@ -47,7 +47,9 @@ HLTConfigData::HLTConfigData() datasetNames_(), datasetIndex_(), datasetContents_(), - hltPrescaleTable_() { + hltPrescaleTable_(), + hltPrescaleTableValuesDouble_{}, + hltPrescaleTableValuesFractional_{} { if (processPSet_->id().isValid()) { extract(); } @@ -72,7 +74,9 @@ HLTConfigData::HLTConfigData(const edm::ParameterSet* iPSet) datasetNames_(), datasetIndex_(), datasetContents_(), - hltPrescaleTable_() { + hltPrescaleTable_(), + hltPrescaleTableValuesDouble_{}, + hltPrescaleTableValuesFractional_{} { if (processPSet_->id().isValid()) { extract(); } @@ -271,6 +275,14 @@ void HLTConfigData::extract() { } } + // fill maps to return prescales values with allowed types (double, FractionalPrescale) + for (auto const& [key, psVals] : hltPrescaleTable_.table()) { + hltPrescaleTableValuesDouble_.insert( + {key, edm::vector_transform(psVals, [](auto const ps) -> double { return ps; })}); + hltPrescaleTableValuesFractional_.insert( + {key, edm::vector_transform(psVals, [](auto const ps) -> FractionalPrescale { return ps; })}); + } + // Determine L1T Type (0=unknown, 1=legacy/stage-1 or 2=stage-2) l1tType_ = 0; unsigned int stage1(0), stage2(0); @@ -411,15 +423,13 @@ void HLTConfigData::dump(const std::string& what) const { } if (n > 0) cout << endl; - const map>& table(hltPrescaleTable_.table()); + auto const& table = hltPrescaleTable_.table(); cout << "HLTConfigData::dump: PrescaleTable: # of paths: " << table.size() << endl; - const map>::const_iterator tb(table.begin()); - const map>::const_iterator te(table.end()); - for (map>::const_iterator ti = tb; ti != te; ++ti) { + for (auto const& [key, val] : table) { for (unsigned int i = 0; i != n; ++i) { - cout << " " << ti->second.at(i); + cout << " " << val.at(i); } - cout << " " << ti->first << endl; + cout << " " << key << endl; } } else { cout << "HLTConfigData::dump: Unkown dump request: " << what << endl; @@ -594,13 +604,17 @@ const std::vector& HLTConfigData::datasetContent(const std::string& } unsigned int HLTConfigData::prescaleSize() const { return hltPrescaleTable_.size(); } -unsigned int HLTConfigData::prescaleValue(unsigned int set, const std::string& trigger) const { - return hltPrescaleTable_.prescale(set, trigger); + +template <> +std::map> const& HLTConfigData::prescaleTable() const { + return hltPrescaleTableValuesDouble_; } -const std::vector& HLTConfigData::prescaleLabels() const { return hltPrescaleTable_.labels(); } -const std::map>& HLTConfigData::prescaleTable() const { - return hltPrescaleTable_.table(); +template <> +std::map> const& HLTConfigData::prescaleTable() const { + return hltPrescaleTableValuesFractional_; } +const std::vector& HLTConfigData::prescaleLabels() const { return hltPrescaleTable_.labels(); } + edm::ParameterSetID HLTConfigData::id() const { return processPSet_->id(); } diff --git a/HLTrigger/HLTcore/src/HLTPrescaleProvider.cc b/HLTrigger/HLTcore/src/HLTPrescaleProvider.cc index dd49a2fefa2d5..64c3f516f90b3 100644 --- a/HLTrigger/HLTcore/src/HLTPrescaleProvider.cc +++ b/HLTrigger/HLTcore/src/HLTPrescaleProvider.cc @@ -104,12 +104,12 @@ int HLTPrescaleProvider::prescaleSet(const edm::Event& iEvent, const edm::EventS } template <> -FractionalPrescale HLTPrescaleProvider::convertL1PS(double val) const { +FractionalPrescale HLTPrescaleProvider::convertL1PS(double val) const { int numer = static_cast(val * kL1PrescaleDenominator_ + 0.5); static constexpr double kL1RoundingEpsilon = 0.001; if (std::abs(numer - val * kL1PrescaleDenominator_) > kL1RoundingEpsilon) { edm::LogWarning("ValueError") << " Error, L1 prescale val " << val - << "does not appear to precisely expressable as int / " << kL1PrescaleDenominator_ + << " does not appear to precisely expressable as int / " << kL1PrescaleDenominator_ << ", using a FractionalPrescale is a loss of precision"; } @@ -215,9 +215,9 @@ double HLTPrescaleProvider::getL1PrescaleValue(const edm::Event& iEvent, return result; } -std::vector > HLTPrescaleProvider::getL1PrescaleValueInDetail( +std::vector> HLTPrescaleProvider::getL1PrescaleValueInDetail( const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) { - std::vector > result; + std::vector> result; const unsigned int l1tType(hltConfigProvider_.l1tType()); if (l1tType == 1) { @@ -232,7 +232,7 @@ std::vector > HLTPrescaleProvider::getL1PrescaleV const std::string l1tname(hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second); L1GtUtils::LogicalExpressionL1Results l1Logical(l1tname, *l1GtUtils_); l1Logical.logicalExpressionRunUpdate(iEvent.getRun(), iSetup, l1tname); - const std::vector >& errorCodes(l1Logical.errorCodes(iEvent)); + const std::vector>& errorCodes(l1Logical.errorCodes(iEvent)); auto resultInt = l1Logical.prescaleFactors(); result.clear(); for (const auto& entry : resultInt) { @@ -362,14 +362,6 @@ void HLTPrescaleProvider::checkL1TGlobalUtil() const { } } -template <> -unsigned int HLTPrescaleProvider::prescaleValue(const edm::Event& iEvent, - const edm::EventSetup& iSetup, - const std::string& trigger) { - const int set(prescaleSet(iEvent, iSetup)); - return set < 0 ? 1 : hltConfigProvider_.prescaleValue(static_cast(set), trigger); -} - void HLTPrescaleProvider::fillPSetDescription(edm::ParameterSetDescription& desc, unsigned int stageL1Trigger, edm::InputTag const& l1tAlgBlkInputTag, diff --git a/HLTrigger/HLTcore/test/BuildFile.xml b/HLTrigger/HLTcore/test/BuildFile.xml index 1d25fc03b1a18..11348b68ec723 100644 --- a/HLTrigger/HLTcore/test/BuildFile.xml +++ b/HLTrigger/HLTcore/test/BuildFile.xml @@ -9,3 +9,6 @@ + + + diff --git a/HLTrigger/HLTcore/test/hltPrescaleExample_cfg.py b/HLTrigger/HLTcore/test/hltPrescaleExample_cfg.py index 7ef175aaac1c4..753918a6c1b83 100644 --- a/HLTrigger/HLTcore/test/hltPrescaleExample_cfg.py +++ b/HLTrigger/HLTcore/test/hltPrescaleExample_cfg.py @@ -1,54 +1,52 @@ - import FWCore.ParameterSet.Config as cms -process = cms.Process("HLTPSCheck") + +process = cms.Process('HLTPSCheck') import FWCore.ParameterSet.VarParsing as VarParsing -options = VarParsing.VarParsing ('analysis') -options.register('globalTag','auto:run2_data',options.multiplicity.singleton,options.varType.string,"global tag to use") +options = VarParsing.VarParsing ('analysis') +options.register('globalTag', 'auto:run3_data', options.multiplicity.singleton, options.varType.string, 'global tag to use') +options.setDefault('inputFiles', [ + '/store/data/Run2022D/HLTPhysics/MINIAOD/PromptReco-v2/000/357/898/00000/99afb702-5640-453c-8d48-49b9ba7098d9.root' +]) +options.setDefault('maxEvents', 10) options.parseArguments() -print options.inputFiles -process.source = cms.Source("PoolSource", - fileNames = cms.untracked.vstring(options.inputFiles), - ) +process.source = cms.Source('PoolSource', + fileNames = cms.untracked.vstring(options.inputFiles) +) +print('process.source.fileNames =', process.source.fileNames) # initialize MessageLogger and output report -process.load("FWCore.MessageLogger.MessageLogger_cfi") +process.load('FWCore.MessageLogger.MessageLogger_cfi') process.MessageLogger.cerr.FwkReport = cms.untracked.PSet( reportEvery = cms.untracked.int32(5000), limit = cms.untracked.int32(10000000) ) -process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(False) ) - +process.options.wantSummary = False +process.maxEvents.input = options.maxEvents process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') from Configuration.AlCa.GlobalTag import GlobalTag process.GlobalTag = GlobalTag(process.GlobalTag, options.globalTag, '') - - -process.maxEvents = cms.untracked.PSet( - input = cms.untracked.int32(options.maxEvents) +print('process.GlobalTag.globaltag =', process.GlobalTag.globaltag) + +_hltPSExample = cms.EDAnalyzer('HLTPrescaleExample', + hltProcess = cms.string('HLT'), + hltPath = cms.string(''), + hltPSProvCfg = cms.PSet( + stageL1Trigger = cms.uint32(2), + l1tAlgBlkInputTag = cms.InputTag('gtStage2Digis'), + l1tExtBlkInputTag = cms.InputTag('gtStage2Digis') + ) ) - -process.hltPSExample = cms.EDAnalyzer("HLTPrescaleExample", - hltProcess=cms.string("HLT"), -# hltPath=cms.string("HLT_Photon50_v13"), - hltPath=cms.string("HLT_Photon33_v5"), - hltPSProvCfg=cms.PSet( - stageL1Trigger = cms.uint32(2) - ) - ) - +process.hltPSExample1 = _hltPSExample.clone(hltPath = 'HLT_Photon33_v6') +process.hltPSExample2 = _hltPSExample.clone(hltPath = 'HLT_Photon50_v14') +process.hltPSExample3 = _hltPSExample.clone(hltPath = 'HLT_Random_v3') process.p = cms.Path( - process.hltPSExample + process.hltPSExample1 + + process.hltPSExample2 + + process.hltPSExample3 ) - - - -print "global tag: ",process.GlobalTag.globaltag - - - diff --git a/HLTrigger/HLTcore/test/test_catch2_HLTConfigData.cc b/HLTrigger/HLTcore/test/test_catch2_HLTConfigData.cc index 95e37903cc88a..3abdd501318f1 100644 --- a/HLTrigger/HLTcore/test/test_catch2_HLTConfigData.cc +++ b/HLTrigger/HLTcore/test/test_catch2_HLTConfigData.cc @@ -4,7 +4,12 @@ #include "HLTrigger/HLTcore/interface/HLTConfigData.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +#include +#include +#include + namespace { + // build PSet of generic module edm::ParameterSet buildModulePSet(std::string const& iLabel, std::string const& iType, std::string const& iEDMType) { edm::ParameterSet pset; pset.addParameter("@module_label", iLabel); @@ -12,6 +17,28 @@ namespace { pset.addParameter("@module_edm_type", iEDMType); return pset; } + + // build PSet of PrescaleService module + edm::ParameterSet buildPrescaleServicePSet(std::string const& iLabel, + std::string const& iType, + std::string const& iEDMType, + std::vector const& labels, + std::map> const& prescaleTable) { + auto pset = buildModulePSet(iLabel, iType, iEDMType); + pset.addParameter("lvl1Labels", labels); + std::vector psTable; + psTable.reserve(psTable.size()); + for (auto const& [key, val] : prescaleTable) { + REQUIRE(labels.size() == val.size()); + edm::ParameterSet psEntry; + psEntry.addParameter("pathName", key); + psEntry.addParameter>("prescales", val); + psTable.emplace_back(psEntry); + } + pset.addParameter>("prescaleTable", psTable); + return pset; + } + } // namespace TEST_CASE("Test HLTConfigData", "[HLTConfigData]") { @@ -37,6 +64,15 @@ TEST_CASE("Test HLTConfigData", "[HLTConfigData]") { pset.addParameter("c1", buildModulePSet("c1", "CProducer", "EDProducer")); pset.addParameter("c2", buildModulePSet("c2", "CProducer", "EDProducer")); + + pset.addParameter( + "PrescaleService", + buildPrescaleServicePSet("PrescaleService", + "PrescaleService", + "Service", + {"col0", "col1", "col2", "col3", "col4"}, + {{"b1", {45, 12, 1, 0, 1000}}, {"b2", {12000, 2, 0, 7, 0}}})); + pset.registerIt(); HLTConfigData cd(&pset); @@ -68,5 +104,30 @@ TEST_CASE("Test HLTConfigData", "[HLTConfigData]") { REQUIRE(cd.moduleLabel(3, 0) == "f5"); //cd.dump("Modules"); } + + SECTION("check prescales") { + // get prescale table reading values as double and FractionalPrescale + auto const& psTableDouble = cd.prescaleTable(); + auto const& psTableFractl = cd.prescaleTable(); + REQUIRE(psTableDouble.size() == psTableFractl.size()); + for (auto const& [key, vec_d] : psTableDouble) { + auto const& vec_f = psTableFractl.at(key); + REQUIRE(vec_d.size() == vec_f.size()); + for (size_t idx = 0; idx < vec_d.size(); ++idx) { + auto const& val_d = vec_d[idx]; + auto const& val_f = vec_f[idx]; + // conversion of prescale value to unsigned int + unsigned int const val_u = vec_d[idx]; + // equal-to comparison of double-or-FractionalPrescale to unsigned int must succeed: + // HLT does not yet fully support non-integer HLT prescales (example: PrescaleService), + // but the HLTConfigData utility (interface to downstream clients) provides access + // to HLT prescales only via types 'double' and 'FractionalPrescale', + // in anticipation of when HLT will fully support the use of non-integer prescales + REQUIRE(val_d == val_u); + REQUIRE(val_f == val_u); + } + } + //cd.dump("PrescaleTable"); + } } } diff --git a/PhysicsTools/Heppy/interface/TriggerBitChecker.h b/PhysicsTools/Heppy/interface/TriggerBitChecker.h index 63c1b01adb1e1..6f6c455bf9fcd 100644 --- a/PhysicsTools/Heppy/interface/TriggerBitChecker.h +++ b/PhysicsTools/Heppy/interface/TriggerBitChecker.h @@ -1,11 +1,15 @@ #ifndef PhysicsTools_Heppy_TriggerBitChecker_h #define PhysicsTools_Heppy_TriggerBitChecker_h +#include +#include +#include +#include +#include + #include "DataFormats/Common/interface/TriggerResults.h" #include "DataFormats/PatCandidates/interface/PackedTriggerPrescales.h" #include "FWCore/Common/interface/EventBase.h" -#include -#include namespace heppy { @@ -24,12 +28,17 @@ namespace heppy { ~TriggerBitChecker() {} bool check(const edm::EventBase &event, const edm::TriggerResults &result) const; + bool check_unprescaled(const edm::EventBase &event, const edm::TriggerResults &result_tr, const pat::PackedTriggerPrescales &result) const; - int getprescale(const edm::EventBase &event, - const edm::TriggerResults &result_tr, - const pat::PackedTriggerPrescales &result) const; + + // method templated to force correct choice of output type + // (as part of deprecating integer types for trigger prescales) + template + T getprescale(const edm::EventBase &event, + const edm::TriggerResults &result_tr, + const pat::PackedTriggerPrescales &result) const; private: // list of path name prefixes @@ -45,6 +54,29 @@ namespace heppy { /// executes a 'rm -rf *' in current directory void rmstar(); }; + + template + T TriggerBitChecker::getprescale(const edm::EventBase &event, + const edm::TriggerResults &result_tr, + const pat::PackedTriggerPrescales &result) const { + static_assert(std::is_same_v, + "\n\n\tPlease use getprescale " + "(other types for trigger prescales are not supported anymore by TriggerBitChecker)"); + if (result_tr.parameterSetID() != lastID_) { + syncIndices(event, result_tr); + lastID_ = result_tr.parameterSetID(); + } + if (indices_.empty()) { + return -999; + } + if (indices_.size() > 1) { + std::cout << " trying to get prescale for multiple trigger objects at the same time" << std::endl; + assert(0); + } + + return result.getPrescaleForIndex(*(indices_.begin())); + } + } // namespace heppy #endif diff --git a/PhysicsTools/Heppy/src/TriggerBitChecker.cc b/PhysicsTools/Heppy/src/TriggerBitChecker.cc index fbf658129b8e3..72e60bac52159 100644 --- a/PhysicsTools/Heppy/src/TriggerBitChecker.cc +++ b/PhysicsTools/Heppy/src/TriggerBitChecker.cc @@ -1,8 +1,5 @@ #include "PhysicsTools/Heppy/interface/TriggerBitChecker.h" - #include "FWCore/Common/interface/TriggerNames.h" -#include -#include namespace heppy { @@ -45,7 +42,7 @@ namespace heppy { } bool outcome = true; for (std::vector::const_iterator it = indices_.begin(), ed = indices_.end(); it != ed; ++it) { - if (result.getPrescaleForIndex(*it) != 1) { + if (result.getPrescaleForIndex(*it) != 1) { outcome = false; break; } @@ -53,25 +50,6 @@ namespace heppy { return outcome; // true only if all paths are unprescaled } - int TriggerBitChecker::getprescale(const edm::EventBase &event, - const edm::TriggerResults &result_tr, - const pat::PackedTriggerPrescales &result) const { - if (result_tr.parameterSetID() != lastID_) { - syncIndices(event, result_tr); - lastID_ = result_tr.parameterSetID(); - } - if (indices_.empty()) { - // std::cout << " trying to check an inexistent trigger" << std::endl; - return -999; - } - if (indices_.size() > 1) { - std::cout << " trying to get prescale for multiple trigger objects at the same time" << std::endl; - assert(0); - } - - return result.getPrescaleForIndex(*(indices_.begin())); - } - void TriggerBitChecker::syncIndices(const edm::EventBase &event, const edm::TriggerResults &result) const { indices_.clear(); const edm::TriggerNames &names = event.triggerNames(result); diff --git a/PhysicsTools/PatAlgos/plugins/LeptonUpdater.cc b/PhysicsTools/PatAlgos/plugins/LeptonUpdater.cc index 3cda27184130a..b50c8a098e40a 100644 --- a/PhysicsTools/PatAlgos/plugins/LeptonUpdater.cc +++ b/PhysicsTools/PatAlgos/plugins/LeptonUpdater.cc @@ -13,6 +13,8 @@ #include "DataFormats/PatCandidates/interface/PackedCandidate.h" #include "DataFormats/MuonReco/interface/MuonSelectors.h" +#include + namespace pat { template diff --git a/PhysicsTools/PatAlgos/plugins/PATTriggerProducer.cc b/PhysicsTools/PatAlgos/plugins/PATTriggerProducer.cc index a8eea2ad499a5..25ff12baa53ff 100644 --- a/PhysicsTools/PatAlgos/plugins/PATTriggerProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATTriggerProducer.cc @@ -558,7 +558,7 @@ void PATTriggerProducer::produce(Event& iEvent, const EventSetup& iSetup) { if (hltConfig.prescaleSize() > 0) { if (hltPrescaleProvider_.prescaleSet(iEvent, iSetup) != -1) { hltPrescaleTable = trigger::HLTPrescaleTable( - hltPrescaleProvider_.prescaleSet(iEvent, iSetup), hltConfig.prescaleLabels(), hltConfig.prescaleTable()); + hltPrescaleProvider_.prescaleSet(iEvent, iSetup), hltConfig.prescaleLabels(), {}); LogDebug("hltPrescaleTable") << "HLT prescale table found in event setup"; } else { LogWarning("hltPrescaleSet") << "HLTPrescaleTable from event setup has error"; @@ -620,7 +620,7 @@ void PATTriggerProducer::produce(Event& iEvent, const EventSetup& iSetup) { } TriggerPath triggerPath(namePath, indexPath, - hltConfig.prescaleValue(set, namePath), + hltConfig.prescaleValue(set, namePath), handleTriggerResults->wasrun(indexPath), handleTriggerResults->accept(indexPath), handleTriggerResults->error(indexPath), @@ -786,15 +786,13 @@ void PATTriggerProducer::produce(Event& iEvent, const EventSetup& iSetup) { packedPrescalesL1min = std::make_unique(handleTriggerResults); packedPrescalesL1max = std::make_unique(handleTriggerResults); const edm::TriggerNames& names = iEvent.triggerNames(*handleTriggerResults); - //std::cout << "Run " << iEvent.id().run() << ", LS " << iEvent.id().luminosityBlock() << ": pset " << set << std::endl; for (unsigned int i = 0, n = names.size(); i < n; ++i) { - auto pvdet = hltPrescaleProvider_.prescaleValuesInDetail(iEvent, iSetup, names.triggerName(i)); - //int hltprescale = hltConfig_.prescaleValue(set, names.triggerName(i)); + auto pvdet = hltPrescaleProvider_.prescaleValuesInDetail(iEvent, iSetup, names.triggerName(i)); if (pvdet.first.empty()) { packedPrescalesL1max->addPrescaledTrigger(i, 1); packedPrescalesL1min->addPrescaledTrigger(i, 1); } else { - int pmin = -1, pmax = -1; + double pmin = -1, pmax = -1; for (const auto& p : pvdet.first) { pmax = std::max(pmax, p.second); if (p.second > 0 && (pmin == -1 || pmin > p.second)) @@ -802,10 +800,8 @@ void PATTriggerProducer::produce(Event& iEvent, const EventSetup& iSetup) { } packedPrescalesL1max->addPrescaledTrigger(i, pmax); packedPrescalesL1min->addPrescaledTrigger(i, pmin); - //std::cout << "\tTrigger " << names.triggerName(i) << ", L1 ps " << pmin << "-" << pmax << ", HLT ps " << hltprescale << std::endl; } packedPrescales->addPrescaledTrigger(i, pvdet.second); - //assert( hltprescale == pvdet.second ); } iEvent.put(std::move(packedPrescales)); iEvent.put(std::move(packedPrescalesL1max), "l1max"); diff --git a/PhysicsTools/TagAndProbe/interface/TriggerCandProducer.icc b/PhysicsTools/TagAndProbe/interface/TriggerCandProducer.icc index 07d753fca8f35..c15b9ae9b5276 100644 --- a/PhysicsTools/TagAndProbe/interface/TriggerCandProducer.icc +++ b/PhysicsTools/TagAndProbe/interface/TriggerCandProducer.icc @@ -108,7 +108,7 @@ void TriggerCandProducer::produce(edm::Event& event, const edm::EventSet for (std::vector::const_iterator iMyHLT = hltTags_.begin(); iMyHLT != hltTags_.end(); ++iMyHLT) { if ((*iMyHLT).label() == *iHLT) { triggerInMenu[(*iMyHLT).label()] = true; - if (hltPrescaleProvider_.prescaleValue(event, eventSetup, *iHLT) == 1) + if (hltPrescaleProvider_.prescaleValue(event, eventSetup, *iHLT) == 1) triggerUnprescaled[(*iMyHLT).label()] = true; } } diff --git a/Validation/RecoVertex/src/AnotherPrimaryVertexAnalyzer.cc b/Validation/RecoVertex/src/AnotherPrimaryVertexAnalyzer.cc index 7f610e7b3d68e..ce00429235b1e 100644 --- a/Validation/RecoVertex/src/AnotherPrimaryVertexAnalyzer.cc +++ b/Validation/RecoVertex/src/AnotherPrimaryVertexAnalyzer.cc @@ -102,15 +102,10 @@ AnotherPrimaryVertexAnalyzer::~AnotherPrimaryVertexAnalyzer() {} // ------------ method called to for each event ------------ void AnotherPrimaryVertexAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { - // compute event weigth - - double weight = 1.; - - if (_weightprov) - weight = _weightprov->prescaleWeight(iEvent, iSetup); + // compute event weight + auto const weight = _weightprov ? _weightprov->prescaleWeight(iEvent, iSetup) : 1.; // get PV - edm::Handle pvcoll; iEvent.getByToken(_recoVertexCollectionToken, pvcoll);