CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
PrescaleWeightProvider Class Reference

#include <PrescaleWeightProvider.h>

Public Member Functions

void initRun (const edm::Run &run, const edm::EventSetup &setup)
 
template<typename T = int>
T prescaleWeight (const edm::Event &event, const edm::EventSetup &setup)
 
template<typename T >
 PrescaleWeightProvider (const edm::ParameterSet &config, edm::ConsumesCollector &&iC, T &module)
 
template<typename T >
 PrescaleWeightProvider (const edm::ParameterSet &config, edm::ConsumesCollector &iC, T &module)
 
 ~PrescaleWeightProvider ()
 

Private Member Functions

void parseL1Seeds (const std::string &l1Seeds)
 
 PrescaleWeightProvider (const edm::ParameterSet &config, edm::ConsumesCollector &iC)
 

Private Attributes

bool configured_
 
std::vector< std::string > hltPaths_
 
std::unique_ptr< HLTPrescaleProviderhltPrescaleProvider_
 
bool init_
 
edm::InputTag l1GtTriggerMenuLiteTag_
 
edm::EDGetTokenT< L1GtTriggerMenuLitel1GtTriggerMenuLiteToken_
 
std::vector< std::string > l1SeedPaths_
 
edm::Handle< L1GtTriggerMenuLitetriggerMenuLite_
 
edm::InputTag triggerResultsTag_
 
edm::EDGetTokenT< edm::TriggerResultstriggerResultsToken_
 
unsigned verbosity_
 

Detailed Description

Definition at line 48 of file PrescaleWeightProvider.h.

Constructor & Destructor Documentation

◆ PrescaleWeightProvider() [1/3]

template<typename T >
PrescaleWeightProvider::PrescaleWeightProvider ( const edm::ParameterSet config,
edm::ConsumesCollector &&  iC,
T module 
)

Definition at line 88 of file PrescaleWeightProvider.h.

PrescaleWeightProvider(const edm::ParameterSet &config, edm::ConsumesCollector &&iC, T &module)
Definition: config.py:1

◆ PrescaleWeightProvider() [2/3]

template<typename T >
PrescaleWeightProvider::PrescaleWeightProvider ( const edm::ParameterSet config,
edm::ConsumesCollector iC,
T module 
)

Definition at line 92 of file PrescaleWeightProvider.h.

References DMR_cfg::config, hltPrescaleProvider_, and callgraph::module.

94  hltPrescaleProvider_ = std::make_unique<HLTPrescaleProvider>(config, iC, module);
95 }
PrescaleWeightProvider(const edm::ParameterSet &config, edm::ConsumesCollector &&iC, T &module)
dictionary config
Read in AllInOne config in JSON format.
Definition: DMR_cfg.py:21
Definition: config.py:1
std::unique_ptr< HLTPrescaleProvider > hltPrescaleProvider_

◆ ~PrescaleWeightProvider()

PrescaleWeightProvider::~PrescaleWeightProvider ( )
inline

Definition at line 72 of file PrescaleWeightProvider.h.

72 {}

◆ PrescaleWeightProvider() [3/3]

PrescaleWeightProvider::PrescaleWeightProvider ( const edm::ParameterSet config,
edm::ConsumesCollector iC 
)
private

Definition at line 17 of file PrescaleWeightProvider.cc.

References configured_, hltPaths_, edm::InRun, l1GtTriggerMenuLiteTag_, l1GtTriggerMenuLiteToken_, edm::InputTag::label(), edm::ConsumesCollector::mayConsume(), edm::InputTag::process(), triggerResultsTag_, triggerResultsToken_, and verbosity_.

19  : init_(false),
20  verbosity_(0),
21  triggerResultsTag_("TriggerResults::HLT"),
23  l1GtTriggerMenuLiteTag_("l1GtTriggerMenuLite"),
25  hltPaths_.clear();
26  if (config.exists("prescaleWeightVerbosityLevel"))
27  verbosity_ = config.getParameter<unsigned>("prescaleWeightVerbosityLevel");
28  if (config.exists("prescaleWeightTriggerResults"))
29  triggerResultsTag_ = config.getParameter<edm::InputTag>("prescaleWeightTriggerResults");
30  if (config.exists("prescaleWeightL1GtTriggerMenuLite"))
31  l1GtTriggerMenuLiteTag_ = config.getParameter<edm::InputTag>("prescaleWeightL1GtTriggerMenuLite");
32  if (config.exists("prescaleWeightHltPaths"))
33  hltPaths_ = config.getParameter<std::vector<std::string> >("prescaleWeightHltPaths");
34 
35  configured_ = true;
36  if (triggerResultsTag_.process().empty()) {
37  configured_ = false;
38  if (verbosity_ > 0)
39  edm::LogWarning("PrescaleWeightProvider") << "Process name not configured via TriggerResults InputTag";
40  } else if (triggerResultsTag_.label().empty()) {
41  configured_ = false;
42  if (verbosity_ > 0)
43  edm::LogWarning("PrescaleWeightProvider") << "TriggerResults label not configured";
44  } else if (l1GtTriggerMenuLiteTag_.label().empty()) {
45  configured_ = false;
46  if (verbosity_ > 0)
47  edm::LogWarning("PrescaleWeightProvider") << "L1GtTriggerMenuLite label not configured";
48  } else if (hltPaths_.empty()) {
49  configured_ = false;
50  if (verbosity_ > 0)
51  edm::LogError("PrescaleWeightProvider") << "HLT paths of interest not configured";
52  }
53  if (configured_) {
56  }
57 }
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
Definition: config.py:1
std::string const & label() const
Definition: InputTag.h:36
Log< level::Error, false > LogError
std::vector< std::string > hltPaths_
edm::EDGetTokenT< L1GtTriggerMenuLite > l1GtTriggerMenuLiteToken_
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
Log< level::Warning, false > LogWarning
std::string const & process() const
Definition: InputTag.h:40

Member Function Documentation

◆ initRun()

void PrescaleWeightProvider::initRun ( const edm::Run run,
const edm::EventSetup setup 
)

Definition at line 59 of file PrescaleWeightProvider.cc.

References configured_, HltComparatorCreateWorkflow::hltConfig, hltPrescaleProvider_, init_, edm::HandleBase::isValid(), l1GtTriggerMenuLiteTag_, l1GtTriggerMenuLiteToken_, edm::InputTag::label(), edm::InputTag::process(), writedatasetfile::run, singleTopDQM_cfi::setup, triggerMenuLite_, triggerResultsTag_, and verbosity_.

59  {
60  init_ = true;
61 
62  if (!configured_) {
63  init_ = false;
64  if (verbosity_ > 0)
65  edm::LogWarning("PrescaleWeightProvider") << "Run initialisation failed due to failing configuration";
66  return;
67  }
68 
69  HLTConfigProvider const& hltConfig = hltPrescaleProvider_->hltConfigProvider();
70  bool hltChanged(false);
71  if (!hltPrescaleProvider_->init(run, setup, triggerResultsTag_.process(), hltChanged)) {
72  if (verbosity_ > 0)
73  edm::LogError("PrescaleWeightProvider")
74  << "HLT config initialization error with process name \"" << triggerResultsTag_.process() << "\"";
75  init_ = false;
76  } else if (hltConfig.size() <= 0) {
77  if (verbosity_ > 0)
78  edm::LogError("PrescaleWeightProvider") << "HLT config size error";
79  init_ = false;
80  } else if (hltChanged) {
81  if (verbosity_ > 0)
82  edm::LogInfo("PrescaleWeightProvider") << "HLT configuration changed";
83  }
84  if (!init_)
85  return;
86 
88  if (!triggerMenuLite_.isValid()) {
89  if (verbosity_ > 0)
90  edm::LogError("PrescaleWeightProvider")
91  << "L1GtTriggerMenuLite with label \"" << l1GtTriggerMenuLiteTag_.label() << "\" not found";
92  init_ = false;
93  }
94 }
edm::Handle< L1GtTriggerMenuLite > triggerMenuLite_
std::string const & label() const
Definition: InputTag.h:36
Log< level::Error, false > LogError
std::unique_ptr< HLTPrescaleProvider > hltPrescaleProvider_
edm::EDGetTokenT< L1GtTriggerMenuLite > l1GtTriggerMenuLiteToken_
Log< level::Info, false > LogInfo
bool isValid() const
Definition: HandleBase.h:70
Log< level::Warning, false > LogWarning
std::string const & process() const
Definition: InputTag.h:40

◆ parseL1Seeds()

void PrescaleWeightProvider::parseL1Seeds ( const std::string &  l1Seeds)
private

Definition at line 96 of file PrescaleWeightProvider.cc.

References visDQMUpload::buf, l1SeedPaths_, contentValuesCheck::ss, AlCaHLTBitMon_QueryRunRegistry::string, and verbosity_.

Referenced by prescaleWeight().

96  {
97  l1SeedPaths_.clear();
98  std::stringstream ss(l1Seeds);
100 
101  while (ss.good() && !ss.eof()) {
102  ss >> buf;
103  if (buf[0] == '(' || buf[buf.size() - 1] == ')' || buf == "AND" || buf == "NOT") {
104  l1SeedPaths_.clear();
105  if (verbosity_ > 0)
106  edm::LogWarning("PrescaleWeightProvider::parseL1Seeds") << "Only supported logical expression is OR";
107  return;
108  } else if (buf == "OR")
109  continue;
110  else
111  l1SeedPaths_.push_back(buf);
112  }
113 }
std::vector< std::string > l1SeedPaths_
Log< level::Warning, false > LogWarning

◆ prescaleWeight()

template<typename T >
T PrescaleWeightProvider::prescaleWeight ( const edm::Event event,
const edm::EventSetup setup 
)

Definition at line 98 of file PrescaleWeightProvider.h.

References L1GtUtils::decision(), edm::InputTag::encode(), edmPickEvents::event, L1GtTriggerMenuLite::gtTechTrigName(), HltComparatorCreateWorkflow::hltConfig, TriggerAnalyzer::hltPath, hltPaths_, hltPrescaleProvider_, init_, l1SeedPaths_, or, parseL1Seeds(), L1GtUtils::prescaleFactor(), singleTopDQM_cfi::setup, AlCaHLTBitMon_QueryRunRegistry::string, triggerMenuLite_, triggerResults, triggerResultsTag_, triggerResultsToken_, interactiveExample::ui, verbosity_, and mps_merge::weight.

98  {
99  static_assert(std::is_same_v<T, double> or std::is_same_v<T, FractionalPrescale>,
100  "\n\tPlease use prescaleWeight<double> or prescaleWeight<FractionalPrescale>"
101  "\n\t(other types for HLT prescales are not supported anymore by PrescaleWeightProvider");
102  if (!init_)
103  return 1;
104 
105  // L1
106  L1GtUtils const& l1GtUtils = hltPrescaleProvider_->l1GtUtils();
107 
108  // HLT
109  HLTConfigProvider const& hltConfig = hltPrescaleProvider_->hltConfigProvider();
110 
112  event.getByToken(triggerResultsToken_, triggerResults);
113  if (!triggerResults.isValid()) {
114  if (verbosity_ > 0)
115  edm::LogError("PrescaleWeightProvider::prescaleWeight")
116  << "TriggerResults product not found for InputTag \"" << triggerResultsTag_.encode() << "\"";
117  return 1;
118  }
119 
120  const int SENTINEL(-1);
121  int weight(SENTINEL);
122 
123  for (unsigned ui = 0; ui < hltPaths_.size(); ui++) {
124  const std::string hltPath(hltPaths_.at(ui));
125  unsigned hltIndex(hltConfig.triggerIndex(hltPath));
126  if (hltIndex == hltConfig.size()) {
127  if (verbosity_ > 0)
128  edm::LogError("PrescaleWeightProvider::prescaleWeight") << "HLT path \"" << hltPath << "\" does not exist";
129  continue;
130  }
131  if (!triggerResults->accept(hltIndex))
132  continue;
133 
134  const std::vector<std::pair<bool, std::string> >& level1Seeds = hltConfig.hltL1GTSeeds(hltPath);
135  if (level1Seeds.size() != 1) {
136  if (verbosity_ > 0)
137  edm::LogError("PrescaleWeightProvider::prescaleWeight")
138  << "HLT path \"" << hltPath << "\" provides too many L1 seeds";
139  return 1;
140  }
141  parseL1Seeds(level1Seeds.at(0).second);
142  if (l1SeedPaths_.empty()) {
143  if (verbosity_ > 0)
144  edm::LogWarning("PrescaleWeightProvider::prescaleWeight")
145  << "Failed to parse L1 seeds for HLT path \"" << hltPath << "\"";
146  continue;
147  }
148 
149  int l1Prescale(SENTINEL);
150  for (unsigned uj = 0; uj < l1SeedPaths_.size(); uj++) {
151  int l1TempPrescale(SENTINEL);
152  int errorCode(0);
153  if (level1Seeds.at(0).first) { // technical triggers
154  unsigned techBit(atoi(l1SeedPaths_.at(uj).c_str()));
155  const std::string techName(*(triggerMenuLite_->gtTechTrigName(techBit, errorCode)));
156  if (errorCode != 0)
157  continue;
158  if (!l1GtUtils.decision(event, techName, errorCode))
159  continue;
160  if (errorCode != 0)
161  continue;
162  l1TempPrescale = l1GtUtils.prescaleFactor(event, techName, errorCode);
163  if (errorCode != 0)
164  continue;
165  } else { // algorithmic triggers
166  if (!l1GtUtils.decision(event, l1SeedPaths_.at(uj), errorCode))
167  continue;
168  if (errorCode != 0)
169  continue;
170  l1TempPrescale = l1GtUtils.prescaleFactor(event, l1SeedPaths_.at(uj), errorCode);
171  if (errorCode != 0)
172  continue;
173  }
174  if (l1TempPrescale > 0) {
175  if (l1Prescale == SENTINEL || l1Prescale > l1TempPrescale)
176  l1Prescale = l1TempPrescale;
177  }
178  }
179  if (l1Prescale == SENTINEL) {
180  if (verbosity_ > 0)
181  edm::LogError("PrescaleWeightProvider::prescaleWeight")
182  << "Unable to find the L1 prescale for HLT path \"" << hltPath << "\"";
183  continue;
184  }
185 
186  auto const prescale = l1Prescale * hltPrescaleProvider_->prescaleValue<T>(event, setup, hltPath);
187 
188  if (prescale > 0) {
189  if (weight == SENTINEL || weight > prescale) {
190  weight = prescale;
191  }
192  }
193  }
194 
195  if (weight == SENTINEL) {
196  if (verbosity_ > 0)
197  edm::LogWarning("PrescaleWeightProvider::prescaleWeight")
198  << "No valid weight for any requested HLT path, returning default weight of 1";
199  return 1;
200  }
201 
202  return weight;
203 }
std::string encode() const
Definition: InputTag.cc:159
const int prescaleFactor(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
return prescale factor for a given algorithm or technical trigger
Definition: L1GtUtils.cc:1078
edm::Handle< L1GtTriggerMenuLite > triggerMenuLite_
Definition: weight.py:1
Log< level::Error, false > LogError
std::vector< std::string > l1SeedPaths_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::vector< std::string > hltPaths_
std::unique_ptr< HLTPrescaleProvider > hltPrescaleProvider_
static std::string const triggerResults
Definition: EdmProvDump.cc:47
const std::string * gtTechTrigName(const unsigned int bitNumber, int &errorCode) const
const bool decision(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
Definition: L1GtUtils.cc:1066
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
Log< level::Warning, false > LogWarning
long double T
void parseL1Seeds(const std::string &l1Seeds)
Definition: event.py:1

Member Data Documentation

◆ configured_

bool PrescaleWeightProvider::configured_
private

Definition at line 49 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

◆ hltPaths_

std::vector<std::string> PrescaleWeightProvider::hltPaths_
private

Definition at line 62 of file PrescaleWeightProvider.h.

Referenced by prescaleWeight(), and PrescaleWeightProvider().

◆ hltPrescaleProvider_

std::unique_ptr<HLTPrescaleProvider> PrescaleWeightProvider::hltPrescaleProvider_
private

Definition at line 51 of file PrescaleWeightProvider.h.

Referenced by initRun(), prescaleWeight(), and PrescaleWeightProvider().

◆ init_

bool PrescaleWeightProvider::init_
private

Definition at line 50 of file PrescaleWeightProvider.h.

Referenced by initRun(), and prescaleWeight().

◆ l1GtTriggerMenuLiteTag_

edm::InputTag PrescaleWeightProvider::l1GtTriggerMenuLiteTag_
private

Definition at line 60 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

◆ l1GtTriggerMenuLiteToken_

edm::EDGetTokenT<L1GtTriggerMenuLite> PrescaleWeightProvider::l1GtTriggerMenuLiteToken_
private

Definition at line 61 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

◆ l1SeedPaths_

std::vector<std::string> PrescaleWeightProvider::l1SeedPaths_
private

Definition at line 54 of file PrescaleWeightProvider.h.

Referenced by parseL1Seeds(), and prescaleWeight().

◆ triggerMenuLite_

edm::Handle<L1GtTriggerMenuLite> PrescaleWeightProvider::triggerMenuLite_
private

Definition at line 52 of file PrescaleWeightProvider.h.

Referenced by initRun(), and prescaleWeight().

◆ triggerResultsTag_

edm::InputTag PrescaleWeightProvider::triggerResultsTag_
private

Definition at line 58 of file PrescaleWeightProvider.h.

Referenced by initRun(), prescaleWeight(), and PrescaleWeightProvider().

◆ triggerResultsToken_

edm::EDGetTokenT<edm::TriggerResults> PrescaleWeightProvider::triggerResultsToken_
private

Definition at line 59 of file PrescaleWeightProvider.h.

Referenced by prescaleWeight(), and PrescaleWeightProvider().

◆ verbosity_

unsigned PrescaleWeightProvider::verbosity_
private