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  const auto& l1GtTriggerMenuRcd = setup.get<L1GtTriggerMenuRcd>();
214  L1GtTriggerMenu const& l1GtTriggerMenu = l1GtTriggerMenuRcd.get(l1GtTriggerMenuToken_);
215 
216  const AlgorithmMap& l1GtPhys(l1GtTriggerMenu.gtAlgorithmMap());
217  for (CItAlgo iAlgo = l1GtPhys.begin(); iAlgo != l1GtPhys.end(); ++iAlgo) {
218  algoNames.push_back(iAlgo->second.algoName());
219  }
220  const AlgorithmMap& l1GtTech(l1GtTriggerMenu.gtTechnicalTriggerMap());
221  for (CItAlgo iAlgo = l1GtTech.begin(); iAlgo != l1GtTech.end(); ++iAlgo) {
222  algoNames.push_back(iAlgo->second.algoName());
223  }
224  }
225 
226  for (unsigned iExpr = 0; iExpr < l1LogicalExpressions_.size(); ++iExpr) {
227  std::string l1LogicalExpression(l1LogicalExpressions_.at(iExpr));
228  L1GtLogicParser l1AlgoLogicParser(l1LogicalExpression);
229  // Loop over algorithms
230  for (size_t iAlgo = 0; iAlgo < l1AlgoLogicParser.operandTokenVector().size(); ++iAlgo) {
231  const std::string l1AlgoName(l1AlgoLogicParser.operandTokenVector().at(iAlgo).tokenName);
232  if (l1AlgoName.find('*') != std::string::npos) {
233  l1LogicalExpression.replace(
234  l1LogicalExpression.find(l1AlgoName), l1AlgoName.size(), expandLogicalExpression(algoNames, l1AlgoName));
235  }
236  }
237  l1LogicalExpressions_[iExpr] = l1LogicalExpression;
238  }
239  std::vector<std::string> tmp = l1LogicalExpressions_;
240  for (unsigned iExpr = 0; iExpr < tmp.size(); ++iExpr)
241  if (std::find(algoNames.begin(), algoNames.end(), tmp[iExpr]) == algoNames.end()) {
242  l1LogicalExpressions_.erase(l1LogicalExpressions_.begin() + iExpr);
243  if (verbose_ > 1)
244  edm::LogWarning("GenericTriggerEventFlag")
245  << "L1 algorithm \"" << tmp[iExpr]
246  << "\" does not exist in the L1 menu ==> drop it from the list of l1LogicalExpressions";
247  }
248  }
249  // HLT
250  if (hltConfigInit_) {
251  for (unsigned iExpr = 0; iExpr < hltLogicalExpressions_.size(); ++iExpr) {
252  std::string hltLogicalExpression(hltLogicalExpressions_.at(iExpr));
253  L1GtLogicParser hltAlgoLogicParser(hltLogicalExpression);
254  // Loop over paths
255  for (size_t iPath = 0; iPath < hltAlgoLogicParser.operandTokenVector().size(); ++iPath) {
256  const std::string hltPathName(hltAlgoLogicParser.operandTokenVector().at(iPath).tokenName);
257  if (hltPathName.find('*') != std::string::npos) {
258  hltLogicalExpression.replace(hltLogicalExpression.find(hltPathName),
259  hltPathName.size(),
261  }
262  }
263  hltLogicalExpressions_[iExpr] = hltLogicalExpression;
264  }
265  }
266 }
267 
270  if (!on_)
271  return true;
272 
273  // Determine decision
274  if (andOr_)
277 }
278 
280  // An empty DCS partitions list acts as switch.
281  if (!onDcs_ || dcsPartitions_.empty())
282  return (!andOr_); // logically neutral, depending on base logical connective
283 
284  bool useDCSRecord(false);
285 
286  // Accessing the DcsStatusCollection
288  event.getByToken(dcsInputToken_, dcsStatus);
289 
291  event.getByToken(dcsRecordToken_, dcsRecord);
292 
293  // none of the DCS products is valid
294  if (!dcsStatus.isValid() && !dcsRecord.isValid()) {
295  if (verbose_ > 1)
296  edm::LogWarning("GenericTriggerEventFlag")
297  << "DcsStatusCollection product with InputTag \"" << dcsInputTag_.encode() << "\" not in event \n"
298  << "DCSRecord product with InputTag \"" << dcsRecordInputTag_.encode() << "\" not in event \n"
299  << " ==> decision: " << errorReplyDcs_;
300  return errorReplyDcs_;
301  }
302  if (dcsStatus.isValid() && (*dcsStatus).empty()) {
303  if (event.eventAuxiliary().isRealData()) {
304  // this is the Data case for >= Run3, DCSStatus is available (unpacked), but empty
305  // becasue SCAL is not in data-taking. In this case we fall back to s/w FED 1022
306  if (dcsRecord.isValid()) {
307  useDCSRecord = true;
308  } else {
309  if (verbose_ > 1)
310  edm::LogWarning("GenericTriggerEventFlag")
311  << "DCSRecord product with InputTag \"" << dcsRecordInputTag_.encode()
312  << "\" empty ==> decision: " << errorReplyDcs_;
313  return errorReplyDcs_;
314  }
315  } else {
316  // this is the case in which the DCS status is empty, but it's not real data.
317  if (verbose_ > 1)
318  edm::LogWarning("GenericTriggerEventFlag")
319  << "DcsStatusCollection product with InputTag \"" << dcsInputTag_.encode()
320  << "\" empty ==> decision: " << errorReplyDcs_;
321  return errorReplyDcs_;
322  }
323  }
324 
325  // Determine decision of DCS partition combination and return
326  if (andOrDcs_) { // OR combination
327  for (std::vector<int>::const_iterator partitionNumber = dcsPartitions_.begin();
328  partitionNumber != dcsPartitions_.end();
329  ++partitionNumber) {
330  if (acceptDcsPartition(dcsStatus, dcsRecord, useDCSRecord, *partitionNumber))
331  return true;
332  }
333  return false;
334  }
335  for (std::vector<int>::const_iterator partitionNumber = dcsPartitions_.begin();
336  partitionNumber != dcsPartitions_.end();
337  ++partitionNumber) {
338  if (!acceptDcsPartition(dcsStatus, dcsRecord, useDCSRecord, *partitionNumber))
339  return false;
340  }
341  return true;
342 }
343 
346  bool useDCSRecord,
347  int dcsPartition) const {
348  int theDCSRecordPartition;
349  // Error checks
350  switch (dcsPartition) {
351  case DcsStatus::EBp:
352  theDCSRecordPartition = DCSRecord::EBp;
353  break;
354  case DcsStatus::EBm:
355  theDCSRecordPartition = DCSRecord::EBm;
356  break;
357  case DcsStatus::EEp:
358  theDCSRecordPartition = DCSRecord::EEp;
359  break;
360  case DcsStatus::EEm:
361  theDCSRecordPartition = DCSRecord::EBm;
362  break;
363  case DcsStatus::HBHEa:
364  theDCSRecordPartition = DCSRecord::HBHEa;
365  break;
366  case DcsStatus::HBHEb:
367  theDCSRecordPartition = DCSRecord::HBHEb;
368  break;
369  case DcsStatus::HBHEc:
370  theDCSRecordPartition = DCSRecord::HBHEc;
371  break;
372  case DcsStatus::HF:
373  theDCSRecordPartition = DCSRecord::HF;
374  break;
375  case DcsStatus::HO:
376  theDCSRecordPartition = DCSRecord::HO;
377  break;
378  case DcsStatus::RPC:
379  theDCSRecordPartition = DCSRecord::RPC;
380  break;
381  case DcsStatus::DT0:
382  theDCSRecordPartition = DCSRecord::DT0;
383  break;
384  case DcsStatus::DTp:
385  theDCSRecordPartition = DCSRecord::DTp;
386  break;
387  case DcsStatus::DTm:
388  theDCSRecordPartition = DCSRecord::DTm;
389  break;
390  case DcsStatus::CSCp:
391  theDCSRecordPartition = DCSRecord::CSCp;
392  break;
393  case DcsStatus::CSCm:
394  theDCSRecordPartition = DCSRecord::CSCm;
395  break;
396  case DcsStatus::CASTOR:
397  theDCSRecordPartition = DCSRecord::CASTOR;
398  break;
399  case DcsStatus::TIBTID:
400  theDCSRecordPartition = DCSRecord::TIBTID;
401  break;
402  case DcsStatus::TOB:
403  theDCSRecordPartition = DCSRecord::TOB;
404  break;
405  case DcsStatus::TECp:
406  theDCSRecordPartition = DCSRecord::TECp;
407  break;
408  case DcsStatus::TECm:
409  theDCSRecordPartition = DCSRecord::TECm;
410  break;
411  case DcsStatus::BPIX:
412  theDCSRecordPartition = DCSRecord::BPIX;
413  break;
414  case DcsStatus::FPIX:
415  theDCSRecordPartition = DCSRecord::FPIX;
416  break;
417  case DcsStatus::ESp:
418  theDCSRecordPartition = DCSRecord::ESp;
419  break;
420  case DcsStatus::ESm:
421  theDCSRecordPartition = DCSRecord::ESm;
422  break;
423  default:
424  if (verbose_ > 1)
425  edm::LogWarning("GenericTriggerEventFlag")
426  << "DCS partition number \"" << dcsPartition << "\" does not exist ==> decision: " << errorReplyDcs_;
427  return errorReplyDcs_;
428  }
429 
430  // Determine decision
431  if (!useDCSRecord) {
432  return dcsStatus->at(0).ready(dcsPartition);
433  } else {
434  if (verbose_ > 2) {
435  LogDebug("GenericTriggerEventFlag")
436  << "using dcs record, dcsPartition:" << dcsPartition << " " << theDCSRecordPartition << " "
437  << (*dcsRecord).partitionName(theDCSRecordPartition) << " "
438  << (*dcsRecord).highVoltageReady(theDCSRecordPartition) << std::endl;
439  }
440  return (*dcsRecord).highVoltageReady(theDCSRecordPartition);
441  }
442 }
443 
446  // An empty GT status bits logical expressions list acts as switch.
447  if (!onGt_ || gtLogicalExpressions_.empty())
448  return (!andOr_); // logically neutral, depending on base logical connective
449 
450  // Determine decision of GT status bits logical expression combination and return
451  if (andOrGt_) { // OR combination
452  for (std::vector<std::string>::const_iterator gtLogicalExpression = gtLogicalExpressions_.begin();
453  gtLogicalExpression != gtLogicalExpressions_.end();
454  ++gtLogicalExpression) {
455  if (acceptGtLogicalExpression(event, *gtLogicalExpression))
456  return true;
457  }
458  return false;
459  }
460  for (std::vector<std::string>::const_iterator gtLogicalExpression = gtLogicalExpressions_.begin();
461  gtLogicalExpression != gtLogicalExpressions_.end();
462  ++gtLogicalExpression) {
463  if (!acceptGtLogicalExpression(event, *gtLogicalExpression))
464  return false;
465  }
466  return true;
467 }
468 
471  // Check empty std::strings
472  if (gtLogicalExpression.empty()) {
473  if (verbose_ > 1)
474  edm::LogWarning("GenericTriggerEventFlag") << "Empty logical expression ==> decision: " << errorReplyGt_;
475  return errorReplyGt_;
476  }
477 
478  // Negated paths
479  bool negExpr(negate(gtLogicalExpression));
480  if (negExpr && gtLogicalExpression.empty()) {
481  if (verbose_ > 1)
482  edm::LogWarning("GenericTriggerEventFlag")
483  << "Empty (negated) logical expression ==> decision: " << errorReplyGt_;
484  return errorReplyGt_;
485  }
486 
487  // Parse logical expression and determine GT status bit decision
488  L1GtLogicParser gtAlgoLogicParser(gtLogicalExpression);
489  // Loop over status bits
490  for (size_t iStatusBit = 0; iStatusBit < gtAlgoLogicParser.operandTokenVector().size(); ++iStatusBit) {
491  const std::string gtStatusBit(gtAlgoLogicParser.operandTokenVector().at(iStatusBit).tokenName);
492  // Manipulate status bit decision as stored in the parser
493  bool decision(errorReplyDcs_);
494  // Hard-coded status bits!!!
495  if (gtStatusBit == "PhysDecl" || gtStatusBit == "PhysicsDeclared") {
497  event.getByToken(gtInputToken_, gtReadoutRecord);
498  if (!gtReadoutRecord.isValid()) {
499  if (verbose_ > 1)
500  edm::LogWarning("GenericTriggerEventFlag")
501  << "L1GlobalTriggerReadoutRecord product with InputTag \"" << gtInputTag_.encode()
502  << "\" not in event ==> decision: " << errorReplyGt_;
503  gtAlgoLogicParser.operandTokenVector().at(iStatusBit).tokenResult = errorReplyDcs_;
504  continue;
505  }
506  decision = (gtReadoutRecord->gtFdlWord().physicsDeclared() == 1);
507  } else if (gtStatusBit == "Stable" || gtStatusBit == "StableBeam" || gtStatusBit == "Adjust" ||
508  gtStatusBit == "Sqeeze" || gtStatusBit == "Flat" || gtStatusBit == "FlatTop" || gtStatusBit == "7TeV" ||
509  gtStatusBit == "8TeV" || gtStatusBit == "13TeV" || gtStatusBit == "2360GeV" || gtStatusBit == "900GeV") {
511  event.getByToken(gtEvmInputToken_, gtEvmReadoutRecord);
512  if (!gtEvmReadoutRecord.isValid()) {
513  if (verbose_ > 1)
514  edm::LogWarning("GenericTriggerEventFlag")
515  << "L1GlobalTriggerEvmReadoutRecord product with InputTag \"" << gtEvmInputTag_.encode()
516  << "\" not in event ==> decision: " << errorReplyGt_;
517  gtAlgoLogicParser.operandTokenVector().at(iStatusBit).tokenResult = errorReplyDcs_;
518  continue;
519  }
520  if (gtStatusBit == "Stable" || gtStatusBit == "StableBeam") {
521  decision = (gtEvmReadoutRecord->gtfeWord().beamMode() == 11);
522  } else if (gtStatusBit == "Adjust") {
523  decision = (10 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11);
524  } else if (gtStatusBit == "Sqeeze") {
525  decision = (9 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11);
526  } else if (gtStatusBit == "Flat" || gtStatusBit == "FlatTop") {
527  decision = (8 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11);
528  } else if (gtStatusBit == "7TeV") {
529  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 3500);
530  } else if (gtStatusBit == "8TeV") {
531  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 4000);
532  } else if (gtStatusBit == "13TeV") {
533  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 6500);
534  } else if (gtStatusBit == "2360GeV") {
535  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 1180);
536  } else if (gtStatusBit == "900GeV") {
537  decision = (gtEvmReadoutRecord->gtfeWord().beamMomentum() == 450);
538  }
539  } else {
540  if (verbose_ > 1)
541  edm::LogWarning("GenericTriggerEventFlag")
542  << "GT status bit \"" << gtStatusBit << "\" is not defined ==> decision: " << errorReplyGt_;
543  }
544  gtAlgoLogicParser.operandTokenVector().at(iStatusBit).tokenResult = decision;
545  }
546 
547  // Determine decision
548  const bool gtDecision(gtAlgoLogicParser.expressionResult());
549  return negExpr ? (!gtDecision) : gtDecision;
550 }
551 
554  // An empty L1 logical expressions list acts as switch.
555  if (!onL1_ || l1LogicalExpressions_.empty())
556  return (!andOr_); // logically neutral, depending on base logical connective
557 
558  // Determine decision of L1 logical expression combination and return
559  if (andOrL1_) { // OR combination
560  for (std::vector<std::string>::const_iterator l1LogicalExpression = l1LogicalExpressions_.begin();
561  l1LogicalExpression != l1LogicalExpressions_.end();
562  ++l1LogicalExpression) {
563  if (acceptL1LogicalExpression(event, setup, *l1LogicalExpression))
564  return true;
565  }
566  return false;
567  }
568  for (std::vector<std::string>::const_iterator l1LogicalExpression = l1LogicalExpressions_.begin();
569  l1LogicalExpression != l1LogicalExpressions_.end();
570  ++l1LogicalExpression) {
571  if (!acceptL1LogicalExpression(event, setup, *l1LogicalExpression))
572  return false;
573  }
574  return true;
575 }
576 
579  const edm::EventSetup& setup,
580  std::string l1LogicalExpression) {
581  // Getting the L1 event setup
582  if (stage2_)
583  l1uGt_->retrieveL1(event, setup);
584  else
585  // FIXME This can possibly go to initRun()
587 
588  // Check empty std::strings
589  if (l1LogicalExpression.empty()) {
590  if (verbose_ > 1)
591  edm::LogWarning("GenericTriggerEventFlag") << "Empty logical expression ==> decision: " << errorReplyL1_;
592  return errorReplyL1_;
593  }
594 
595  // Negated logical expression
596  bool negExpr(negate(l1LogicalExpression));
597  if (negExpr && l1LogicalExpression.empty()) {
598  if (verbose_ > 1)
599  edm::LogWarning("GenericTriggerEventFlag")
600  << "Empty (negated) logical expression ==> decision: " << errorReplyL1_;
601  return errorReplyL1_;
602  }
603 
604  // Parse logical expression and determine L1 decision
605  L1GtLogicParser l1AlgoLogicParser(l1LogicalExpression);
606  // Loop over algorithms
607  for (size_t iAlgorithm = 0; iAlgorithm < l1AlgoLogicParser.operandTokenVector().size(); ++iAlgorithm) {
608  const std::string l1AlgoName(l1AlgoLogicParser.operandTokenVector().at(iAlgorithm).tokenName);
609 
610  bool decision = false;
611  bool error = false;
612  if (stage2_) {
613  bool errorBOOL = (l1BeforeMask_ ? l1uGt_->getInitialDecisionByName(l1AlgoName, decision)
614  : l1uGt_->getFinalDecisionByName(l1AlgoName, decision));
615  error = !errorBOOL;
616  } else {
617  int errorINT(-1);
618  // const bool decision( l1BeforeMask_ ? l1Gt_->decisionBeforeMask( event, l1AlgoName, errorINT ) : l1Gt_->decisionAfterMask( event, l1AlgoName, errorINT ) );
619  decision = (l1BeforeMask_ ? l1Gt_->decisionBeforeMask(event, l1AlgoName, errorINT)
620  : l1Gt_->decisionAfterMask(event, l1AlgoName, errorINT));
621  error = (errorINT != 0);
622  if (errorINT > 1)
623  if (verbose_ > 1)
624  edm::LogWarning("GenericTriggerEventFlag")
625  << "L1 algorithm \"" << l1AlgoName << "\" received error code " << error
626  << " from L1GtUtils::decisionBeforeMask ==> decision: " << errorReplyL1_;
627  }
628 
629  // Error checks
630  if (error) {
631  if (verbose_ > 1)
632  edm::LogWarning("GenericTriggerEventFlag")
633  << "L1 algorithm \"" << l1AlgoName << "\" does not exist in the L1 menu ==> decision: " << errorReplyL1_;
634  l1AlgoLogicParser.operandTokenVector().at(iAlgorithm).tokenResult = errorReplyL1_;
635  continue;
636  }
637  // Manipulate algo decision as stored in the parser
638  l1AlgoLogicParser.operandTokenVector().at(iAlgorithm).tokenResult = decision;
639  }
640 
641  // Return decision
642  const bool l1Decision(l1AlgoLogicParser.expressionResult());
643  return negExpr ? (!l1Decision) : l1Decision;
644 }
645 
648  // An empty HLT logical expressions list acts as switch.
649  if (!onHlt_ || hltLogicalExpressions_.empty())
650  return (!andOr_); // logically neutral, depending on base logical connective
651 
652  // Checking the HLT configuration,
653  if (!hltConfigInit_) {
654  if (verbose_ > 1)
655  edm::LogWarning("GenericTriggerEventFlag") << "HLT config error ==> decision: " << errorReplyHlt_;
656  return errorReplyHlt_;
657  }
658 
659  // Accessing the TriggerResults
660  edm::Handle<edm::TriggerResults> hltTriggerResults;
661  event.getByToken(hltInputToken_, hltTriggerResults);
662  if (!hltTriggerResults.isValid()) {
663  if (verbose_ > 1)
664  edm::LogWarning("GenericTriggerEventFlag") << "TriggerResults product with InputTag \"" << hltInputTag_.encode()
665  << "\" not in event ==> decision: " << errorReplyHlt_;
666  return errorReplyHlt_;
667  }
668  if ((*hltTriggerResults).size() == 0) {
669  if (verbose_ > 1)
670  edm::LogWarning("GenericTriggerEventFlag") << "TriggerResults product with InputTag \"" << hltInputTag_.encode()
671  << "\" empty ==> decision: " << errorReplyHlt_;
672  return errorReplyDcs_;
673  }
674 
675  // Determine decision of HLT logical expression combination and return
676  if (andOrHlt_) { // OR combination
677  for (std::vector<std::string>::const_iterator hltLogicalExpression = hltLogicalExpressions_.begin();
678  hltLogicalExpression != hltLogicalExpressions_.end();
679  ++hltLogicalExpression) {
680  if (acceptHltLogicalExpression(hltTriggerResults, *hltLogicalExpression))
681  return true;
682  }
683  return false;
684  }
685  for (std::vector<std::string>::const_iterator hltLogicalExpression = hltLogicalExpressions_.begin();
686  hltLogicalExpression != hltLogicalExpressions_.end();
687  ++hltLogicalExpression) {
688  if (!acceptHltLogicalExpression(hltTriggerResults, *hltLogicalExpression))
689  return false;
690  }
691  return true;
692 }
693 
696  std::string hltLogicalExpression) const {
697  // Check empty std::strings
698  if (hltLogicalExpression.empty()) {
699  if (verbose_ > 1)
700  edm::LogWarning("GenericTriggerEventFlag") << "Empty logical expression ==> decision: " << errorReplyHlt_;
701  return errorReplyHlt_;
702  }
703 
704  // Negated paths
705  bool negExpr(negate(hltLogicalExpression));
706  if (negExpr && hltLogicalExpression.empty()) {
707  if (verbose_ > 1)
708  edm::LogWarning("GenericTriggerEventFlag")
709  << "Empty (negated) logical expression ==> decision: " << errorReplyHlt_;
710  return errorReplyHlt_;
711  }
712 
713  // Parse logical expression and determine HLT decision
714  L1GtLogicParser hltAlgoLogicParser(hltLogicalExpression);
715  // Loop over paths
716  for (size_t iPath = 0; iPath < hltAlgoLogicParser.operandTokenVector().size(); ++iPath) {
717  const std::string hltPathName(hltAlgoLogicParser.operandTokenVector().at(iPath).tokenName);
718  const unsigned indexPath(hltConfig_.triggerIndex(hltPathName));
719  // Further error checks
720  if (indexPath == hltConfig_.size()) {
721  if (verbose_ > 1)
722  edm::LogWarning("GenericTriggerEventFlag") << "HLT path \"" << hltPathName << "\" is not found in process "
723  << hltInputTag_.process() << " ==> decision: " << errorReplyHlt_;
724  hltAlgoLogicParser.operandTokenVector().at(iPath).tokenResult = errorReplyHlt_;
725  continue;
726  }
727  if (hltTriggerResults->error(indexPath)) {
728  if (verbose_ > 1)
729  edm::LogWarning("GenericTriggerEventFlag")
730  << "HLT path \"" << hltPathName << "\" in error ==> decision: " << errorReplyHlt_;
731  hltAlgoLogicParser.operandTokenVector().at(iPath).tokenResult = errorReplyHlt_;
732  continue;
733  }
734  // Manipulate algo decision as stored in the parser
735  const bool decision(hltTriggerResults->accept(indexPath));
736  hltAlgoLogicParser.operandTokenVector().at(iPath).tokenResult = decision;
737  }
738 
739  // Determine decision
740  const bool hltDecision(hltAlgoLogicParser.expressionResult());
741  return negExpr ? (!hltDecision) : hltDecision;
742 }
743 
746  const std::string& expr,
747  bool useAnd) const {
748  // Find matching entries in the menu
749  std::vector<std::string> matched;
750  const std::string versionWildcard("_v*");
751  if (expr.substr(expr.size() - versionWildcard.size()) == versionWildcard) {
752  const std::string exprBase(expr.substr(0, expr.size() - versionWildcard.size()));
754  } else {
756  }
757 
758  // Return input, if no match is found
759  if (matched.empty()) {
760  if (verbose_ > 1)
761  edm::LogWarning("GenericTriggerEventFlag") << "Logical expression: \"" << expr << "\" could not be resolved";
762  return expr;
763  }
764 
765  // Compose logical expression
766  std::string expanded("(");
767  for (unsigned iVers = 0; iVers < matched.size(); ++iVers) {
768  if (iVers > 0)
769  expanded.append(useAnd ? " AND " : " OR ");
770  expanded.append(matched.at(iVers));
771  }
772  expanded.append(")");
773  if (verbose_ > 1)
774  edm::LogInfo("GenericTriggerEventFlag") << "Logical expression: \"" << expr << "\"\n"
775  << " --> expanded to \"" << expanded << "\"";
776 
777  return expanded;
778 }
779 
782  bool negate(false);
783  if (word.at(0) == '~') {
784  negate = true;
785  word.erase(0, 1);
786  }
787  return negate;
788 }
789 
792  const edm::EventSetup& setup) {
793  if (key.empty())
794  return std::vector<std::string>(1, emptyKeyError_);
795  std::vector<edm::eventsetup::DataKey> labels;
796  setup.get<AlCaRecoTriggerBitsRcd>().fillRegisteredDataKeys(labels);
797  std::vector<edm::eventsetup::DataKey>::const_iterator iKey = labels.begin();
798  while (iKey != labels.end() && iKey->name().value() != dbLabel_)
799  ++iKey;
800  if (iKey == labels.end()) {
801  if (verbose_ > 0)
802  edm::LogWarning("GenericTriggerEventFlag")
803  << "Label " << dbLabel_ << " not found in DB for 'AlCaRecoTriggerBitsRcd'";
804  return std::vector<std::string>(1, configError_);
805  }
806  auto const& alCaRecoTriggerBits = setup.getData(alCaRecoTriggerBitsToken_);
807  const std::map<std::string, std::string>& expressionMap = alCaRecoTriggerBits.m_alcarecoToTrig;
808  std::map<std::string, std::string>::const_iterator listIter = expressionMap.find(key);
809  if (listIter == expressionMap.end()) {
810  if (verbose_ > 0)
811  edm::LogWarning("GenericTriggerEventFlag")
812  << "No logical expressions found under key " << key << " in 'AlCaRecoTriggerBitsRcd'";
813  return std::vector<std::string>(1, configError_);
814  }
815  return alCaRecoTriggerBits.decompose(listIter->second);
816 }
817 
819  if (not onHlt_) {
820  return true;
821  }
822 
823  if (not hltConfigInit_) {
824  if (verbose_ > 0) {
825  edm::LogWarning("GenericTriggerEventFlag::allHLTPathsAreValid()")
826  << "HLTConfigProvider is not initialized, method will return \"false\"";
827  }
828 
829  return false;
830  }
831 
832  for (unsigned iExpr = 0; iExpr < hltLogicalExpressions_.size(); ++iExpr) {
833  std::string hltLogicalExpression = hltLogicalExpressions_.at(iExpr);
834 
835  L1GtLogicParser hltAlgoLogicParser(hltLogicalExpression);
836 
837  if (hltAlgoLogicParser.operandTokenVector().empty()) {
838  return false;
839  }
840 
841  for (size_t iPath = 0; iPath < hltAlgoLogicParser.operandTokenVector().size(); ++iPath) {
842  const std::string hltPathName(hltAlgoLogicParser.operandTokenVector().at(iPath).tokenName);
843 
844  const unsigned indexPath(hltConfig_.triggerIndex(hltPathName));
845 
846  if (indexPath == hltConfig_.size()) {
847  if (verbose_ > 1) {
848  edm::LogWarning("GenericTriggerEventFlag::allHLTPathsAreValid()")
849  << "HLT path \"" << hltPathName << "\" is not found in process " << hltInputTag_.process();
850  }
851 
852  return false;
853  }
854  }
855  }
856 
857  return true;
858 }
859 
861  desc.add<bool>("ReadPrescalesFromFile", false);
862  desc.add<bool>("andOr", false);
863  desc.add<bool>("andOrDcs", false);
864  desc.add<bool>("andOrHlt", false);
865  desc.add<bool>("andOrL1", false);
866  desc.add<bool>("errorReplyDcs", false);
867  desc.add<bool>("errorReplyHlt", false);
868  desc.add<bool>("errorReplyL1", false);
869  desc.add<bool>("l1BeforeMask", false);
870  desc.add<bool>("stage2", false);
871  desc.add<edm::InputTag>("dcsInputTag", edm::InputTag("scalersRawToDigi"));
872  desc.add<edm::InputTag>("dcsRecordInputTag", edm::InputTag("onlineMetaDataDigis"));
873  desc.add<edm::InputTag>("hltInputTag", edm::InputTag("TriggerResults::HLT"));
874  desc.add<edm::InputTag>("l1tAlgBlkInputTag", edm::InputTag("gtStage2Digis"));
875  desc.add<edm::InputTag>("l1tExtBlkInputTag", edm::InputTag("gtStage2Digis"));
876  desc.add<std::string>("dbLabel", "");
877  desc.add<std::string>("hltDBKey", "");
878  desc.add<std::vector<int>>("dcsPartitions", {});
879  desc.add<std::vector<std::string>>("hltPaths", {});
880  desc.add<std::vector<std::string>>("l1Algorithms", {});
881  desc.add<unsigned int>("verbosityLevel", 0);
882 }
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_
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?
key
prepare the HTCondor submission files and eventually submit them
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_
dictionary config
Read in AllInOne config in JSON format.
Definition: DiMuonV_cfg.py:30
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
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?