File indexing completed on 2023-01-17 23:57:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include "FWCore/Framework/interface/EventSelector.h"
0018 #include "DataFormats/Common/interface/TriggerResults.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/Framework/interface/TriggerNamesService.h"
0021 #include "FWCore/ServiceRegistry/interface/ServiceWrapper.h"
0022 #include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
0023 #include "FWCore/ServiceRegistry/interface/ServiceToken.h"
0024 #include "FWCore/Utilities/interface/Exception.h"
0025
0026 #include <array>
0027 #include <vector>
0028 #include <string>
0029 #include <iostream>
0030 #include <memory>
0031 #include <cassert>
0032
0033 using namespace edm;
0034
0035 typedef std::vector<std::vector<bool> > Answers;
0036
0037 typedef std::vector<std::string> Strings;
0038 typedef std::vector<Strings> VStrings;
0039 typedef std::vector<bool> Bools;
0040 typedef std::vector<Bools> VBools;
0041
0042
0043
0044
0045 size_t const num_trig_paths = 8;
0046 std::array<char const*, num_trig_paths> cpaths = {{
0047 "ap1",
0048 "ap2",
0049 "aq1",
0050 "aq2",
0051 "bp1",
0052 "bp2",
0053 "bq1",
0054 "bq2",
0055 }};
0056 Strings trigger_path_names(cpaths.begin(), cpaths.end());
0057
0058 struct PathSpecifiers {
0059 Strings path;
0060 PathSpecifiers(std::string const& s0,
0061 std::string const& s1 = "",
0062 std::string const& s2 = "",
0063 std::string const& s3 = "",
0064 std::string const& s4 = "",
0065 std::string const& s5 = "",
0066 std::string const& s6 = "",
0067 std::string const& s7 = "",
0068 std::string const& s8 = "",
0069 std::string const& s9 = "")
0070 : path() {
0071 if (s0 != "")
0072 path.push_back(s0);
0073 if (s1 != "")
0074 path.push_back(s1);
0075 if (s2 != "")
0076 path.push_back(s2);
0077 if (s3 != "")
0078 path.push_back(s3);
0079 if (s4 != "")
0080 path.push_back(s4);
0081 if (s5 != "")
0082 path.push_back(s5);
0083 if (s6 != "")
0084 path.push_back(s6);
0085 if (s7 != "")
0086 path.push_back(s7);
0087 if (s8 != "")
0088 path.push_back(s8);
0089 if (s9 != "")
0090 path.push_back(s9);
0091 }
0092 };
0093
0094 const HLTPathStatus pass = HLTPathStatus(edm::hlt::Pass);
0095 const HLTPathStatus fail = HLTPathStatus(edm::hlt::Fail);
0096 const HLTPathStatus excp = HLTPathStatus(edm::hlt::Exception);
0097 const HLTPathStatus redy = HLTPathStatus(edm::hlt::Ready);
0098
0099 struct TrigResults {
0100 std::vector<HLTPathStatus> bit;
0101 TrigResults(HLTPathStatus const& b0,
0102 HLTPathStatus const& b1,
0103 HLTPathStatus const& b2,
0104 HLTPathStatus const& b3,
0105 HLTPathStatus const& b4,
0106 HLTPathStatus const& b5,
0107 HLTPathStatus const& b6,
0108 HLTPathStatus const& b7)
0109 : bit(8) {
0110 bit[0] = b0;
0111 bit[1] = b1;
0112 bit[2] = b2;
0113 bit[3] = b3;
0114 bit[4] = b4;
0115 bit[5] = b5;
0116 bit[6] = b6;
0117 bit[7] = b7;
0118 assert(bit.size() == num_trig_paths);
0119 }
0120 void set(HLTPathStatus const& b0,
0121 HLTPathStatus const& b1,
0122 HLTPathStatus const& b2,
0123 HLTPathStatus const& b3,
0124 HLTPathStatus const& b4,
0125 HLTPathStatus const& b5,
0126 HLTPathStatus const& b6,
0127 HLTPathStatus const& b7) {
0128 bit[0] = b0;
0129 bit[1] = b1;
0130 bit[2] = b2;
0131 bit[3] = b3;
0132 bit[4] = b4;
0133 bit[5] = b5;
0134 bit[6] = b6;
0135 bit[7] = b7;
0136 }
0137 };
0138
0139 std::ostream& operator<<(std::ostream& ost, const Strings& s) {
0140 for (Strings::const_iterator i(s.begin()), e(s.end()); i != e; ++i) {
0141 ost << *i << " ";
0142 }
0143 return ost;
0144 }
0145
0146 std::ostream& operator<<(std::ostream& ost, const Bools& b) {
0147 for (unsigned int i = 0; i < b.size(); ++i) {
0148 ost << b[i] << " ";
0149 }
0150 return ost;
0151 }
0152
0153 std::ostream& operator<<(std::ostream& ost, const TrigResults& tr) {
0154 for (unsigned int i = 0; i < tr.bit.size(); ++i) {
0155 HLTPathStatus b = tr.bit[i];
0156 if (b.state() == edm::hlt::Ready)
0157 ost << "ready ";
0158 if (b.state() == edm::hlt::Pass)
0159 ost << "pass ";
0160 if (b.state() == edm::hlt::Fail)
0161 ost << "fail ";
0162 if (b.state() == edm::hlt::Exception)
0163 ost << "excp ";
0164 }
0165 return ost;
0166 }
0167
0168 template <size_t nb>
0169 Bools toBools(std::array<bool, nb> const& t) {
0170 Bools b;
0171 b.insert(b.end(), t.begin(), t.end());
0172 return b;
0173 }
0174
0175 void evSelTest(PathSpecifiers const& ps, TrigResults const& tr, bool ans) {
0176
0177
0178 EventSelector select_based_on_path_specifiers_and_names(ps.path, trigger_path_names);
0179 EventSelector select_based_on_path_specifiers_only(ps.path);
0180
0181 int number_of_trigger_paths = 0;
0182 std::vector<unsigned char> bitArray;
0183
0184 HLTGlobalStatus bm(tr.bit.size());
0185 for (unsigned int b = 0; b < tr.bit.size(); ++b) {
0186 bm[b] = (tr.bit[b]);
0187
0188
0189
0190
0191 if ((number_of_trigger_paths % 4) == 0)
0192 bitArray.push_back(0);
0193 int byteIndex = number_of_trigger_paths / 4;
0194 int subIndex = number_of_trigger_paths % 4;
0195 bitArray[byteIndex] |= (static_cast<unsigned char>(bm[b].state())) << (subIndex * 2);
0196 ++number_of_trigger_paths;
0197 }
0198
0199 TriggerResults results(bm, trigger_path_names);
0200
0201 bool a = select_based_on_path_specifiers_and_names.acceptEvent(results);
0202 bool b = select_based_on_path_specifiers_only.acceptEvent(results);
0203 bool aa = select_based_on_path_specifiers_and_names.acceptEvent(&(bitArray[0]), number_of_trigger_paths);
0204
0205
0206
0207
0208 if (a != ans || b != ans || aa != ans) {
0209 std::cerr << "failed to compare path specifiers with trigger results: "
0210 << "correct=" << ans << " "
0211 << "results=" << a << " " << b << " " << aa << "\n"
0212 << "pathspecs = " << ps.path << "\n"
0213 << "trigger results = " << tr << "\n";
0214 abort();
0215 }
0216
0217
0218
0219
0220 ParameterSet trigger_pset;
0221 trigger_pset.addParameter<Strings>("@trigger_paths", trigger_path_names);
0222 trigger_pset.registerIt();
0223
0224 TriggerResults results_id(bm, trigger_pset.id());
0225
0226 bool x = select_based_on_path_specifiers_and_names.acceptEvent(results_id);
0227 bool y = select_based_on_path_specifiers_only.acceptEvent(results_id);
0228
0229 if (x != ans || y != ans) {
0230 std::cerr << "failed to compare pathspecs with trigger results using pset ID: "
0231 << "correct=" << ans << " "
0232 << "results=" << x << " " << y << "\n"
0233 << "pathspecs =" << ps.path << "\n"
0234 << "trigger results = " << tr << "\n";
0235 abort();
0236 }
0237 }
0238
0239 int main() try {
0240
0241
0242
0243
0244 ParameterSet proc_pset;
0245
0246 std::string processName("HLT");
0247 proc_pset.addParameter<std::string>("@process_name", processName);
0248
0249 ParameterSet trigPaths;
0250 trigPaths.addParameter<Strings>("@trigger_paths", trigger_path_names);
0251 proc_pset.addParameter<ParameterSet>("@trigger_paths", trigPaths);
0252
0253 Strings endPaths;
0254 proc_pset.addParameter<Strings>("@end_paths", endPaths);
0255
0256
0257
0258 Strings dummy;
0259 for (size_t i = 0; i < num_trig_paths; ++i) {
0260 proc_pset.addParameter<Strings>(trigger_path_names[i], dummy);
0261 }
0262 proc_pset.registerIt();
0263
0264
0265 typedef edm::service::TriggerNamesService TNS;
0266 typedef serviceregistry::ServiceWrapper<TNS> w_TNS;
0267
0268 auto tnsptr = std::make_shared<w_TNS>(std::make_unique<TNS>(proc_pset));
0269
0270 ServiceToken serviceToken_ = ServiceRegistry::createContaining(tnsptr);
0271
0272
0273 ServiceRegistry::Operate operate(serviceToken_);
0274
0275
0276
0277
0278 PathSpecifiers ps_a("ap2");
0279 TrigResults tr_01(fail, pass, fail, fail, fail, fail, excp, fail);
0280 evSelTest(ps_a, tr_01, true);
0281 tr_01.set(fail, pass, fail, fail, fail, fail, fail, fail);
0282 evSelTest(ps_a, tr_01, true);
0283 tr_01.set(pass, fail, pass, pass, fail, fail, fail, pass);
0284 evSelTest(ps_a, tr_01, false);
0285 tr_01.set(pass, excp, pass, pass, fail, fail, fail, pass);
0286 evSelTest(ps_a, tr_01, false);
0287 tr_01.set(pass, redy, pass, pass, fail, fail, fail, pass);
0288 evSelTest(ps_a, tr_01, false);
0289
0290
0291 PathSpecifiers ps_b("!aq2");
0292 TrigResults tr_02(pass, pass, pass, fail, pass, pass, excp, pass);
0293 evSelTest(ps_b, tr_02, true);
0294 tr_02.set(pass, pass, pass, fail, pass, pass, pass, pass);
0295 evSelTest(ps_b, tr_02, true);
0296 tr_02.set(pass, pass, pass, pass, pass, pass, pass, pass);
0297 evSelTest(ps_b, tr_01, false);
0298 tr_02.set(pass, pass, pass, excp, pass, pass, pass, pass);
0299 evSelTest(ps_b, tr_01, false);
0300 tr_02.set(pass, pass, pass, redy, pass, pass, pass, pass);
0301 evSelTest(ps_b, tr_01, false);
0302
0303
0304 PathSpecifiers ps_c("bp1", "!aq1", "!bq2");
0305 TrigResults tr_03(pass, pass, pass, pass, fail, pass, pass, pass);
0306 evSelTest(ps_c, tr_03, false);
0307 tr_03.set(excp, pass, pass, pass, pass, pass, pass, pass);
0308 evSelTest(ps_c, tr_03, true);
0309 tr_03.set(excp, pass, fail, pass, fail, pass, pass, pass);
0310 evSelTest(ps_c, tr_03, true);
0311 tr_03.set(excp, pass, pass, pass, fail, pass, pass, fail);
0312 evSelTest(ps_c, tr_03, true);
0313 tr_03.set(redy, pass, pass, pass, pass, pass, pass, fail);
0314 evSelTest(ps_c, tr_03, true);
0315
0316
0317 PathSpecifiers ps_d("ap2&noexception");
0318 TrigResults tr_04(fail, pass, fail, fail, fail, fail, excp, fail);
0319 evSelTest(ps_d, tr_04, false);
0320 tr_04.set(fail, pass, fail, fail, fail, fail, fail, fail);
0321 evSelTest(ps_d, tr_04, true);
0322 tr_04.set(pass, fail, pass, pass, fail, fail, fail, pass);
0323 evSelTest(ps_d, tr_04, false);
0324 tr_04.set(pass, excp, pass, pass, fail, fail, fail, pass);
0325 evSelTest(ps_d, tr_04, false);
0326 tr_04.set(pass, pass, pass, pass, fail, fail, redy, pass);
0327 evSelTest(ps_d, tr_04, true);
0328
0329
0330 PathSpecifiers ps_e("bp1", "!aq1&noexception", "!bq2");
0331 TrigResults tr_05(pass, pass, pass, pass, fail, pass, pass, pass);
0332 evSelTest(ps_e, tr_05, false);
0333 tr_05.set(excp, pass, pass, pass, pass, pass, pass, pass);
0334 evSelTest(ps_e, tr_05, true);
0335 tr_05.set(pass, pass, fail, pass, fail, pass, pass, pass);
0336 evSelTest(ps_e, tr_05, true);
0337 tr_05.set(pass, pass, fail, pass, fail, pass, excp, pass);
0338 evSelTest(ps_e, tr_05, false);
0339
0340
0341 PathSpecifiers ps_f("a*2", "?p2");
0342 TrigResults tr_06(fail, pass, fail, fail, fail, fail, excp, fail);
0343 evSelTest(ps_f, tr_06, true);
0344 tr_06.set(fail, fail, fail, pass, fail, fail, fail, fail);
0345 evSelTest(ps_f, tr_06, true);
0346 tr_06.set(pass, fail, pass, fail, fail, pass, excp, excp);
0347 evSelTest(ps_f, tr_06, true);
0348 tr_06.set(pass, fail, pass, fail, pass, fail, pass, pass);
0349 evSelTest(ps_f, tr_06, false);
0350
0351
0352 PathSpecifiers ps_g("!*2", "!ap?");
0353 TrigResults tr_07(fail, pass, fail, fail, fail, fail, fail, fail);
0354 evSelTest(ps_g, tr_07, false);
0355 tr_07.set(pass, fail, pass, fail, excp, fail, pass, fail);
0356 evSelTest(ps_g, tr_07, true);
0357 tr_07.set(fail, fail, pass, pass, fail, pass, excp, excp);
0358 evSelTest(ps_g, tr_07, true);
0359 tr_07.set(pass, fail, fail, fail, fail, fail, fail, redy);
0360 evSelTest(ps_g, tr_07, false);
0361
0362
0363 PathSpecifiers ps_h("a*2&noexception", "?p2");
0364 TrigResults tr_08(fail, pass, fail, fail, fail, fail, excp, fail);
0365 evSelTest(ps_h, tr_08, true);
0366 tr_08.set(fail, fail, fail, pass, fail, fail, excp, fail);
0367 evSelTest(ps_h, tr_08, false);
0368 tr_08.set(pass, fail, pass, fail, fail, pass, excp, excp);
0369 evSelTest(ps_h, tr_08, true);
0370 tr_08.set(pass, fail, pass, fail, pass, fail, pass, pass);
0371 evSelTest(ps_h, tr_08, false);
0372 tr_08.set(excp, fail, pass, pass, pass, fail, pass, pass);
0373 evSelTest(ps_h, tr_08, false);
0374
0375
0376 PathSpecifiers ps_i("!*2&noexception");
0377 TrigResults tr_09(fail, pass, fail, fail, fail, fail, fail, fail);
0378 evSelTest(ps_i, tr_09, false);
0379 tr_09.set(pass, fail, pass, fail, excp, fail, pass, fail);
0380 evSelTest(ps_i, tr_09, false);
0381 tr_09.set(fail, fail, pass, pass, fail, pass, excp, excp);
0382 evSelTest(ps_i, tr_09, false);
0383 tr_09.set(pass, fail, fail, fail, fail, fail, fail, redy);
0384 evSelTest(ps_i, tr_09, false);
0385 tr_09.set(fail, fail, pass, fail, fail, fail, pass, fail);
0386 evSelTest(ps_i, tr_09, true);
0387
0388
0389 PathSpecifiers ps_j("*&noexception", "!*&noexception");
0390 TrigResults tr_10(fail, pass, fail, fail, fail, fail, fail, fail);
0391 evSelTest(ps_j, tr_10, true);
0392 tr_10.set(pass, fail, pass, fail, excp, fail, pass, fail);
0393 evSelTest(ps_j, tr_10, false);
0394 tr_10.set(fail, fail, pass, pass, fail, pass, excp, excp);
0395 evSelTest(ps_j, tr_10, false);
0396 tr_10.set(fail, fail, fail, fail, fail, fail, fail, redy);
0397 evSelTest(ps_j, tr_10, false);
0398 tr_10.set(fail, fail, fail, fail, fail, fail, fail, fail);
0399 evSelTest(ps_j, tr_10, true);
0400 tr_10.set(pass, pass, pass, pass, pass, pass, pass, pass);
0401 evSelTest(ps_j, tr_10, true);
0402 tr_10.set(redy, redy, redy, redy, redy, redy, redy, redy);
0403 evSelTest(ps_j, tr_10, false);
0404
0405
0406 PathSpecifiers ps_k("exception@*");
0407 TrigResults tr_11(fail, pass, fail, fail, fail, fail, fail, fail);
0408 evSelTest(ps_k, tr_11, false);
0409 tr_11.set(pass, fail, pass, fail, excp, fail, pass, fail);
0410 evSelTest(ps_k, tr_11, true);
0411 tr_11.set(redy, redy, redy, redy, redy, redy, redy, excp);
0412 evSelTest(ps_k, tr_11, true);
0413 tr_11.set(pass, pass, pass, pass, pass, pass, pass, excp);
0414 evSelTest(ps_k, tr_11, true);
0415 tr_11.set(redy, redy, redy, redy, redy, redy, redy, redy);
0416 evSelTest(ps_k, tr_11, false);
0417 tr_11.set(pass, fail, fail, fail, fail, fail, fail, excp);
0418 evSelTest(ps_k, tr_11, true);
0419
0420
0421 PathSpecifiers ps_m("exception@a*", "exception@bp1");
0422 TrigResults tr_12(fail, pass, fail, fail, fail, fail, fail, fail);
0423 evSelTest(ps_m, tr_12, false);
0424 tr_12.set(pass, fail, pass, fail, excp, fail, pass, fail);
0425 evSelTest(ps_m, tr_12, true);
0426 tr_12.set(redy, redy, excp, redy, redy, redy, redy, excp);
0427 evSelTest(ps_m, tr_12, true);
0428 tr_12.set(pass, pass, pass, pass, pass, pass, pass, excp);
0429 evSelTest(ps_m, tr_12, false);
0430
0431
0432 PathSpecifiers ps_n("*", "!*", "exception@*");
0433 TrigResults tr_13(fail, pass, fail, fail, fail, fail, fail, fail);
0434 evSelTest(ps_n, tr_13, true);
0435 tr_13.set(pass, pass, pass, pass, pass, pass, pass, pass);
0436 evSelTest(ps_n, tr_13, true);
0437 tr_13.set(redy, redy, redy, redy, redy, redy, redy, excp);
0438 evSelTest(ps_n, tr_13, true);
0439 tr_13.set(redy, redy, redy, redy, redy, redy, redy, redy);
0440 evSelTest(ps_n, tr_13, true);
0441 tr_13.set(pass, pass, pass, pass, pass, pass, pass, excp);
0442 evSelTest(ps_n, tr_13, true);
0443 tr_13.set(excp, excp, excp, excp, excp, excp, excp, excp);
0444 evSelTest(ps_n, tr_13, true);
0445 tr_13.set(fail, redy, redy, redy, redy, redy, redy, redy);
0446 evSelTest(ps_n, tr_13, true);
0447 tr_13.set(fail, fail, fail, fail, fail, fail, fail, fail);
0448 evSelTest(ps_n, tr_13, true);
0449
0450
0451
0452 return 0;
0453 } catch (cms::Exception const& e) {
0454 std::cerr << e.explainSelf() << std::endl;
0455 return 1;
0456 } catch (std::exception const& e) {
0457 std::cerr << e.what() << std::endl;
0458 return 1;
0459 }