CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GenericTriggerEventFlag.cc
Go to the documentation of this file.
1 //
2 // $Id: GenericTriggerEventFlag.cc,v 1.13 2012/04/22 15:09:29 vadler Exp $
3 //
4 
6 
8 
9 #include <memory>
10 
11 #include <vector>
12 
15 
16 // Constants' definitions
17 static const bool useL1EventSetup(true);
18 static const bool useL1GtTriggerMenuLite(false);
19 
23  : GenericTriggerEventFlag(config, iC, false) {
24  if (config.exists("andOrL1")) {
25  if (stage2_) {
26  l1uGt_ = std::make_unique<l1t::L1TGlobalUtil>(config, iC, use);
27  }
28  }
29 }
30 
34  bool stage1Valid)
35  : watchDB_(),
36  hltConfigInit_(false),
37  andOr_(false),
38  dbLabel_(""),
39  verbose_(0),
40  andOrDcs_(false),
41  errorReplyDcs_(false),
42  andOrGt_(false),
43  gtInputTag_(""),
44  gtEvmInputTag_(""),
45  gtDBKey_(""),
46  errorReplyGt_(false),
47  andOrL1_(false),
48  stage2_(false),
49  l1BeforeMask_(true),
50  l1DBKey_(""),
51  errorReplyL1_(false),
52  andOrHlt_(false),
53  hltDBKey_(""),
54  errorReplyHlt_(false),
55  on_(true),
56  onDcs_(true),
57  onGt_(true),
58  onL1_(true),
59  onHlt_(true),
60  configError_("CONFIG_ERROR"),
61  emptyKeyError_("EMPTY_KEY_ERROR") {
62  // General switch(es)
63  if (config.exists("andOr")) {
64  andOr_ = config.getParameter<bool>("andOr");
65  if (config.exists("verbosityLevel"))
66  verbose_ = config.getParameter<unsigned>("verbosityLevel");
67  } else {
68  on_ = false;
69  onDcs_ = false;
70  onGt_ = false;
71  onL1_ = false;
72  onHlt_ = false;
73  }
74 
75  if (on_) {
76  if (config.exists("andOrDcs")) {
77  andOrDcs_ = config.getParameter<bool>("andOrDcs");
78  dcsInputTag_ = config.getParameter<edm::InputTag>("dcsInputTag");
80  dcsPartitions_ = config.getParameter<std::vector<int> >("dcsPartitions");
81  errorReplyDcs_ = config.getParameter<bool>("errorReplyDcs");
82  } else {
83  onDcs_ = false;
84  }
85  if (config.exists("andOrGt")) {
86  andOrGt_ = config.getParameter<bool>("andOrGt");
87  gtInputTag_ = config.getParameter<edm::InputTag>("gtInputTag");
89  gtLogicalExpressions_ = config.getParameter<std::vector<std::string> >("gtStatusBits");
90  errorReplyGt_ = config.getParameter<bool>("errorReplyGt");
91  if (config.exists("gtEvmInputTag")) {
92  gtEvmInputTag_ = config.getParameter<edm::InputTag>("gtEvmInputTag");
94  }
95  if (config.exists("gtDBKey"))
96  gtDBKey_ = config.getParameter<std::string>("gtDBKey");
97  } else {
98  onGt_ = false;
99  }
100  if (config.exists("andOrL1")) {
101  andOrL1_ = config.getParameter<bool>("andOrL1");
102  if (config.exists("stage2"))
103  stage2_ = config.getParameter<bool>("stage2");
104  else
105  stage2_ = false;
106  l1LogicalExpressionsCache_ = config.getParameter<std::vector<std::string> >("l1Algorithms");
107  errorReplyL1_ = config.getParameter<bool>("errorReplyL1");
108  if (config.exists("l1DBKey"))
109  l1DBKey_ = config.getParameter<std::string>("l1DBKey");
110  if (config.exists("l1BeforeMask"))
111  l1BeforeMask_ = config.getParameter<bool>("l1BeforeMask");
112  } else {
113  onL1_ = false;
114  }
115  if (config.exists("andOrHlt")) {
116  andOrHlt_ = config.getParameter<bool>("andOrHlt");
117  hltInputTag_ = config.getParameter<edm::InputTag>("hltInputTag");
119  hltLogicalExpressionsCache_ = config.getParameter<std::vector<std::string> >("hltPaths");
120  errorReplyHlt_ = config.getParameter<bool>("errorReplyHlt");
121  if (config.exists("hltDBKey"))
122  hltDBKey_ = config.getParameter<std::string>("hltDBKey");
123  } else {
124  onHlt_ = false;
125  }
126  if (!onDcs_ && !onGt_ && !onL1_ && !onHlt_)
127  on_ = false;
128  else {
129  if (config.exists("dbLabel"))
130  dbLabel_ = config.getParameter<std::string>("dbLabel");
131  watchDB_ = std::make_unique<edm::ESWatcher<AlCaRecoTriggerBitsRcd> >();
132  }
133  }
134 
135  if (onL1_ && !stage2_) {
137  }
138  if ((onGt_ && !gtDBKey_.empty()) || (onL1_ && !l1DBKey_.empty()) || (onHlt_ && !hltDBKey_.empty())) {
141  }
142 
143  //check to see we arent trying to setup legacy / stage-1 from a constructor call
144  //that does not support it
145  if (config.exists("andOrL1") && stage2_ == false) { //stage-1 setup
146  if (stage1Valid == false)
147  throw cms::Exception("ConfigError") << " Error when constructing GenericTriggerEventFlag, legacy/stage-1 is "
148  "requested but the constructor called is stage2 only";
149  }
150 }
151 
154  if (watchDB_->check(setup)) {
155  if (onGt_ && !gtDBKey_.empty()) {
156  const std::vector<std::string> exprs(expressionsFromDB(gtDBKey_, setup));
157  if (exprs.empty() || exprs.at(0) != configError_)
158  gtLogicalExpressions_ = exprs;
159  }
160  if (onL1_ && !l1DBKey_.empty()) {
161  const std::vector<std::string> exprs(expressionsFromDB(l1DBKey_, setup));
162  if (exprs.empty() || exprs.at(0) != configError_)
164  }
165  if (onHlt_ && !hltDBKey_.empty()) {
166  const std::vector<std::string> exprs(expressionsFromDB(hltDBKey_, setup));
167  if (exprs.empty() || exprs.at(0) != configError_)
169  }
170  }
171 
172  // Re-initialise starting valuse before wild-card expansion
175 
176  hltConfigInit_ = false;
177  if (onHlt_) {
178  if (hltInputTag_.process().empty()) {
179  if (verbose_ > 0)
180  edm::LogError("GenericTriggerEventFlag")
181  << "HLT TriggerResults InputTag \"" << hltInputTag_.encode() << "\" specifies no process";
182  } else {
183  bool hltChanged(false);
184  if (!hltConfig_.init(run, setup, hltInputTag_.process(), hltChanged)) {
185  if (verbose_ > 0)
186  edm::LogError("GenericTriggerEventFlag")
187  << "HLT config initialization error with process name \"" << hltInputTag_.process() << "\"";
188  } else if (hltConfig_.size() <= 0) {
189  if (verbose_ > 0)
190  edm::LogError("GenericTriggerEventFlag") << "HLT config size error";
191  } else
192  hltConfigInit_ = true;
193  }
194  }
195 
196  // Expand version wild-cards in HLT logical expressions
197  // L1
198  if (onL1_) {
199  // build vector of algo names
200 
201  std::vector<std::string> algoNames;
202 
203  if (stage2_) {
204  l1uGt_->retrieveL1Setup(setup);
205 
206  const std::vector<std::pair<std::string, double> > prescales = l1uGt_->prescales();
207  for (const auto& ip : prescales)
208  algoNames.push_back(ip.first);
209  } else {
210  l1Gt_->getL1GtRunCache(run, setup, useL1EventSetup, useL1GtTriggerMenuLite);
211  L1GtTriggerMenu const& l1GtTriggerMenu = setup.get<L1GtTriggerMenuRcd>().get(l1GtTriggerMenuToken_);
212 
213  const AlgorithmMap& l1GtPhys(l1GtTriggerMenu.gtAlgorithmMap());
214  for (CItAlgo iAlgo = l1GtPhys.begin(); iAlgo != l1GtPhys.end(); ++iAlgo) {
215  algoNames.push_back(iAlgo->second.algoName());
216  }
217  const AlgorithmMap& l1GtTech(l1GtTriggerMenu.gtTechnicalTriggerMap());
218  for (CItAlgo iAlgo = l1GtTech.begin(); iAlgo != l1GtTech.end(); ++iAlgo) {
219  algoNames.push_back(iAlgo->second.algoName());
220  }
221  }
222 
223  for (unsigned iExpr = 0; iExpr < l1LogicalExpressions_.size(); ++iExpr) {
224  std::string l1LogicalExpression(l1LogicalExpressions_.at(iExpr));
225  L1GtLogicParser l1AlgoLogicParser(l1LogicalExpression);
226  // Loop over algorithms
227  for (size_t iAlgo = 0; iAlgo < l1AlgoLogicParser.operandTokenVector().size(); ++iAlgo) {
228  const std::string l1AlgoName(l1AlgoLogicParser.operandTokenVector().at(iAlgo).tokenName);
229  if (l1AlgoName.find('*') != std::string::npos) {
230  l1LogicalExpression.replace(
231  l1LogicalExpression.find(l1AlgoName), l1AlgoName.size(), expandLogicalExpression(algoNames, l1AlgoName));
232  }
233  }
234  l1LogicalExpressions_[iExpr] = l1LogicalExpression;
235  }
236  std::vector<std::string> tmp = l1LogicalExpressions_;
237  for (unsigned iExpr = 0; iExpr < tmp.size(); ++iExpr)
238  if (std::find(algoNames.begin(), algoNames.end(), tmp[iExpr]) == algoNames.end()) {
239  l1LogicalExpressions_.erase(l1LogicalExpressions_.begin() + iExpr);
240  if (verbose_ > 1)
241  edm::LogWarning("GenericTriggerEventFlag")
242  << "L1 algorithm \"" << tmp[iExpr]
243  << "\" does not exist in the L1 menu ==> drop it from the list of l1LogicalExpressions";
244  }
245  }
246  // HLT
247  if (hltConfigInit_) {
248  for (unsigned iExpr = 0; iExpr < hltLogicalExpressions_.size(); ++iExpr) {
249  std::string hltLogicalExpression(hltLogicalExpressions_.at(iExpr));
250  L1GtLogicParser hltAlgoLogicParser(hltLogicalExpression);
251  // Loop over paths
252  for (size_t iPath = 0; iPath < hltAlgoLogicParser.operandTokenVector().size(); ++iPath) {
253  const std::string hltPathName(hltAlgoLogicParser.operandTokenVector().at(iPath).tokenName);
254  if (hltPathName.find('*') != std::string::npos) {
255  hltLogicalExpression.replace(hltLogicalExpression.find(hltPathName),
256  hltPathName.size(),
258  }
259  }
260  hltLogicalExpressions_[iExpr] = hltLogicalExpression;
261  }
262  }
263 }
264 
267  if (!on_)
268  return true;
269 
270  // Determine decision
271  if (andOr_)
272  return (acceptDcs(event) || acceptGt(event) || acceptL1(event, setup) || acceptHlt(event));
273  return (acceptDcs(event) && acceptGt(event) && acceptL1(event, setup) && acceptHlt(event));
274 }
275 
277  // An empty DCS partitions list acts as switch.
278  if (!onDcs_ || dcsPartitions_.empty())
279  return (!andOr_); // logically neutral, depending on base logical connective
280 
281  // Accessing the DcsStatusCollection
283  event.getByToken(dcsInputToken_, dcsStatus);
284  if (!dcsStatus.isValid()) {
285  if (verbose_ > 1)
286  edm::LogWarning("GenericTriggerEventFlag")
287  << "DcsStatusCollection product with InputTag \"" << dcsInputTag_.encode()
288  << "\" not in event ==> decision: " << errorReplyDcs_;
289  return errorReplyDcs_;
290  }
291  if ((*dcsStatus).empty()) {
292  if (verbose_ > 1)
293  edm::LogWarning("GenericTriggerEventFlag")
294  << "DcsStatusCollection product with InputTag \"" << dcsInputTag_.encode()
295  << "\" empty ==> decision: " << errorReplyDcs_;
296  return errorReplyDcs_;
297  }
298 
299  // Determine decision of DCS partition combination and return
300  if (andOrDcs_) { // OR combination
301  for (std::vector<int>::const_iterator partitionNumber = dcsPartitions_.begin();
302  partitionNumber != dcsPartitions_.end();
303  ++partitionNumber) {
304  if (acceptDcsPartition(dcsStatus, *partitionNumber))
305  return true;
306  }
307  return false;
308  }
309  for (std::vector<int>::const_iterator partitionNumber = dcsPartitions_.begin();
310  partitionNumber != dcsPartitions_.end();
311  ++partitionNumber) {
312  if (!acceptDcsPartition(dcsStatus, *partitionNumber))
313  return false;
314  }
315  return true;
316 }
317 
319  int dcsPartition) const {
320  // Error checks
321  switch (dcsPartition) {
322  case DcsStatus::EBp:
323  case DcsStatus::EBm:
324  case DcsStatus::EEp:
325  case DcsStatus::EEm:
326  case DcsStatus::HBHEa:
327  case DcsStatus::HBHEb:
328  case DcsStatus::HBHEc:
329  case DcsStatus::HF:
330  case DcsStatus::HO:
331  case DcsStatus::RPC:
332  case DcsStatus::DT0:
333  case DcsStatus::DTp:
334  case DcsStatus::DTm:
335  case DcsStatus::CSCp:
336  case DcsStatus::CSCm:
337  case DcsStatus::CASTOR:
338  case DcsStatus::TIBTID:
339  case DcsStatus::TOB:
340  case DcsStatus::TECp:
341  case DcsStatus::TECm:
342  case DcsStatus::BPIX:
343  case DcsStatus::FPIX:
344  case DcsStatus::ESp:
345  case DcsStatus::ESm:
346  break;
347  default:
348  if (verbose_ > 1)
349  edm::LogWarning("GenericTriggerEventFlag")
350  << "DCS partition number \"" << dcsPartition << "\" does not exist ==> decision: " << errorReplyDcs_;
351  return errorReplyDcs_;
352  }
353 
354  // Determine decision
355  return dcsStatus->at(0).ready(dcsPartition);
356 }
357 
360  // An empty GT status bits logical expressions list acts as switch.
361  if (!onGt_ || gtLogicalExpressions_.empty())
362  return (!andOr_); // logically neutral, depending on base logical connective
363 
364  // Determine decision of GT status bits logical expression combination and return
365  if (andOrGt_) { // OR combination
366  for (std::vector<std::string>::const_iterator gtLogicalExpression = gtLogicalExpressions_.begin();
367  gtLogicalExpression != gtLogicalExpressions_.end();
368  ++gtLogicalExpression) {
369  if (acceptGtLogicalExpression(event, *gtLogicalExpression))
370  return true;
371  }
372  return false;
373  }
374  for (std::vector<std::string>::const_iterator gtLogicalExpression = gtLogicalExpressions_.begin();
375  gtLogicalExpression != gtLogicalExpressions_.end();
376  ++gtLogicalExpression) {
377  if (!acceptGtLogicalExpression(event, *gtLogicalExpression))
378  return false;
379  }
380  return true;
381 }
382 
385  // Check empty std::strings
386  if (gtLogicalExpression.empty()) {
387  if (verbose_ > 1)
388  edm::LogWarning("GenericTriggerEventFlag") << "Empty logical expression ==> decision: " << errorReplyGt_;
389  return errorReplyGt_;
390  }
391 
392  // Negated paths
393  bool negExpr(negate(gtLogicalExpression));
394  if (negExpr && gtLogicalExpression.empty()) {
395  if (verbose_ > 1)
396  edm::LogWarning("GenericTriggerEventFlag")
397  << "Empty (negated) logical expression ==> decision: " << errorReplyGt_;
398  return errorReplyGt_;
399  }
400 
401  // Parse logical expression and determine GT status bit decision
402  L1GtLogicParser gtAlgoLogicParser(gtLogicalExpression);
403  // Loop over status bits
404  for (size_t iStatusBit = 0; iStatusBit < gtAlgoLogicParser.operandTokenVector().size(); ++iStatusBit) {
405  const std::string gtStatusBit(gtAlgoLogicParser.operandTokenVector().at(iStatusBit).tokenName);
406  // Manipulate status bit decision as stored in the parser
407  bool decision(errorReplyDcs_);
408  // Hard-coded status bits!!!
409  if (gtStatusBit == "PhysDecl" || gtStatusBit == "PhysicsDeclared") {
411  event.getByToken(gtInputToken_, gtReadoutRecord);
412  if (!gtReadoutRecord.isValid()) {
413  if (verbose_ > 1)
414  edm::LogWarning("GenericTriggerEventFlag")
415  << "L1GlobalTriggerReadoutRecord product with InputTag \"" << gtInputTag_.encode()
416  << "\" not in event ==> decision: " << errorReplyGt_;
417  gtAlgoLogicParser.operandTokenVector().at(iStatusBit).tokenResult = errorReplyDcs_;
418  continue;
419  }
420  decision = (gtReadoutRecord->gtFdlWord().physicsDeclared() == 1);
421  } else if (gtStatusBit == "Stable" || gtStatusBit == "StableBeam" || gtStatusBit == "Adjust" ||
422  gtStatusBit == "Sqeeze" || gtStatusBit == "Flat" || gtStatusBit == "FlatTop" || gtStatusBit == "7TeV" ||
423  gtStatusBit == "8TeV" || gtStatusBit == "13TeV" || gtStatusBit == "2360GeV" || gtStatusBit == "900GeV") {
425  event.getByToken(gtEvmInputToken_, gtEvmReadoutRecord);
426  if (!gtEvmReadoutRecord.isValid()) {
427  if (verbose_ > 1)
428  edm::LogWarning("GenericTriggerEventFlag")
429  << "L1GlobalTriggerEvmReadoutRecord product with InputTag \"" << gtEvmInputTag_.encode()
430  << "\" not in event ==> decision: " << errorReplyGt_;
431  gtAlgoLogicParser.operandTokenVector().at(iStatusBit).tokenResult = errorReplyDcs_;
432  continue;
433  }
434  if (gtStatusBit == "Stable" || gtStatusBit == "StableBeam") {
435  decision = (gtEvmReadoutRecord->gtfeWord().beamMode() == 11);
436  } else if (gtStatusBit == "Adjust") {
437  decision = (10 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11);
438  } else if (gtStatusBit == "Sqeeze") {
439  decision = (9 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11);
440  } else if (gtStatusBit == "Flat" || gtStatusBit == "FlatTop") {
441  decision = (8 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11);
442  } else if (gtStatusBit == "7TeV") {
443  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 3500);
444  } else if (gtStatusBit == "8TeV") {
445  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 4000);
446  } else if (gtStatusBit == "13TeV") {
447  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 6500);
448  } else if (gtStatusBit == "2360GeV") {
449  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 1180);
450  } else if (gtStatusBit == "900GeV") {
451  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 450);
452  }
453  } else {
454  if (verbose_ > 1)
455  edm::LogWarning("GenericTriggerEventFlag")
456  << "GT status bit \"" << gtStatusBit << "\" is not defined ==> decision: " << errorReplyGt_;
457  }
458  gtAlgoLogicParser.operandTokenVector().at(iStatusBit).tokenResult = decision;
459  }
460 
461  // Determine decision
462  const bool gtDecision(gtAlgoLogicParser.expressionResult());
463  return negExpr ? (!gtDecision) : gtDecision;
464 }
465 
468  // An empty L1 logical expressions list acts as switch.
469  if (!onL1_ || l1LogicalExpressions_.empty())
470  return (!andOr_); // logically neutral, depending on base logical connective
471 
472  // Determine decision of L1 logical expression combination and return
473  if (andOrL1_) { // OR combination
474  for (std::vector<std::string>::const_iterator l1LogicalExpression = l1LogicalExpressions_.begin();
475  l1LogicalExpression != l1LogicalExpressions_.end();
476  ++l1LogicalExpression) {
477  if (acceptL1LogicalExpression(event, setup, *l1LogicalExpression))
478  return true;
479  }
480  return false;
481  }
482  for (std::vector<std::string>::const_iterator l1LogicalExpression = l1LogicalExpressions_.begin();
483  l1LogicalExpression != l1LogicalExpressions_.end();
484  ++l1LogicalExpression) {
485  if (!acceptL1LogicalExpression(event, setup, *l1LogicalExpression))
486  return false;
487  }
488  return true;
489 }
490 
493  const edm::EventSetup& setup,
494  std::string l1LogicalExpression) {
495  // Getting the L1 event setup
496  if (stage2_)
497  l1uGt_->retrieveL1(event, setup);
498  else
499  // FIXME This can possibly go to initRun()
500  l1Gt_->getL1GtRunCache(event, setup, useL1EventSetup, useL1GtTriggerMenuLite);
501 
502  // Check empty std::strings
503  if (l1LogicalExpression.empty()) {
504  if (verbose_ > 1)
505  edm::LogWarning("GenericTriggerEventFlag") << "Empty logical expression ==> decision: " << errorReplyL1_;
506  return errorReplyL1_;
507  }
508 
509  // Negated logical expression
510  bool negExpr(negate(l1LogicalExpression));
511  if (negExpr && l1LogicalExpression.empty()) {
512  if (verbose_ > 1)
513  edm::LogWarning("GenericTriggerEventFlag")
514  << "Empty (negated) logical expression ==> decision: " << errorReplyL1_;
515  return errorReplyL1_;
516  }
517 
518  // Parse logical expression and determine L1 decision
519  L1GtLogicParser l1AlgoLogicParser(l1LogicalExpression);
520  // Loop over algorithms
521  for (size_t iAlgorithm = 0; iAlgorithm < l1AlgoLogicParser.operandTokenVector().size(); ++iAlgorithm) {
522  const std::string l1AlgoName(l1AlgoLogicParser.operandTokenVector().at(iAlgorithm).tokenName);
523 
524  bool decision = false;
525  bool error = false;
526  if (stage2_) {
527  bool errorBOOL = (l1BeforeMask_ ? l1uGt_->getInitialDecisionByName(l1AlgoName, decision)
528  : l1uGt_->getFinalDecisionByName(l1AlgoName, decision));
529  error = !errorBOOL;
530  } else {
531  int errorINT(-1);
532  // const bool decision( l1BeforeMask_ ? l1Gt_->decisionBeforeMask( event, l1AlgoName, errorINT ) : l1Gt_->decisionAfterMask( event, l1AlgoName, errorINT ) );
533  decision = (l1BeforeMask_ ? l1Gt_->decisionBeforeMask(event, l1AlgoName, errorINT)
534  : l1Gt_->decisionAfterMask(event, l1AlgoName, errorINT));
535  error = (errorINT != 0);
536  if (errorINT > 1)
537  if (verbose_ > 1)
538  edm::LogWarning("GenericTriggerEventFlag")
539  << "L1 algorithm \"" << l1AlgoName << "\" received error code " << error
540  << " from L1GtUtils::decisionBeforeMask ==> decision: " << errorReplyL1_;
541  }
542 
543  // Error checks
544  if (error) {
545  if (verbose_ > 1)
546  edm::LogWarning("GenericTriggerEventFlag")
547  << "L1 algorithm \"" << l1AlgoName << "\" does not exist in the L1 menu ==> decision: " << errorReplyL1_;
548  l1AlgoLogicParser.operandTokenVector().at(iAlgorithm).tokenResult = errorReplyL1_;
549  continue;
550  }
551  // Manipulate algo decision as stored in the parser
552  l1AlgoLogicParser.operandTokenVector().at(iAlgorithm).tokenResult = decision;
553  }
554 
555  // Return decision
556  const bool l1Decision(l1AlgoLogicParser.expressionResult());
557  return negExpr ? (!l1Decision) : l1Decision;
558 }
559 
562  // An empty HLT logical expressions list acts as switch.
563  if (!onHlt_ || hltLogicalExpressions_.empty())
564  return (!andOr_); // logically neutral, depending on base logical connective
565 
566  // Checking the HLT configuration,
567  if (!hltConfigInit_) {
568  if (verbose_ > 1)
569  edm::LogWarning("GenericTriggerEventFlag") << "HLT config error ==> decision: " << errorReplyHlt_;
570  return errorReplyHlt_;
571  }
572 
573  // Accessing the TriggerResults
574  edm::Handle<edm::TriggerResults> hltTriggerResults;
575  event.getByToken(hltInputToken_, hltTriggerResults);
576  if (!hltTriggerResults.isValid()) {
577  if (verbose_ > 1)
578  edm::LogWarning("GenericTriggerEventFlag") << "TriggerResults product with InputTag \"" << hltInputTag_.encode()
579  << "\" not in event ==> decision: " << errorReplyHlt_;
580  return errorReplyHlt_;
581  }
582  if ((*hltTriggerResults).size() == 0) {
583  if (verbose_ > 1)
584  edm::LogWarning("GenericTriggerEventFlag") << "TriggerResults product with InputTag \"" << hltInputTag_.encode()
585  << "\" empty ==> decision: " << errorReplyHlt_;
586  return errorReplyDcs_;
587  }
588 
589  // Determine decision of HLT logical expression combination and return
590  if (andOrHlt_) { // OR combination
591  for (std::vector<std::string>::const_iterator hltLogicalExpression = hltLogicalExpressions_.begin();
592  hltLogicalExpression != hltLogicalExpressions_.end();
593  ++hltLogicalExpression) {
594  if (acceptHltLogicalExpression(hltTriggerResults, *hltLogicalExpression))
595  return true;
596  }
597  return false;
598  }
599  for (std::vector<std::string>::const_iterator hltLogicalExpression = hltLogicalExpressions_.begin();
600  hltLogicalExpression != hltLogicalExpressions_.end();
601  ++hltLogicalExpression) {
602  if (!acceptHltLogicalExpression(hltTriggerResults, *hltLogicalExpression))
603  return false;
604  }
605  return true;
606 }
607 
610  std::string hltLogicalExpression) const {
611  // Check empty std::strings
612  if (hltLogicalExpression.empty()) {
613  if (verbose_ > 1)
614  edm::LogWarning("GenericTriggerEventFlag") << "Empty logical expression ==> decision: " << errorReplyHlt_;
615  return errorReplyHlt_;
616  }
617 
618  // Negated paths
619  bool negExpr(negate(hltLogicalExpression));
620  if (negExpr && hltLogicalExpression.empty()) {
621  if (verbose_ > 1)
622  edm::LogWarning("GenericTriggerEventFlag")
623  << "Empty (negated) logical expression ==> decision: " << errorReplyHlt_;
624  return errorReplyHlt_;
625  }
626 
627  // Parse logical expression and determine HLT decision
628  L1GtLogicParser hltAlgoLogicParser(hltLogicalExpression);
629  // Loop over paths
630  for (size_t iPath = 0; iPath < hltAlgoLogicParser.operandTokenVector().size(); ++iPath) {
631  const std::string hltPathName(hltAlgoLogicParser.operandTokenVector().at(iPath).tokenName);
632  const unsigned indexPath(hltConfig_.triggerIndex(hltPathName));
633  // Further error checks
634  if (indexPath == hltConfig_.size()) {
635  if (verbose_ > 1)
636  edm::LogWarning("GenericTriggerEventFlag") << "HLT path \"" << hltPathName << "\" is not found in process "
637  << hltInputTag_.process() << " ==> decision: " << errorReplyHlt_;
638  hltAlgoLogicParser.operandTokenVector().at(iPath).tokenResult = errorReplyHlt_;
639  continue;
640  }
641  if (hltTriggerResults->error(indexPath)) {
642  if (verbose_ > 1)
643  edm::LogWarning("GenericTriggerEventFlag")
644  << "HLT path \"" << hltPathName << "\" in error ==> decision: " << errorReplyHlt_;
645  hltAlgoLogicParser.operandTokenVector().at(iPath).tokenResult = errorReplyHlt_;
646  continue;
647  }
648  // Manipulate algo decision as stored in the parser
649  const bool decision(hltTriggerResults->accept(indexPath));
650  hltAlgoLogicParser.operandTokenVector().at(iPath).tokenResult = decision;
651  }
652 
653  // Determine decision
654  const bool hltDecision(hltAlgoLogicParser.expressionResult());
655  return negExpr ? (!hltDecision) : hltDecision;
656 }
657 
660  const std::string& expr,
661  bool useAnd) const {
662  // Find matching entries in the menu
663  std::vector<std::string> matched;
664  const std::string versionWildcard("_v*");
665  if (expr.substr(expr.size() - versionWildcard.size()) == versionWildcard) {
666  const std::string exprBase(expr.substr(0, expr.size() - versionWildcard.size()));
667  matched = hltConfig_.restoreVersion(targets, exprBase);
668  } else {
669  matched = hltConfig_.matched(targets, expr);
670  }
671 
672  // Return input, if no match is found
673  if (matched.empty()) {
674  if (verbose_ > 1)
675  edm::LogWarning("GenericTriggerEventFlag") << "Logical expression: \"" << expr << "\" could not be resolved";
676  return expr;
677  }
678 
679  // Compose logical expression
680  std::string expanded("(");
681  for (unsigned iVers = 0; iVers < matched.size(); ++iVers) {
682  if (iVers > 0)
683  expanded.append(useAnd ? " AND " : " OR ");
684  expanded.append(matched.at(iVers));
685  }
686  expanded.append(")");
687  if (verbose_ > 1)
688  edm::LogInfo("GenericTriggerEventFlag") << "Logical expression: \"" << expr << "\"\n"
689  << " --> expanded to \"" << expanded << "\"";
690 
691  return expanded;
692 }
693 
696  bool negate(false);
697  if (word.at(0) == '~') {
698  negate = true;
699  word.erase(0, 1);
700  }
701  return negate;
702 }
703 
706  const edm::EventSetup& setup) {
707  if (key.empty())
708  return std::vector<std::string>(1, emptyKeyError_);
709  std::vector<edm::eventsetup::DataKey> labels;
710  setup.get<AlCaRecoTriggerBitsRcd>().fillRegisteredDataKeys(labels);
711  std::vector<edm::eventsetup::DataKey>::const_iterator iKey = labels.begin();
712  while (iKey != labels.end() && iKey->name().value() != dbLabel_)
713  ++iKey;
714  if (iKey == labels.end()) {
715  if (verbose_ > 0)
716  edm::LogWarning("GenericTriggerEventFlag")
717  << "Label " << dbLabel_ << " not found in DB for 'AlCaRecoTriggerBitsRcd'";
718  return std::vector<std::string>(1, configError_);
719  }
720  auto const& alCaRecoTriggerBits = setup.getData(alCaRecoTriggerBitsToken_);
721  const std::map<std::string, std::string>& expressionMap = alCaRecoTriggerBits.m_alcarecoToTrig;
722  std::map<std::string, std::string>::const_iterator listIter = expressionMap.find(key);
723  if (listIter == expressionMap.end()) {
724  if (verbose_ > 0)
725  edm::LogWarning("GenericTriggerEventFlag")
726  << "No logical expressions found under key " << key << " in 'AlCaRecoTriggerBitsRcd'";
727  return std::vector<std::string>(1, configError_);
728  }
729  return alCaRecoTriggerBits.decompose(listIter->second);
730 }
731 
733  if (not onHlt_) {
734  return true;
735  }
736 
737  if (not hltConfigInit_) {
738  if (verbose_ > 0) {
739  edm::LogWarning("GenericTriggerEventFlag::allHLTPathsAreValid()")
740  << "HLTConfigProvider is not initialized, method will return \"false\"";
741  }
742 
743  return false;
744  }
745 
746  for (unsigned iExpr = 0; iExpr < hltLogicalExpressions_.size(); ++iExpr) {
747  std::string hltLogicalExpression = hltLogicalExpressions_.at(iExpr);
748 
749  L1GtLogicParser hltAlgoLogicParser(hltLogicalExpression);
750 
751  if (hltAlgoLogicParser.operandTokenVector().empty()) {
752  return false;
753  }
754 
755  for (size_t iPath = 0; iPath < hltAlgoLogicParser.operandTokenVector().size(); ++iPath) {
756  const std::string hltPathName(hltAlgoLogicParser.operandTokenVector().at(iPath).tokenName);
757 
758  const unsigned indexPath(hltConfig_.triggerIndex(hltPathName));
759 
760  if (indexPath == hltConfig_.size()) {
761  if (verbose_ > 1) {
762  edm::LogWarning("GenericTriggerEventFlag::allHLTPathsAreValid()")
763  << "HLT path \"" << hltPathName << "\" is not found in process " << hltInputTag_.process();
764  }
765 
766  return false;
767  }
768  }
769  }
770 
771  return true;
772 }
unsigned int size() const
number of trigger paths in trigger table
bool negate(std::string &word) const
Checks for negated words.
edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > gtInputToken_
GenericTriggerEventFlag(const edm::ParameterSet &config, edm::ConsumesCollector &&iC, l1t::UseEventSetupIn use=l1t::UseEventSetupIn::RunAndEvent)
edm::ESGetToken< L1GtTriggerMenu, L1GtTriggerMenuRcd > l1GtTriggerMenuToken_
static const std::vector< std::string > matched(const std::vector< std::string > &inputs, const std::string &pattern)
regexp processing
static const bool useL1GtTriggerMenuLite(false)
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
std::map< std::string, L1GtAlgorithm > AlgorithmMap
map containing the algorithms
std::vector< std::string > hltLogicalExpressions_
std::vector< std::string > gtLogicalExpressions_
const std::vector< std::string > & triggerNames() const
names of trigger paths
edm::EDGetTokenT< DcsStatusCollection > dcsInputToken_
bool exists(std::string const &parameterName) const
checks if a parameter exists
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::string encode() const
Definition: InputTag.cc:159
std::unique_ptr< L1GtUtils > l1Gt_
bool acceptHlt(const edm::Event &event)
Was this event accepted by the configured HLT logical expression combination?
AlgorithmMap::const_iterator CItAlgo
iterators through map containing the algorithms
bool acceptDcsPartition(const edm::Handle< DcsStatusCollection > &dcsStatus, int dcsPartition) const
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
std::vector< std::string > expressionsFromDB(const std::string &key, const edm::EventSetup &setup)
Reads and returns logical expressions from DB.
uint64_t word
edm::EDGetTokenT< edm::TriggerResults > hltInputToken_
std::vector< OperandToken > & operandTokenVector()
return the vector of operand tokens
bool accept(const edm::Event &event, const edm::EventSetup &setup)
To be called from analyze/filter() methods.
bool acceptGtLogicalExpression(const edm::Event &event, std::string gtLogicalExpression)
Does this event fulfill this particular GT status bits&#39; logical expression?
tuple key
prepare the HTCondor submission files and eventually submit them
std::vector< std::string > l1LogicalExpressionsCache_
static const bool useL1EventSetup(true)
bool isValid() const
Definition: HandleBase.h:70
std::vector< DcsStatus > DcsStatusCollection
Definition: DcsStatus.h:110
Log< level::Info, false > LogInfo
bool acceptDcs(const edm::Event &event)
static const std::vector< std::string > restoreVersion(const std::vector< std::string > &inputs, const std::string &trigger)
edm::ESGetToken< AlCaRecoTriggerBits, AlCaRecoTriggerBitsRcd > alCaRecoTriggerBitsToken_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
bool acceptL1LogicalExpression(const edm::Event &event, const edm::EventSetup &setup, std::string l1LogicalExpression)
Was this event accepted by this particular L1 algorithms&#39; logical expression?
edm::EDGetTokenT< L1GlobalTriggerEvmReadoutRecord > gtEvmInputToken_
std::vector< std::string > hltLogicalExpressionsCache_
std::string const & process() const
Definition: InputTag.h:40
tuple config
parse the configuration file
std::vector< int > dcsPartitions_
T get() const
Definition: EventSetup.h:88
const AlgorithmMap & gtAlgorithmMap() const
get / set the algorithm map (by name)
const AlgorithmMap & gtTechnicalTriggerMap() const
get / set the technical trigger map
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
Log< level::Warning, false > LogWarning
std::string expandLogicalExpression(const std::vector< std::string > &target, const std::string &expr, bool useAnd=false) const
Expand wild-carded logical expressions, giving version postfixes priority.
std::unique_ptr< edm::ESWatcher< AlCaRecoTriggerBitsRcd > > watchDB_
UseEventSetupIn
Definition: L1TGlobalUtil.h:42
tmp
align.sh
Definition: createJobs.py:716
std::unique_ptr< l1t::L1TGlobalUtil > l1uGt_
Definition: Run.h:45
bool acceptHltLogicalExpression(const edm::Handle< edm::TriggerResults > &hltTriggerResults, std::string hltLogicalExpression) const
Was this event accepted by this particular HLT paths&#39; logical expression?
std::vector< std::string > l1LogicalExpressions_
bool acceptL1(const edm::Event &event, const edm::EventSetup &setup)
Was this event accepted by the configured L1 logical expression combination?
virtual const bool expressionResult() const
bool acceptGt(const edm::Event &event)
Does this event fulfill the configured GT status logical expression combination?