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