Skip to content

Commit

Permalink
changing to new HLT prescale interface as suggested by A. Bocci
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Harper authored and rekovic committed Jan 26, 2021
1 parent 2d2109d commit 2f038e3
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 65 deletions.
7 changes: 7 additions & 0 deletions HLTrigger/HLTcore/interface/FractionalPrescale.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef HLTrigger_HLTcore_FractionalPrescale_h
#define HLTrigger_HLTcore_FractionalPrescale_h

#include <boost/rational.hpp>
using FractionalPrescale = boost::rational<int>;

#endif
9 changes: 8 additions & 1 deletion HLTrigger/HLTcore/interface/HLTConfigProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "FWCore/Framework/interface/LuminosityBlock.h"

#include "HLTrigger/HLTcore/interface/HLTConfigData.h"
#include "HLTrigger/HLTcore/interface/FractionalPrescale.h"

#include <map>
#include <string>
Expand Down Expand Up @@ -183,7 +184,13 @@ class HLTConfigProvider {
/// Number of HLT prescale sets
unsigned int prescaleSize() const { return hltConfigData_->prescaleSize(); }
/// HLT prescale value in specific prescale set for a specific trigger path
unsigned int prescaleValue(unsigned int set, const std::string& trigger) const {
template <typename T = unsigned int>
T prescaleValue(unsigned int set, const std::string& trigger) const {
//limit to only 4 allowed types
static_assert(std::is_same_v<T, unsigned int> or std::is_same_v<T, FractionalPrescale> or std::is_same_v<T, int> or
std::is_same_v<T, double>,
"Please use prescaleValue<unsigned int>, prescaleValue<int>, prescaleValue<double>, or "
"prescaleValue<FractionalPrescale>,\n note int and unsigned int will be depreated soon");
return hltConfigData_->prescaleValue(set, trigger);
}

Expand Down
52 changes: 45 additions & 7 deletions HLTrigger/HLTcore/interface/HLTPrescaleProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* function calls were added. W. David Dagenhart
*/

#include "HLTrigger/HLTcore/interface/FractionalPrescale.h"
#include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
#include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtUtils.h"
#include "L1Trigger/L1TGlobal/interface/L1TGlobalUtil.h"
Expand Down Expand Up @@ -58,25 +59,53 @@ class HLTPrescaleProvider {
// negative == error

/// combining the two methods above
unsigned int prescaleValue(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger);
template <typename T = unsigned int>
T prescaleValue(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) {
const int set(prescaleSet(iEvent, iSetup));
//there is a template specialisation for unsigned in which returns +1 which
//emulates old behaviour
return set < 0 ? -1 : hltConfigProvider_.prescaleValue<T>(static_cast<unsigned int>(set), trigger);
}

/// Combined L1T (pair.first) and HLT (pair.second) prescales per HLT path
std::pair<int, int> prescaleValues(const edm::Event& iEvent,
const edm::EventSetup& iSetup,
const std::string& trigger);
template <typename TL1 = int, typename THLT = TL1>
std::pair<TL1, THLT> prescaleValues(const edm::Event& iEvent,
const edm::EventSetup& iSetup,
const std::string& trigger) {
return {convertL1PS<TL1>(getL1PrescaleValue(iEvent, iSetup, trigger)),
prescaleValue<THLT>(iEvent, iSetup, trigger)};
}
// any one negative => error in retrieving this (L1T or HLT) prescale

// In case of a complex Boolean expression as L1 seed
std::pair<std::vector<std::pair<std::string, int> >, int> prescaleValuesInDetail(const edm::Event& iEvent,
const edm::EventSetup& iSetup,
const std::string& trigger);
template <typename TL1 = int, typename THLT = TL1>
std::pair<std::vector<std::pair<std::string, TL1> >, THLT> prescaleValuesInDetail(const edm::Event& iEvent,
const edm::EventSetup& iSetup,
const std::string& trigger) {
std::pair<std::vector<std::pair<std::string, TL1> >, THLT> retval;
for (auto& entry : getL1PrescaleValueInDetail(iEvent, iSetup, trigger)) {
retval.first.emplace_back(std::move(entry.first), convertL1PS<TL1>(entry.second));
}
retval.second = prescaleValue<THLT>(iEvent, iSetup, trigger);
return retval;
}
// Event rejected by HLTPrescaler on ith HLT path?
bool rejectedByHLTPrescaler(const edm::TriggerResults& triggerResults, unsigned int i) const;
static int l1PrescaleDenominator() { return kL1PrescaleDenominator_; }

private:
void checkL1GtUtils() const;
void checkL1TGlobalUtil() const;
template <typename T>
T convertL1PS(double val) const {
return T(val);
}

double getL1PrescaleValue(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger);
std::vector<std::pair<std::string, double> > getL1PrescaleValueInDetail(const edm::Event& iEvent,
const edm::EventSetup& iSetup,
const std::string& trigger);
static constexpr int kL1PrescaleDenominator_ = 100;
HLTConfigProvider hltConfigProvider_;
std::unique_ptr<L1GtUtils> l1GtUtils_;
std::unique_ptr<l1t::L1TGlobalUtil> l1tGlobalUtil_;
Expand All @@ -97,4 +126,13 @@ HLTPrescaleProvider::HLTPrescaleProvider(edm::ParameterSet const& pset, edm::Con
l1tGlobalUtil_ = std::make_unique<l1t::L1TGlobalUtil>(pset, iC, module, l1t::UseEventSetupIn::Run);
}
}

template <>
FractionalPrescale HLTPrescaleProvider::convertL1PS<FractionalPrescale>(double val) const;

template <>
unsigned int HLTPrescaleProvider::prescaleValue<unsigned int>(const edm::Event& iEvent,
const edm::EventSetup& iSetup,
const std::string& trigger);

#endif
71 changes: 71 additions & 0 deletions HLTrigger/HLTcore/plugins/HLTPrescaleExample.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "HLTrigger/HLTcore/interface/HLTPrescaleProvider.h"
#include <iostream>

class HLTPrescaleExample : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
public:
HLTPrescaleExample(edm::ParameterSet const& iPSet);

void beginJob() override {}
void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override;
void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
void endJob() override {}

private:
HLTPrescaleProvider hltPSProvider_;
std::string hltProcess_;
std::string hltPath_;
};

HLTPrescaleExample::HLTPrescaleExample(edm::ParameterSet const& iPSet)
: hltPSProvider_(iPSet.getParameter<edm::ParameterSet>("hltPSProvCfg"), consumesCollector(), *this),
hltProcess_(iPSet.getParameter<std::string>("hltProcess")),
hltPath_(iPSet.getParameter<std::string>("hltPath")) {}

void HLTPrescaleExample::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
bool changed = false;
hltPSProvider_.init(iRun, iSetup, hltProcess_, changed);
}

void HLTPrescaleExample::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
auto hltPSDouble = hltPSProvider_.prescaleValue<double>(iEvent, iSetup, hltPath_);
auto hltPSInt = hltPSProvider_.prescaleValue<int>(iEvent, iSetup, hltPath_);
auto hltPSUInt = hltPSProvider_.prescaleValue<unsigned int>(iEvent, iSetup, hltPath_);
auto hltPSFrac = hltPSProvider_.prescaleValue<FractionalPrescale>(iEvent, iSetup, hltPath_);

auto l1HLTPSDouble = hltPSProvider_.prescaleValues<double>(iEvent, iSetup, hltPath_);
auto l1HLTPSInt = hltPSProvider_.prescaleValues<int>(iEvent, iSetup, hltPath_);
auto l1HLTPSFrac = hltPSProvider_.prescaleValues<FractionalPrescale>(iEvent, iSetup, hltPath_);
auto l1HLTPSDoubleFrac = hltPSProvider_.prescaleValues<double, FractionalPrescale>(iEvent, iSetup, hltPath_);

auto l1HLTDetailPSDouble = hltPSProvider_.prescaleValuesInDetail<double>(iEvent, iSetup, hltPath_);
auto l1HLTDetailPSInt = hltPSProvider_.prescaleValuesInDetail<int>(iEvent, iSetup, hltPath_);
auto l1HLTDetailPSFrac = hltPSProvider_.prescaleValuesInDetail<FractionalPrescale>(iEvent, iSetup, hltPath_);

std::cout << "---------Begin Event--------" << std::endl;
std::cout << "hltDouble " << hltPSDouble << " hltInt " << hltPSInt << " hltPSUInt " << hltPSUInt << " hltFrac "
<< hltPSFrac << std::endl;

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;
for (const auto& entry : val.first) {
out << entry.first << ":" << entry.second << " ";
}
out << " HLT : " << val.second << std::endl;
};

printL1HLTDetail("l1HLTDetailDouble ", l1HLTDetailPSDouble, std::cout);
printL1HLTDetail("l1HLTDetailInt ", l1HLTDetailPSInt, std::cout);
printL1HLTDetail("l1HLTDetailFrac ", l1HLTDetailPSFrac, std::cout);
std::cout << "---------End Event--------" << std::endl << std::endl;
}

DEFINE_FWK_MODULE(HLTPrescaleExample);
Loading

0 comments on commit 2f038e3

Please sign in to comment.