File indexing completed on 2024-04-06 12:18:26
0001 #define CATCH_CONFIG_MAIN
0002 #include "catch.hpp"
0003
0004 #include "HLTrigger/HLTcore/interface/HLTConfigData.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006
0007 #include <string>
0008 #include <vector>
0009 #include <map>
0010
0011 namespace {
0012
0013 edm::ParameterSet buildModulePSet(std::string const& iLabel, std::string const& iType, std::string const& iEDMType) {
0014 edm::ParameterSet pset;
0015 pset.addParameter<std::string>("@module_label", iLabel);
0016 pset.addParameter<std::string>("@module_type", iType);
0017 pset.addParameter<std::string>("@module_edm_type", iEDMType);
0018 return pset;
0019 }
0020
0021
0022 edm::ParameterSet buildPrescaleServicePSet(std::string const& iLabel,
0023 std::string const& iType,
0024 std::string const& iEDMType,
0025 std::vector<std::string> const& labels,
0026 std::map<std::string, std::vector<unsigned int>> const& prescaleTable) {
0027 auto pset = buildModulePSet(iLabel, iType, iEDMType);
0028 pset.addParameter("lvl1Labels", labels);
0029 std::vector<edm::ParameterSet> psTable;
0030 psTable.reserve(psTable.size());
0031 for (auto const& [key, val] : prescaleTable) {
0032 REQUIRE(labels.size() == val.size());
0033 edm::ParameterSet psEntry;
0034 psEntry.addParameter<std::string>("pathName", key);
0035 psEntry.addParameter<std::vector<unsigned int>>("prescales", val);
0036 psTable.emplace_back(psEntry);
0037 }
0038 pset.addParameter<std::vector<edm::ParameterSet>>("prescaleTable", psTable);
0039 return pset;
0040 }
0041
0042 }
0043
0044 TEST_CASE("Test HLTConfigData", "[HLTConfigData]") {
0045 SECTION("TriggerPaths") {
0046 edm::ParameterSet pset;
0047 pset.addParameter<std::string>("@process_name", "TEST");
0048 const std::vector<std::string> names = {{"b1"}, {"b2"}, {"a1"}, {"z5"}};
0049 {
0050 edm::ParameterSet tpset;
0051 tpset.addParameter<std::vector<std::string>>("@trigger_paths", names);
0052 pset.addParameter<edm::ParameterSet>("@trigger_paths", tpset);
0053 }
0054 pset.addParameter<std::vector<std::string>>("b1", {{"f1"}, {"f2"}});
0055 pset.addParameter<std::vector<std::string>>("b2", {{"f3"}, {"#"}, {"c1"}, {"c2"}, {"@"}});
0056 pset.addParameter<std::vector<std::string>>("a1", {{"f1"}, {"f4"}});
0057 pset.addParameter<std::vector<std::string>>("z5", {{"f5"}});
0058
0059 pset.addParameter<edm::ParameterSet>("f1", buildModulePSet("f1", "F1Filter", "EDFilter"));
0060 pset.addParameter<edm::ParameterSet>("f2", buildModulePSet("f2", "F2Filter", "EDFilter"));
0061 pset.addParameter<edm::ParameterSet>("f3", buildModulePSet("f3", "F3Filter", "EDFilter"));
0062 pset.addParameter<edm::ParameterSet>("f4", buildModulePSet("f4", "F4Filter", "EDFilter"));
0063 pset.addParameter<edm::ParameterSet>("f5", buildModulePSet("f5", "F5Filter", "EDFilter"));
0064
0065 pset.addParameter<edm::ParameterSet>("c1", buildModulePSet("c1", "CProducer", "EDProducer"));
0066 pset.addParameter<edm::ParameterSet>("c2", buildModulePSet("c2", "CProducer", "EDProducer"));
0067
0068 pset.addParameter<edm::ParameterSet>(
0069 "PrescaleService",
0070 buildPrescaleServicePSet("PrescaleService",
0071 "PrescaleService",
0072 "Service",
0073 {"col0", "col1", "col2", "col3", "col4"},
0074 {{"b1", {45, 12, 1, 0, 1000}}, {"b2", {12000, 2, 0, 7, 0}}}));
0075
0076 pset.registerIt();
0077
0078 HLTConfigData cd(&pset);
0079
0080 SECTION("check paths") {
0081 REQUIRE(cd.size() == 4);
0082 REQUIRE(cd.triggerName(0) == names[0]);
0083 REQUIRE(cd.triggerName(1) == names[1]);
0084 REQUIRE(cd.triggerName(2) == names[2]);
0085 REQUIRE(cd.triggerName(3) == names[3]);
0086
0087 }
0088
0089 SECTION("check modules on paths") {
0090 REQUIRE(cd.size(0) == 2);
0091 REQUIRE(cd.moduleLabel(0, 0) == "f1");
0092 REQUIRE(cd.moduleLabel(0, 1) == "f2");
0093
0094 REQUIRE(cd.size(1) == 3);
0095 REQUIRE(cd.moduleLabel(1, 0) == "f3");
0096 REQUIRE(cd.moduleLabel(1, 1) == "c1");
0097 REQUIRE(cd.moduleLabel(1, 2) == "c2");
0098
0099 REQUIRE(cd.size(2) == 2);
0100 REQUIRE(cd.moduleLabel(2, 0) == "f1");
0101 REQUIRE(cd.moduleLabel(2, 1) == "f4");
0102
0103 REQUIRE(cd.size(3) == 1);
0104 REQUIRE(cd.moduleLabel(3, 0) == "f5");
0105
0106 }
0107
0108 SECTION("check prescales") {
0109
0110 auto const& psTableDouble = cd.prescaleTable<double>();
0111 auto const& psTableFractl = cd.prescaleTable<FractionalPrescale>();
0112 REQUIRE(psTableDouble.size() == psTableFractl.size());
0113 for (auto const& [key, vec_d] : psTableDouble) {
0114 auto const& vec_f = psTableFractl.at(key);
0115 REQUIRE(vec_d.size() == vec_f.size());
0116 for (size_t idx = 0; idx < vec_d.size(); ++idx) {
0117 auto const& val_d = vec_d[idx];
0118 auto const& val_f = vec_f[idx];
0119
0120 unsigned int const val_u = vec_d[idx];
0121
0122
0123
0124
0125
0126 REQUIRE(val_d == val_u);
0127 REQUIRE(val_f == val_u);
0128 }
0129 }
0130
0131 }
0132 }
0133 }