CMS 3D CMS Logo

HLTPrescaleProvider.cc
Go to the documentation of this file.
1 
12 
13 #include <cassert>
14 #include <sstream>
15 
16 static const bool useL1EventSetup(true);
17 static const bool useL1GtTriggerMenuLite(false);
18 static const unsigned char countMax(2);
19 
21  const edm::EventSetup& iSetup,
22  const std::string& processName,
23  bool& changed) {
24  count_[0] = 0;
25  count_[1] = 0;
26  count_[2] = 0;
27  count_[3] = 0;
28  count_[4] = 0;
29 
30  const bool result(hltConfigProvider_.init(iRun, iSetup, processName, changed));
31 
32  const unsigned int l1tType(hltConfigProvider_.l1tType());
33  if (l1tType == 1) {
36  } else if (l1tType == 2) {
38  } else {
39  edm::LogError("HLTPrescaleProvider") << " Unknown L1T Type " << l1tType << " - prescales will not be avaiable!";
40  }
41 
42  return result;
43 }
44 
46  const unsigned int l1tType(hltConfigProvider_.l1tType());
47  if (l1tType == 1) {
48  // return hltPrescaleTable_.set();
50  int errorTech(0);
51  const int psfsiTech(l1GtUtils_.prescaleFactorSetIndex(iEvent, L1GtUtils::TechnicalTrigger, errorTech));
52  int errorPhys(0);
53  const int psfsiPhys(l1GtUtils_.prescaleFactorSetIndex(iEvent, L1GtUtils::AlgorithmTrigger, errorPhys));
54  assert(psfsiTech == psfsiPhys);
55  if ((errorTech == 0) && (errorPhys == 0) && (psfsiTech >= 0) && (psfsiPhys >= 0) && (psfsiTech == psfsiPhys)) {
56  return psfsiPhys;
57  } else {
59  if (count_[0] < countMax) {
60  count_[0] += 1;
61  edm::LogError("HLTPrescaleProvider")
62  << " Using processName '" << hltConfigProvider_.processName() << "':"
63  << " Error in determining HLT prescale set index from L1 data using L1GtUtils:"
64  << " Tech/Phys error = " << errorTech << "/" << errorPhys << " Tech/Phys psfsi = " << psfsiTech << "/"
65  << psfsiPhys;
66  }
67  return -1;
68  }
69  } else if (l1tType == 2) {
70  l1tGlobalUtil_.retrieveL1Event(iEvent, iSetup);
71  return static_cast<int>(l1tGlobalUtil_.prescaleColumn());
72  } else {
73  if (count_[0] < countMax) {
74  count_[0] += 1;
75  edm::LogError("HLTPrescaleProvider")
76  << " Using processName '" << hltConfigProvider_.processName() << "':"
77  << " Unknown L1T Type " << l1tType << " - can not determine prescale set index!";
78  }
79  return -1;
80  }
81 }
82 
84  const edm::EventSetup& iSetup,
85  const std::string& trigger) {
86  const int set(prescaleSet(iEvent, iSetup));
87  if (set < 0) {
88  return 1;
89  } else {
90  return hltConfigProvider_.prescaleValue(static_cast<unsigned int>(set), trigger);
91  }
92 }
93 
95  const edm::EventSetup& iSetup,
96  const std::string& trigger) {
97  // start with setting both L1T and HLT prescale values to 0
98  std::pair<int, int> result(std::pair<int, int>(0, 0));
99 
100  // get HLT prescale (possible if HLT prescale set index is correctly found)
101  const int set(prescaleSet(iEvent, iSetup));
102  if (set < 0) {
103  result.second = -1;
104  } else {
105  result.second = static_cast<int>(hltConfigProvider_.prescaleValue(static_cast<unsigned int>(set), trigger));
106  }
107 
108  // get L1T prescale - works only for those hlt trigger paths with
109  // exactly one L1GT seed module which has exactly one L1T name as seed
110 
111  const unsigned int l1tType(hltConfigProvider_.l1tType());
112  if (l1tType == 1) {
113  const unsigned int nL1GTSeedModules(hltConfigProvider_.hltL1GTSeeds(trigger).size());
114  if (nL1GTSeedModules == 0) {
115  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
116  result.first = 1;
117  } else if (nL1GTSeedModules == 1) {
119  const std::string l1tname(hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second);
120  int l1error(0);
121  result.first = l1GtUtils_.prescaleFactor(iEvent, l1tname, l1error);
122  if (l1error != 0) {
123  if (count_[1] < countMax) {
124  count_[1] += 1;
125  edm::LogError("HLTPrescaleProvider")
126  << " Error in determining L1T prescale for HLT path: '" << trigger << "' with L1T seed: '" << l1tname
127  << "' using L1GtUtils: error code = " << l1error << "." << std::endl
128  << " Note: for this method ('prescaleValues'), only a single L1T name (and not a bit number) is allowed "
129  "as seed!"
130  << std::endl
131  << " For seeds being complex logical expressions, try the new method 'prescaleValuesInDetail'."
132  << std::endl;
133  }
134  result.first = -1;
135  }
136  } else {
138  if (count_[2] < countMax) {
139  count_[2] += 1;
140  std::string dump("'" + hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second + "'");
141  for (unsigned int i = 1; i != nL1GTSeedModules; ++i) {
142  dump += " * '" + hltConfigProvider_.hltL1GTSeeds(trigger).at(i).second + "'";
143  }
144  edm::LogError("HLTPrescaleProvider")
145  << " Error in determining L1T prescale for HLT path: '" << trigger << "' has multiple L1GTSeed modules, "
146  << nL1GTSeedModules << ", with L1 seeds: " << dump
147  << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
148  }
149  result.first = -1;
150  }
151  } else if (l1tType == 2) {
152  const unsigned int nL1TSeedModules(hltConfigProvider_.hltL1TSeeds(trigger).size());
153  if (nL1TSeedModules == 0) {
154  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
155  result.first = 1;
156  } else if (nL1TSeedModules == 1) {
157  // l1tGlobalUtil_.retrieveL1Event(iEvent,iSetup);
158  const std::string l1tname(hltConfigProvider_.hltL1TSeeds(trigger).at(0));
159  bool l1error(!l1tGlobalUtil_.getPrescaleByName(l1tname, result.first));
160  if (l1error) {
161  if (count_[1] < countMax) {
162  count_[1] += 1;
163  edm::LogError("HLTPrescaleProvider")
164  << " Error in determining L1T prescale for HLT path: '" << trigger << "' with L1T seed: '" << l1tname
165  << "' using L1TGlobalUtil: error cond = " << l1error << "." << std::endl
166  << " Note: for this method ('prescaleValues'), only a single L1T name (and not a bit number) is allowed "
167  "as seed!"
168  << std::endl
169  << " For seeds being complex logical expressions, try the new method 'prescaleValuesInDetail'."
170  << std::endl;
171  }
172  result.first = -1;
173  }
174  } else {
176  if (count_[2] < countMax) {
177  count_[2] += 1;
178  std::string dump("'" + hltConfigProvider_.hltL1TSeeds(trigger).at(0) + "'");
179  for (unsigned int i = 1; i != nL1TSeedModules; ++i) {
180  dump += " * '" + hltConfigProvider_.hltL1TSeeds(trigger).at(i) + "'";
181  }
182  edm::LogError("HLTPrescaleProvider")
183  << " Error in determining L1T prescale for HLT path: '" << trigger << "' has multiple L1TSeed modules, "
184  << nL1TSeedModules << ", with L1T seeds: " << dump
185  << ". (Note: at most one L1TSeed module is allowed for a proper determination of the L1T prescale!)";
186  }
187  result.first = -1;
188  }
189  } else {
190  if (count_[1] < countMax) {
191  count_[1] += 1;
192  edm::LogError("HLTPrescaleProvider") << " Unknown L1T Type " << l1tType << " - can not determine L1T prescale! ";
193  }
194  result.first = -1;
195  }
196 
197  return result;
198 }
199 
200 std::pair<std::vector<std::pair<std::string, int> >, int> HLTPrescaleProvider::prescaleValuesInDetail(
201  const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) {
202  std::pair<std::vector<std::pair<std::string, int> >, int> result;
203  result.first.clear();
204 
205  // get HLT prescale (possible if HLT prescale set index is correctly found)
206  const int set(prescaleSet(iEvent, iSetup));
207  if (set < 0) {
208  result.second = -1;
209  } else {
210  result.second = static_cast<int>(hltConfigProvider_.prescaleValue(static_cast<unsigned int>(set), trigger));
211  }
212 
213  // get L1T prescale - works only for those hlt trigger paths with
214  // exactly one L1GT seed module
215 
216  const unsigned int l1tType(hltConfigProvider_.l1tType());
217  if (l1tType == 1) {
218  const unsigned int nL1GTSeedModules(hltConfigProvider_.hltL1GTSeeds(trigger).size());
219  if (nL1GTSeedModules == 0) {
220  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
221  result.first.clear();
222  } else if (nL1GTSeedModules == 1) {
224  const std::string l1tname(hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second);
226  l1Logical.logicalExpressionRunUpdate(iEvent.getRun(), iSetup, l1tname);
227  const std::vector<std::pair<std::string, int> >& errorCodes(l1Logical.errorCodes(iEvent));
228  result.first = l1Logical.prescaleFactors();
229  int l1error(l1Logical.isValid() ? 0 : 1);
230  for (auto const& errorCode : errorCodes) {
231  l1error += std::abs(errorCode.second);
232  }
233  if (l1error != 0) {
234  if (count_[3] < countMax) {
235  count_[3] += 1;
236  std::ostringstream message;
237  message << " Error in determining L1T prescales for HLT path: '" << trigger << "' with complex L1T seed: '"
238  << l1tname << "' using L1GtUtils: " << std::endl
239  << " isValid=" << l1Logical.isValid() << " l1tname/error/prescale " << errorCodes.size() << std::endl;
240  for (unsigned int i = 0; i < errorCodes.size(); ++i) {
241  message << " " << i << ":" << errorCodes[i].first << "/" << errorCodes[i].second << "/"
242  << result.first[i].second;
243  }
244  message << ".";
245  edm::LogError("HLTPrescaleProvider") << message.str();
246  }
247  result.first.clear();
248  }
249  } else {
251  if (count_[4] < countMax) {
252  count_[4] += 1;
253  std::string dump("'" + hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second + "'");
254  for (unsigned int i = 1; i != nL1GTSeedModules; ++i) {
255  dump += " * '" + hltConfigProvider_.hltL1GTSeeds(trigger).at(i).second + "'";
256  }
257  edm::LogError("HLTPrescaleProvider")
258  << " Error in determining L1T prescale for HLT path: '" << trigger << "' has multiple L1GTSeed modules, "
259  << nL1GTSeedModules << ", with L1 seeds: " << dump
260  << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
261  }
262  result.first.clear();
263  }
264  } else if (l1tType == 2) {
265  const unsigned int nL1TSeedModules(hltConfigProvider_.hltL1TSeeds(trigger).size());
266  if (nL1TSeedModules == 0) {
267  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
268  result.first.clear();
269  } else if (nL1TSeedModules == 1) {
270  // l1tGlobalUtil_.retrieveL1Event(iEvent,iSetup);
271  std::string l1tname(hltConfigProvider_.hltL1TSeeds(trigger).at(0));
272  GlobalLogicParser l1tGlobalLogicParser = GlobalLogicParser(l1tname);
273  const std::vector<GlobalLogicParser::OperandToken> l1tSeeds = l1tGlobalLogicParser.expressionSeedsOperandList();
274  int l1error(0);
275  int l1tPrescale(-1);
276  for (auto const& i : l1tSeeds) {
277  const string& l1tSeed = i.tokenName;
278  if (!l1tGlobalUtil_.getPrescaleByName(l1tSeed, l1tPrescale)) {
279  l1error += 1;
280  }
281  result.first.push_back(std::pair<std::string, int>(l1tSeed, l1tPrescale));
282  }
283  if (l1error != 0) {
284  if (count_[3] < countMax) {
285  count_[3] += 1;
286  string l1name = l1tname;
287  std::ostringstream message;
288  message << " Error in determining L1T prescales for HLT path: '" << trigger << "' with complex L1T seed: '"
289  << l1tname << "' using L1TGlobalUtil: " << std::endl
290  << " isValid=" << l1tGlobalLogicParser.checkLogicalExpression(l1name) << " l1tname/error/prescale "
291  << l1tSeeds.size() << std::endl;
292  for (unsigned int i = 0; i < l1tSeeds.size(); ++i) {
293  const string& l1tSeed = l1tSeeds[i].tokenName;
294  message << " " << i << ":" << l1tSeed << "/" << l1tGlobalUtil_.getPrescaleByName(l1tSeed, l1tPrescale)
295  << "/" << result.first[i].second;
296  }
297  message << ".";
298  edm::LogError("HLTPrescaleProvider") << message.str();
299  }
300  result.first.clear();
301  }
302  } else {
304  if (count_[4] < countMax) {
305  count_[4] += 1;
306  std::string dump("'" + hltConfigProvider_.hltL1TSeeds(trigger).at(0) + "'");
307  for (unsigned int i = 1; i != nL1TSeedModules; ++i) {
308  dump += " * '" + hltConfigProvider_.hltL1TSeeds(trigger).at(i) + "'";
309  }
310  edm::LogError("HLTPrescaleProvider")
311  << " Error in determining L1T prescale for HLT path: '" << trigger << "' has multiple L1TSeed modules, "
312  << nL1TSeedModules << ", with L1T seeds: " << dump
313  << ". (Note: at most one L1TSeed module is allowed for a proper determination of the L1T prescale!)";
314  }
315  result.first.clear();
316  }
317  } else {
318  if (count_[3] < countMax) {
319  count_[3] += 1;
320  edm::LogError("HLTPrescaleProvider") << " Unknown L1T Type " << l1tType << " - can not determine L1T prescale! ";
321  }
322  result.first.clear();
323  }
324 
325  return result;
326 }
327 
329  return hltConfigProvider_.moduleType(hltConfigProvider_.moduleLabel(i, triggerResults.index(i))) == "HLTPrescaler";
330 }
HLTConfigProvider hltConfigProvider_
std::pair< std::vector< std::pair< std::string, int > >, int > prescaleValuesInDetail(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
const std::string moduleType(const std::string &module) const
C++ class name of module.
unsigned int l1tType() const
L1T type (0=unknown, 1=legacy/stage-1 or 2=stage-2)
void retrieveL1Event(const edm::Event &iEvent, const edm::EventSetup &evSetup)
const std::vector< std::vector< std::string > > & hltL1TSeeds() const
const int prescaleFactorSetIndex(const edm::Event &iEvent, const TriggerCategory &trigCategory, int &errorCode) const
Definition: L1GtUtils.cc:1227
Run const & getRun() const
Definition: Event.cc:108
const std::string & moduleLabel(unsigned int trigger, unsigned int module) const
static const unsigned char countMax(2)
unsigned int prescaleValue(unsigned int set, const std::string &trigger) const
HLT prescale value in specific prescale set for a specific trigger path.
int iEvent
Definition: GenABIO.cc:224
static const bool useL1GtTriggerMenuLite(false)
unsigned int index(const unsigned int i) const
Get index (slot position) of module giving the decision of the ith path.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned int prescaleColumn() const
static std::string const triggerResults
Definition: EdmProvDump.cc:45
l1t::L1TGlobalUtil l1tGlobalUtil_
bool rejectedByHLTPrescaler(const edm::TriggerResults &triggerResults, unsigned int i) const
const std::string & processName() const
process name
int prescaleSet(const edm::Event &iEvent, const edm::EventSetup &iSetup)
const std::vector< std::vector< std::pair< bool, std::string > > > & hltL1GTSeeds() const
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
std::pair< int, int > prescaleValues(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
Combined L1T (pair.first) and HLT (pair.second) prescales per HLT path.
void getL1GtRunCache(const edm::Run &, const edm::EventSetup &, const bool, const bool)
get all the run-constant quantities for L1 trigger and cache them
Definition: L1GtUtils.cc:274
unsigned char count_[5]
const bool getPrescaleByName(const std::string &algName, int &prescale) const
unsigned int prescaleValue(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
combining the two methods above
void retrieveL1Setup(const edm::EventSetup &evSetup)
static const bool useL1EventSetup(true)
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
Definition: Run.h:45
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:1036