Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-14 03:16:37

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 }  // namespace
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 }  // namespace edm::test
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     //Now fill
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<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     std::vector<std::vector<unsigned int>> produceMethodIDs = {{21, 22, 23}, {}, {24}};
0078 
0079     unsigned int index = 0;
0080     for (auto const& pr : orderedOfKeys) {
0081       REQUIRE(index + 1 ==
0082               r2pi.dataKeysInRecord(index, pr.first, pr.second.first, pr.second.second, produceMethodIDs[index]));
0083       ++index;
0084     }
0085     auto idIter = produceMethodIDs.begin();
0086     for (auto const& pr : orderedOfKeys) {
0087       index = 0;
0088       auto it = pr.second.second.begin();
0089       for (auto const& dk : pr.second.first) {
0090         REQUIRE(index == (unsigned)r2pi.indexInRecord(pr.first, dk).value());
0091         REQUIRE(*it == r2pi.component(pr.first, dk));
0092         auto [componentDescription, produceMethodID] =
0093             r2pi.componentAndProduceMethodID(pr.first, edm::ESResolverIndex(index));
0094         REQUIRE(*it == componentDescription);
0095         REQUIRE((*idIter)[index] == produceMethodID);
0096         ++index;
0097         ++it;
0098       }
0099       ++idIter;
0100     }
0101     {
0102       auto v = ESTagGetterTester::info(r2pi.makeTagGetter(records[0], dataKeys[0].type()));
0103       REQUIRE(v.size() == 1);
0104       REQUIRE(v.front().index_ == r2pi.indexInRecord(records[0], dataKeys[0]));
0105       REQUIRE(v.front().productLabel_ == dataKeys[0].name().value());
0106       REQUIRE(v.front().moduleLabel_ == (p + 1)->label_);
0107     }
0108     {
0109       auto v = ESTagGetterTester::info(r2pi.makeTagGetter(records[0], dataKeys[1].type()));
0110       REQUIRE(v.size() == 1);
0111       REQUIRE(v.front().index_ == r2pi.indexInRecord(records[0], dataKeys[1]));
0112       REQUIRE(v.front().productLabel_ == dataKeys[1].name().value());
0113       REQUIRE(v.front().moduleLabel_ == (p + 2)->label_);
0114     }
0115     {
0116       auto v = ESTagGetterTester::info(r2pi.makeTagGetter(records[0], dataKeys[2].type()));
0117       REQUIRE(v.size() == 1);
0118       REQUIRE(v.front().index_ == r2pi.indexInRecord(records[0], dataKeys[2]));
0119       REQUIRE(v.front().productLabel_ == dataKeys[2].name().value());
0120       REQUIRE(v.front().moduleLabel_ == (p + 3)->label_);
0121     }
0122 
0123     REQUIRE(kMissingKey == r2pi.indexInRecord(missingRcdKey, dataKeys[0]));
0124     REQUIRE(kMissingKey == r2pi.indexInRecord(records[1], dataKeys[0]));
0125     REQUIRE(kMissingKey == r2pi.indexInRecord(records[2], dataKeys[0]));
0126 
0127     REQUIRE(r2pi.makeTagGetter(missingRcdKey, dataKeys[0].type()).hasNothingToGet());
0128     REQUIRE(r2pi.makeTagGetter(records[1], dataKeys[0].type()).hasNothingToGet());
0129     REQUIRE(r2pi.makeTagGetter(records[2], dataKeys[0].type()).hasNothingToGet());
0130   }
0131 }