CMS 3D CMS Logo

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 
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  dcsRecordInputTag_ = config.getParameter<edm::InputTag>("dcsRecordInputTag");
82  dcsPartitions_ = config.getParameter<std::vector<int>>("dcsPartitions");
83  errorReplyDcs_ = config.getParameter<bool>("errorReplyDcs");
84  } else {
85  onDcs_ = false;
86  }
87  if (config.exists("andOrGt")) {
88  andOrGt_ = config.getParameter<bool>("andOrGt");
89  gtInputTag_ = config.getParameter<edm::InputTag>("gtInputTag");
91  gtLogicalExpressions_ = config.getParameter<std::vector<std::string>>("gtStatusBits");
92  errorReplyGt_ = config.getParameter<bool>("errorReplyGt");
93  if (config.exists("gtEvmInputTag")) {
94  gtEvmInputTag_ = config.getParameter<edm::InputTag>("gtEvmInputTag");
96  }
97  if (config.exists("gtDBKey"))
98  gtDBKey_ = config.getParameter<std::string>("gtDBKey");
99  } else {
100  onGt_ = false;
101  }
102  if (config.exists("andOrL1")) {
103  andOrL1_ = config.getParameter<bool>("andOrL1");
104  if (config.exists("stage2"))
105  stage2_ = config.getParameter<bool>("stage2");
106  else
107  stage2_ = false;
108  l1LogicalExpressionsCache_ = config.getParameter<std::vector<std::string>>("l1Algorithms");
109  errorReplyL1_ = config.getParameter<bool>("errorReplyL1");
110  if (config.exists("l1DBKey"))
111  l1DBKey_ = config.getParameter<std::string>("l1DBKey");
112  if (config.exists("l1BeforeMask"))
113  l1BeforeMask_ = config.getParameter<bool>("l1BeforeMask");
114  } else {
115  onL1_ = false;
116  }
117  if (config.exists("andOrHlt")) {
118  andOrHlt_ = config.getParameter<bool>("andOrHlt");
119  hltInputTag_ = config.getParameter<edm::InputTag>("hltInputTag");
121  hltLogicalExpressionsCache_ = config.getParameter<std::vector<std::string>>("hltPaths");
122  errorReplyHlt_ = config.getParameter<bool>("errorReplyHlt");
123  if (config.exists("hltDBKey"))
124  hltDBKey_ = config.getParameter<std::string>("hltDBKey");
125  } else {
126  onHlt_ = false;
127  }
128  if (!onDcs_ && !onGt_ && !onL1_ && !onHlt_)
129  on_ = false;
130  else {
131  if (config.exists("dbLabel"))
132  dbLabel_ = config.getParameter<std::string>("dbLabel");
133  watchDB_ = std::make_unique<edm::ESWatcher<AlCaRecoTriggerBitsRcd>>();
134  }
135  }
136 
137  if (onL1_ && !stage2_) {
139  }
140  if ((onGt_ && !gtDBKey_.empty()) || (onL1_ && !l1DBKey_.empty()) || (onHlt_ && !hltDBKey_.empty())) {
143  }
144 
145  //check to see we arent trying to setup legacy / stage-1 from a constructor call
146  //that does not support it
147  if (config.exists("andOrL1") && stage2_ == false) { //stage-1 setup
148  if (stage1Valid == false)
149  throw cms::Exception("ConfigError") << " Error when constructing GenericTriggerEventFlag, legacy/stage-1 is "
150  "requested but the constructor called is stage2 only";
151  }
152 }
153 
156  if (watchDB_->check(setup)) {
157  if (onGt_ && !gtDBKey_.empty()) {
158  const std::vector<std::string> exprs(expressionsFromDB(gtDBKey_, setup));
159  if (exprs.empty() || exprs.at(0) != configError_)
160  gtLogicalExpressions_ = exprs;
161  }
162  if (onL1_ && !l1DBKey_.empty()) {
163  const std::vector<std::string> exprs(expressionsFromDB(l1DBKey_, setup));
164  if (exprs.empty() || exprs.at(0) != configError_)
166  }
167  if (onHlt_ && !hltDBKey_.empty()) {
168  const std::vector<std::string> exprs(expressionsFromDB(hltDBKey_, setup));
169  if (exprs.empty() || exprs.at(0) != configError_)
171  }
172  }
173 
174  // Re-initialise starting valuse before wild-card expansion
177 
178  hltConfigInit_ = false;
179  if (onHlt_) {
180  if (hltInputTag_.process().empty()) {
181  if (verbose_ > 0)
182  edm::LogError("GenericTriggerEventFlag")
183  << "HLT TriggerResults InputTag \"" << hltInputTag_.encode() << "\" specifies no process";
184  } else {
185  bool hltChanged(false);
186  if (!hltConfig_.init(run, setup, hltInputTag_.process(), hltChanged)) {
187  if (verbose_ > 0)
188  edm::LogError("GenericTriggerEventFlag")
189  << "HLT config initialization error with process name \"" << hltInputTag_.process() << "\"";
190  } else if (hltConfig_.size() <= 0) {
191  if (verbose_ > 0)
192  edm::LogError("GenericTriggerEventFlag") << "HLT config size error";
193  } else
194  hltConfigInit_ = true;
195  }
196  }
197 
198  // Expand version wild-cards in HLT logical expressions
199  // L1
200  if (onL1_) {
201  // build vector of algo names
202 
203  std::vector<std::string> algoNames;
204 
205  if (stage2_) {
206  l1uGt_->retrieveL1Setup(setup);
207 
208  const std::vector<std::pair<std::string, double>> prescales = l1uGt_->prescales();
209  for (const auto& ip : prescales)
210  algoNames.push_back(ip.first);
211  } else {
213  L1GtTriggerMenu const& l1GtTriggerMenu = setup.get<L1GtTriggerMenuRcd>().get(l1GtTriggerMenuToken_);
214 
215  const AlgorithmMap& l1GtPhys(l1GtTriggerMenu.gtAlgorithmMap());
216  for (CItAlgo iAlgo = l1GtPhys.begin(); iAlgo != l1GtPhys.end(); ++iAlgo) {
217  algoNames.push_back(iAlgo->second.algoName());
218  }
219  const AlgorithmMap& l1GtTech(l1GtTriggerMenu.gtTechnicalTriggerMap());
220  for (CItAlgo iAlgo = l1GtTech.begin(); iAlgo != l1GtTech.end(); ++iAlgo) {
221  algoNames.push_back(iAlgo->second.algoName());
222  }
223  }
224 
225  for (unsigned iExpr = 0; iExpr < l1LogicalExpressions_.size(); ++iExpr) {
226  std::string l1LogicalExpression(l1LogicalExpressions_.at(iExpr));
227  L1GtLogicParser l1AlgoLogicParser(l1LogicalExpression);
228  // Loop over algorithms
229  for (size_t iAlgo = 0; iAlgo < l1AlgoLogicParser.operandTokenVector().size(); ++iAlgo) {
230  const std::string l1AlgoName(l1AlgoLogicParser.operandTokenVector().at(iAlgo).tokenName);
231  if (l1AlgoName.find('*') != std::string::npos) {
232  l1LogicalExpression.replace(
233  l1LogicalExpression.find(l1AlgoName), l1AlgoName.size(), expandLogicalExpression(algoNames, l1AlgoName));
234  }
235  }
236  l1LogicalExpressions_[iExpr] = l1LogicalExpression;
237  }
238  std::vector<std::string> tmp = l1LogicalExpressions_;
239  for (unsigned iExpr = 0; iExpr < tmp.size(); ++iExpr)
240  if (std::find(algoNames.begin(), algoNames.end(), tmp[iExpr]) == algoNames.end()) {
241  l1LogicalExpressions_.erase(l1LogicalExpressions_.begin() + iExpr);
242  if (verbose_ > 1)
243  edm::LogWarning("GenericTriggerEventFlag")
244  << "L1 algorithm \"" << tmp[iExpr]
245  << "\" does not exist in the L1 menu ==> drop it from the list of l1LogicalExpressions";
246  }
247  }
248  // HLT
249  if (hltConfigInit_) {
250  for (unsigned iExpr = 0; iExpr < hltLogicalExpressions_.size(); ++iExpr) {
251  std::string hltLogicalExpression(hltLogicalExpressions_.at(iExpr));
252  L1GtLogicParser hltAlgoLogicParser(hltLogicalExpression);
253  // Loop over paths
254  for (size_t iPath = 0; iPath < hltAlgoLogicParser.operandTokenVector().size(); ++iPath) {
255  const std::string hltPathName(hltAlgoLogicParser.operandTokenVector().at(iPath).tokenName);
256  if (hltPathName.find('*') != std::string::npos) {
257  hltLogicalExpression.replace(hltLogicalExpression.find(hltPathName),
258  hltPathName.size(),
260  }
261  }
262  hltLogicalExpressions_[iExpr] = hltLogicalExpression;
263  }
264  }
265 }
266 
269  if (!on_)
270  return true;
271 
272  // Determine decision
273  if (andOr_)
276 }
277 
279  // An empty DCS partitions list acts as switch.
280  if (!onDcs_ || dcsPartitions_.empty())
281  return (!andOr_); // logically neutral, depending on base logical connective
282 
283  bool useDCSRecord(false);
284 
285  // Accessing the DcsStatusCollection
287  event.getByToken(dcsInputToken_, dcsStatus);
288 
290  event.getByToken(dcsRecordToken_, dcsRecord);
291 
292  // none of the DCS products is valid
293  if (!dcsStatus.isValid() && !dcsRecord.isValid()) {
294  if (verbose_ > 1)
295  edm::LogWarning("GenericTriggerEventFlag")
296  << "DcsStatusCollection product with InputTag \"" << dcsInputTag_.encode() << "\" not in event \n"
297  << "DCSRecord product with InputTag \"" << dcsRecordInputTag_.encode() << "\" not in event \n"
298  << " ==> decision: " << errorReplyDcs_;
299  return errorReplyDcs_;
300  }
301  if (dcsStatus.isValid() && (*dcsStatus).empty()) {
302  if (event.eventAuxiliary().isRealData()) {
303  // this is the Data case for >= Run3, DCSStatus is available (unpacked), but empty
304  // becasue SCAL is not in data-taking. In this case we fall back to s/w FED 1022
305  if (dcsRecord.isValid()) {
306  useDCSRecord = true;
307  } else {
308  if (verbose_ > 1)
309  edm::LogWarning("GenericTriggerEventFlag")
310  << "DCSRecord product with InputTag \"" << dcsRecordInputTag_.encode()
311  << "\" empty ==> decision: " << errorReplyDcs_;
312  return errorReplyDcs_;
313  }
314  } else {
315  // this is the case in which the DCS status is empty, but it's not real data.
316  if (verbose_ > 1)
317  edm::LogWarning("GenericTriggerEventFlag")
318  << "DcsStatusCollection product with InputTag \"" << dcsInputTag_.encode()
319  << "\" empty ==> decision: " << errorReplyDcs_;
320  return errorReplyDcs_;
321  }
322  }
323 
324  // Determine decision of DCS partition combination and return
325  if (andOrDcs_) { // OR combination
326  for (std::vector<int>::const_iterator partitionNumber = dcsPartitions_.begin();
327  partitionNumber != dcsPartitions_.end();
328  ++partitionNumber) {
329  if (acceptDcsPartition(dcsStatus, dcsRecord, useDCSRecord, *partitionNumber))
330  return true;
331  }
332  return false;
333  }
334  for (std::vector<int>::const_iterator partitionNumber = dcsPartitions_.begin();
335  partitionNumber != dcsPartitions_.end();
336  ++partitionNumber) {
337  if (!acceptDcsPartition(dcsStatus, dcsRecord, useDCSRecord, *partitionNumber))
338  return false;
339  }
340  return true;
341 }
342 
345  bool useDCSRecord,
346  int dcsPartition) const {
347  int theDCSRecordPartition;
348  // Error checks
349  switch (dcsPartition) {
350  case DcsStatus::EBp:
351  theDCSRecordPartition = DCSRecord::EBp;
352  break;
353  case DcsStatus::EBm:
354  theDCSRecordPartition = DCSRecord::EBm;
355  break;
356  case DcsStatus::EEp:
357  theDCSRecordPartition = DCSRecord::EEp;
358  break;
359  case DcsStatus::EEm:
360  theDCSRecordPartition = DCSRecord::EBm;
361  break;
362  case DcsStatus::HBHEa:
363  theDCSRecordPartition = DCSRecord::HBHEa;
364  break;
365  case DcsStatus::HBHEb:
366  theDCSRecordPartition = DCSRecord::HBHEb;
367  break;
368  case DcsStatus::HBHEc:
369  theDCSRecordPartition = DCSRecord::HBHEc;
370  break;
371  case DcsStatus::HF:
372  theDCSRecordPartition = DCSRecord::HF;
373  break;
374  case DcsStatus::HO:
375  theDCSRecordPartition = DCSRecord::HO;
376  break;
377  case DcsStatus::RPC:
378  theDCSRecordPartition = DCSRecord::RPC;
379  break;
380  case DcsStatus::DT0:
381  theDCSRecordPartition = DCSRecord::DT0;
382  break;
383  case DcsStatus::DTp:
384  theDCSRecordPartition = DCSRecord::DTp;
385  break;
386  case DcsStatus::DTm:
387  theDCSRecordPartition = DCSRecord::DTm;
388  break;
389  case DcsStatus::CSCp:
390  theDCSRecordPartition = DCSRecord::CSCp;
391  break;
392  case DcsStatus::CSCm:
393  theDCSRecordPartition = DCSRecord::CSCm;
394  break;
395  case DcsStatus::CASTOR:
396  theDCSRecordPartition = DCSRecord::CASTOR;
397  break;
398  case DcsStatus::TIBTID:
399  theDCSRecordPartition = DCSRecord::TIBTID;
400  break;
401  case DcsStatus::TOB:
402  theDCSRecordPartition = DCSRecord::TOB;
403  break;
404  case DcsStatus::TECp:
405  theDCSRecordPartition = DCSRecord::TECp;
406  break;
407  case DcsStatus::TECm:
408  theDCSRecordPartition = DCSRecord::TECm;
409  break;
410  case DcsStatus::BPIX:
411  theDCSRecordPartition = DCSRecord::BPIX;
412  break;
413  case DcsStatus::FPIX:
414  theDCSRecordPartition = DCSRecord::FPIX;
415  break;
416  case DcsStatus::ESp:
417  theDCSRecordPartition = DCSRecord::ESp;
418  break;
419  case DcsStatus::ESm:
420  theDCSRecordPartition = DCSRecord::ESm;
421  break;
422  default:
423  if (verbose_ > 1)
424  edm::LogWarning("GenericTriggerEventFlag")
425  << "DCS partition number \"" << dcsPartition << "\" does not exist ==> decision: " << errorReplyDcs_;
426  return errorReplyDcs_;
427  }
428 
429  // Determine decision
430  if (!useDCSRecord) {
431  return dcsStatus->at(0).ready(dcsPartition);
432  } else {
433  if (verbose_ > 2) {
434  LogDebug("GenericTriggerEventFlag")
435  << "using dcs record, dcsPartition:" << dcsPartition << " " << theDCSRecordPartition << " "
436  << (*dcsRecord).partitionName(theDCSRecordPartition) << " "
437  << (*dcsRecord).highVoltageReady(theDCSRecordPartition) << std::endl;
438  }
439  return (*dcsRecord).highVoltageReady(theDCSRecordPartition);
440  }
441 }
442 
445  // An empty GT status bits logical expressions list acts as switch.
446  if (!onGt_ || gtLogicalExpressions_.empty())
447  return (!andOr_); // logically neutral, depending on base logical connective
448 
449  // Determine decision of GT status bits logical expression combination and return
450  if (andOrGt_) { // OR combination
451  for (std::vector<std::string>::const_iterator gtLogicalExpression = gtLogicalExpressions_.begin();
452  gtLogicalExpression != gtLogicalExpressions_.end();
453  ++gtLogicalExpression) {
454  if (acceptGtLogicalExpression(event, *gtLogicalExpression))
455  return true;
456  }
457  return false;
458  }
459  for (std::vector<std::string>::const_iterator gtLogicalExpression = gtLogicalExpressions_.begin();
460  gtLogicalExpression != gtLogicalExpressions_.end();
461  ++gtLogicalExpression) {
462  if (!acceptGtLogicalExpression(event, *gtLogicalExpression))
463  return false;
464  }
465  return true;
466 }
467 
470  // Check empty std::strings
471  if (gtLogicalExpression.empty()) {
472  if (verbose_ > 1)
473  edm::LogWarning("GenericTriggerEventFlag") << "Empty logical expression ==> decision: " << errorReplyGt_;
474  return errorReplyGt_;
475  }
476 
477  // Negated paths
478  bool negExpr(negate(gtLogicalExpression));
479  if (negExpr && gtLogicalExpression.empty()) {
480  if (verbose_ > 1)
481  edm::LogWarning("GenericTriggerEventFlag")
482  << "Empty (negated) logical expression ==> decision: " << errorReplyGt_;
483  return errorReplyGt_;
484  }
485 
486  // Parse logical expression and determine GT status bit decision
487  L1GtLogicParser gtAlgoLogicParser(gtLogicalExpression);
488  // Loop over status bits
489  for (size_t iStatusBit = 0; iStatusBit < gtAlgoLogicParser.operandTokenVector().size(); ++iStatusBit) {
490  const std::string gtStatusBit(gtAlgoLogicParser.operandTokenVector().at(iStatusBit).tokenName);
491  // Manipulate status bit decision as stored in the parser
492  bool decision(errorReplyDcs_);
493  // Hard-coded status bits!!!
494  if (gtStatusBit == "PhysDecl" || gtStatusBit == "PhysicsDeclared") {
496  event.getByToken(gtInputToken_, gtReadoutRecord);
497  if (!gtReadoutRecord.isValid()) {
498  if (verbose_ > 1)
499  edm::LogWarning("GenericTriggerEventFlag")
500  << "L1GlobalTriggerReadoutRecord product with InputTag \"" << gtInputTag_.encode()
501  << "\" not in event ==> decision: " << errorReplyGt_;
502  gtAlgoLogicParser.operandTokenVector().at(iStatusBit).tokenResult = errorReplyDcs_;
503  continue;
504  }
505  decision = (gtReadoutRecord->gtFdlWord().physicsDeclared() == 1);
506  } else if (gtStatusBit == "Stable" || gtStatusBit == "StableBeam" || gtStatusBit == "Adjust" ||
507  gtStatusBit == "Sqeeze" || gtStatusBit == "Flat" || gtStatusBit == "FlatTop" || gtStatusBit == "7TeV" ||
508  gtStatusBit == "8TeV" || gtStatusBit == "13TeV" || gtStatusBit == "2360GeV" || gtStatusBit == "900GeV") {
510  event.getByToken(gtEvmInputToken_, gtEvmReadoutRecord);
511  if (!gtEvmReadoutRecord.isValid()) {
512  if (verbose_ > 1)
513  edm::LogWarning("GenericTriggerEventFlag")
514  << "L1GlobalTriggerEvmReadoutRecord product with InputTag \"" << gtEvmInputTag_.encode()
515  << "\" not in event ==> decision: " << errorReplyGt_;
516  gtAlgoLogicParser.operandTokenVector().at(iStatusBit).tokenResult = errorReplyDcs_;
517  continue;
518  }
519  if (gtStatusBit == "Stable" || gtStatusBit == "StableBeam") {
520  decision = (gtEvmReadoutRecord->gtfeWord().beamMode() == 11);
521  } else if (gtStatusBit == "Adjust") {
522  decision = (10 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11);
523  } else if (gtStatusBit == "Sqeeze") {
524  decision = (9 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11);
525  } else if (gtStatusBit == "Flat" || gtStatusBit == "FlatTop") {
526  decision = (8 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11);
527  } else if (gtStatusBit == "7TeV") {
528  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 3500);
529  } else if (gtStatusBit == "8TeV") {
530  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 4000);
531  } else if (gtStatusBit == "13TeV") {
532  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 6500);
533  } else if (gtStatusBit == "2360GeV") {
534  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 1180);
535  } else if (gtStatusBit == "900GeV") {
536  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 450);
537  }
538  } else {
539  if (verbose_ > 1)
540  edm::LogWarning("GenericTriggerEventFlag")
541  << "GT status bit \"" << gtStatusBit << "\" is not defined ==> decision: " << errorReplyGt_;
542  }
543  gtAlgoLogicParser.operandTokenVector().at(iStatusBit).tokenResult = decision;
544  }
545 
546  // Determine decision
547  const bool gtDecision(gtAlgoLogicParser.expressionResult());
548  return negExpr ? (!gtDecision) : gtDecision;
549 }
550 
553  // An empty L1 logical expressions list acts as switch.
554  if (!onL1_ || l1LogicalExpressions_.empty())
555  return (!andOr_); // logically neutral, depending on base logical connective
556 
557  // Determine decision of L1 logical expression combination and return
558  if (andOrL1_) { // OR combination
559  for (std::vector<std::string>::const_iterator l1LogicalExpression = l1LogicalExpressions_.begin();
560  l1LogicalExpression != l1LogicalExpressions_.end();
561  ++l1LogicalExpression) {
562  if (acceptL1LogicalExpression(event, setup, *l1LogicalExpression))
563  return true;
564  }
565  return false;
566  }
567  for (std::vector<std::string>::const_iterator l1LogicalExpression = l1LogicalExpressions_.begin();
568  l1LogicalExpression != l1LogicalExpressions_.end();
569  ++l1LogicalExpression) {
570  if (!acceptL1LogicalExpression(event, setup, *l1LogicalExpression))
571  return false;
572  }
573  return true;
574 }
575 
578  const edm::EventSetup& setup,
579  std::string l1LogicalExpression) {
580  // Getting the L1 event setup
581  if (stage2_)
582  l1uGt_->retrieveL1(event, setup);
583  else
584  // FIXME This can possibly go to initRun()
586 
587  // Check empty std::strings
588  if (l1LogicalExpression.empty()) {
589  if (verbose_ > 1)
590  edm::LogWarning("GenericTriggerEventFlag") << "Empty logical expression ==> decision: " << errorReplyL1_;
591  return errorReplyL1_;
592  }
593 
594  // Negated logical expression
595  bool negExpr(negate(l1LogicalExpression));
596  if (negExpr && l1LogicalExpression.empty()) {
597  if (verbose_ > 1)
598  edm::LogWarning("GenericTriggerEventFlag")
599  << "Empty (negated) logical expression ==> decision: " << errorReplyL1_;
600  return errorReplyL1_;
601  }
602 
603  // Parse logical expression and determine L1 decision
604  L1GtLogicParser l1AlgoLogicParser(l1LogicalExpression);
605  // Loop over algorithms
606  for (size_t iAlgorithm = 0; iAlgorithm < l1AlgoLogicParser.operandTokenVector().size(); ++iAlgorithm) {
607  const std::string l1AlgoName(l1AlgoLogicParser.operandTokenVector().at(iAlgorithm).tokenName);
608 
609  bool decision = false;
610  bool error = false;
611  if (stage2_) {
612  bool errorBOOL = (l1BeforeMask_ ? l1uGt_->getInitialDecisionByName(l1AlgoName, decision)
613  : l1uGt_->getFinalDecisionByName(l1AlgoName, decision));
614  error = !errorBOOL;
615  } else {
616  int errorINT(-1);
617  // const bool decision( l1BeforeMask_ ? l1Gt_->decisionBeforeMask( event, l1AlgoName, errorINT ) : l1Gt_->decisionAfterMask( event, l1AlgoName, errorINT ) );
618  decision = (l1BeforeMask_ ? l1Gt_->decisionBeforeMask(event, l1AlgoName, errorINT)
619  : l1Gt_->decisionAfterMask(event, l1AlgoName, errorINT));
620  error = (errorINT != 0);
621  if (errorINT > 1)
622  if (verbose_ > 1)
623  edm::LogWarning("GenericTriggerEventFlag")
624  << "L1 algorithm \"" << l1AlgoName << "\" received error code " << error
625  << " from L1GtUtils::decisionBeforeMask ==> decision: " << errorReplyL1_;
626  }
627 
628  // Error checks
629  if (error) {
630  if (verbose_ > 1)
631  edm::LogWarning("GenericTriggerEventFlag")
632  << "L1 algorithm \"" << l1AlgoName << "\" does not exist in the L1 menu ==> decision: " << errorReplyL1_;
633  l1AlgoLogicParser.operandTokenVector().at(iAlgorithm).tokenResult = errorReplyL1_;
634  continue;
635  }
636  // Manipulate algo decision as stored in the parser
637  l1AlgoLogicParser.operandTokenVector().at(iAlgorithm).tokenResult = decision;
638  }
639 
640  // Return decision
641  const bool l1Decision(l1AlgoLogicParser.expressionResult());
642  return negExpr ? (!l1Decision) : l1Decision;
643 }
644 
647  // An empty HLT logical expressions list acts as switch.
648  if (!onHlt_ || hltLogicalExpressions_.empty())
649  return (!andOr_); // logically neutral, depending on base logical connective
650 
651  // Checking the HLT configuration,
652  if (!hltConfigInit_) {
653  if (verbose_ > 1)
654  edm::LogWarning("GenericTriggerEventFlag") << "HLT config error ==> decision: " << errorReplyHlt_;
655  return errorReplyHlt_;
656  }
657 
658  // Accessing the TriggerResults
659  edm::Handle<edm::TriggerResults> hltTriggerResults;
660  event.getByToken(hltInputToken_, hltTriggerResults);
661  if (!hltTriggerResults.isValid()) {
662  if (verbose_ > 1)
663  edm::LogWarning("GenericTriggerEventFlag") << "TriggerResults product with InputTag \"" << hltInputTag_.encode()
664  << "\" not in event ==> decision: " << errorReplyHlt_;
665  return errorReplyHlt_;
666  }
667  if ((*hltTriggerResults).size() == 0) {
668  if (verbose_ > 1)
669  edm::LogWarning("GenericTriggerEventFlag") << "TriggerResults product with InputTag \"" << hltInputTag_.encode()
670  << "\" empty ==> decision: " << errorReplyHlt_;
671  return errorReplyDcs_;
672  }
673 
674  // Determine decision of HLT logical expression combination and return
675  if (andOrHlt_) { // OR combination
676  for (std::vector<std::string>::const_iterator hltLogicalExpression = hltLogicalExpressions_.begin();
677  hltLogicalExpression != hltLogicalExpressions_.end();
678  ++hltLogicalExpression) {
679  if (acceptHltLogicalExpression(hltTriggerResults, *hltLogicalExpression))
680  return true;
681  }
682  return false;
683  }
684  for (std::vector<std::string>::const_iterator hltLogicalExpression = hltLogicalExpressions_.begin();
685  hltLogicalExpression != hltLogicalExpressions_.end();
686  ++hltLogicalExpression) {
687  if (!acceptHltLogicalExpression(hltTriggerResults, *hltLogicalExpression))
688  return false;
689  }
690  return true;
691 }
692 
695  std::string hltLogicalExpression) const {
696  // Check empty std::strings
697  if (hltLogicalExpression.empty()) {
698  if (verbose_ > 1)
699  edm::LogWarning("GenericTriggerEventFlag") << "Empty logical expression ==> decision: " << errorReplyHlt_;
700  return errorReplyHlt_;
701  }
702 
703  // Negated paths
704  bool negExpr(negate(hltLogicalExpression));
705  if (negExpr && hltLogicalExpression.empty()) {
706  if (verbose_ > 1)
707  edm::LogWarning("GenericTriggerEventFlag")
708  << "Empty (negated) logical expression ==> decision: " << errorReplyHlt_;
709  return errorReplyHlt_;
710  }
711 
712  // Parse logical expression and determine HLT decision
713  L1GtLogicParser hltAlgoLogicParser(hltLogicalExpression);
714  // Loop over paths
715  for (size_t iPath = 0; iPath < hltAlgoLogicParser.operandTokenVector().size(); ++iPath) {
716  const std::string hltPathName(hltAlgoLogicParser.operandTokenVector().at(iPath).tokenName);
717  const unsigned indexPath(hltConfig_.triggerIndex(hltPathName));
718  // Further error checks
719  if (indexPath == hltConfig_.size()) {
720  if (verbose_ > 1)
721  edm::LogWarning("GenericTriggerEventFlag") << "HLT path \"" << hltPathName << "\" is not found in process "
722  << hltInputTag_.process() << " ==> decision: " << errorReplyHlt_;
723  hltAlgoLogicParser.operandTokenVector().at(iPath).tokenResult = errorReplyHlt_;
724  continue;
725  }
726  if (hltTriggerResults->error(indexPath)) {
727  if (verbose_ > 1)
728  edm::LogWarning("GenericTriggerEventFlag")
729  << "HLT path \"" << hltPathName << "\" in error ==> decision: " << errorReplyHlt_;
730  hltAlgoLogicParser.operandTokenVector().at(iPath).tokenResult = errorReplyHlt_;
731  continue;
732  }
733  // Manipulate algo decision as stored in the parser
734  const bool decision(hltTriggerResults->accept(indexPath));
735  hltAlgoLogicParser.operandTokenVector().at(iPath).tokenResult = decision;
736  }
737 
738  // Determine decision
739  const bool hltDecision(hltAlgoLogicParser.expressionResult());
740  return negExpr ? (!hltDecision) : hltDecision;
741 }
742 
745  const std::string& expr,
746  bool useAnd) const {
747  // Find matching entries in the menu
748  std::vector<std::string> matched;
749  const std::string versionWildcard("_v*");
750  if (expr.substr(expr.size() - versionWildcard.size()) == versionWildcard) {
751  const std::string exprBase(expr.substr(0, expr.size() - versionWildcard.size()));
753  } else {
755  }
756 
757  // Return input, if no match is found
758  if (matched.empty()) {
759  if (verbose_ > 1)
760  edm::LogWarning("GenericTriggerEventFlag") << "Logical expression: \"" << expr << "\" could not be resolved";
761  return expr;
762  }
763 
764  // Compose logical expression
765  std::string expanded("(");
766  for (unsigned iVers = 0; iVers < matched.size(); ++iVers) {
767  if (iVers > 0)
768  expanded.append(useAnd ? " AND " : " OR ");
769  expanded.append(matched.at(iVers));
770  }
771  expanded.append(")");
772  if (verbose_ > 1)
773  edm::LogInfo("GenericTriggerEventFlag") << "Logical expression: \"" << expr << "\"\n"
774  << " --> expanded to \"" << expanded << "\"";
775 
776  return expanded;
777 }
778 
781  bool negate(false);
782  if (word.at(0) == '~') {
783  negate = true;
784  word.erase(0, 1);
785  }
786  return negate;
787 }
788 
791  const edm::EventSetup& setup) {
792  if (key.empty())
793  return std::vector<std::string>(1, emptyKeyError_);
794  std::vector<edm::eventsetup::DataKey> labels;
795  setup.get<AlCaRecoTriggerBitsRcd>().fillRegisteredDataKeys(labels);
796  std::vector<edm::eventsetup::DataKey>::const_iterator iKey = labels.begin();
797  while (iKey != labels.end() && iKey->name().value() != dbLabel_)
798  ++iKey;
799  if (iKey == labels.end()) {
800  if (verbose_ > 0)
801  edm::LogWarning("GenericTriggerEventFlag")
802  << "Label " << dbLabel_ << " not found in DB for 'AlCaRecoTriggerBitsRcd'";
803  return std::vector<std::string>(1, configError_);
804  }
805  auto const& alCaRecoTriggerBits = setup.getData(alCaRecoTriggerBitsToken_);
806  const std::map<std::string, std::string>& expressionMap = alCaRecoTriggerBits.m_alcarecoToTrig;
807  std::map<std::string, std::string>::const_iterator listIter = expressionMap.find(key);
808  if (listIter == expressionMap.end()) {
809  if (verbose_ > 0)
810  edm::LogWarning("GenericTriggerEventFlag")
811  << "No logical expressions found under key " << key << " in 'AlCaRecoTriggerBitsRcd'";
812  return std::vector<std::string>(1, configError_);
813  }
814  return alCaRecoTriggerBits.decompose(listIter->second);
815 }
816 
818  if (not onHlt_) {
819  return true;
820  }
821 
822  if (not hltConfigInit_) {
823  if (verbose_ > 0) {
824  edm::LogWarning("GenericTriggerEventFlag::allHLTPathsAreValid()")
825  << "HLTConfigProvider is not initialized, method will return \"false\"";
826  }
827 
828  return false;
829  }
830 
831  for (unsigned iExpr = 0; iExpr < hltLogicalExpressions_.size(); ++iExpr) {
832  std::string hltLogicalExpression = hltLogicalExpressions_.at(iExpr);
833 
834  L1GtLogicParser hltAlgoLogicParser(hltLogicalExpression);
835 
836  if (hltAlgoLogicParser.operandTokenVector().empty()) {
837  return false;
838  }
839 
840  for (size_t iPath = 0; iPath < hltAlgoLogicParser.operandTokenVector().size(); ++iPath) {
841  const std::string hltPathName(hltAlgoLogicParser.operandTokenVector().at(iPath).tokenName);
842 
843  const unsigned indexPath(hltConfig_.triggerIndex(hltPathName));
844 
845  if (indexPath == hltConfig_.size()) {
846  if (verbose_ > 1) {
847  edm::LogWarning("GenericTriggerEventFlag::allHLTPathsAreValid()")
848  << "HLT path \"" << hltPathName << "\" is not found in process " << hltInputTag_.process();
849  }
850 
851  return false;
852  }
853  }
854  }
855 
856  return true;
857 }
858 
860  desc.add<bool>("ReadPrescalesFromFile", false);
861  desc.add<bool>("andOr", false);
862  desc.add<bool>("andOrDcs", false);
863  desc.add<bool>("andOrHlt", false);
864  desc.add<bool>("andOrL1", false);
865  desc.add<bool>("errorReplyDcs", false);
866  desc.add<bool>("errorReplyHlt", false);
867  desc.add<bool>("errorReplyL1", false);
868  desc.add<bool>("l1BeforeMask", false);
869  desc.add<bool>("stage2", false);
870  desc.add<edm::InputTag>("dcsInputTag", edm::InputTag("scalersRawToDigi"));
871  desc.add<edm::InputTag>("dcsRecordInputTag", edm::InputTag("onlineMetaDataDigis"));
872  desc.add<edm::InputTag>("hltInputTag", edm::InputTag("TriggerResults::HLT"));
873  desc.add<edm::InputTag>("l1tAlgBlkInputTag", edm::InputTag("gtStage2Digis"));
874  desc.add<edm::InputTag>("l1tExtBlkInputTag", edm::InputTag("gtStage2Digis"));
875  desc.add<std::string>("dbLabel", "");
876  desc.add<std::string>("hltDBKey", "");
877  desc.add<std::vector<int>>("dcsPartitions", {});
878  desc.add<std::vector<std::string>>("hltPaths", {});
879  desc.add<std::vector<std::string>>("l1Algorithms", {});
880  desc.add<unsigned int>("verbosityLevel", 0);
881 }
const AlgorithmMap & gtTechnicalTriggerMap() const
get / set the technical trigger map
edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > gtInputToken_
bool accept() const
Has at least one path accepted the event?
GenericTriggerEventFlag(const edm::ParameterSet &config, edm::ConsumesCollector &&iC, l1t::UseEventSetupIn use=l1t::UseEventSetupIn::RunAndEvent)
edm::ESGetToken< L1GtTriggerMenu, L1GtTriggerMenuRcd > l1GtTriggerMenuToken_
const cms_uint16_t beamMode() const
const cms_uint16_t physicsDeclared() const
get/set "physics declared" bit
Definition: L1GtFdlWord.h:169
static const std::vector< std::string > matched(const std::vector< std::string > &inputs, const std::string &pattern)
regexp processing
bool acceptDcsPartition(const edm::Handle< DcsStatusCollection > &dcsStatus, const edm::Handle< DCSRecord > &dcsRecord, bool useDCSRecord, int dcsPartition) const
static const bool useL1GtTriggerMenuLite(false)
bool error() const
Has any path encountered an error (exception)
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
std::string encode() const
Definition: InputTag.cc:159
bool negate(std::string &word) const
Checks for negated words.
std::map< std::string, L1GtAlgorithm > AlgorithmMap
map containing the algorithms
std::vector< std::string > hltLogicalExpressions_
std::vector< std::string > gtLogicalExpressions_
dictionary config
Read in AllInOne config in JSON format.
Definition: DMR_cfg.py:21
edm::EDGetTokenT< DcsStatusCollection > dcsInputToken_
const L1GtfeExtWord gtfeWord() const
get / set GTFE word (record) in the GT readout record
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
Definition: config.py:1
Class to contain DCS information from soft FED 1022.
Definition: DCSRecord.h:20
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.
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
const L1GtFdlWord gtFdlWord(int bxInEventValue) const
get / set FDL word (record) in the GT readout record
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
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
unsigned int size() const
number of trigger paths in trigger table
edm::EDGetTokenT< DCSRecord > dcsRecordToken_
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?
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
std::vector< std::string > l1LogicalExpressionsCache_
static const bool useL1EventSetup(true)
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
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?
const cms_uint16_t beamMomentum() const
const std::vector< std::string > & triggerNames() const
names of trigger paths
edm::EDGetTokenT< L1GlobalTriggerEvmReadoutRecord > gtEvmInputToken_
bool isValid() const
Definition: HandleBase.h:70
std::vector< std::string > hltLogicalExpressionsCache_
std::vector< int > dcsPartitions_
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
Log< level::Warning, false > LogWarning
std::string const & process() const
Definition: InputTag.h:40
const AlgorithmMap & gtAlgorithmMap() const
get / set the algorithm map (by name)
std::unique_ptr< edm::ESWatcher< AlCaRecoTriggerBitsRcd > > watchDB_
UseEventSetupIn
Definition: L1TGlobalUtil.h:42
tmp
align.sh
Definition: createJobs.py:716
static void fillPSetDescription(edm::ParameterSetDescription &desc)
virtual const bool expressionResult() const
std::unique_ptr< l1t::L1TGlobalUtil > l1uGt_
bool acceptHltLogicalExpression(const edm::Handle< edm::TriggerResults > &hltTriggerResults, std::string hltLogicalExpression) const
Was this event accepted by this particular HLT paths&#39; logical expression?
Definition: event.py:1
Definition: Run.h:45
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?
#define LogDebug(id)
bool acceptGt(const edm::Event &event)
Does this event fulfill the configured GT status logical expression combination?