File indexing completed on 2024-04-06 12:12:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include "FWCore/Framework/interface/EventSelector.h"
0035 #include "FWCore/Framework/interface/TriggerNamesService.h"
0036 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0037 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0038 #include "FWCore/ParameterSet/interface/Registry.h"
0039 #include "FWCore/ServiceRegistry/interface/Service.h"
0040 #include "FWCore/Utilities/interface/EDMException.h"
0041 #include "FWCore/Utilities/interface/RegexMatch.h"
0042
0043 #include <algorithm>
0044 #include <cctype>
0045 #include <cassert>
0046
0047 namespace edm {
0048 using Strings = EventSelector::Strings;
0049 EventSelector::EventSelector(Strings const& pathspecs, Strings const& pathNames)
0050 : pathspecs_(initPathSpecs(pathspecs)),
0051 results_from_current_process_(true),
0052 accept_all_(initAcceptAll()),
0053 absolute_acceptors_(),
0054 conditional_acceptors_(),
0055 exception_acceptors_(),
0056 all_must_fail_(),
0057 all_must_fail_noex_(),
0058 psetID_(),
0059 nPathNames_(0) {
0060 initPathNames(pathNames);
0061 }
0062
0063 EventSelector::EventSelector(Strings const& pathspecs)
0064 : pathspecs_(initPathSpecs(pathspecs)),
0065 results_from_current_process_(false),
0066 accept_all_(initAcceptAll()),
0067 absolute_acceptors_(),
0068 conditional_acceptors_(),
0069 exception_acceptors_(),
0070 all_must_fail_(),
0071 all_must_fail_noex_(),
0072 psetID_(),
0073 nPathNames_(0) {}
0074
0075 Strings EventSelector::initPathSpecs(Strings const& pathSpecs) {
0076 Strings trimmedPathSpecs(pathSpecs);
0077 for (auto& pathspecifier : trimmedPathSpecs) {
0078 pathspecifier.erase(std::remove_if(pathspecifier.begin(),
0079 pathspecifier.end(),
0080 [](char c) { return std::isspace(static_cast<unsigned char>(c)); }),
0081 pathspecifier.end());
0082 }
0083
0084 return trimmedPathSpecs;
0085 }
0086
0087 bool EventSelector::initAcceptAll() {
0088 if (pathspecs_.empty()) {
0089 return true;
0090 }
0091
0092
0093 bool unrestricted_star = false;
0094 bool negated_star = false;
0095 bool exception_star = false;
0096
0097 for (auto const& pathspecifier : pathspecs_) {
0098 if (pathspecifier == "*")
0099 unrestricted_star = true;
0100 if (pathspecifier == "!*")
0101 negated_star = true;
0102 if (pathspecifier == "exception@*")
0103 exception_star = true;
0104 }
0105 return (unrestricted_star && negated_star && exception_star);
0106 }
0107
0108 void EventSelector::initPathNames(Strings const& pathNames) {
0109 if (accept_all_) {
0110 return;
0111 }
0112
0113 absolute_acceptors_.clear(), conditional_acceptors_.clear(), exception_acceptors_.clear(), all_must_fail_.clear();
0114 all_must_fail_noex_.clear();
0115 nPathNames_ = pathNames.size();
0116
0117 for (auto const& pathspecifier : pathspecs_) {
0118 std::string basePathSpec(pathspecifier);
0119 bool noex_demanded = false;
0120 std::string::size_type and_noexception = pathspecifier.find("&noexception");
0121 if (and_noexception != std::string::npos) {
0122 basePathSpec = pathspecifier.substr(0, and_noexception);
0123 noex_demanded = true;
0124 }
0125 std::string::size_type and_noex = pathspecifier.find("&noex");
0126 if (and_noex != std::string::npos) {
0127 basePathSpec = pathspecifier.substr(0, and_noexception);
0128 noex_demanded = true;
0129 }
0130 and_noexception = basePathSpec.find("&noexception");
0131 and_noex = basePathSpec.find("&noex");
0132 if (and_noexception != std::string::npos || and_noex != std::string::npos)
0133 throw edm::Exception(errors::Configuration) << "EventSelector::init, An OutputModule is using SelectEvents\n"
0134 "to request a trigger name, but specifying &noexceptions twice\n"
0135 << "The improper trigger name is: " << pathspecifier << "\n";
0136
0137 std::string realname(basePathSpec);
0138 bool negative_criterion = false;
0139 if (basePathSpec[0] == '!') {
0140 negative_criterion = true;
0141 realname = basePathSpec.substr(1, std::string::npos);
0142 }
0143 bool exception_spec = false;
0144 if (realname.find("exception@") == 0) {
0145 exception_spec = true;
0146 realname = realname.substr(10, std::string::npos);
0147
0148 }
0149 if (negative_criterion && exception_spec)
0150 throw edm::Exception(errors::Configuration) << "EventSelector::init, An OutputModule is using SelectEvents\n"
0151 "to request a trigger name starting with !exception@.\n"
0152 "This is not supported.\n"
0153 << "The improper trigger name is: " << pathspecifier << "\n";
0154 if (noex_demanded && exception_spec)
0155 throw edm::Exception(errors::Configuration) << "EventSelector::init, An OutputModule is using SelectEvents\n"
0156 "to request a trigger name starting with exception@ "
0157 "and also demanding no &exceptions.\n"
0158 << "The improper trigger name is: " << pathspecifier << "\n";
0159
0160
0161
0162 std::vector<Strings::const_iterator> matches = regexMatch(pathNames, realname);
0163
0164 if (matches.empty() && !is_glob(realname)) {
0165 throw edm::Exception(errors::Configuration) << "EventSelector::init, An OutputModule is using SelectEvents\n"
0166 "to request a trigger name that does not exist\n"
0167 << "The unknown trigger name is: " << realname << "\n";
0168 }
0169 if (matches.empty() && is_glob(realname)) {
0170 LogWarning("Configuration") << "EventSelector::init, An OutputModule is using SelectEvents\n"
0171 "to request a wildcarded trigger name that does not match any trigger \n"
0172 << "The wildcarded trigger name is: " << realname << "\n";
0173 }
0174
0175 if (!negative_criterion && !noex_demanded && !exception_spec) {
0176 for (unsigned int t = 0; t != matches.size(); ++t) {
0177 BitInfo bi(distance(pathNames.begin(), matches[t]), true);
0178 absolute_acceptors_.push_back(bi);
0179 }
0180 } else if (!negative_criterion && noex_demanded) {
0181 for (unsigned int t = 0; t != matches.size(); ++t) {
0182 BitInfo bi(distance(pathNames.begin(), matches[t]), true);
0183 conditional_acceptors_.push_back(bi);
0184 }
0185 } else if (exception_spec) {
0186 for (unsigned int t = 0; t != matches.size(); ++t) {
0187 BitInfo bi(distance(pathNames.begin(), matches[t]), true);
0188 exception_acceptors_.push_back(bi);
0189 }
0190 } else if (negative_criterion && !noex_demanded) {
0191 if (matches.empty()) {
0192 throw edm::Exception(errors::Configuration)
0193 << "EventSelector::init, An OutputModule is using SelectEvents\n"
0194 "to request all fails on a set of trigger names that do not exist\n"
0195 << "The problematic name is: " << pathspecifier << "\n";
0196
0197 } else if (matches.size() == 1) {
0198 BitInfo bi(distance(pathNames.begin(), matches[0]), false);
0199 absolute_acceptors_.push_back(bi);
0200 } else {
0201 Bits mustfail;
0202 for (unsigned int t = 0; t != matches.size(); ++t) {
0203 BitInfo bi(distance(pathNames.begin(), matches[t]), false);
0204
0205 mustfail.push_back(bi);
0206 }
0207 all_must_fail_.push_back(mustfail);
0208 }
0209 } else if (negative_criterion && noex_demanded) {
0210 if (matches.empty()) {
0211 throw edm::Exception(errors::Configuration)
0212 << "EventSelector::init, An OutputModule is using SelectEvents\n"
0213 "to request all fails on a set of trigger names that do not exist\n"
0214 << "The problematic name is: " << pathspecifier << "\n";
0215
0216 } else if (matches.size() == 1) {
0217 BitInfo bi(distance(pathNames.begin(), matches[0]), false);
0218 conditional_acceptors_.push_back(bi);
0219 } else {
0220 Bits mustfail;
0221 for (unsigned int t = 0; t != matches.size(); ++t) {
0222 BitInfo bi(distance(pathNames.begin(), matches[t]), false);
0223 mustfail.push_back(bi);
0224 }
0225 all_must_fail_noex_.push_back(mustfail);
0226 }
0227 }
0228 }
0229
0230
0231
0232 }
0233
0234 bool EventSelector::acceptEvent(TriggerResults const& tr) {
0235 if (accept_all_)
0236 return true;
0237
0238 if (!results_from_current_process_) {
0239
0240
0241 if (!psetID_.isValid() || psetID_ != tr.parameterSetID()) {
0242 Strings pathNames;
0243 bool fromPSetRegistry = false;
0244 Service<service::TriggerNamesService> tns;
0245 if (tns->getTrigPaths(tr, pathNames, fromPSetRegistry)) {
0246 initPathNames(pathNames);
0247 if (fromPSetRegistry) {
0248 psetID_ = tr.parameterSetID();
0249 } else {
0250
0251
0252 psetID_.reset();
0253 }
0254 } else {
0255
0256 throw edm::Exception(errors::Unknown)
0257 << "EventSelector::acceptEvent cannot find the trigger names for\n"
0258 "a process for which the configuration has requested that the\n"
0259 "OutputModule use TriggerResults to select events from. This should\n"
0260 "be impossible, please send information to reproduce this problem to\n"
0261 "the edm developers.\n";
0262 }
0263 }
0264 }
0265
0266
0267
0268
0269 return selectionDecision(tr);
0270
0271 }
0272
0273 bool EventSelector::acceptEvent(unsigned char const* array_of_trigger_results, int number_of_trigger_paths) const {
0274
0275
0276 if (!results_from_current_process_) {
0277 throw edm::Exception(errors::Configuration) << "\nEventSelector.cc::acceptEvent, you are attempting to\n"
0278 << "use a bit array for trigger results instead of the\n"
0279 << "TriggerResults object for a previous process. This\n"
0280 << "will not work and ought to be impossible\n";
0281 }
0282
0283 if (accept_all_)
0284 return true;
0285
0286
0287 HLTGlobalStatus tr(number_of_trigger_paths);
0288 int byteIndex = 0;
0289 int subIndex = 0;
0290 for (int pathIndex = 0; pathIndex < number_of_trigger_paths; ++pathIndex) {
0291 int state = array_of_trigger_results[byteIndex] >> (subIndex * 2);
0292 state &= 0x3;
0293 HLTPathStatus pathStatus(static_cast<hlt::HLTState>(state));
0294 tr[pathIndex] = pathStatus;
0295 ++subIndex;
0296 if (subIndex == 4) {
0297 ++byteIndex;
0298 subIndex = 0;
0299 }
0300 }
0301
0302
0303
0304
0305 return selectionDecision(tr);
0306
0307 }
0308
0309 bool EventSelector::selectionDecision(HLTGlobalStatus const& tr) const {
0310 if (accept_all_)
0311 return true;
0312
0313 bool exceptionPresent = false;
0314 bool exceptionsLookedFor = false;
0315
0316 if (acceptOneBit(absolute_acceptors_, tr))
0317 return true;
0318 if (acceptOneBit(conditional_acceptors_, tr)) {
0319 exceptionPresent = containsExceptions(tr);
0320 if (!exceptionPresent)
0321 return true;
0322 exceptionsLookedFor = true;
0323 }
0324 if (acceptOneBit(exception_acceptors_, tr, hlt::Exception))
0325 return true;
0326
0327 for (auto const& bit : all_must_fail_) {
0328 if (acceptAllBits(bit, tr))
0329 return true;
0330 }
0331 for (auto const& bitn : all_must_fail_noex_) {
0332 if (acceptAllBits(bitn, tr)) {
0333 if (!exceptionsLookedFor)
0334 exceptionPresent = containsExceptions(tr);
0335 return (!exceptionPresent);
0336 }
0337 }
0338
0339
0340
0341
0342 return false;
0343
0344 }
0345
0346
0347 bool EventSelector::acceptTriggerPath(HLTPathStatus const& pathStatus, BitInfo const& pathInfo) const {
0348 return (((pathStatus.state() == hlt::Pass) && (pathInfo.accept_state_)) ||
0349 ((pathStatus.state() == hlt::Fail) && !(pathInfo.accept_state_)) ||
0350 ((pathStatus.state() == hlt::Exception)));
0351 }
0352
0353
0354
0355
0356 bool EventSelector::acceptOneBit(Bits const& b, HLTGlobalStatus const& tr, hlt::HLTState const& s) const {
0357 bool lookForException = (s == hlt::Exception);
0358 for (auto const& bit : b) {
0359 hlt::HLTState bstate = lookForException ? hlt::Exception : bit.accept_state_ ? hlt::Pass : hlt::Fail;
0360 if (tr.at(bit.pos_).state() == bstate)
0361 return true;
0362 }
0363 return false;
0364 }
0365
0366
0367
0368 bool EventSelector::acceptAllBits(Bits const& b, HLTGlobalStatus const& tr) const {
0369 for (auto const& bit : b) {
0370 hlt::HLTState bstate = bit.accept_state_ ? hlt::Pass : hlt::Fail;
0371 if (tr.at(bit.pos_).state() != bstate)
0372 return false;
0373 }
0374 return true;
0375 }
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392 bool EventSelector::selectionIsValid(Strings const& pathspecs, Strings const& fullPathList) {
0393
0394
0395
0396 if (pathspecs.empty()) {
0397 return false;
0398 }
0399
0400
0401 for (unsigned int idx = 0; idx < pathspecs.size(); idx++) {
0402 Strings workingList;
0403 workingList.push_back(pathspecs[idx]);
0404
0405
0406
0407
0408
0409 try {
0410
0411 EventSelector evtSelector(workingList, fullPathList);
0412
0413
0414 unsigned int fullPathCount = fullPathList.size();
0415 HLTGlobalStatus hltGS(fullPathCount);
0416 TriggerResults sampleResults(hltGS, fullPathList);
0417
0418
0419 bool oneResultMatched = false;
0420 for (unsigned int iPath = 0; iPath < fullPathCount; iPath++) {
0421
0422 for (int iState = static_cast<int>(hlt::Pass); iState <= static_cast<int>(hlt::Exception); iState++) {
0423 sampleResults[iPath] = HLTPathStatus(static_cast<hlt::HLTState>(iState), 0);
0424 if (evtSelector.wantAll() || evtSelector.acceptEvent(sampleResults)) {
0425 oneResultMatched = true;
0426 break;
0427 }
0428
0429 sampleResults.reset(iPath);
0430 }
0431
0432 if (oneResultMatched)
0433 break;
0434 }
0435
0436
0437
0438
0439 if (!oneResultMatched) {
0440 for (unsigned int iPath = 0; iPath < fullPathCount; iPath++) {
0441 sampleResults[iPath] = HLTPathStatus(hlt::Fail, 0);
0442 }
0443 if (evtSelector.acceptEvent(sampleResults)) {
0444 oneResultMatched = true;
0445 }
0446 }
0447
0448
0449
0450
0451 if (!oneResultMatched) {
0452 return false;
0453 }
0454 } catch (edm::Exception const&) {
0455 return false;
0456 }
0457 }
0458
0459
0460
0461 return true;
0462 }
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474 evtSel::OverlapResult EventSelector::testSelectionOverlap(Strings const& pathspec1,
0475 Strings const& pathspec2,
0476 Strings const& fullPathList) {
0477 bool overlap = false;
0478
0479
0480 if (!selectionIsValid(pathspec1, fullPathList) || !selectionIsValid(pathspec2, fullPathList)) {
0481 return evtSel::InvalidSelection;
0482 }
0483
0484
0485
0486 try {
0487
0488 EventSelector a(pathspec1, fullPathList);
0489 EventSelector b(pathspec2, fullPathList);
0490
0491 unsigned int N = fullPathList.size();
0492
0493
0494 std::vector<bool> aPassAbs = expandDecisionList(a.absolute_acceptors_, true, N);
0495 std::vector<bool> aPassCon = expandDecisionList(a.conditional_acceptors_, true, N);
0496 std::vector<bool> aFailAbs = expandDecisionList(a.absolute_acceptors_, false, N);
0497 std::vector<bool> aFailCon = expandDecisionList(a.conditional_acceptors_, false, N);
0498 std::vector<bool> aExc = expandDecisionList(a.exception_acceptors_, true, N);
0499 std::vector<std::vector<bool>> aMustFail;
0500 for (unsigned int m = 0; m != a.all_must_fail_.size(); ++m) {
0501 aMustFail.push_back(expandDecisionList(a.all_must_fail_[m], false, N));
0502 }
0503 std::vector<std::vector<bool>> aMustFailNoex;
0504 for (unsigned int m = 0; m != a.all_must_fail_noex_.size(); ++m) {
0505 aMustFailNoex.push_back(expandDecisionList(a.all_must_fail_noex_[m], false, N));
0506 }
0507
0508 std::vector<bool> bPassAbs = expandDecisionList(b.absolute_acceptors_, true, N);
0509 std::vector<bool> bPassCon = expandDecisionList(b.conditional_acceptors_, true, N);
0510 std::vector<bool> bFailAbs = expandDecisionList(b.absolute_acceptors_, false, N);
0511 std::vector<bool> bFailCon = expandDecisionList(b.conditional_acceptors_, false, N);
0512 std::vector<bool> bExc = expandDecisionList(b.exception_acceptors_, true, N);
0513 std::vector<std::vector<bool>> bMustFail;
0514 for (unsigned int m = 0; m != b.all_must_fail_.size(); ++m) {
0515 bMustFail.push_back(expandDecisionList(b.all_must_fail_[m], false, N));
0516 }
0517 std::vector<std::vector<bool>> bMustFailNoex;
0518 for (unsigned int m = 0; m != b.all_must_fail_noex_.size(); ++m) {
0519 bMustFailNoex.push_back(expandDecisionList(b.all_must_fail_noex_[m], false, N));
0520 }
0521
0522 std::vector<bool> aPass = combine(aPassAbs, aPassCon);
0523 std::vector<bool> bPass = combine(bPassAbs, bPassCon);
0524 std::vector<bool> aFail = combine(aFailAbs, aFailCon);
0525 std::vector<bool> bFail = combine(bFailAbs, bFailCon);
0526
0527
0528 overlap = overlapping(aPass, bPass) || overlapping(aFail, bFail) || overlapping(aExc, bExc);
0529 if (overlap)
0530 return identical(a, b, N) ? evtSel::ExactMatch : evtSel::PartialOverlap;
0531
0532
0533 for (unsigned int f = 0; f != aMustFail.size(); ++f) {
0534 overlap = overlapping(aMustFail[f], bFail);
0535 if (overlap)
0536 return evtSel::PartialOverlap;
0537 for (unsigned int g = 0; g != bMustFail.size(); ++g) {
0538 overlap = subset(aMustFail[f], bMustFail[g]);
0539 if (overlap)
0540 return evtSel::PartialOverlap;
0541 }
0542 for (unsigned int g = 0; g != bMustFailNoex.size(); ++g) {
0543 overlap = subset(aMustFail[f], bMustFailNoex[g]);
0544 if (overlap)
0545 return evtSel::PartialOverlap;
0546 }
0547 }
0548 for (unsigned int f = 0; f != aMustFailNoex.size(); ++f) {
0549 overlap = overlapping(aMustFailNoex[f], bFail);
0550 if (overlap)
0551 return evtSel::PartialOverlap;
0552 for (unsigned int g = 0; g != bMustFail.size(); ++g) {
0553 overlap = subset(aMustFailNoex[f], bMustFail[g]);
0554 if (overlap)
0555 return evtSel::PartialOverlap;
0556 }
0557 for (unsigned int g = 0; g != bMustFailNoex.size(); ++g) {
0558 overlap = subset(aMustFailNoex[f], bMustFailNoex[g]);
0559 if (overlap)
0560 return evtSel::PartialOverlap;
0561 }
0562 }
0563 for (unsigned int g = 0; g != bMustFail.size(); ++g) {
0564 overlap = overlapping(bMustFail[g], aFail);
0565 if (overlap)
0566 return evtSel::PartialOverlap;
0567 }
0568 for (unsigned int g = 0; g != bMustFailNoex.size(); ++g) {
0569 overlap = overlapping(bMustFail[g], aFail);
0570 if (overlap)
0571 return evtSel::PartialOverlap;
0572 }
0573
0574 } catch (edm::Exception const&) {
0575 return evtSel::InvalidSelection;
0576 }
0577
0578
0579
0580 return evtSel::NoOverlap;
0581
0582 }
0583
0584 #ifdef REMOVE
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595 evtSel::OverlapResult EventSelector::testSelectionOverlap(Strings const& pathspec1,
0596 Strings const& pathspec2,
0597 Strings const& fullPathList) {
0598
0599 if (!selectionIsValid(pathspec1, fullPathList) || !selectionIsValid(pathspec2, fullPathList)) {
0600 return evtSel::InvalidSelection;
0601 }
0602
0603
0604 bool noOverlap = true;
0605 bool exactMatch = true;
0606
0607
0608
0609 try {
0610
0611 EventSelector selector1(pathspec1, fullPathList);
0612 EventSelector selector2(pathspec2, fullPathList);
0613
0614
0615 unsigned int fullPathCount = fullPathList.size();
0616 HLTGlobalStatus hltGS(fullPathCount);
0617 TriggerResults sampleResults(hltGS, fullPathList);
0618
0619
0620 for (unsigned int iPath = 0; iPath < fullPathCount; iPath++) {
0621
0622 for (int iState = static_cast<int>(hlt::Pass); iState <= static_cast<int>(hlt::Exception); iState++) {
0623 sampleResults[iPath] = HLTPathStatus(static_cast<hlt::HLTState>(iState), 0);
0624 bool accept1 = selector1.wantAll() || selector1.acceptEvent(sampleResults);
0625 bool accept2 = selector2.wantAll() || selector2.acceptEvent(sampleResults);
0626 if (accept1 != accept2) {
0627 exactMatch = false;
0628 }
0629 if (accept1 && accept2) {
0630 noOverlap = false;
0631 }
0632 sampleResults.reset(iPath);
0633 }
0634 }
0635 } catch (edm::Exception const& excpt) {
0636 return evtSel::InvalidSelection;
0637 }
0638
0639 if (exactMatch) {
0640 return evtSel::ExactMatch;
0641 }
0642 if (noOverlap) {
0643 return evtSel::NoOverlap;
0644 }
0645 return evtSel::PartialOverlap;
0646 }
0647 #endif
0648
0649
0650
0651
0652
0653
0654
0655
0656
0657
0658
0659
0660
0661
0662
0663
0664
0665 std::shared_ptr<TriggerResults> EventSelector::maskTriggerResults(TriggerResults const& inputResults) {
0666
0667 unsigned int fullPathCount = nPathNames_;
0668 unsigned int N = fullPathCount;
0669 if (fullPathCount != inputResults.size()) {
0670 throw edm::Exception(errors::EventCorruption)
0671 << "EventSelector::maskTriggerResults, the TriggerResults\n"
0672 << "size (" << inputResults.size() << ") does not match the number of paths in the\n"
0673 << "full trigger list (" << fullPathCount << ").\n";
0674 }
0675
0676
0677 HLTGlobalStatus mask(fullPathCount);
0678
0679
0680 for (unsigned int m = 0; m < this->all_must_fail_.size(); ++m) {
0681 std::vector<bool> f = expandDecisionList(this->all_must_fail_[m], false, N);
0682 bool all_fail = true;
0683 for (unsigned int ipath = 0; ipath < N; ++ipath) {
0684 if ((f[ipath]) && (inputResults[ipath].state() != hlt::Fail)) {
0685 all_fail = false;
0686 break;
0687 }
0688 }
0689 if (all_fail) {
0690 for (unsigned int ipath = 0; ipath < N; ++ipath) {
0691 if (f[ipath]) {
0692 mask[ipath] = hlt::Fail;
0693 }
0694 }
0695 }
0696 }
0697 for (unsigned int m = 0; m < this->all_must_fail_noex_.size(); ++m) {
0698 std::vector<bool> f = expandDecisionList(this->all_must_fail_noex_[m], false, N);
0699 bool all_fail = true;
0700 for (unsigned int ipath = 0; ipath < N; ++ipath) {
0701 if ((f[ipath]) && (inputResults[ipath].state() != hlt::Fail)) {
0702 all_fail = false;
0703 break;
0704 }
0705 }
0706 if (all_fail) {
0707 for (unsigned int ipath = 0; ipath < N; ++ipath) {
0708 if (f[ipath]) {
0709 mask[ipath] = hlt::Fail;
0710 }
0711 }
0712 }
0713 }
0714
0715
0716 std::vector<bool> aPassAbs = expandDecisionList(this->absolute_acceptors_, true, N);
0717 std::vector<bool> aPassCon = expandDecisionList(this->conditional_acceptors_, true, N);
0718 std::vector<bool> aFailAbs = expandDecisionList(this->absolute_acceptors_, false, N);
0719 std::vector<bool> aFailCon = expandDecisionList(this->conditional_acceptors_, false, N);
0720 std::vector<bool> aExc = expandDecisionList(this->exception_acceptors_, true, N);
0721 for (unsigned int ipath = 0; ipath < N; ++ipath) {
0722 hlt::HLTState s = inputResults[ipath].state();
0723 if (((aPassAbs[ipath]) && (s == hlt::Pass)) || ((aPassCon[ipath]) && (s == hlt::Pass)) ||
0724 ((aFailAbs[ipath]) && (s == hlt::Fail)) || ((aFailCon[ipath]) && (s == hlt::Fail)) ||
0725 ((aExc[ipath]) && (s == hlt::Exception))) {
0726 mask[ipath] = s;
0727 }
0728 }
0729
0730
0731
0732 auto maskedResults = std::make_shared<TriggerResults>(mask, inputResults.parameterSetID());
0733 return maskedResults;
0734 }
0735
0736 #ifdef REMOVE
0737
0738
0739
0740
0741
0742
0743
0744
0745
0746
0747
0748
0749
0750
0751
0752
0753
0754
0755 std::shared_ptr<TriggerResults> EventSelector::maskTriggerResults(Strings const& pathspecs,
0756 TriggerResults const& inputResults,
0757 Strings const& fullPathList) {
0758
0759 unsigned int fullPathCount = fullPathList.size();
0760 if (fullPathCount != inputResults.size()) {
0761 throw edm::Exception(errors::EventCorruption)
0762 << "EventSelector::maskTriggerResults, the TriggerResults\n"
0763 << "size (" << inputResults.size() << ") does not match the number of paths in the\n"
0764 << "full trigger list (" << fullPathCount << ").\n";
0765 }
0766
0767
0768 HLTGlobalStatus hltGS(fullPathCount);
0769 auto maskedResults = std::make_shared<TriggerResults>(hltGS, inputResults.parameterSetID());
0770 for (unsigned int iPath = 0; iPath < fullPathCount; iPath++) {
0771 (*maskedResults)[iPath] = inputResults[iPath];
0772 }
0773
0774
0775 EventSelector selector(pathspecs, fullPathList);
0776
0777
0778 HLTGlobalStatus hltGS2(fullPathCount);
0779 TriggerResults sampleResults(hltGS2, fullPathList);
0780
0781
0782 for (unsigned int iPath = 0; iPath < fullPathCount; iPath++) {
0783 sampleResults[iPath] = (*maskedResults)[iPath];
0784 if (!selector.wantAll() && !selector.acceptEvent(sampleResults)) {
0785 maskedResults->reset(iPath);
0786 }
0787 sampleResults.reset(iPath);
0788 }
0789 return maskedResults;
0790 }
0791 #endif
0792
0793
0794
0795
0796
0797
0798
0799
0800
0801 std::vector<std::string> EventSelector::getEventSelectionVString(ParameterSet const& pset) {
0802
0803 Strings selection;
0804 selection.push_back("*");
0805 selection.push_back("!*");
0806 selection.push_back("exception@*");
0807
0808
0809
0810 ParameterSet selectEventsParamSet = pset.getUntrackedParameter("SelectEvents", ParameterSet());
0811 if (!selectEventsParamSet.empty()) {
0812 Strings path_specs = selectEventsParamSet.getParameter<Strings>("SelectEvents");
0813 if (!path_specs.empty()) {
0814 selection = path_specs;
0815 }
0816 }
0817
0818
0819 return selection;
0820 }
0821
0822 bool EventSelector::containsExceptions(HLTGlobalStatus const& tr) const {
0823 unsigned int e = tr.size();
0824 for (unsigned int i = 0; i < e; ++i) {
0825 if (tr[i].state() == hlt::Exception)
0826 return true;
0827 }
0828 return false;
0829 }
0830
0831
0832
0833 bool EventSelector::identical(std::vector<bool> const& a, std::vector<bool> const& b) {
0834 unsigned int n = a.size();
0835 if (n != b.size())
0836 return false;
0837 for (unsigned int i = 0; i != n; ++i) {
0838 if (a[i] != b[i])
0839 return false;
0840 }
0841 return true;
0842 }
0843
0844 bool EventSelector::identical(EventSelector const& a, EventSelector const& b, unsigned int N) {
0845
0846 if (!identical(expandDecisionList(a.absolute_acceptors_, true, N),
0847 expandDecisionList(b.absolute_acceptors_, true, N)))
0848 return false;
0849 if (!identical(expandDecisionList(a.conditional_acceptors_, true, N),
0850 expandDecisionList(b.conditional_acceptors_, true, N)))
0851 return false;
0852 if (!identical(expandDecisionList(a.absolute_acceptors_, false, N),
0853 expandDecisionList(b.absolute_acceptors_, false, N)))
0854 return false;
0855 if (!identical(expandDecisionList(a.conditional_acceptors_, false, N),
0856 expandDecisionList(b.conditional_acceptors_, false, N)))
0857 return false;
0858 if (!identical(expandDecisionList(a.exception_acceptors_, true, N),
0859 expandDecisionList(b.exception_acceptors_, true, N)))
0860 return false;
0861 if (a.all_must_fail_.size() != b.all_must_fail_.size())
0862 return false;
0863
0864 std::vector<std::vector<bool>> aMustFail;
0865 for (unsigned int m = 0; m != a.all_must_fail_.size(); ++m) {
0866 aMustFail.push_back(expandDecisionList(a.all_must_fail_[m], false, N));
0867 }
0868 std::vector<std::vector<bool>> aMustFailNoex;
0869 for (unsigned int m = 0; m != a.all_must_fail_noex_.size(); ++m) {
0870 aMustFailNoex.push_back(expandDecisionList(a.all_must_fail_noex_[m], false, N));
0871 }
0872 std::vector<std::vector<bool>> bMustFail;
0873 for (unsigned int m = 0; m != b.all_must_fail_.size(); ++m) {
0874 bMustFail.push_back(expandDecisionList(b.all_must_fail_[m], false, N));
0875 }
0876 std::vector<std::vector<bool>> bMustFailNoex;
0877 for (unsigned int m = 0; m != b.all_must_fail_noex_.size(); ++m) {
0878 bMustFailNoex.push_back(expandDecisionList(b.all_must_fail_noex_[m], false, N));
0879 }
0880
0881 for (unsigned int m = 0; m != aMustFail.size(); ++m) {
0882 bool match = false;
0883 for (unsigned int k = 0; k != bMustFail.size(); ++k) {
0884 if (identical(aMustFail[m], bMustFail[k])) {
0885 match = true;
0886 break;
0887 }
0888 }
0889 if (!match)
0890 return false;
0891 }
0892 for (unsigned int m = 0; m != aMustFailNoex.size(); ++m) {
0893 bool match = false;
0894 for (unsigned int k = 0; k != bMustFailNoex.size(); ++k) {
0895 if (identical(aMustFailNoex[m], bMustFailNoex[k])) {
0896 match = true;
0897 break;
0898 }
0899 }
0900 if (!match)
0901 return false;
0902 }
0903
0904 return true;
0905
0906 }
0907
0908 std::vector<bool> EventSelector::expandDecisionList(Bits const& b, bool PassOrFail, unsigned int n) {
0909 std::vector<bool> x(n, false);
0910 for (unsigned int i = 0; i != b.size(); ++i) {
0911 if (b[i].accept_state_ == PassOrFail)
0912 x[b[i].pos_] = true;
0913 }
0914 return x;
0915 }
0916
0917
0918 bool EventSelector::overlapping(std::vector<bool> const& a, std::vector<bool> const& b) {
0919 if (a.size() != b.size())
0920 return false;
0921 for (unsigned int i = 0; i != a.size(); ++i) {
0922 if (a[i] && b[i])
0923 return true;
0924 }
0925 return false;
0926 }
0927
0928
0929
0930 bool EventSelector::subset(std::vector<bool> const& a, std::vector<bool> const& b) {
0931 if (a.size() != b.size())
0932 return false;
0933
0934 bool aPresent = false;
0935 bool aSubset = true;
0936 for (unsigned int i = 0; i != a.size(); ++i) {
0937 if (a[i]) {
0938 aPresent = true;
0939 if (!b[i]) {
0940 aSubset = false;
0941 break;
0942 }
0943 }
0944 }
0945 if (!aPresent)
0946 return false;
0947 if (aSubset)
0948 return true;
0949
0950
0951 bool bPresent = false;
0952 bool bSubset = true;
0953 for (unsigned int i = 0; i != b.size(); ++i) {
0954 if (b[i]) {
0955 bPresent = true;
0956 if (!a[i]) {
0957 bSubset = false;
0958 break;
0959 }
0960 }
0961 }
0962 if (!bPresent)
0963 return false;
0964 if (bSubset)
0965 return true;
0966
0967 return false;
0968 }
0969
0970
0971 std::vector<bool> EventSelector::combine(std::vector<bool> const& a, std::vector<bool> const& b) {
0972 assert(a.size() == b.size());
0973 std::vector<bool> x(a.size());
0974 for (unsigned int i = 0; i != a.size(); ++i) {
0975 x[i] = a[i] || b[i];
0976 }
0977
0978 return x;
0979 }
0980
0981 void EventSelector::fillDescription(ParameterSetDescription& desc) {
0982 ParameterSetDescription selector;
0983 selector.addOptional<std::vector<std::string>>("SelectEvents");
0984 desc.addUntracked<ParameterSetDescription>("SelectEvents", selector);
0985 }
0986
0987 }