CMS 3D CMS Logo

PrescaleWeightProvider.cc
Go to the documentation of this file.
1 //
2 // See header file for description
3 //
4 
6 
7 #include <sstream>
8 
13 
17 
19  // default values
20  : init_(false),
21  verbosity_(0),
22  triggerResultsTag_("TriggerResults::HLT"),
23  triggerResultsToken_(iC.mayConsume<edm::TriggerResults>(triggerResultsTag_)),
24  l1GtTriggerMenuLiteTag_("l1GtTriggerMenuLite"),
25  l1GtTriggerMenuLiteToken_(iC.mayConsume<L1GtTriggerMenuLite, edm::InRun>(l1GtTriggerMenuLiteTag_)) {
26  hltPaths_.clear();
27  if (config.exists("prescaleWeightVerbosityLevel"))
28  verbosity_ = config.getParameter<unsigned>("prescaleWeightVerbosityLevel");
29  if (config.exists("prescaleWeightTriggerResults"))
30  triggerResultsTag_ = config.getParameter<edm::InputTag>("prescaleWeightTriggerResults");
31  if (config.exists("prescaleWeightL1GtTriggerMenuLite"))
32  l1GtTriggerMenuLiteTag_ = config.getParameter<edm::InputTag>("prescaleWeightL1GtTriggerMenuLite");
33  if (config.exists("prescaleWeightHltPaths"))
34  hltPaths_ = config.getParameter<std::vector<std::string> >("prescaleWeightHltPaths");
35 
36  configured_ = true;
37  if (triggerResultsTag_.process().empty()) {
38  configured_ = false;
39  if (verbosity_ > 0)
40  edm::LogWarning("PrescaleWeightProvider") << "Process name not configured via TriggerResults InputTag";
41  } else if (triggerResultsTag_.label().empty()) {
42  configured_ = false;
43  if (verbosity_ > 0)
44  edm::LogWarning("PrescaleWeightProvider") << "TriggerResults label not configured";
45  } else if (l1GtTriggerMenuLiteTag_.label().empty()) {
46  configured_ = false;
47  if (verbosity_ > 0)
48  edm::LogWarning("PrescaleWeightProvider") << "L1GtTriggerMenuLite label not configured";
49  } else if (hltPaths_.empty()) {
50  configured_ = false;
51  if (verbosity_ > 0)
52  edm::LogError("PrescaleWeightProvider") << "HLT paths of interest not configured";
53  }
54  if (configured_) {
57  }
58 }
59 
61  init_ = true;
62 
63  if (!configured_) {
64  init_ = false;
65  if (verbosity_ > 0)
66  edm::LogWarning("PrescaleWeightProvider") << "Run initialisation failed due to failing configuration";
67  return;
68  }
69 
70  HLTConfigProvider const& hltConfig = hltPrescaleProvider_->hltConfigProvider();
71  bool hltChanged(false);
72  if (!hltPrescaleProvider_->init(run, setup, triggerResultsTag_.process(), hltChanged)) {
73  if (verbosity_ > 0)
74  edm::LogError("PrescaleWeightProvider")
75  << "HLT config initialization error with process name \"" << triggerResultsTag_.process() << "\"";
76  init_ = false;
77  } else if (hltConfig.size() <= 0) {
78  if (verbosity_ > 0)
79  edm::LogError("PrescaleWeightProvider") << "HLT config size error";
80  init_ = false;
81  } else if (hltChanged) {
82  if (verbosity_ > 0)
83  edm::LogInfo("PrescaleWeightProvider") << "HLT configuration changed";
84  }
85  if (!init_)
86  return;
87 
89  if (!triggerMenuLite_.isValid()) {
90  if (verbosity_ > 0)
91  edm::LogError("PrescaleWeightProvider")
92  << "L1GtTriggerMenuLite with label \"" << l1GtTriggerMenuLiteTag_.label() << "\" not found";
93  init_ = false;
94  }
95 }
96 
98  if (!init_)
99  return 1;
100 
101  // L1
102  L1GtUtils const& l1GtUtils = hltPrescaleProvider_->l1GtUtils();
103 
104  // HLT
105  HLTConfigProvider const& hltConfig = hltPrescaleProvider_->hltConfigProvider();
106 
108  event.getByToken(triggerResultsToken_, triggerResults);
109  if (!triggerResults.isValid()) {
110  if (verbosity_ > 0)
111  edm::LogError("PrescaleWeightProvider::prescaleWeight")
112  << "TriggerResults product not found for InputTag \"" << triggerResultsTag_.encode() << "\"";
113  return 1;
114  }
115 
116  const int SENTINEL(-1);
117  int weight(SENTINEL);
118 
119  for (unsigned ui = 0; ui < hltPaths_.size(); ui++) {
120  const std::string hltPath(hltPaths_.at(ui));
121  unsigned hltIndex(hltConfig.triggerIndex(hltPath));
122  if (hltIndex == hltConfig.size()) {
123  if (verbosity_ > 0)
124  edm::LogError("PrescaleWeightProvider::prescaleWeight") << "HLT path \"" << hltPath << "\" does not exist";
125  continue;
126  }
127  if (!triggerResults->accept(hltIndex))
128  continue;
129 
130  const std::vector<std::pair<bool, std::string> >& level1Seeds = hltConfig.hltL1GTSeeds(hltPath);
131  if (level1Seeds.size() != 1) {
132  if (verbosity_ > 0)
133  edm::LogError("PrescaleWeightProvider::prescaleWeight")
134  << "HLT path \"" << hltPath << "\" provides too many L1 seeds";
135  return 1;
136  }
137  parseL1Seeds(level1Seeds.at(0).second);
138  if (l1SeedPaths_.empty()) {
139  if (verbosity_ > 0)
140  edm::LogWarning("PrescaleWeightProvider::prescaleWeight")
141  << "Failed to parse L1 seeds for HLT path \"" << hltPath << "\"";
142  continue;
143  }
144 
145  int l1Prescale(SENTINEL);
146  for (unsigned uj = 0; uj < l1SeedPaths_.size(); uj++) {
147  int l1TempPrescale(SENTINEL);
148  int errorCode(0);
149  if (level1Seeds.at(0).first) { // technical triggers
150  unsigned techBit(atoi(l1SeedPaths_.at(uj).c_str()));
151  const std::string techName(*(triggerMenuLite_->gtTechTrigName(techBit, errorCode)));
152  if (errorCode != 0)
153  continue;
154  if (!l1GtUtils.decision(event, techName, errorCode))
155  continue;
156  if (errorCode != 0)
157  continue;
158  l1TempPrescale = l1GtUtils.prescaleFactor(event, techName, errorCode);
159  if (errorCode != 0)
160  continue;
161  } else { // algorithmic triggers
162  if (!l1GtUtils.decision(event, l1SeedPaths_.at(uj), errorCode))
163  continue;
164  if (errorCode != 0)
165  continue;
166  l1TempPrescale = l1GtUtils.prescaleFactor(event, l1SeedPaths_.at(uj), errorCode);
167  if (errorCode != 0)
168  continue;
169  }
170  if (l1TempPrescale > 0) {
171  if (l1Prescale == SENTINEL || l1Prescale > l1TempPrescale)
172  l1Prescale = l1TempPrescale;
173  }
174  }
175  if (l1Prescale == SENTINEL) {
176  if (verbosity_ > 0)
177  edm::LogError("PrescaleWeightProvider::prescaleWeight")
178  << "Unable to find the L1 prescale for HLT path \"" << hltPath << "\"";
179  continue;
180  }
181 
182  int hltPrescale(hltPrescaleProvider_->prescaleValue(event, setup, hltPath));
183 
184  if (hltPrescale * l1Prescale > 0) {
185  if (weight == SENTINEL || weight > hltPrescale * l1Prescale) {
186  weight = hltPrescale * l1Prescale;
187  }
188  }
189  }
190 
191  if (weight == SENTINEL) {
192  if (verbosity_ > 0)
193  edm::LogWarning("PrescaleWeightProvider::prescaleWeight")
194  << "No valid weight for any requested HLT path, returning default weight of 1";
195  return 1;
196  }
197  return weight;
198 }
199 
201  l1SeedPaths_.clear();
202  std::stringstream ss(l1Seeds);
204 
205  while (ss.good() && !ss.eof()) {
206  ss >> buf;
207  if (buf[0] == '(' || buf[buf.size() - 1] == ')' || buf == "AND" || buf == "NOT") {
208  l1SeedPaths_.clear();
209  if (verbosity_ > 0)
210  edm::LogWarning("PrescaleWeightProvider::parseL1Seeds") << "Only supported logical expression is OR";
211  return;
212  } else if (buf == "OR")
213  continue;
214  else
215  l1SeedPaths_.push_back(buf);
216  }
217 }
interactiveExample.ui
ui
Definition: interactiveExample.py:13
PrescaleWeightProvider::hltPrescaleProvider_
std::unique_ptr< HLTPrescaleProvider > hltPrescaleProvider_
Definition: PrescaleWeightProvider.h:50
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
BranchType.h
TriggerResults.h
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
mps_merge.weight
weight
Definition: mps_merge.py:88
PrescaleWeightProvider::initRun
void initRun(const edm::Run &run, const edm::EventSetup &setup)
Definition: PrescaleWeightProvider.cc:60
TriggerAnalyzer.hltPath
hltPath
Definition: TriggerAnalyzer.py:62
PrescaleWeightProvider::hltPaths_
std::vector< std::string > hltPaths_
Definition: PrescaleWeightProvider.h:61
triggerResults
static const std::string triggerResults
Definition: EdmProvDump.cc:45
edm::InputTag::process
std::string const & process() const
Definition: InputTag.h:40
L1GtUtils::decision
const bool decision(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
Definition: L1GtUtils.cc:1066
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
L1GtTriggerMenuLite.h
edm::Handle< edm::TriggerResults >
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::InRun
Definition: BranchType.h:11
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
L1GtTriggerMenuLite::gtTechTrigName
const std::string * gtTechTrigName(const unsigned int bitNumber, int &errorCode) const
Definition: L1GtTriggerMenuLite.cc:346
PrescaleWeightProvider::triggerResultsToken_
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
Definition: PrescaleWeightProvider.h:58
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
config
Definition: config.py:1
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
PrescaleWeightProvider::configured_
bool configured_
Definition: PrescaleWeightProvider.h:48
PrescaleWeightProvider::prescaleWeight
int prescaleWeight(const edm::Event &event, const edm::EventSetup &setup)
Definition: PrescaleWeightProvider.cc:97
L1GtUtils
Definition: L1GtUtils.h:66
PrescaleWeightProvider::l1GtTriggerMenuLiteTag_
edm::InputTag l1GtTriggerMenuLiteTag_
Definition: PrescaleWeightProvider.h:59
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PrescaleWeightProvider::parseL1Seeds
void parseL1Seeds(const std::string &l1Seeds)
Definition: PrescaleWeightProvider.cc:200
PrescaleWeightProvider::verbosity_
unsigned verbosity_
Definition: PrescaleWeightProvider.h:56
edm::ParameterSet
Definition: ParameterSet.h:47
edm::ConsumesCollector::mayConsume
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
Definition: ConsumesCollector.h:72
PrescaleWeightProvider.h
edm::InputTag::encode
std::string encode() const
Definition: InputTag.cc:159
edm::EventSetup
Definition: EventSetup.h:58
PrescaleWeightProvider::triggerMenuLite_
edm::Handle< L1GtTriggerMenuLite > triggerMenuLite_
Definition: PrescaleWeightProvider.h:51
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
HLTConfigProvider.h
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
L1GtTriggerMenuLite
Definition: L1GtTriggerMenuLite.h:39
HLTConfigProvider
Definition: HLTConfigProvider.h:29
writedatasetfile.run
run
Definition: writedatasetfile.py:27
L1GtUtils.h
PrescaleWeightProvider::PrescaleWeightProvider
PrescaleWeightProvider(const edm::ParameterSet &config, edm::ConsumesCollector &&iC, T &module)
Definition: PrescaleWeightProvider.h:85
HltComparatorCreateWorkflow.hltConfig
hltConfig
Definition: HltComparatorCreateWorkflow.py:161
PrescaleWeightProvider::init_
bool init_
Definition: PrescaleWeightProvider.h:49
ParameterSet.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
event
Definition: event.py:1
HLTObjectsMonitor_cfi.TriggerResults
TriggerResults
Definition: HLTObjectsMonitor_cfi.py:9
edm::Event
Definition: Event.h:73
L1GtUtils::prescaleFactor
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::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
edm::TriggerResults
Definition: TriggerResults.h:35
weight
Definition: weight.py:1
PrescaleWeightProvider::l1SeedPaths_
std::vector< std::string > l1SeedPaths_
Definition: PrescaleWeightProvider.h:53
PrescaleWeightProvider::triggerResultsTag_
edm::InputTag triggerResultsTag_
Definition: PrescaleWeightProvider.h:57
PrescaleWeightProvider::l1GtTriggerMenuLiteToken_
edm::EDGetTokenT< L1GtTriggerMenuLite > l1GtTriggerMenuLiteToken_
Definition: PrescaleWeightProvider.h:60