CMS 3D CMS Logo

EventSelector.cc
Go to the documentation of this file.
1 // Change Log
2 //
3 // 1 - M Fischler 2/8/08 Enable partial wildcards, as in HLT* or !CAL*
4 // A version of this code with cerr debugging traces has
5 // been placed in the doc area.
6 // See ../doc/EventSelector-behavior.doc for details of
7 // reactions to Ready or Exception states.
8 // 1a M Fischler 2/13/08 Clear the all_must_fail_ array at the start of initPathNames.
9 // This is needed in the case of paths with wildcards,
10 // on explicit processes other than a current process
11 // (in which case initPathNames() is called whenever the trigger
12 // PSetID changes, and we don't want the old array
13 // contents to stick around.
14 //
15 // 2 - M Fischler 2/21/08 (In preparation for "exception-awareness" features):
16 // Factored out the decision making logic from the
17 // two forms of acceptEvent, into the single routine
18 // selectionDecision().
19 //
20 // 3 - M Fischler 2/25/08 (Toward commit of "exception-awareness" features):
21 // @exception and noexception& features
22 //
23 // 4- M Fischler 2/28/08 Repair ommision in selectionIsValid when pathspecs
24 // is just "!*"
25 //
26 // 5- M Fischler 3/3/08 testSelectionOverlap and maskTriggerResults appropriate
27 // for the new forms of pathspecs
28 //
29 // 6 - K Biery 03/24/08 modified maskTriggerResults (no longer static) to
30 // avoid performance penalty of creating a new
31 // EventSelector instance for each call (in static case)
32 //
33 
41 
42 #include "boost/algorithm/string.hpp"
43 
44 #include <algorithm>
45 #include <cassert>
46 
47 namespace edm {
49  EventSelector::EventSelector(Strings const& pathspecs, Strings const& pathNames)
50  : pathspecs_(initPathSpecs(pathspecs)),
51  results_from_current_process_(true),
52  accept_all_(initAcceptAll()),
53  absolute_acceptors_(),
54  conditional_acceptors_(),
55  exception_acceptors_(),
56  all_must_fail_(),
57  all_must_fail_noex_(),
58  psetID_(),
59  nPathNames_(0) {
60  initPathNames(pathNames);
61  }
62 
64  : pathspecs_(initPathSpecs(pathspecs)),
72  psetID_(),
73  nPathNames_(0) {}
74 
76  : pathspecs_(config.empty() ? Strings() : initPathSpecs(config.getParameter<Strings>("SelectEvents"))),
84  psetID_(),
85  nPathNames_(0) {
86  initPathNames(pathNames);
87  }
88 
90  Strings trimmedPathSpecs(pathSpecs);
91  for (auto& pathspecifier : trimmedPathSpecs) {
92  boost::erase_all(pathspecifier, " \t"); // whitespace eliminated
93  }
94  // Return value optimization should avoid another copy;
95  return trimmedPathSpecs;
96  }
97 
99  if (pathspecs_.empty()) {
100  return true;
101  }
102  // The following are for the purpose of establishing accept_all_ by
103  // virtue of an inclusive set of paths:
104  bool unrestricted_star = false;
105  bool negated_star = false;
106  bool exception_star = false;
107 
108  for (auto const& pathspecifier : pathspecs_) {
109  if (pathspecifier == "*")
110  unrestricted_star = true;
111  if (pathspecifier == "!*")
112  negated_star = true;
113  if (pathspecifier == "exception@*")
114  exception_star = true;
115  }
116  return (unrestricted_star && negated_star && exception_star);
117  }
118 
119  void EventSelector::initPathNames(Strings const& pathNames) {
120  if (accept_all_) {
121  return;
122  }
123  // std::cerr << "### init entered\n";
125  all_must_fail_noex_.clear();
126  nPathNames_ = pathNames.size();
127 
128  for (auto const& pathspecifier : pathspecs_) {
129  std::string basePathSpec(pathspecifier);
130  bool noex_demanded = false;
131  std::string::size_type and_noexception = pathspecifier.find("&noexception");
132  if (and_noexception != std::string::npos) {
133  basePathSpec = pathspecifier.substr(0, and_noexception);
134  noex_demanded = true;
135  }
136  std::string::size_type and_noex = pathspecifier.find("&noex");
137  if (and_noex != std::string::npos) {
138  basePathSpec = pathspecifier.substr(0, and_noexception);
139  noex_demanded = true;
140  }
141  and_noexception = basePathSpec.find("&noexception");
142  and_noex = basePathSpec.find("&noex");
143  if (and_noexception != std::string::npos || and_noex != std::string::npos)
144  throw edm::Exception(errors::Configuration) << "EventSelector::init, An OutputModule is using SelectEvents\n"
145  "to request a trigger name, but specifying &noexceptions twice\n"
146  << "The improper trigger name is: " << pathspecifier << "\n";
147 
148  std::string realname(basePathSpec);
149  bool negative_criterion = false;
150  if (basePathSpec[0] == '!') {
151  negative_criterion = true;
152  realname = basePathSpec.substr(1, std::string::npos);
153  }
154  bool exception_spec = false;
155  if (realname.find("exception@") == 0) {
156  exception_spec = true;
157  realname = realname.substr(10, std::string::npos);
158  // strip off 10 chars, which is length of "exception@"
159  }
160  if (negative_criterion && exception_spec)
161  throw edm::Exception(errors::Configuration) << "EventSelector::init, An OutputModule is using SelectEvents\n"
162  "to request a trigger name starting with !exception@.\n"
163  "This is not supported.\n"
164  << "The improper trigger name is: " << pathspecifier << "\n";
165  if (noex_demanded && exception_spec)
166  throw edm::Exception(errors::Configuration) << "EventSelector::init, An OutputModule is using SelectEvents\n"
167  "to request a trigger name starting with exception@ "
168  "and also demanding no &exceptions.\n"
169  << "The improper trigger name is: " << pathspecifier << "\n";
170 
171  // instead of "see if the name can be found in the full list of paths"
172  // we want to find all paths that match this name.
173  std::vector<Strings::const_iterator> matches = regexMatch(pathNames, realname);
174 
175  if (matches.empty() && !is_glob(realname)) {
176  throw edm::Exception(errors::Configuration) << "EventSelector::init, An OutputModule is using SelectEvents\n"
177  "to request a trigger name that does not exist\n"
178  << "The unknown trigger name is: " << realname << "\n";
179  }
180  if (matches.empty() && is_glob(realname)) {
181  LogWarning("Configuration") << "EventSelector::init, An OutputModule is using SelectEvents\n"
182  "to request a wildcarded trigger name that does not match any trigger \n"
183  << "The wildcarded trigger name is: " << realname << "\n";
184  }
185 
186  if (!negative_criterion && !noex_demanded && !exception_spec) {
187  for (unsigned int t = 0; t != matches.size(); ++t) {
188  BitInfo bi(distance(pathNames.begin(), matches[t]), true);
189  absolute_acceptors_.push_back(bi);
190  }
191  } else if (!negative_criterion && noex_demanded) {
192  for (unsigned int t = 0; t != matches.size(); ++t) {
193  BitInfo bi(distance(pathNames.begin(), matches[t]), true);
194  conditional_acceptors_.push_back(bi);
195  }
196  } else if (exception_spec) {
197  for (unsigned int t = 0; t != matches.size(); ++t) {
198  BitInfo bi(distance(pathNames.begin(), matches[t]), true);
199  exception_acceptors_.push_back(bi);
200  }
201  } else if (negative_criterion && !noex_demanded) {
202  if (matches.empty()) {
204  << "EventSelector::init, An OutputModule is using SelectEvents\n"
205  "to request all fails on a set of trigger names that do not exist\n"
206  << "The problematic name is: " << pathspecifier << "\n";
207 
208  } else if (matches.size() == 1) {
209  BitInfo bi(distance(pathNames.begin(), matches[0]), false);
210  absolute_acceptors_.push_back(bi);
211  } else {
212  Bits mustfail;
213  for (unsigned int t = 0; t != matches.size(); ++t) {
214  BitInfo bi(distance(pathNames.begin(), matches[t]), false);
215  // We set this to false because that will demand bits are Fail.
216  mustfail.push_back(bi);
217  }
218  all_must_fail_.push_back(mustfail);
219  }
220  } else if (negative_criterion && noex_demanded) {
221  if (matches.empty()) {
223  << "EventSelector::init, An OutputModule is using SelectEvents\n"
224  "to request all fails on a set of trigger names that do not exist\n"
225  << "The problematic name is: " << pathspecifier << "\n";
226 
227  } else if (matches.size() == 1) {
228  BitInfo bi(distance(pathNames.begin(), matches[0]), false);
229  conditional_acceptors_.push_back(bi);
230  } else {
231  Bits mustfail;
232  for (unsigned int t = 0; t != matches.size(); ++t) {
233  BitInfo bi(distance(pathNames.begin(), matches[t]), false);
234  mustfail.push_back(bi);
235  }
236  all_must_fail_noex_.push_back(mustfail);
237  }
238  }
239  } // end of the for loop on pathspecs
240 
241  // std::cerr << "### init exited\n";
242 
243  } // EventSelector::init
244 
246  if (accept_all_)
247  return true;
248 
250  // The path names for prior processes may be different in different runs.
251  // Check for this, and modify the selector accordingly if necessary.
252  if (!psetID_.isValid() || psetID_ != tr.parameterSetID()) {
253  Strings pathNames;
254  bool fromPSetRegistry = false;
256  if (tns->getTrigPaths(tr, pathNames, fromPSetRegistry)) {
257  initPathNames(pathNames);
258  if (fromPSetRegistry) {
259  psetID_ = tr.parameterSetID();
260  } else {
261  // This can only happen for very old data, when the path names were stored
262  // in TriggerResults itself, rather than in the parameter set registry.
263  psetID_.reset();
264  }
265  } else {
266  // This should never happen
268  << "EventSelector::acceptEvent cannot find the trigger names for\n"
269  "a process for which the configuration has requested that the\n"
270  "OutputModule use TriggerResults to select events from. This should\n"
271  "be impossible, please send information to reproduce this problem to\n"
272  "the edm developers.\n";
273  }
274  }
275  }
276 
277  // Now make the decision, based on the supplied TriggerResults tr,
278  // which of course can be treated as an HLTGlobalStatus by inheritance
279 
280  return selectionDecision(tr);
281 
282  } // acceptEvent(TriggerResults const& tr)
283 
284  bool EventSelector::acceptEvent(unsigned char const* array_of_trigger_results, int number_of_trigger_paths) const {
285  // This should never occur unless someone uses this function in
286  // an incorrect way ...
288  throw edm::Exception(errors::Configuration) << "\nEventSelector.cc::acceptEvent, you are attempting to\n"
289  << "use a bit array for trigger results instead of the\n"
290  << "TriggerResults object for a previous process. This\n"
291  << "will not work and ought to be impossible\n";
292  }
293 
294  if (accept_all_)
295  return true;
296 
297  // Form HLTGlobalStatus object to represent the array_of_trigger_results
298  HLTGlobalStatus tr(number_of_trigger_paths);
299  int byteIndex = 0;
300  int subIndex = 0;
301  for (int pathIndex = 0; pathIndex < number_of_trigger_paths; ++pathIndex) {
302  int state = array_of_trigger_results[byteIndex] >> (subIndex * 2);
303  state &= 0x3;
304  HLTPathStatus pathStatus(static_cast<hlt::HLTState>(state));
305  tr[pathIndex] = pathStatus;
306  ++subIndex;
307  if (subIndex == 4) {
308  ++byteIndex;
309  subIndex = 0;
310  }
311  }
312 
313  // Now make the decision, based on the HLTGlobalStatus tr,
314  // which we have created from the supplied array of results
315 
316  return selectionDecision(tr);
317 
318  } // acceptEvent(array_of_trigger_results, number_of_trigger_paths)
319 
321  if (accept_all_)
322  return true;
323 
324  bool exceptionPresent = false;
325  bool exceptionsLookedFor = false;
326 
328  return true;
330  exceptionPresent = containsExceptions(tr);
331  if (!exceptionPresent)
332  return true;
333  exceptionsLookedFor = true;
334  }
336  return true;
337 
338  for (auto const& bit : all_must_fail_) {
339  if (acceptAllBits(bit, tr))
340  return true;
341  }
342  for (auto const& bitn : all_must_fail_noex_) {
343  if (acceptAllBits(bitn, tr)) {
344  if (!exceptionsLookedFor)
345  exceptionPresent = containsExceptions(tr);
346  return (!exceptionPresent);
347  }
348  }
349 
350  // If we have not accepted based on any of the acceptors, nor on any one of
351  // the all_must_fail_ collections, then we reject this event.
352 
353  return false;
354 
355  } // selectionDecision()
356 
357  // Obsolete...
358  bool EventSelector::acceptTriggerPath(HLTPathStatus const& pathStatus, BitInfo const& pathInfo) const {
359  return (((pathStatus.state() == hlt::Pass) && (pathInfo.accept_state_)) ||
360  ((pathStatus.state() == hlt::Fail) && !(pathInfo.accept_state_)) ||
361  ((pathStatus.state() == hlt::Exception)));
362  }
363 
364  // Indicate if any bit in the trigger results matches the desired value
365  // at that position, based on the Bits array. If s is Exception, this
366  // looks for a Exceptionmatch; otherwise, true-->Pass, false-->Fail.
367  bool EventSelector::acceptOneBit(Bits const& b, HLTGlobalStatus const& tr, hlt::HLTState const& s) const {
368  bool lookForException = (s == hlt::Exception);
369  for (auto const& bit : b) {
370  hlt::HLTState bstate = lookForException ? hlt::Exception : bit.accept_state_ ? hlt::Pass : hlt::Fail;
371  if (tr[bit.pos_].state() == bstate)
372  return true;
373  }
374  return false;
375  } // acceptOneBit
376 
377  // Indicate if *every* bit in the trigger results matches the desired value
378  // at that position, based on the Bits array: true-->Pass, false-->Fail.
379  bool EventSelector::acceptAllBits(Bits const& b, HLTGlobalStatus const& tr) const {
380  for (auto const& bit : b) {
381  hlt::HLTState bstate = bit.accept_state_ ? hlt::Pass : hlt::Fail;
382  if (tr[bit.pos_].state() != bstate)
383  return false;
384  }
385  return true;
386  } // acceptAllBits
387 
403  bool EventSelector::selectionIsValid(Strings const& pathspecs, Strings const& fullPathList) {
404  // an empty selection list is not valid
405  // (we default an empty "SelectEvents" parameter to {"*","!*"} in
406  // the getEventSelectionVString method below to help avoid this)
407  if (pathspecs.empty()) {
408  return false;
409  }
410 
411  // loop over each element in the selection list
412  for (unsigned int idx = 0; idx < pathspecs.size(); idx++) {
413  Strings workingList;
414  workingList.push_back(pathspecs[idx]);
415 
416  // catch exceptions from the EventSelector constructor
417  // (and anywhere else) and mark those as failures.
418  // The EventSelector constructor seems to do the work of
419  // checking if the selection is outside the full trigger list.
420  try {
421  // create an EventSelector instance for this selection
422  EventSelector evtSelector(workingList, fullPathList);
423 
424  // create the TriggerResults instance that we'll use for testing
425  unsigned int fullPathCount = fullPathList.size();
426  HLTGlobalStatus hltGS(fullPathCount);
427  TriggerResults sampleResults(hltGS, fullPathList);
428 
429  // loop over each path
430  bool oneResultMatched = false;
431  for (unsigned int iPath = 0; iPath < fullPathCount; iPath++) {
432  // loop over the possible values for the path status
433  for (int iState = static_cast<int>(hlt::Pass); iState <= static_cast<int>(hlt::Exception); iState++) {
434  sampleResults[iPath] = HLTPathStatus(static_cast<hlt::HLTState>(iState), 0);
435  if (evtSelector.wantAll() || evtSelector.acceptEvent(sampleResults)) {
436  oneResultMatched = true;
437  break;
438  }
439 
440  sampleResults.reset(iPath);
441  }
442 
443  if (oneResultMatched)
444  break;
445  }
446 
447  // Finally, check in case the selection element was a wildcarded
448  // negative such as "!*":
449 
450  if (!oneResultMatched) {
451  for (unsigned int iPath = 0; iPath < fullPathCount; iPath++) {
452  sampleResults[iPath] = HLTPathStatus(hlt::Fail, 0);
453  }
454  if (evtSelector.acceptEvent(sampleResults)) {
455  oneResultMatched = true;
456  }
457  }
458 
459  // if none of the possible trigger results matched the
460  // selection element, then we declare the whole selection
461  // list invalid
462  if (!oneResultMatched) {
463  return false;
464  }
465  } catch (edm::Exception const&) {
466  return false;
467  }
468  }
469 
470  // if we made it to this point, then it must have been possible
471  // to satisfy every selection element one way or another
472  return true;
473  }
474 
486  Strings const& pathspec2,
487  Strings const& fullPathList) {
488  bool overlap = false;
489 
490  // first, test that the selection lists are valid
491  if (!selectionIsValid(pathspec1, fullPathList) || !selectionIsValid(pathspec2, fullPathList)) {
493  }
494 
495  // catch exceptions from the EventSelector constructor
496  // (and anywhere else) and mark those as failures
497  try {
498  // create an EventSelector instance for each selection list
499  EventSelector a(pathspec1, fullPathList);
500  EventSelector b(pathspec2, fullPathList);
501 
502  unsigned int N = fullPathList.size();
503 
504  // create the expanded masks for the various decision lists in a and b
505  std::vector<bool> aPassAbs = expandDecisionList(a.absolute_acceptors_, true, N);
506  std::vector<bool> aPassCon = expandDecisionList(a.conditional_acceptors_, true, N);
507  std::vector<bool> aFailAbs = expandDecisionList(a.absolute_acceptors_, false, N);
508  std::vector<bool> aFailCon = expandDecisionList(a.conditional_acceptors_, false, N);
509  std::vector<bool> aExc = expandDecisionList(a.exception_acceptors_, true, N);
510  std::vector<std::vector<bool> > aMustFail;
511  for (unsigned int m = 0; m != a.all_must_fail_.size(); ++m) {
512  aMustFail.push_back(expandDecisionList(a.all_must_fail_[m], false, N));
513  }
514  std::vector<std::vector<bool> > aMustFailNoex;
515  for (unsigned int m = 0; m != a.all_must_fail_noex_.size(); ++m) {
516  aMustFailNoex.push_back(expandDecisionList(a.all_must_fail_noex_[m], false, N));
517  }
518 
519  std::vector<bool> bPassAbs = expandDecisionList(b.absolute_acceptors_, true, N);
520  std::vector<bool> bPassCon = expandDecisionList(b.conditional_acceptors_, true, N);
521  std::vector<bool> bFailAbs = expandDecisionList(b.absolute_acceptors_, false, N);
522  std::vector<bool> bFailCon = expandDecisionList(b.conditional_acceptors_, false, N);
523  std::vector<bool> bExc = expandDecisionList(b.exception_acceptors_, true, N);
524  std::vector<std::vector<bool> > bMustFail;
525  for (unsigned int m = 0; m != b.all_must_fail_.size(); ++m) {
526  bMustFail.push_back(expandDecisionList(b.all_must_fail_[m], false, N));
527  }
528  std::vector<std::vector<bool> > bMustFailNoex;
529  for (unsigned int m = 0; m != b.all_must_fail_noex_.size(); ++m) {
530  bMustFailNoex.push_back(expandDecisionList(b.all_must_fail_noex_[m], false, N));
531  }
532 
533  std::vector<bool> aPass = combine(aPassAbs, aPassCon);
534  std::vector<bool> bPass = combine(bPassAbs, bPassCon);
535  std::vector<bool> aFail = combine(aFailAbs, aFailCon);
536  std::vector<bool> bFail = combine(bFailAbs, bFailCon);
537 
538  // Check for overlap in the primary masks
539  overlap = overlapping(aPass, bPass) || overlapping(aFail, bFail) || overlapping(aExc, bExc);
540  if (overlap)
542 
543  // Check for overlap of a primary fail mask with a must fail mask
544  for (unsigned int f = 0; f != aMustFail.size(); ++f) {
545  overlap = overlapping(aMustFail[f], bFail);
546  if (overlap)
547  return evtSel::PartialOverlap;
548  for (unsigned int g = 0; g != bMustFail.size(); ++g) {
549  overlap = subset(aMustFail[f], bMustFail[g]);
550  if (overlap)
551  return evtSel::PartialOverlap;
552  }
553  for (unsigned int g = 0; g != bMustFailNoex.size(); ++g) {
554  overlap = subset(aMustFail[f], bMustFailNoex[g]);
555  if (overlap)
556  return evtSel::PartialOverlap;
557  }
558  }
559  for (unsigned int f = 0; f != aMustFailNoex.size(); ++f) {
560  overlap = overlapping(aMustFailNoex[f], bFail);
561  if (overlap)
562  return evtSel::PartialOverlap;
563  for (unsigned int g = 0; g != bMustFail.size(); ++g) {
564  overlap = subset(aMustFailNoex[f], bMustFail[g]);
565  if (overlap)
566  return evtSel::PartialOverlap;
567  }
568  for (unsigned int g = 0; g != bMustFailNoex.size(); ++g) {
569  overlap = subset(aMustFailNoex[f], bMustFailNoex[g]);
570  if (overlap)
571  return evtSel::PartialOverlap;
572  }
573  }
574  for (unsigned int g = 0; g != bMustFail.size(); ++g) {
575  overlap = overlapping(bMustFail[g], aFail);
576  if (overlap)
577  return evtSel::PartialOverlap;
578  }
579  for (unsigned int g = 0; g != bMustFailNoex.size(); ++g) {
580  overlap = overlapping(bMustFail[g], aFail);
581  if (overlap)
582  return evtSel::PartialOverlap;
583  }
584 
585  } catch (edm::Exception const&) {
587  }
588 
589  // If we get to here without overlap becoming true, there is no overlap
590 
591  return evtSel::NoOverlap;
592 
593  } // testSelectionOverlap
594 
595 #ifdef REMOVE
596 
607  Strings const& pathspec2,
608  Strings const& fullPathList) {
609  // first, test that the selection lists are valid
610  if (!selectionIsValid(pathspec1, fullPathList) || !selectionIsValid(pathspec2, fullPathList)) {
612  }
613 
614  // initialize possible states
615  bool noOverlap = true;
616  bool exactMatch = true;
617 
618  // catch exceptions from the EventSelector constructor
619  // (and anywhere else) and mark those as failures
620  try {
621  // create an EventSelector instance for each selection list
622  EventSelector selector1(pathspec1, fullPathList);
623  EventSelector selector2(pathspec2, fullPathList);
624 
625  // create the TriggerResults instance that we'll use for testing
626  unsigned int fullPathCount = fullPathList.size();
627  HLTGlobalStatus hltGS(fullPathCount);
628  TriggerResults sampleResults(hltGS, fullPathList);
629 
630  // loop over each path
631  for (unsigned int iPath = 0; iPath < fullPathCount; iPath++) {
632  // loop over the possible values for the path status
633  for (int iState = static_cast<int>(hlt::Pass); iState <= static_cast<int>(hlt::Exception); iState++) {
634  sampleResults[iPath] = HLTPathStatus(static_cast<hlt::HLTState>(iState), 0);
635  bool accept1 = selector1.wantAll() || selector1.acceptEvent(sampleResults);
636  bool accept2 = selector2.wantAll() || selector2.acceptEvent(sampleResults);
637  if (accept1 != accept2) {
638  exactMatch = false;
639  }
640  if (accept1 && accept2) {
641  noOverlap = false;
642  }
643  sampleResults.reset(iPath);
644  }
645  }
646  } catch (edm::Exception const& excpt) {
648  }
649 
650  if (exactMatch) {
651  return evtSel::ExactMatch;
652  }
653  if (noOverlap) {
654  return evtSel::NoOverlap;
655  }
656  return evtSel::PartialOverlap;
657  }
658 #endif
659 
676  std::shared_ptr<TriggerResults> EventSelector::maskTriggerResults(TriggerResults const& inputResults) {
677  // fetch and validate the total number of paths
678  unsigned int fullPathCount = nPathNames_;
679  unsigned int N = fullPathCount;
680  if (fullPathCount != inputResults.size()) {
682  << "EventSelector::maskTriggerResults, the TriggerResults\n"
683  << "size (" << inputResults.size() << ") does not match the number of paths in the\n"
684  << "full trigger list (" << fullPathCount << ").\n";
685  }
686 
687  // create a suitable global status object to work with, all in Ready state
688  HLTGlobalStatus mask(fullPathCount);
689 
690  // Deal with must_fail acceptors that would cause selection
691  for (unsigned int m = 0; m < this->all_must_fail_.size(); ++m) {
692  std::vector<bool> f = expandDecisionList(this->all_must_fail_[m], false, N);
693  bool all_fail = true;
694  for (unsigned int ipath = 0; ipath < N; ++ipath) {
695  if ((f[ipath]) && (inputResults[ipath].state() != hlt::Fail)) {
696  all_fail = false;
697  break;
698  }
699  }
700  if (all_fail) {
701  for (unsigned int ipath = 0; ipath < N; ++ipath) {
702  if (f[ipath]) {
703  mask[ipath] = hlt::Fail;
704  }
705  }
706  }
707  }
708  for (unsigned int m = 0; m < this->all_must_fail_noex_.size(); ++m) {
709  std::vector<bool> f = expandDecisionList(this->all_must_fail_noex_[m], false, N);
710  bool all_fail = true;
711  for (unsigned int ipath = 0; ipath < N; ++ipath) {
712  if ((f[ipath]) && (inputResults[ipath].state() != hlt::Fail)) {
713  all_fail = false;
714  break;
715  }
716  }
717  if (all_fail) {
718  for (unsigned int ipath = 0; ipath < N; ++ipath) {
719  if (f[ipath]) {
720  mask[ipath] = hlt::Fail;
721  }
722  }
723  }
724  } // factoring opportunity - work done for fail_noex_ is same as for fail_
725 
726  // Deal with normal acceptors that would cause selection
727  std::vector<bool> aPassAbs = expandDecisionList(this->absolute_acceptors_, true, N);
728  std::vector<bool> aPassCon = expandDecisionList(this->conditional_acceptors_, true, N);
729  std::vector<bool> aFailAbs = expandDecisionList(this->absolute_acceptors_, false, N);
730  std::vector<bool> aFailCon = expandDecisionList(this->conditional_acceptors_, false, N);
731  std::vector<bool> aExc = expandDecisionList(this->exception_acceptors_, true, N);
732  for (unsigned int ipath = 0; ipath < N; ++ipath) {
733  hlt::HLTState s = inputResults[ipath].state();
734  if (((aPassAbs[ipath]) && (s == hlt::Pass)) || ((aPassCon[ipath]) && (s == hlt::Pass)) ||
735  ((aFailAbs[ipath]) && (s == hlt::Fail)) || ((aFailCon[ipath]) && (s == hlt::Fail)) ||
736  ((aExc[ipath]) && (s == hlt::Exception))) {
737  mask[ipath] = s;
738  }
739  }
740 
741  // Based on the global status for the mask, create and return a
742  // TriggerResults
743  auto maskedResults = std::make_shared<TriggerResults>(mask, inputResults.parameterSetID());
744  return maskedResults;
745  } // maskTriggerResults
746 
747 #ifdef REMOVE
748 
766  std::shared_ptr<TriggerResults> EventSelector::maskTriggerResults(Strings const& pathspecs,
767  TriggerResults const& inputResults,
768  Strings const& fullPathList) {
769  // fetch and validate the total number of paths
770  unsigned int fullPathCount = fullPathList.size();
771  if (fullPathCount != inputResults.size()) {
773  << "EventSelector::maskTriggerResults, the TriggerResults\n"
774  << "size (" << inputResults.size() << ") does not match the number of paths in the\n"
775  << "full trigger list (" << fullPathCount << ").\n";
776  }
777 
778  // create a working copy of the TriggerResults object
779  HLTGlobalStatus hltGS(fullPathCount);
780  auto maskedResults = std::make_shared<TriggerResults>(hltGS, inputResults.parameterSetID());
781  for (unsigned int iPath = 0; iPath < fullPathCount; iPath++) {
782  (*maskedResults)[iPath] = inputResults[iPath];
783  }
784 
785  // create an EventSelector to use when testing if a path status passes
786  EventSelector selector(pathspecs, fullPathList);
787 
788  // create the TriggerResults instance that we'll use for testing
789  HLTGlobalStatus hltGS2(fullPathCount);
790  TriggerResults sampleResults(hltGS2, fullPathList);
791 
792  // loop over each path and reset the path status if needed
793  for (unsigned int iPath = 0; iPath < fullPathCount; iPath++) {
794  sampleResults[iPath] = (*maskedResults)[iPath];
795  if (!selector.wantAll() && !selector.acceptEvent(sampleResults)) {
796  maskedResults->reset(iPath);
797  }
798  sampleResults.reset(iPath);
799  }
800  return maskedResults;
801  }
802 #endif
803 
812  std::vector<std::string> EventSelector::getEventSelectionVString(ParameterSet const& pset) {
813  // default the selection to everything (wildcard)
815  selection.push_back("*");
816  selection.push_back("!*");
817  selection.push_back("exception@*");
818 
819  // the SelectEvents parameter is a ParameterSet within
820  // a ParameterSet, so we have to pull it out twice
821  ParameterSet selectEventsParamSet = pset.getUntrackedParameter("SelectEvents", ParameterSet());
822  if (!selectEventsParamSet.empty()) {
823  Strings path_specs = selectEventsParamSet.getParameter<Strings>("SelectEvents");
824  if (!path_specs.empty()) {
825  selection = path_specs;
826  }
827  }
828 
829  // return the result
830  return selection;
831  }
832 
834  unsigned int e = tr.size();
835  for (unsigned int i = 0; i < e; ++i) {
836  if (tr[i].state() == hlt::Exception)
837  return true;
838  }
839  return false;
840  }
841 
842  // The following routines are helpers for testSelectionOverlap
843 
844  bool EventSelector::identical(std::vector<bool> const& a, std::vector<bool> const& b) {
845  unsigned int n = a.size();
846  if (n != b.size())
847  return false;
848  for (unsigned int i = 0; i != n; ++i) {
849  if (a[i] != b[i])
850  return false;
851  }
852  return true;
853  }
854 
855  bool EventSelector::identical(EventSelector const& a, EventSelector const& b, unsigned int N) {
856  // create the expanded masks for the various decision lists in a and b
859  return false;
862  return false;
865  return false;
868  return false;
871  return false;
872  if (a.all_must_fail_.size() != b.all_must_fail_.size())
873  return false;
874 
875  std::vector<std::vector<bool> > aMustFail;
876  for (unsigned int m = 0; m != a.all_must_fail_.size(); ++m) {
877  aMustFail.push_back(expandDecisionList(a.all_must_fail_[m], false, N));
878  }
879  std::vector<std::vector<bool> > aMustFailNoex;
880  for (unsigned int m = 0; m != a.all_must_fail_noex_.size(); ++m) {
881  aMustFailNoex.push_back(expandDecisionList(a.all_must_fail_noex_[m], false, N));
882  }
883  std::vector<std::vector<bool> > bMustFail;
884  for (unsigned int m = 0; m != b.all_must_fail_.size(); ++m) {
885  bMustFail.push_back(expandDecisionList(b.all_must_fail_[m], false, N));
886  }
887  std::vector<std::vector<bool> > bMustFailNoex;
888  for (unsigned int m = 0; m != b.all_must_fail_noex_.size(); ++m) {
889  bMustFailNoex.push_back(expandDecisionList(b.all_must_fail_noex_[m], false, N));
890  }
891 
892  for (unsigned int m = 0; m != aMustFail.size(); ++m) {
893  bool match = false;
894  for (unsigned int k = 0; k != bMustFail.size(); ++k) {
895  if (identical(aMustFail[m], bMustFail[k])) {
896  match = true;
897  break;
898  }
899  }
900  if (!match)
901  return false;
902  }
903  for (unsigned int m = 0; m != aMustFailNoex.size(); ++m) {
904  bool match = false;
905  for (unsigned int k = 0; k != bMustFailNoex.size(); ++k) {
906  if (identical(aMustFailNoex[m], bMustFailNoex[k])) {
907  match = true;
908  break;
909  }
910  }
911  if (!match)
912  return false;
913  }
914 
915  return true;
916 
917  } // identical (EventSelector, EventSelector, N);
918 
919  std::vector<bool> EventSelector::expandDecisionList(Bits const& b, bool PassOrFail, unsigned int n) {
920  std::vector<bool> x(n, false);
921  for (unsigned int i = 0; i != b.size(); ++i) {
922  if (b[i].accept_state_ == PassOrFail)
923  x[b[i].pos_] = true;
924  }
925  return x;
926  } // expandDecisionList
927 
928  // Determines whether a and b share a true bit at any position
929  bool EventSelector::overlapping(std::vector<bool> const& a, std::vector<bool> const& b) {
930  if (a.size() != b.size())
931  return false;
932  for (unsigned int i = 0; i != a.size(); ++i) {
933  if (a[i] && b[i])
934  return true;
935  }
936  return false;
937  } // overlapping
938 
939  // determines whether the true bits of a are a non-empty subset of those of b,
940  // or vice-versa. The subset need not be proper.
941  bool EventSelector::subset(std::vector<bool> const& a, std::vector<bool> const& b) {
942  if (a.size() != b.size())
943  return false;
944  // First test whether a is a non-empty subset of b
945  bool aPresent = false;
946  bool aSubset = true;
947  for (unsigned int i = 0; i != a.size(); ++i) {
948  if (a[i]) {
949  aPresent = true;
950  if (!b[i]) {
951  aSubset = false;
952  break;
953  }
954  }
955  }
956  if (!aPresent)
957  return false;
958  if (aSubset)
959  return true;
960 
961  // Now test whether b is a non-empty subset of a
962  bool bPresent = false;
963  bool bSubset = true;
964  for (unsigned int i = 0; i != b.size(); ++i) {
965  if (b[i]) {
966  bPresent = true;
967  if (!a[i]) {
968  bSubset = false;
969  break;
970  }
971  }
972  }
973  if (!bPresent)
974  return false;
975  if (bSubset)
976  return true;
977 
978  return false;
979  } // subset
980 
981  // Creates a vector of bits which is the OR of a and b
982  std::vector<bool> EventSelector::combine(std::vector<bool> const& a, std::vector<bool> const& b) {
983  assert(a.size() == b.size());
984  std::vector<bool> x(a.size());
985  for (unsigned int i = 0; i != a.size(); ++i) {
986  x[i] = a[i] || b[i];
987  } // a really sharp compiler will optimize the hell out of this,
988  // exploiting word-size OR operations.
989  return x;
990  } // combine
991 
993  ParameterSetDescription selector;
994  selector.addOptional<std::vector<std::string> >("SelectEvents");
995  desc.addUntracked<ParameterSetDescription>("SelectEvents", selector);
996  }
997 
998 } // namespace edm
std::vector< Bits > all_must_fail_noex_
Definition: EventSelector.h:80
EventSelector(Strings const &pathspecs, Strings const &names)
T getParameter(std::string const &) const
void initPathNames(Strings const &pathNames)
bool empty() const
Definition: ParameterSet.h:191
T getUntrackedParameter(std::string const &, T const &) const
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static bool selectionIsValid(Strings const &pathspec, Strings const &fullPathList)
std::vector< std::string > Strings
Definition: EventSelector.h:37
EventSelector::Strings Strings
bool const accept_all_
Definition: EventSelector.h:72
HLTState
status of a trigger path
Definition: HLTenums.h:18
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:17
selection
main part
Definition: corrVsCorr.py:100
reject
Definition: HLTenums.h:20
Definition: config.py:1
std::vector< BitInfo > Bits
Definition: EventSelector.h:74
static std::vector< bool > combine(std::vector< bool > const &a, std::vector< bool > const &b)
uint16_t size_type
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
bool overlap(const reco::Muon &muon1, const reco::Muon &muon2, double pullX=1.0, double pullY=1.0, bool checkAdjacentChambers=false)
Strings initPathSpecs(Strings const &pathSpecs)
bool acceptAllBits(Bits const &b, HLTGlobalStatus const &tr) const
bool acceptEvent(TriggerResults const &)
std::vector< Bits > all_must_fail_
Definition: EventSelector.h:79
accept
Definition: HLTenums.h:19
void reset()
Reset status for all paths.
unsigned int size() const
Get number of paths stored.
Strings const pathspecs_
Definition: EventSelector.h:70
static std::vector< std::string > getEventSelectionVString(edm::ParameterSet const &pset)
bool acceptOneBit(Bits const &b, HLTGlobalStatus const &tr, hlt::HLTState const &s=hlt::Ready) const
bool acceptTriggerPath(HLTPathStatus const &, BitInfo const &) const
double f[11][100]
static void fillDescription(ParameterSetDescription &desc)
bool wantAll() const
Definition: EventSelector.h:45
hlt::HLTState state() const
get state of path
Definition: HLTPathStatus.h:51
int k[5][pyjets_maxn]
static bool overlapping(std::vector< bool > const &a, std::vector< bool > const &b)
static evtSel::OverlapResult testSelectionOverlap(Strings const &pathspec1, Strings const &pathspec2, Strings const &fullPathList)
bool selectionDecision(HLTGlobalStatus const &tr) const
static bool subset(std::vector< bool > const &a, std::vector< bool > const &b)
#define N
Definition: blowfish.cc:9
double b
Definition: hdecay.h:120
ParameterSetID psetID_
Definition: EventSelector.h:82
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, std::regex const &regexp)
Definition: RegexMatch.cc:26
HLT enums.
static bool identical(std::vector< bool > const &a, std::vector< bool > const &b)
bool isValid() const
Definition: Hash.h:154
double a
Definition: hdecay.h:121
static std::vector< bool > expandDecisionList(Bits const &b, bool PassOrFail, unsigned int n)
bool const results_from_current_process_
Definition: EventSelector.h:71
std::shared_ptr< TriggerResults > maskTriggerResults(TriggerResults const &inputResults)
void reset()
Definition: Hash.h:147
const ParameterSetID & parameterSetID() const
Get stored parameter set id.
bool containsExceptions(HLTGlobalStatus const &tr) const
hlt::HLTState state(const unsigned int i) const
Get status of ith path.
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)