File indexing completed on 2025-08-19 01:41:30
0001 #define CATCH_CONFIG_MAIN
0002 #include <catch.hpp>
0003
0004 #include "DataFormats/Provenance/interface/EventID.h"
0005 #include "DataFormats/Provenance/interface/ProductID.h"
0006 #include "DataFormats/Provenance/interface/ProductResolverIndexHelper.h"
0007 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0008
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 #include "FWCore/Utilities/interface/ProductKindOfType.h"
0011 #include "FWCore/Utilities/interface/TypeID.h"
0012
0013 #include <iostream>
0014 #include <iomanip>
0015
0016 using namespace edm;
0017
0018 TEST_CASE("ProductResolverIndexHelper", "[ProductResolverIndexHelper]") {
0019 TypeID typeID_ProductID(typeid(ProductID));
0020 TypeID typeID_EventID(typeid(EventID));
0021
0022 SECTION("CreateEmpty") {
0023 edm::ProductResolverIndexHelper helper;
0024 helper.setFrozen("processA");
0025
0026 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") ==
0027 ProductResolverIndexInvalid);
0028 REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") ==
0029 ProductResolverIndexInvalid);
0030 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "") == ProductResolverIndexInvalid);
0031 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA") == ProductResolverIndexInvalid);
0032
0033 edm::ProductResolverIndexHelper::Matches matches =
0034 helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID, "label_A", "instance_A");
0035 REQUIRE(matches.numberOfMatches() == 0);
0036 matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID);
0037 REQUIRE(matches.numberOfMatches() == 0);
0038
0039 TypeID typeID(typeid(ProductID));
0040 REQUIRE_THROWS_AS(helper.insert(typeID, "labelA", "instanceA", "processA"), cms::Exception);
0041 }
0042
0043 SECTION("OneEntry") {
0044 edm::ProductResolverIndexHelper helper;
0045
0046 TypeID typeIDProductID(typeid(ProductID));
0047 helper.insert(typeIDProductID, "labelA", "instanceA", "processA");
0048
0049 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") ==
0050 ProductResolverIndexInvalid);
0051 REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") ==
0052 ProductResolverIndexInvalid);
0053 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "") == ProductResolverIndexInvalid);
0054 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA") == ProductResolverIndexInvalid);
0055
0056 edm::ProductResolverIndexHelper::Matches matches =
0057 helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID, "label_A", "instance_A");
0058 REQUIRE(matches.numberOfMatches() == 0);
0059 matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID);
0060 REQUIRE(matches.numberOfMatches() == 0);
0061
0062 helper.setFrozen("processA");
0063
0064 matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA");
0065 REQUIRE(matches.numberOfMatches() == 2);
0066 edm::ProductResolverIndex indexEmptyProcess = matches.index(0);
0067 edm::ProductResolverIndex indexWithProcess = matches.index(1);
0068 REQUIRE_THROWS_AS(matches.index(2), cms::Exception);
0069 REQUIRE(indexEmptyProcess < 2);
0070 REQUIRE(indexWithProcess < 2);
0071 REQUIRE(indexEmptyProcess != indexWithProcess);
0072
0073
0074 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA") == indexWithProcess);
0075 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "") == indexWithProcess);
0076 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", 0) == indexWithProcess);
0077 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") == indexWithProcess);
0078
0079 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instance", "processA") ==
0080 ProductResolverIndexInvalid);
0081 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceAX", "processA") ==
0082 ProductResolverIndexInvalid);
0083 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "label", "instanceA", "processA") ==
0084 ProductResolverIndexInvalid);
0085 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelAX", "instanceA", "processA") ==
0086 ProductResolverIndexInvalid);
0087 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "process") ==
0088 ProductResolverIndexInvalid);
0089 REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processAX") ==
0090 ProductResolverIndexInvalid);
0091 REQUIRE(helper.index(PRODUCT_TYPE, typeID_EventID, "labelA", "instanceA", "processA") ==
0092 ProductResolverIndexInvalid);
0093
0094 REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA") == ProductResolverIndexInvalid);
0095 REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") ==
0096 ProductResolverIndexInvalid);
0097
0098 matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID);
0099 REQUIRE(matches.numberOfMatches() == 2);
0100 REQUIRE(matches.index(0) == indexEmptyProcess);
0101 REQUIRE(matches.index(1) == indexWithProcess);
0102
0103 matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_EventID);
0104 REQUIRE(matches.numberOfMatches() == 0);
0105
0106 matches = helper.relatedIndexes(ELEMENT_TYPE, typeID_ProductID);
0107 REQUIRE(matches.numberOfMatches() == 0);
0108
0109 matches = helper.relatedIndexes(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA");
0110 REQUIRE(matches.numberOfMatches() == 0);
0111
0112 {
0113 auto indexToModules = helper.indiciesForModulesInProcess("processA");
0114 REQUIRE(indexToModules.size() == 1);
0115 REQUIRE(indexToModules.count("labelA") == 1);
0116 auto const& range = indexToModules.equal_range("labelA");
0117 REQUIRE(std::get<2>(range.first->second) == indexWithProcess);
0118 }
0119
0120 {
0121 auto indexToModules = helper.indiciesForModulesInProcess("processNotHere");
0122 REQUIRE(indexToModules.size() == 0);
0123 }
0124 }
0125
0126 SECTION("ManyEntries") {
0127 edm::ProductResolverIndexHelper helper;
0128
0129 TypeID typeIDProductID(typeid(ProductID));
0130 TypeID typeIDEventID(typeid(EventID));
0131 TypeID typeIDVectorInt(typeid(std::vector<int>));
0132 TypeID typeIDSetInt(typeid(std::set<int>));
0133 TypeID typeIDVSimpleDerived(typeid(std::vector<edmtest::SimpleDerived>));
0134
0135 helper.insert(typeIDVectorInt, "labelC", "instanceC", "processC");
0136 helper.insert(typeIDVectorInt, "label", "instance", "process");
0137 helper.insert(typeIDEventID, "labelB", "instanceB", "processB");
0138 helper.insert(typeIDEventID, "label", "instanceB", "processB");
0139 helper.insert(typeIDEventID, "labelX", "instanceB", "processB");
0140 helper.insert(typeIDEventID, "labelB", "instance", "processB");
0141 helper.insert(typeIDEventID, "labelB", "instanceX", "processB");
0142 helper.insert(typeIDEventID, "labelB", "instanceB", "processB1");
0143 helper.insert(typeIDEventID, "labelB", "instanceB", "processB3");
0144 helper.insert(typeIDEventID, "labelB", "instanceB", "processB2");
0145 helper.insert(typeIDProductID, "label", "instance", "process");
0146 helper.insert(typeIDEventID, "label", "instance", "process");
0147 helper.insert(typeIDProductID, "labelA", "instanceA", "processA");
0148 REQUIRE_THROWS_AS(helper.insert(typeIDProductID, "labelA", "instanceA", "processA"), cms::Exception);
0149
0150 helper.insert(typeIDSetInt, "labelC", "instanceC", "processC");
0151
0152 helper.insert(typeIDVSimpleDerived, "labelC", "instanceC", "processC");
0153
0154 helper.setFrozen("processC");
0155
0156 TypeID typeID_int(typeid(int));
0157 REQUIRE(helper.index(ELEMENT_TYPE, typeID_int, "labelC", "instanceC", "processC") == ProductResolverIndexAmbiguous);
0158 REQUIRE(helper.index(ELEMENT_TYPE, typeID_int, "labelC", "instanceC", "processQ") == ProductResolverIndexInvalid);
0159 REQUIRE(helper.index(ELEMENT_TYPE, typeID_int, "labelC", "instanceC") == ProductResolverIndexAmbiguous);
0160 edm::ProductResolverIndexHelper::Matches matches = helper.relatedIndexes(ELEMENT_TYPE, typeID_int);
0161 REQUIRE(matches.numberOfMatches() == 4);
0162 REQUIRE(matches.index(0) == 5);
0163 REQUIRE(matches.index(1) == 3);
0164 REQUIRE(matches.index(2) == 2);
0165 REQUIRE(matches.index(3) == ProductResolverIndexAmbiguous);
0166
0167 TypeID typeID_vint(typeid(std::vector<int>));
0168 REQUIRE(helper.index(PRODUCT_TYPE, typeID_vint, "labelC", "instanceC", "processC") == 0);
0169 REQUIRE(helper.index(PRODUCT_TYPE, typeID_vint, "labelC", "instanceC") == 0);
0170
0171 TypeID typeID_sint(typeid(std::set<int>));
0172 REQUIRE(helper.index(PRODUCT_TYPE, typeID_sint, "labelC", "instanceC", "processC") == 25);
0173 REQUIRE(helper.index(PRODUCT_TYPE, typeID_sint, "labelC", "instanceC") == 25);
0174
0175 TypeID typeID_Simple(typeid(edmtest::Simple));
0176 REQUIRE(helper.index(ELEMENT_TYPE, typeID_Simple, "labelC", "instanceC") == 27);
0177 REQUIRE(helper.index(ELEMENT_TYPE, typeID_Simple, "labelC", "instanceC", "processC") == 27);
0178
0179 TypeID typeID_SimpleDerived(typeid(edmtest::SimpleDerived));
0180 REQUIRE(helper.index(ELEMENT_TYPE, typeID_SimpleDerived, "labelC", "instanceC") == 27);
0181 REQUIRE(helper.index(ELEMENT_TYPE, typeID_SimpleDerived, "labelC", "instanceC", "processC") == 27);
0182
0183 TypeID typeID_VSimpleDerived(typeid(std::vector<edmtest::SimpleDerived>));
0184 REQUIRE(helper.index(PRODUCT_TYPE, typeID_VSimpleDerived, "labelC", "instanceC") == 27);
0185 REQUIRE(helper.index(PRODUCT_TYPE, typeID_VSimpleDerived, "labelC", "instanceC", "processC") == 27);
0186
0187 matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_EventID, "labelB", "instanceB");
0188 REQUIRE(matches.numberOfMatches() == 5);
0189 ProductResolverIndex indexEmptyProcess = matches.index(0);
0190 ProductResolverIndex indexB = matches.index(1);
0191 ProductResolverIndex indexB1 = matches.index(2);
0192 ProductResolverIndex indexB2 = matches.index(3);
0193 ProductResolverIndex indexB3 = matches.index(4);
0194 REQUIRE_THROWS_AS(matches.index(5), cms::Exception);
0195 REQUIRE(indexEmptyProcess == 7);
0196 REQUIRE(indexB == 6);
0197 REQUIRE(indexB1 == 16);
0198 REQUIRE(indexB2 == 18);
0199 REQUIRE(indexB3 == 17);
0200
0201 REQUIRE(std::string(matches.moduleLabel(4)) == "labelB");
0202 REQUIRE(std::string(matches.productInstanceName(4)) == "instanceB");
0203 REQUIRE(std::string(matches.processName(4)) == "processB3");
0204 REQUIRE(std::string(matches.processName(0)) == "");
0205
0206 matches = helper.relatedIndexes(ELEMENT_TYPE, typeID_Simple);
0207 REQUIRE(matches.numberOfMatches() == 2);
0208 ProductResolverIndex indexC = matches.index(1);
0209 REQUIRE_THROWS_AS(matches.index(2), cms::Exception);
0210 REQUIRE(indexC == 27);
0211
0212 {
0213 auto indexToModules = helper.indiciesForModulesInProcess("processA");
0214 REQUIRE(indexToModules.size() == 1);
0215 }
0216 {
0217 auto indexToModules = helper.indiciesForModulesInProcess("processB");
0218 REQUIRE(indexToModules.size() == 5);
0219 }
0220 {
0221 auto indexToModules = helper.indiciesForModulesInProcess("processB1");
0222 REQUIRE(indexToModules.size() == 1);
0223 }
0224 {
0225 auto indexToModules = helper.indiciesForModulesInProcess("processB2");
0226 REQUIRE(indexToModules.size() == 1);
0227 }
0228 {
0229 auto indexToModules = helper.indiciesForModulesInProcess("processB3");
0230 REQUIRE(indexToModules.size() == 1);
0231 }
0232 {
0233 auto indexToModules = helper.indiciesForModulesInProcess("processC");
0234 REQUIRE(indexToModules.size() == 3);
0235 }
0236 }
0237 }