CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 init.
9 // This is needed in the case of paths with wildcards,
10 // on explicit processes other than a current process
11 // (in which case init() 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 
34 
41 
42 #include "boost/algorithm/string.hpp"
43 
44 #include <algorithm>
45 #include <cassert>
46 
47 namespace edm
48 {
50  Strings const& names):
51  accept_all_(false),
52  absolute_acceptors_(),
53  conditional_acceptors_(),
54  exception_acceptors_(),
55  all_must_fail_(),
56  all_must_fail_noex_(),
57  results_from_current_process_(true),
58  psetID_initialized_(false),
59  psetID_(),
60  paths_(),
61  nTriggerNames_(0),
62  notStarPresent_(false)
63  {
64  init(pathspecs, names);
65  }
66 
68  accept_all_(false),
69  absolute_acceptors_(),
70  conditional_acceptors_(),
71  exception_acceptors_(),
72  all_must_fail_(),
73  all_must_fail_noex_(),
74  results_from_current_process_(false),
75  psetID_initialized_(false),
76  psetID_(),
77  paths_(pathspecs),
78  nTriggerNames_(0),
79  notStarPresent_(false)
80  {
81  }
82 
84  Strings const& triggernames):
85  accept_all_(false),
86  absolute_acceptors_(),
87  conditional_acceptors_(),
88  exception_acceptors_(),
89  all_must_fail_(),
90  all_must_fail_noex_(),
91  results_from_current_process_(true),
92  psetID_initialized_(false),
93  psetID_(),
94  paths_(),
95  nTriggerNames_(0),
96  notStarPresent_(false)
97  {
98  Strings paths; // default is empty...
99 
100  if (!config.empty())
101  paths = config.getParameter<Strings>("SelectEvents");
102 
103  init(paths, triggernames);
104  }
105 
106  void
108  Strings const& triggernames)
109  {
110  // std::cerr << "### init entered\n";
111  accept_all_ = false;
112  absolute_acceptors_.clear(),
113  conditional_acceptors_.clear(),
114  exception_acceptors_.clear(),
115  all_must_fail_.clear();
116  all_must_fail_noex_.clear();
117  nTriggerNames_ = triggernames.size();
118  notStarPresent_ = false;
119 
120  if (paths.empty())
121  {
122  accept_all_ = true;
123  return;
124  }
125 
126  // The following are for the purpose of establishing accept_all_ by
127  // virtue of an inclusive set of paths:
128  bool unrestricted_star = false;
129  bool negated_star = false;
130  bool exception_star = false;
131 
132  for (Strings::const_iterator i(paths.begin()), end(paths.end());
133  i!=end; ++i)
134  {
135  std::string pathSpecifier(*i);
136  boost::erase_all(pathSpecifier, " \t"); // whitespace eliminated
137  if (pathSpecifier == "*") unrestricted_star = true;
138  if (pathSpecifier == "!*") negated_star = true;
139  if (pathSpecifier == "exception@*") exception_star = true;
140 
141  std::string basePathSpec(pathSpecifier);
142  bool noex_demanded = false;
144  and_noexception = pathSpecifier.find("&noexception");
145  if (and_noexception != std::string::npos) {
146  basePathSpec = pathSpecifier.substr(0,and_noexception);
147  noex_demanded = true;
148  }
149  std::string::size_type and_noex = pathSpecifier.find("&noex");
150  if (and_noex != std::string::npos) {
151  basePathSpec = pathSpecifier.substr(0,and_noexception);
152  noex_demanded = true;
153  }
154  and_noexception = basePathSpec.find("&noexception");
155  and_noex = basePathSpec.find("&noex");
156  if (and_noexception != std::string::npos ||
157  and_noex != std::string::npos)
159  << "EventSelector::init, An OutputModule is using SelectEvents\n"
160  "to request a trigger name, but specifying &noexceptions twice\n"
161  << "The improper trigger name is: " << pathSpecifier << "\n";
162 
163  std::string realname(basePathSpec);
164  bool negative_criterion = false;
165  if (basePathSpec[0] == '!') {
166  negative_criterion = true;
167  realname = basePathSpec.substr(1,std::string::npos);
168  }
169  bool exception_spec = false;
170  if (realname.find("exception@") == 0) {
171  exception_spec = true;
172  realname = realname.substr(10, std::string::npos);
173  // strip off 10 chars, which is length of "exception@"
174  }
175  if (negative_criterion && exception_spec)
177  << "EventSelector::init, An OutputModule is using SelectEvents\n"
178  "to request a trigger name starting with !exception@.\n"
179  "This is not supported.\n"
180  << "The improper trigger name is: " << pathSpecifier << "\n";
181  if (noex_demanded && exception_spec)
183  << "EventSelector::init, An OutputModule is using SelectEvents\n"
184  "to request a trigger name starting with exception@ "
185  "and also demanding no &exceptions.\n"
186  << "The improper trigger name is: " << pathSpecifier << "\n";
187 
188 
189  // instead of "see if the name can be found in the full list of paths"
190  // we want to find all paths that match this name.
191  std::vector<Strings::const_iterator> matches =
192  regexMatch(triggernames, realname);
193 
194  if (matches.empty() && !is_glob(realname))
195  {
197  << "EventSelector::init, An OutputModule is using SelectEvents\n"
198  "to request a trigger name that does not exist\n"
199  << "The unknown trigger name is: " << realname << "\n";
200  }
201  if (matches.empty() && is_glob(realname))
202  {
203  LogWarning("Configuration")
204  << "EventSelector::init, An OutputModule is using SelectEvents\n"
205  "to request a wildcarded trigger name that does not match any trigger \n"
206  << "The wildcarded trigger name is: " << realname << "\n";
207  }
208 
209  if (!negative_criterion && !noex_demanded && !exception_spec) {
210  for (unsigned int t = 0; t != matches.size(); ++t) {
211  BitInfo bi(distance(triggernames.begin(),matches[t]), true);
212  absolute_acceptors_.push_back(bi);
213  }
214  } else if (!negative_criterion && noex_demanded) {
215  for (unsigned int t = 0; t != matches.size(); ++t) {
216  BitInfo bi(distance(triggernames.begin(),matches[t]), true);
217  conditional_acceptors_.push_back(bi);
218  }
219  } else if (exception_spec) {
220  for (unsigned int t = 0; t != matches.size(); ++t) {
221  BitInfo bi(distance(triggernames.begin(),matches[t]), true);
222  exception_acceptors_.push_back(bi);
223  }
224  } else if (negative_criterion && !noex_demanded) {
225  if (matches.empty()) {
227  << "EventSelector::init, An OutputModule is using SelectEvents\n"
228  "to request all fails on a set of trigger names that do not exist\n"
229  << "The problematic name is: " << pathSpecifier << "\n";
230 
231  } else if (matches.size() == 1) {
232  BitInfo bi(distance(triggernames.begin(),matches[0]), false);
233  absolute_acceptors_.push_back(bi);
234  } else {
235  Bits mustfail;
236  for (unsigned int t = 0; t != matches.size(); ++t) {
237  BitInfo bi(distance(triggernames.begin(),matches[t]), false);
238  // We set this to false because that will demand bits are Fail.
239  mustfail.push_back(bi);
240  }
241  all_must_fail_.push_back(mustfail);
242  }
243  } else if (negative_criterion && noex_demanded) {
244  if (matches.empty()) {
246  << "EventSelector::init, An OutputModule is using SelectEvents\n"
247  "to request all fails on a set of trigger names that do not exist\n"
248  << "The problematic name is: " << pathSpecifier << "\n";
249 
250  } else if (matches.size() == 1) {
251  BitInfo bi(distance(triggernames.begin(),matches[0]), false);
252  conditional_acceptors_.push_back(bi);
253  } else {
254  Bits mustfail;
255  for (unsigned int t = 0; t != matches.size(); ++t) {
256  BitInfo bi(distance(triggernames.begin(),matches[t]), false);
257  mustfail.push_back(bi);
258  }
259  all_must_fail_noex_.push_back(mustfail);
260  }
261  }
262  } // end of the for loop on i(paths.begin()), end(paths.end())
263 
264  if (unrestricted_star && negated_star && exception_star) accept_all_ = true;
265 
266  // std::cerr << "### init exited\n";
267 
268  } // EventSelector::init
269 
271  {
272  if (accept_all_) return true;
273 
274  // For the current process we already initialized in the constructor,
275  // The trigger names will not change so we can skip initialization.
277 
278  // For previous processes we need to get the trigger names that
279  // correspond to the bits in TriggerResults from the ParameterSet
280  // set registry, which is stored once per file. The ParameterSetID
281  // stored in TriggerResults is the key used to find the info in the
282  // registry. We optimize using the fact the ID is unique. If the ID
283  // has not changed since the last time we initialized with new triggernames,
284  // then the names have not changed and we can skip this initialization.
285  if (!(psetID_initialized_ && psetID_ == tr.parameterSetID())) {
286 
287  Strings triggernames;
288  bool fromPSetRegistry;
289 
291  if (tns->getTrigPaths(tr, triggernames, fromPSetRegistry)) {
292 
293  init(paths_, triggernames);
294 
295  if (fromPSetRegistry) {
296  psetID_ = tr.parameterSetID();
297  psetID_initialized_ = true;
298  }
299  else {
300  psetID_initialized_ = false;
301  }
302  }
303  // This should never happen
304  else {
306  << "EventSelector::acceptEvent cannot find the trigger names for\n"
307  "a process for which the configuration has requested that the\n"
308  "OutputModule use TriggerResults to select events from. This should\n"
309  "be impossible, please send information to reproduce this problem to\n"
310  "the edm developers.\n";
311  }
312  }
313  }
314 
315  // Now make the decision, based on the supplied TriggerResults tr,
316  // which of course can be treated as an HLTGlobalStatus by inheritance
317 
318  return selectionDecision(tr);
319 
320  } // acceptEvent(TriggerResults const& tr)
321 
322  bool
323  EventSelector::acceptEvent(unsigned char const* array_of_trigger_results,
324  int number_of_trigger_paths) const
325  {
326 
327  // This should never occur unless someone uses this function in
328  // an incorrect way ...
331  << "\nEventSelector.cc::acceptEvent, you are attempting to\n"
332  << "use a bit array for trigger results instead of the\n"
333  << "TriggerResults object for a previous process. This\n"
334  << "will not work and ought to be impossible\n";
335  }
336 
337  if (accept_all_) return true;
338 
339  // Form HLTGlobalStatus object to represent the array_of_trigger_results
340  HLTGlobalStatus tr(number_of_trigger_paths);
341  int byteIndex = 0;
342  int subIndex = 0;
343  for (int pathIndex = 0; pathIndex < number_of_trigger_paths; ++pathIndex)
344  {
345  int state = array_of_trigger_results[byteIndex] >> (subIndex * 2);
346  state &= 0x3;
347  HLTPathStatus pathStatus(static_cast<hlt::HLTState>(state));
348  tr[pathIndex] = pathStatus;
349  ++subIndex;
350  if (subIndex == 4)
351  { ++byteIndex;
352  subIndex = 0;
353  }
354  }
355 
356  // Now make the decision, based on the HLTGlobalStatus tr,
357  // which we have created from the supplied array of results
358 
359  return selectionDecision(tr);
360 
361  } // acceptEvent(array_of_trigger_results, number_of_trigger_paths)
362 
363  bool
365  {
366  if (accept_all_) return true;
367 
368  bool exceptionPresent = false;
369  bool exceptionsLookedFor = false;
370 
371  if (acceptOneBit(absolute_acceptors_, tr)) return true;
373  exceptionPresent = containsExceptions(tr);
374  if (!exceptionPresent) return true;
375  exceptionsLookedFor = true;
376  }
377  if (acceptOneBit(exception_acceptors_, tr, hlt::Exception)) return true;
378 
379  for (std::vector<Bits>::const_iterator f = all_must_fail_.begin();
380  f != all_must_fail_.end(); ++f)
381  {
382  if (acceptAllBits(*f, tr)) return true;
383  }
384  for (std::vector<Bits>::const_iterator fn = all_must_fail_noex_.begin();
385  fn != all_must_fail_noex_.end(); ++fn)
386  {
387  if (acceptAllBits(*fn, tr)) {
388  if (!exceptionsLookedFor) exceptionPresent = containsExceptions(tr);
389  return (!exceptionPresent);
390  }
391  }
392 
393  // If we have not accepted based on any of the acceptors, nor on any one of
394  // the all_must_fail_ collections, then we reject this event.
395 
396  return false;
397 
398  } // selectionDecision()
399 
400 // Obsolete...
402  BitInfo const& pathInfo) const
403  {
404  return (((pathStatus.state()==hlt::Pass) && (pathInfo.accept_state_)) ||
405  ((pathStatus.state()==hlt::Fail) && !(pathInfo.accept_state_)) ||
406  ((pathStatus.state()==hlt::Exception)));
407  }
408 
409  // Indicate if any bit in the trigger results matches the desired value
410  // at that position, based on the Bits array. If s is Exception, this
411  // looks for a Exceptionmatch; otherwise, true-->Pass, false-->Fail.
412  bool
414  HLTGlobalStatus const& tr,
415  hlt::HLTState const& s) const
416  {
417  bool lookForException = (s == hlt::Exception);
418  Bits::const_iterator i(b.begin());
419  Bits::const_iterator e(b.end());
420  for(;i!=e;++i) {
421  hlt::HLTState bstate =
422  lookForException ? hlt::Exception
423  : i->accept_state_ ? hlt::Pass
424  : hlt::Fail;
425  if (tr[i->pos_].state() == bstate) return true;
426  }
427  return false;
428  } // acceptOneBit
429 
430  // Indicate if *every* bit in the trigger results matches the desired value
431  // at that position, based on the Bits array: true-->Pass, false-->Fail.
432  bool
434  HLTGlobalStatus const& tr) const
435  {
436  Bits::const_iterator i(b.begin());
437  Bits::const_iterator e(b.end());
438  for(;i!=e;++i) {
439  hlt::HLTState bstate = i->accept_state_ ? hlt::Pass : hlt::Fail;
440  if (tr[i->pos_].state() != bstate) return false;
441  }
442  return true;
443  } // acceptAllBits
444 
461  Strings const& fullTriggerList)
462  {
463  // an empty selection list is not valid
464  // (we default an empty "SelectEvents" parameter to {"*","!*"} in
465  // the getEventSelectionVString method below to help avoid this)
466  if (pathspec.size() == 0)
467  {
468  return false;
469  }
470 
471  // loop over each element in the selection list
472  for (unsigned int idx = 0; idx < pathspec.size(); idx++)
473  {
474  Strings workingList;
475  workingList.push_back(pathspec[idx]);
476 
477  // catch exceptions from the EventSelector constructor
478  // (and anywhere else) and mark those as failures.
479  // The EventSelector constructor seems to do the work of
480  // checking if the selection is outside the full trigger list.
481  try
482  {
483  // create an EventSelector instance for this selection
484  EventSelector evtSelector(workingList, fullTriggerList);
485 
486  // create the TriggerResults instance that we'll use for testing
487  unsigned int fullTriggerCount = fullTriggerList.size();
488  HLTGlobalStatus hltGS(fullTriggerCount);
489  TriggerResults sampleResults(hltGS, fullTriggerList);
490 
491  // loop over each path
492  bool oneResultMatched = false;
493  for (unsigned int iPath = 0; iPath < fullTriggerCount; iPath++)
494  {
495  // loop over the possible values for the path status
496  for (int iState = static_cast<int>(hlt::Pass);
497  iState <= static_cast<int>(hlt::Exception);
498  iState++)
499  {
500  sampleResults[iPath] = HLTPathStatus(static_cast<hlt::HLTState>(iState), 0);
501  if (evtSelector.wantAll() || evtSelector.acceptEvent(sampleResults))
502  {
503  oneResultMatched = true;
504  break;
505  }
506 
507  sampleResults.reset(iPath);
508  }
509 
510  if (oneResultMatched) break;
511  }
512 
513  // Finally, check in case the selection element was a wildcarded
514  // negative such as "!*":
515 
516  if (!oneResultMatched) {
517  for (unsigned int iPath = 0; iPath < fullTriggerCount; iPath++) {
518  sampleResults[iPath] = HLTPathStatus(hlt::Fail, 0);
519  }
520  if (evtSelector.acceptEvent(sampleResults)) {
521  oneResultMatched = true;
522  }
523  }
524 
525  // if none of the possible trigger results matched the
526  // selection element, then we declare the whole selection
527  // list invalid
528  if (!oneResultMatched)
529  {
530  return false;
531  }
532  }
533  catch (edm::Exception const& excpt)
534  {
535  return false;
536  }
537  }
538 
539  // if we made it to this point, then it must have been possible
540  // to satisfy every selection element one way or another
541  return true;
542  }
543 
544 
557  Strings const& pathspec2,
558  Strings const& fullTriggerList)
559  {
560  bool overlap = false;
561 
562  // first, test that the selection lists are valid
563  if (!selectionIsValid(pathspec1, fullTriggerList) ||
564  !selectionIsValid(pathspec2, fullTriggerList))
565  {
567  }
568 
569  // catch exceptions from the EventSelector constructor
570  // (and anywhere else) and mark those as failures
571  try
572  {
573  // create an EventSelector instance for each selection list
574  EventSelector a(pathspec1, fullTriggerList);
575  EventSelector b(pathspec2, fullTriggerList);
576 
577  unsigned int N = fullTriggerList.size();
578 
579  // create the expanded masks for the various decision lists in a and b
580  std::vector<bool>
581  aPassAbs = expandDecisionList(a.absolute_acceptors_,true,N);
582  std::vector<bool>
583  aPassCon = expandDecisionList(a.conditional_acceptors_,true,N);
584  std::vector<bool>
585  aFailAbs = expandDecisionList(a.absolute_acceptors_,false,N);
586  std::vector<bool>
587  aFailCon = expandDecisionList(a.conditional_acceptors_,false,N);
588  std::vector<bool>
589  aExc = expandDecisionList(a.exception_acceptors_,true,N);
590  std::vector< std::vector<bool> > aMustFail;
591  for (unsigned int m = 0; m != a.all_must_fail_.size(); ++m) {
592  aMustFail.push_back(expandDecisionList(a.all_must_fail_[m],false,N));
593  }
594  std::vector< std::vector<bool> > aMustFailNoex;
595  for (unsigned int m = 0; m != a.all_must_fail_noex_.size(); ++m) {
596  aMustFailNoex.push_back
598  }
599 
600  std::vector<bool>
601  bPassAbs = expandDecisionList(b.absolute_acceptors_,true,N);
602  std::vector<bool>
603  bPassCon = expandDecisionList(b.conditional_acceptors_,true,N);
604  std::vector<bool>
605  bFailAbs = expandDecisionList(b.absolute_acceptors_,false,N);
606  std::vector<bool>
607  bFailCon = expandDecisionList(b.conditional_acceptors_,false,N);
608  std::vector<bool>
609  bExc = expandDecisionList(b.exception_acceptors_,true,N);
610  std::vector< std::vector<bool> > bMustFail;
611  for (unsigned int m = 0; m != b.all_must_fail_.size(); ++m) {
612  bMustFail.push_back(expandDecisionList(b.all_must_fail_[m],false,N));
613  }
614  std::vector< std::vector<bool> > bMustFailNoex;
615  for (unsigned int m = 0; m != b.all_must_fail_noex_.size(); ++m) {
616  bMustFailNoex.push_back
618  }
619 
620  std::vector<bool> aPass = combine(aPassAbs, aPassCon);
621  std::vector<bool> bPass = combine(bPassAbs, bPassCon);
622  std::vector<bool> aFail = combine(aFailAbs, aFailCon);
623  std::vector<bool> bFail = combine(bFailAbs, bFailCon);
624 
625  // Check for overlap in the primary masks
626  overlap = overlapping(aPass, bPass) ||
627  overlapping(aFail, bFail) ||
628  overlapping(aExc, bExc);
629  if (overlap) return identical(a,b,N) ? evtSel::ExactMatch
631 
632  // Check for overlap of a primary fail mask with a must fail mask
633  for (unsigned int f = 0; f != aMustFail.size(); ++f) {
634  overlap = overlapping(aMustFail[f], bFail);
635  if (overlap) return evtSel::PartialOverlap;
636  for (unsigned int g = 0; g != bMustFail.size(); ++g) {
637  overlap = subset(aMustFail[f], bMustFail[g]);
638  if (overlap) return evtSel::PartialOverlap;
639  }
640  for (unsigned int g = 0; g != bMustFailNoex.size(); ++g) {
641  overlap = subset(aMustFail[f], bMustFailNoex[g]);
642  if (overlap) return evtSel::PartialOverlap;
643  }
644  }
645  for (unsigned int f = 0; f != aMustFailNoex.size(); ++f) {
646  overlap = overlapping(aMustFailNoex[f], bFail);
647  if (overlap) return evtSel::PartialOverlap;
648  for (unsigned int g = 0; g != bMustFail.size(); ++g) {
649  overlap = subset(aMustFailNoex[f], bMustFail[g]);
650  if (overlap) return evtSel::PartialOverlap;
651  }
652  for (unsigned int g = 0; g != bMustFailNoex.size(); ++g) {
653  overlap = subset(aMustFailNoex[f], bMustFailNoex[g]);
654  if (overlap) return evtSel::PartialOverlap;
655  }
656  }
657  for (unsigned int g = 0; g != bMustFail.size(); ++g) {
658  overlap = overlapping(bMustFail[g], aFail);
659  if (overlap) return evtSel::PartialOverlap;
660  }
661  for (unsigned int g = 0; g != bMustFailNoex.size(); ++g) {
662  overlap = overlapping(bMustFail[g], aFail);
663  if (overlap) return evtSel::PartialOverlap;
664  }
665 
666  }
667  catch (edm::Exception const& excpt)
668  {
670  }
671 
672  // If we get to here without overlap becoming true, there is no overlap
673 
674  return evtSel::NoOverlap;
675 
676  } // testSelectionOverlap
677 
678 #ifdef REMOVE
679 
691  Strings const& pathspec2,
692  Strings const& fullTriggerList)
693  {
694  // first, test that the selection lists are valid
695  if (!selectionIsValid(pathspec1, fullTriggerList) ||
696  !selectionIsValid(pathspec2, fullTriggerList))
697  {
699  }
700 
701  // initialize possible states
702  bool noOverlap = true;
703  bool exactMatch = true;
704 
705  // catch exceptions from the EventSelector constructor
706  // (and anywhere else) and mark those as failures
707  try
708  {
709  // create an EventSelector instance for each selection list
710  EventSelector selector1(pathspec1, fullTriggerList);
711  EventSelector selector2(pathspec2, fullTriggerList);
712 
713  // create the TriggerResults instance that we'll use for testing
714  unsigned int fullTriggerCount = fullTriggerList.size();
715  HLTGlobalStatus hltGS(fullTriggerCount);
716  TriggerResults sampleResults(hltGS, fullTriggerList);
717 
718  // loop over each path
719  for (unsigned int iPath = 0; iPath < fullTriggerCount; iPath++)
720  {
721  // loop over the possible values for the path status
722  for (int iState = static_cast<int>(hlt::Pass);
723  iState <= static_cast<int>(hlt::Exception);
724  iState++)
725  {
726  sampleResults[iPath] =
727  HLTPathStatus(static_cast<hlt::HLTState>(iState), 0);
728  bool accept1 = selector1.wantAll() ||
729  selector1.acceptEvent(sampleResults);
730  bool accept2 = selector2.wantAll() ||
731  selector2.acceptEvent(sampleResults);
732  if (accept1 != accept2)
733  {
734  exactMatch = false;
735  }
736  if (accept1 && accept2)
737  {
738  noOverlap = false;
739  }
740  sampleResults.reset(iPath);
741  }
742  }
743  }
744  catch (edm::Exception const& excpt)
745  {
747  }
748 
749  if (exactMatch) {return evtSel::ExactMatch;}
750  if (noOverlap) {return evtSel::NoOverlap;}
751  return evtSel::PartialOverlap;
752  }
753 #endif
754 
771  boost::shared_ptr<TriggerResults>
773  {
774  // fetch and validate the total number of paths
775  unsigned int fullTriggerCount = nTriggerNames_;
776  unsigned int N = fullTriggerCount;
777  if (fullTriggerCount != inputResults.size())
778  {
780  << "EventSelector::maskTriggerResults, the TriggerResults\n"
781  << "size (" << inputResults.size()
782  << ") does not match the number of paths in the\n"
783  << "full trigger list (" << fullTriggerCount << ").\n";
784  }
785 
786  // create a suitable global status object to work with, all in Ready state
787  HLTGlobalStatus mask(fullTriggerCount);
788 
789  // Deal with must_fail acceptors that would cause selection
790  for (unsigned int m = 0; m < this->all_must_fail_.size(); ++m) {
791  std::vector<bool>
792  f = expandDecisionList(this->all_must_fail_[m],false,N);
793  bool all_fail = true;
794  for (unsigned int ipath = 0; ipath < N; ++ipath) {
795  if ((f[ipath]) && (inputResults [ipath].state() != hlt::Fail)) {
796  all_fail = false;
797  break;
798  }
799  }
800  if (all_fail) {
801  for (unsigned int ipath = 0; ipath < N; ++ipath) {
802  if (f[ipath]) {
803  mask[ipath] = hlt::Fail;
804  }
805  }
806  }
807  }
808  for (unsigned int m = 0; m < this->all_must_fail_noex_.size(); ++m) {
809  std::vector<bool>
810  f = expandDecisionList(this->all_must_fail_noex_[m],false,N);
811  bool all_fail = true;
812  for (unsigned int ipath = 0; ipath < N; ++ipath) {
813  if ((f[ipath]) && (inputResults [ipath].state() != hlt::Fail)) {
814  all_fail = false;
815  break;
816  }
817  }
818  if (all_fail) {
819  for (unsigned int ipath = 0; ipath < N; ++ipath) {
820  if (f[ipath]) {
821  mask[ipath] = hlt::Fail;
822  }
823  }
824  }
825  } // factoring opportunity - work done for fail_noex_ is same as for fail_
826 
827  // Deal with normal acceptors that would cause selection
828  std::vector<bool>
829  aPassAbs = expandDecisionList(this->absolute_acceptors_,true,N);
830  std::vector<bool>
831  aPassCon = expandDecisionList(this->conditional_acceptors_,true,N);
832  std::vector<bool>
833  aFailAbs = expandDecisionList(this->absolute_acceptors_,false,N);
834  std::vector<bool>
835  aFailCon = expandDecisionList(this->conditional_acceptors_,false,N);
836  std::vector<bool>
837  aExc = expandDecisionList(this->exception_acceptors_,true,N);
838  for (unsigned int ipath = 0; ipath < N; ++ipath) {
839  hlt::HLTState s = inputResults [ipath].state();
840  if (((aPassAbs[ipath]) && (s == hlt::Pass))
841  ||
842  ((aPassCon[ipath]) && (s == hlt::Pass))
843  ||
844  ((aFailAbs[ipath]) && (s == hlt::Fail))
845  ||
846  ((aFailCon[ipath]) && (s == hlt::Fail))
847  ||
848  ((aExc[ipath]) && (s == hlt::Exception)))
849  {
850  mask[ipath] = s;
851  }
852  }
853 
854  // Based on the global status for the mask, create and return a
855  // TriggerResults
856  boost::shared_ptr<TriggerResults>
857  maskedResults(new TriggerResults(mask, inputResults.parameterSetID()));
858  return maskedResults;
859  } // maskTriggerResults
860 
861 
862 
863 
864 
865 #ifdef REMOVE
866 
884  boost::shared_ptr<TriggerResults>
886  TriggerResults const& inputResults,
887  Strings const& fullTriggerList)
888  {
889  // fetch and validate the total number of paths
890  unsigned int fullTriggerCount = fullTriggerList.size();
891  if (fullTriggerCount != inputResults.size())
892  {
894  << "EventSelector::maskTriggerResults, the TriggerResults\n"
895  << "size (" << inputResults.size()
896  << ") does not match the number of paths in the\n"
897  << "full trigger list (" << fullTriggerCount << ").\n";
898  }
899 
900  // create a working copy of the TriggerResults object
901  HLTGlobalStatus hltGS(fullTriggerCount);
902  boost::shared_ptr<TriggerResults>
903  maskedResults(new TriggerResults(hltGS, inputResults.parameterSetID()));
904  for (unsigned int iPath = 0; iPath < fullTriggerCount; iPath++)
905  {
906  (*maskedResults)[iPath] = inputResults[iPath];
907  }
908 
909  // create an EventSelector to use when testing if a path status passes
910  EventSelector selector(pathspecs, fullTriggerList);
911 
912  // create the TriggerResults instance that we'll use for testing
913  HLTGlobalStatus hltGS2(fullTriggerCount);
914  TriggerResults sampleResults(hltGS2, fullTriggerList);
915 
916  // loop over each path and reset the path status if needed
917  for (unsigned int iPath = 0; iPath < fullTriggerCount; iPath++)
918  {
919  sampleResults[iPath] = (*maskedResults)[iPath];
920  if (!selector.wantAll() && !selector.acceptEvent(sampleResults))
921  {
922  maskedResults->reset(iPath);
923  }
924  sampleResults.reset(iPath);
925  }
926  return maskedResults;
927  }
928 #endif
929 
938  std::vector<std::string>
940  {
941  // default the selection to everything (wildcard)
943  selection.push_back("*");
944  selection.push_back("!*");
945  selection.push_back("exception@*");
946 
947  // the SelectEvents parameter is a ParameterSet within
948  // a ParameterSet, so we have to pull it out twice
949  ParameterSet selectEventsParamSet =
950  pset.getUntrackedParameter("SelectEvents", ParameterSet());
951  if (!selectEventsParamSet.empty()) {
952  Strings path_specs =
953  selectEventsParamSet.getParameter<Strings>("SelectEvents");
954  if (!path_specs.empty()) {
955  selection = path_specs;
956  }
957  }
958 
959  // return the result
960  return selection;
961  }
962 
964  {
965  unsigned int e = tr.size();
966  for (unsigned int i = 0; i < e; ++i) {
967  if (tr[i].state() == hlt::Exception) return true;
968  }
969  return false;
970  }
971 
972  // The following routines are helpers for testSelectionOverlap
973 
974  bool
975  EventSelector::identical(std::vector<bool> const& a,
976  std::vector<bool> const& b) {
977  unsigned int n = a.size();
978  if (n != b.size()) return false;
979  for (unsigned int i=0; i!=n; ++i) {
980  if (a[i] != b[i]) return false;
981  }
982  return true;
983  }
984 
985  bool
987  EventSelector const& b,
988  unsigned int N)
989  {
990  // create the expanded masks for the various decision lists in a and b
993  return false;
996  return false;
999  return false;
1002  return false;
1005  return false;
1006  if (a.all_must_fail_.size() != b.all_must_fail_.size()) return false;
1007 
1008  std::vector< std::vector<bool> > aMustFail;
1009  for (unsigned int m = 0; m != a.all_must_fail_.size(); ++m) {
1010  aMustFail.push_back(expandDecisionList(a.all_must_fail_[m],false,N));
1011  }
1012  std::vector< std::vector<bool> > aMustFailNoex;
1013  for (unsigned int m = 0; m != a.all_must_fail_noex_.size(); ++m) {
1014  aMustFailNoex.push_back
1016  }
1017  std::vector< std::vector<bool> > bMustFail;
1018  for (unsigned int m = 0; m != b.all_must_fail_.size(); ++m) {
1019  bMustFail.push_back(expandDecisionList(b.all_must_fail_[m],false,N));
1020  }
1021  std::vector< std::vector<bool> > bMustFailNoex;
1022  for (unsigned int m = 0; m != b.all_must_fail_noex_.size(); ++m) {
1023  bMustFailNoex.push_back
1025  }
1026 
1027  for (unsigned int m = 0; m != aMustFail.size(); ++m) {
1028  bool match = false;
1029  for (unsigned int k = 0; k != bMustFail.size(); ++k) {
1030  if (identical(aMustFail[m],bMustFail[k])) {
1031  match = true;
1032  break;
1033  }
1034  }
1035  if (!match) return false;
1036  }
1037  for (unsigned int m = 0; m != aMustFailNoex.size(); ++m) {
1038  bool match = false;
1039  for (unsigned int k = 0; k != bMustFailNoex.size(); ++k) {
1040  if (identical(aMustFailNoex[m],bMustFailNoex[k])) {
1041  match = true;
1042  break;
1043  }
1044  }
1045  if (!match) return false;
1046  }
1047 
1048  return true;
1049 
1050  } // identical (EventSelector, EventSelector, N);
1051 
1052  std::vector<bool>
1054  bool PassOrFail,
1055  unsigned int n)
1056  {
1057  std::vector<bool> x(n, false);
1058  for (unsigned int i = 0; i != b.size(); ++i) {
1059  if (b[i].accept_state_ == PassOrFail) x[b[i].pos_] = true;
1060  }
1061  return x;
1062  } // expandDecisionList
1063 
1064  // Determines whether a and b share a true bit at any position
1065  bool EventSelector::overlapping(std::vector<bool> const& a,
1066  std::vector<bool> const& b)
1067  {
1068  if (a.size() != b.size()) return false;
1069  for (unsigned int i = 0; i != a.size(); ++i) {
1070  if (a[i] && b[i]) return true;
1071  }
1072  return false;
1073  } // overlapping
1074 
1075  // determines whether the true bits of a are a non-empty subset of those of b,
1076  // or vice-versa. The subset need not be proper.
1077  bool EventSelector::subset(std::vector<bool> const& a,
1078  std::vector<bool> const& b)
1079  {
1080  if (a.size() != b.size()) return false;
1081  // First test whether a is a non-empty subset of b
1082  bool aPresent = false;
1083  bool aSubset = true;
1084  for (unsigned int i = 0; i != a.size(); ++i) {
1085  if (a[i]) {
1086  aPresent = true;
1087  if (!b[i]) {
1088  aSubset = false;
1089  break;
1090  }
1091  }
1092  }
1093  if (!aPresent) return false;
1094  if (aSubset) return true;
1095 
1096  // Now test whether b is a non-empty subset of a
1097  bool bPresent = false;
1098  bool bSubset = true;
1099  for (unsigned int i = 0; i != b.size(); ++i) {
1100  if (b[i]) {
1101  bPresent = true;
1102  if (!a[i]) {
1103  bSubset = false;
1104  break;
1105  }
1106  }
1107  }
1108  if (!bPresent) return false;
1109  if (bSubset) return true;
1110 
1111  return false;
1112  } // subset
1113 
1114  // Creates a vector of bits which is the OR of a and b
1115  std::vector<bool>
1116  EventSelector::combine(std::vector<bool> const& a,
1117  std::vector<bool> const& b)
1118  {
1119  assert(a.size() == b.size());
1120  std::vector<bool> x(a.size());
1121  for (unsigned int i = 0; i != a.size(); ++i) {
1122  x[i] = a[i] || b[i];
1123  } // a really sharp compiler will optimize the hell out of this,
1124  // exploiting word-size OR operations.
1125  return x;
1126  } // combine
1127 
1128  void
1130  ParameterSetDescription selector;
1131  selector.addOptional<std::vector<std::string> >("SelectEvents");
1132  desc.addUntracked<ParameterSetDescription>("SelectEvents", selector);
1133  }
1134 
1135 }
std::vector< Bits > all_must_fail_noex_
Definition: EventSelector.h:95
EventSelector(Strings const &pathspecs, Strings const &names)
T getParameter(std::string const &) const
bool empty() const
Definition: ParameterSet.h:219
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
boost::shared_ptr< TriggerResults > maskTriggerResults(TriggerResults const &inputResults)
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
std::vector< std::string > Strings
Definition: EventSelector.h:44
static const HistoName names[]
std::vector< std::string > Strings
Definition: MsgTools.h:18
HLTState
status of a trigger path
Definition: HLTenums.h:21
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:18
selection
main part
Definition: corrVsCorr.py:98
reject
Definition: HLTenums.h:23
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName, BranchDescription::MatchMode m)
std::vector< BitInfo > Bits
Definition: EventSelector.h:88
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)
bool acceptAllBits(Bits const &b, HLTGlobalStatus const &tr) const
bool results_from_current_process_
Definition: EventSelector.h:97
bool acceptEvent(TriggerResults const &)
std::vector< Bits > all_must_fail_
Definition: EventSelector.h:94
void init(Strings const &paths, Strings const &triggernames)
accept
Definition: HLTenums.h:22
void reset()
Reset status for all paths.
unsigned int size() const
Get number of paths stored.
static std::vector< std::string > getEventSelectionVString(edm::ParameterSet const &pset)
static evtSel::OverlapResult testSelectionOverlap(Strings const &pathspec1, Strings const &pathspec2, Strings const &fullTriggerList)
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)
#define end
Definition: vmac.h:38
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, boost::regex const &regexp)
Definition: RegexMatch.cc:30
static bool selectionIsValid(Strings const &pathspec, Strings const &fullTriggerList)
bool wantAll() const
Definition: EventSelector.h:55
hlt::HLTState state() const
get state of path
Definition: HLTPathStatus.h:54
int k[5][pyjets_maxn]
static bool overlapping(std::vector< bool > const &a, std::vector< bool > const &b)
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
A selector of events.
Definition: EventSelector.h:15
char state
Definition: procUtils.cc:75
ParameterSetID psetID_
Definition: EventSelector.h:99
static bool identical(std::vector< bool > const &a, std::vector< bool > const &b)
double a
Definition: hdecay.h:121
static std::vector< bool > expandDecisionList(Bits const &b, bool PassOrFail, unsigned int n)
x
Definition: VDTMath.h:216
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.