File indexing completed on 2024-09-12 04:16:29
0001 #include "catch.hpp"
0002
0003 #include "FWCore/Framework/interface/ESRecordsToProductResolverIndices.h"
0004 #include "FWCore/Framework/interface/ComponentDescription.h"
0005 #include "FWCore/Utilities/interface/ESIndices.h"
0006
0007 #include <memory>
0008 #include <string>
0009 #include <vector>
0010
0011 namespace {
0012 struct Data1 {};
0013 struct Data2 {};
0014 struct Data3 {};
0015 struct Rcd1 {};
0016 struct Rcd2 {};
0017 struct Rcd3 {};
0018 struct MissingRcd {};
0019 }
0020
0021 namespace edm::test {
0022 class ESTagGetterTester {
0023 public:
0024 static std::vector<ESTagGetter::Info> const& info(ESTagGetter const& iGet) { return iGet.lookup_; }
0025 };
0026 }
0027 using edm::test::ESTagGetterTester;
0028
0029 TYPELOOKUP_DATA_REG(Rcd1);
0030 TYPELOOKUP_DATA_REG(Rcd2);
0031 TYPELOOKUP_DATA_REG(Rcd3);
0032 TYPELOOKUP_DATA_REG(MissingRcd);
0033
0034 TYPELOOKUP_DATA_REG(Data1);
0035 TYPELOOKUP_DATA_REG(Data2);
0036 TYPELOOKUP_DATA_REG(Data3);
0037
0038 using namespace edm::eventsetup;
0039 TEST_CASE("test ESRecordsToProductResolverIndices", "[ESRecordsToProductResolverIndices]") {
0040 DataKey const data1Key{DataKey::makeTypeTag<Data1>(), ""};
0041 DataKey const data2Key{DataKey::makeTypeTag<Data2>(), "foo"};
0042 DataKey const data3Key{DataKey::makeTypeTag<Data3>(), ""};
0043 auto const rcd1Key = EventSetupRecordKey::makeKey<Rcd1>();
0044 auto const rcd2Key = EventSetupRecordKey::makeKey<Rcd2>();
0045 auto const rcd3Key = EventSetupRecordKey::makeKey<Rcd3>();
0046 auto const missingRcdKey = EventSetupRecordKey::makeKey<MissingRcd>();
0047
0048 auto constexpr kMissingKey = edm::ESResolverIndex::noResolverConfigured();
0049
0050 SECTION("test empty") {
0051 ESRecordsToProductResolverIndices empty{{}};
0052
0053 REQUIRE(kMissingKey == empty.indexInRecord(rcd1Key, data1Key));
0054 REQUIRE(nullptr == empty.component(rcd1Key, data1Key));
0055 REQUIRE(empty.makeTagGetter(rcd1Key, data1Key.type()).hasNothingToGet());
0056 }
0057
0058 SECTION(" test full") {
0059 std::vector<EventSetupRecordKey> records = {rcd1Key, rcd2Key, rcd3Key};
0060 std::sort(records.begin(), records.end());
0061 ESRecordsToProductResolverIndices r2pi{records};
0062
0063 std::vector<DataKey> dataKeys = {data1Key, data2Key, data3Key};
0064 std::sort(dataKeys.begin(), dataKeys.end());
0065
0066 ComponentDescription const p[5] = {
0067 {"zero", "zero", false, false},
0068 {"one", "one", false, false},
0069 {"two", "two", false, false},
0070 {"three", "three", false, false},
0071 {"four", "four", false, false},
0072 };
0073 std::vector<
0074 std::pair<EventSetupRecordKey, std::pair<std::vector<DataKey>, std::vector<ComponentDescription const*> > > >
0075 orderedOfKeys = {{records[0], {{dataKeys[0], dataKeys[1], dataKeys[2]}, {p + 1, p + 2, p + 3}}},
0076 {records[1], {{}, {}}},
0077 {records[2], {{dataKeys[1]}, {p + 4}}}};
0078
0079 unsigned int index = 0;
0080 for (auto const& pr : orderedOfKeys) {
0081 REQUIRE(index + 1 == r2pi.dataKeysInRecord(index, pr.first, pr.second.first, pr.second.second));
0082 ++index;
0083 }
0084 for (auto const& pr : orderedOfKeys) {
0085 index = 0;
0086 auto it = pr.second.second.begin();
0087 for (auto const& dk : pr.second.first) {
0088 REQUIRE(index == (unsigned)r2pi.indexInRecord(pr.first, dk).value());
0089 REQUIRE(*it == r2pi.component(pr.first, dk));
0090 ++index;
0091 ++it;
0092 }
0093 }
0094 {
0095 auto v = ESTagGetterTester::info(r2pi.makeTagGetter(records[0], dataKeys[0].type()));
0096 REQUIRE(v.size() == 1);
0097 REQUIRE(v.front().index_ == r2pi.indexInRecord(records[0], dataKeys[0]));
0098 REQUIRE(v.front().productLabel_ == dataKeys[0].name().value());
0099 REQUIRE(v.front().moduleLabel_ == (p + 1)->label_);
0100 }
0101 {
0102 auto v = ESTagGetterTester::info(r2pi.makeTagGetter(records[0], dataKeys[1].type()));
0103 REQUIRE(v.size() == 1);
0104 REQUIRE(v.front().index_ == r2pi.indexInRecord(records[0], dataKeys[1]));
0105 REQUIRE(v.front().productLabel_ == dataKeys[1].name().value());
0106 REQUIRE(v.front().moduleLabel_ == (p + 2)->label_);
0107 }
0108 {
0109 auto v = ESTagGetterTester::info(r2pi.makeTagGetter(records[0], dataKeys[2].type()));
0110 REQUIRE(v.size() == 1);
0111 REQUIRE(v.front().index_ == r2pi.indexInRecord(records[0], dataKeys[2]));
0112 REQUIRE(v.front().productLabel_ == dataKeys[2].name().value());
0113 REQUIRE(v.front().moduleLabel_ == (p + 3)->label_);
0114 }
0115
0116 REQUIRE(kMissingKey == r2pi.indexInRecord(missingRcdKey, dataKeys[0]));
0117 REQUIRE(kMissingKey == r2pi.indexInRecord(records[1], dataKeys[0]));
0118 REQUIRE(kMissingKey == r2pi.indexInRecord(records[2], dataKeys[0]));
0119
0120 REQUIRE(r2pi.makeTagGetter(missingRcdKey, dataKeys[0].type()).hasNothingToGet());
0121 REQUIRE(r2pi.makeTagGetter(records[1], dataKeys[0].type()).hasNothingToGet());
0122 REQUIRE(r2pi.makeTagGetter(records[2], dataKeys[0].type()).hasNothingToGet());
0123 }
0124 }