Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-07-16 00:28:31

0001 /*
0002  *  dependentrecord_t.cpp
0003  *  EDMProto
0004  *
0005  *  Created by Chris Jones on 4/29/05.
0006  *  Changed by Viji Sundararajan on 29-Jun-2005
0007  *
0008  */
0009 
0010 #include "FWCore/Framework/test/DummyRecord.h"
0011 #include "FWCore/Framework/test/Dummy2Record.h"
0012 #include "FWCore/Framework/test/DepRecord.h"
0013 #include "FWCore/Framework/test/DepOn2Record.h"
0014 #include "FWCore/Framework/test/DummyFinder.h"
0015 #include "FWCore/Framework/test/DummyData.h"
0016 #include "FWCore/Framework/test/DummyProxyProvider.h"
0017 #include "FWCore/Framework/interface/DependentRecordIntervalFinder.h"
0018 #include "FWCore/Framework/interface/EventSetupImpl.h"
0019 #include "FWCore/Framework/interface/EventSetupProvider.h"
0020 #include "FWCore/Framework/interface/EventSetup.h"
0021 #include "FWCore/Framework/interface/DataProxyProvider.h"
0022 #include "FWCore/Framework/interface/DataProxyTemplate.h"
0023 #include "FWCore/Framework/interface/ESRecordsToProxyIndices.h"
0024 #include "FWCore/Framework/interface/EDConsumerBase.h"
0025 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0026 #include "FWCore/Framework/interface/EventSetupRecordProvider.h"
0027 #include "FWCore/Framework/src/SynchronousEventSetupsController.h"
0028 #include "FWCore/Framework/interface/NoRecordException.h"
0029 #include "FWCore/Framework/test/print_eventsetup_record_dependencies.h"
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0032 #include "FWCore/ServiceRegistry/interface/ESParentContext.h"
0033 #include "FWCore/Utilities/interface/propagate_const.h"
0034 #include "FWCore/Concurrency/interface/ThreadsController.h"
0035 #include "FWCore/Concurrency/interface/FinalWaitingTask.h"
0036 
0037 #include "cppunit/extensions/HelperMacros.h"
0038 
0039 #include <memory>
0040 #include <string>
0041 #include <vector>
0042 #include <cstring>
0043 
0044 using namespace edm::eventsetup;
0045 
0046 namespace {
0047   edm::ParameterSet createDummyPset() {
0048     edm::ParameterSet pset;
0049     std::vector<std::string> emptyVStrings;
0050     pset.addParameter<std::vector<std::string>>("@all_esprefers", emptyVStrings);
0051     pset.addParameter<std::vector<std::string>>("@all_essources", emptyVStrings);
0052     pset.addParameter<std::vector<std::string>>("@all_esmodules", emptyVStrings);
0053     return pset;
0054   }
0055 }  // namespace
0056 
0057 class testdependentrecord : public CppUnit::TestFixture {
0058   CPPUNIT_TEST_SUITE(testdependentrecord);
0059 
0060   CPPUNIT_TEST(dependentConstructorTest);
0061   CPPUNIT_TEST(dependentFinder1Test);
0062   CPPUNIT_TEST(dependentFinder2Test);
0063   CPPUNIT_TEST(testIncomparibleIOVAlgorithm);
0064   CPPUNIT_TEST(testInvalidIOVAlgorithm);
0065   CPPUNIT_TEST(testInvalidIOVFirstTime);
0066   CPPUNIT_TEST(testInvalidIOVFirstEventID);
0067   CPPUNIT_TEST(timeAndRunTest);
0068   CPPUNIT_TEST(dependentSetproviderTest);
0069   CPPUNIT_TEST(getTest);
0070   CPPUNIT_TEST(getDataWithESGetTokenTest);
0071   CPPUNIT_TEST(getHandleWithESGetTokenTest);
0072   CPPUNIT_TEST(getTransientHandleWithESGetTokenTest);
0073   CPPUNIT_TEST(oneOfTwoRecordTest);
0074   CPPUNIT_TEST(resetTest);
0075   CPPUNIT_TEST(alternateFinderTest);
0076   CPPUNIT_TEST(invalidRecordTest);
0077   CPPUNIT_TEST(extendIOVTest);
0078 
0079   CPPUNIT_TEST_SUITE_END();
0080 
0081 public:
0082   void setUp() { m_scheduler = std::make_unique<edm::ThreadsController>(1); }
0083   void tearDown() {}
0084 
0085   void dependentConstructorTest();
0086   void dependentFinder1Test();
0087   void dependentFinder2Test();
0088   void testIncomparibleIOVAlgorithm();
0089   void testInvalidIOVAlgorithm();
0090   void testInvalidIOVFirstTime();
0091   void testInvalidIOVFirstEventID();
0092   void timeAndRunTest();
0093   void dependentSetproviderTest();
0094   void getTest();
0095   void getDataWithESGetTokenTest();
0096   void getHandleWithESGetTokenTest();
0097   void getTransientHandleWithESGetTokenTest();
0098   void oneOfTwoRecordTest();
0099   void resetTest();
0100   void alternateFinderTest();
0101   void invalidRecordTest();
0102   void extendIOVTest();
0103 
0104 private:
0105   edm::propagate_const<std::unique_ptr<edm::ThreadsController>> m_scheduler;
0106 
0107 };  //Cppunit class declaration over
0108 
0109 ///registration of the test so that the runner can find it
0110 CPPUNIT_TEST_SUITE_REGISTRATION(testdependentrecord);
0111 
0112 /* The Records used in the test have the following dependencies
0113    DepRecord -----> DummyRecord
0114                 /
0115    DepOn2Record---> Dummy2Record
0116 
0117  */
0118 
0119 namespace {
0120 
0121   edm::ActivityRegistry activityRegistry;
0122 
0123   class DummyProxyProvider : public edm::eventsetup::DataProxyProvider {
0124   public:
0125     DummyProxyProvider() { usingRecord<DummyRecord>(); }
0126 
0127   protected:
0128     KeyedProxiesVector registerProxies(const EventSetupRecordKey&, unsigned int /* iovIndex */) override {
0129       return KeyedProxiesVector();
0130     }
0131   };
0132 
0133   class DepRecordProxyProvider : public edm::eventsetup::DataProxyProvider {
0134   public:
0135     DepRecordProxyProvider() { usingRecord<DepRecord>(); }
0136 
0137   protected:
0138     KeyedProxiesVector registerProxies(const EventSetupRecordKey&, unsigned int /* iovIndex */) override {
0139       return KeyedProxiesVector();
0140     }
0141   };
0142 
0143   class WorkingDepRecordProxy : public edm::eventsetup::DataProxyTemplate<DepRecord, edm::eventsetup::test::DummyData> {
0144   public:
0145     WorkingDepRecordProxy(const edm::eventsetup::test::DummyData* iDummy) : data_(iDummy) {}
0146 
0147   protected:
0148     const value_type* make(const record_type&, const DataKey&) final { return data_; }
0149     void const* getAfterPrefetchImpl() const final { return data_; }
0150 
0151   private:
0152     const edm::eventsetup::test::DummyData* data_;
0153   };
0154 
0155   class DepRecordProxyProviderWithData : public edm::eventsetup::DataProxyProvider {
0156   public:
0157     DepRecordProxyProviderWithData(const edm::eventsetup::test::DummyData& iData = edm::eventsetup::test::DummyData())
0158         : dummy_(iData) {
0159       usingRecord<DepRecord>();
0160     }
0161 
0162   protected:
0163     KeyedProxiesVector registerProxies(const EventSetupRecordKey&, unsigned int /* iovIndex */) override {
0164       KeyedProxiesVector keyedProxiesVector;
0165       std::shared_ptr<WorkingDepRecordProxy> pProxy = std::make_shared<WorkingDepRecordProxy>(&dummy_);
0166       edm::eventsetup::DataKey dataKey(edm::eventsetup::DataKey::makeTypeTag<edm::eventsetup::test::DummyData>(), "");
0167       keyedProxiesVector.emplace_back(dataKey, pProxy);
0168       return keyedProxiesVector;
0169     }
0170 
0171   private:
0172     edm::eventsetup::test::DummyData dummy_;
0173   };
0174 
0175   class DepOn2RecordProxyProvider : public edm::eventsetup::DataProxyProvider {
0176   public:
0177     DepOn2RecordProxyProvider() { usingRecord<DepOn2Record>(); }
0178 
0179   protected:
0180     KeyedProxiesVector registerProxies(const EventSetupRecordKey&, unsigned int /* iovIndex */) override {
0181       return KeyedProxiesVector();
0182     }
0183   };
0184 
0185   class DepRecordFinder : public edm::EventSetupRecordIntervalFinder {
0186   public:
0187     DepRecordFinder() : edm::EventSetupRecordIntervalFinder(), interval_() { this->findingRecord<DepRecord>(); }
0188 
0189     void setInterval(const edm::ValidityInterval& iInterval) { interval_ = iInterval; }
0190 
0191   protected:
0192     void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0193                         const edm::IOVSyncValue& iTime,
0194                         edm::ValidityInterval& iInterval) override {
0195       if (interval_.validFor(iTime)) {
0196         iInterval = interval_;
0197       } else {
0198         if (interval_.last() == edm::IOVSyncValue::invalidIOVSyncValue() &&
0199             interval_.first() != edm::IOVSyncValue::invalidIOVSyncValue() && interval_.first() <= iTime) {
0200           iInterval = interval_;
0201         } else {
0202           iInterval = edm::ValidityInterval();
0203         }
0204       }
0205     }
0206 
0207   private:
0208     edm::ValidityInterval interval_;
0209   };
0210 
0211   class Dummy2RecordFinder : public edm::EventSetupRecordIntervalFinder {
0212   public:
0213     Dummy2RecordFinder() : edm::EventSetupRecordIntervalFinder(), interval_() { this->findingRecord<Dummy2Record>(); }
0214 
0215     void setInterval(const edm::ValidityInterval& iInterval) { interval_ = iInterval; }
0216 
0217   protected:
0218     void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0219                         const edm::IOVSyncValue& iTime,
0220                         edm::ValidityInterval& iInterval) override {
0221       if (interval_.validFor(iTime)) {
0222         iInterval = interval_;
0223       } else {
0224         if (interval_.last() == edm::IOVSyncValue::invalidIOVSyncValue() &&
0225             interval_.first() != edm::IOVSyncValue::invalidIOVSyncValue() && interval_.first() <= iTime) {
0226           iInterval = interval_;
0227         } else {
0228           iInterval = edm::ValidityInterval();
0229         }
0230       }
0231     }
0232 
0233   private:
0234     edm::ValidityInterval interval_;
0235   };
0236 }  // namespace
0237 
0238 using namespace edm::eventsetup;
0239 void testdependentrecord::dependentConstructorTest() {
0240   EventSetupRecordProvider depProvider(DepRecord::keyForClass(), &activityRegistry);
0241 
0242   CPPUNIT_ASSERT(1 == depProvider.dependentRecords().size());
0243   CPPUNIT_ASSERT(*(depProvider.dependentRecords().begin()) == DummyRecord::keyForClass());
0244 
0245   edm::print_eventsetup_record_dependencies<DepRecord>(std::cout);
0246 }
0247 
0248 void testdependentrecord::dependentFinder1Test() {
0249   auto dummyProvider = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
0250   const edm::EventID eID_1(1, 1, 1);
0251   const edm::IOVSyncValue sync_1(eID_1);
0252   const edm::EventID eID_3(1, 1, 3);
0253   const edm::ValidityInterval definedInterval(sync_1, edm::IOVSyncValue(eID_3));
0254   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
0255   dummyFinder->setInterval(definedInterval);
0256   dummyProvider->addFinder(dummyFinder);
0257 
0258   const EventSetupRecordKey depRecordKey = DepRecord::keyForClass();
0259   DependentRecordIntervalFinder finder(depRecordKey);
0260   finder.addProviderWeAreDependentOn(dummyProvider);
0261 
0262   CPPUNIT_ASSERT(definedInterval == finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 2))));
0263 
0264   dummyFinder->setInterval(edm::ValidityInterval::invalidInterval());
0265   dummyProvider->initializeForNewSyncValue();
0266   CPPUNIT_ASSERT(edm::ValidityInterval::invalidInterval() ==
0267                  finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 4))));
0268 
0269   const edm::EventID eID_5(1, 1, 5);
0270   const edm::IOVSyncValue sync_5(eID_5);
0271   const edm::ValidityInterval unknownedEndInterval(sync_5, edm::IOVSyncValue::invalidIOVSyncValue());
0272   dummyFinder->setInterval(unknownedEndInterval);
0273 
0274   dummyProvider->initializeForNewSyncValue();
0275   CPPUNIT_ASSERT(unknownedEndInterval ==
0276                  finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 5))));
0277 }
0278 
0279 void testdependentrecord::dependentFinder2Test() {
0280   auto dummyProvider1 = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
0281 
0282   const edm::EventID eID_1(1, 1, 1);
0283   const edm::IOVSyncValue sync_1(eID_1);
0284   const edm::ValidityInterval definedInterval1(sync_1, edm::IOVSyncValue(edm::EventID(1, 1, 5)));
0285   dummyProvider1->setValidityInterval_forTesting(definedInterval1);
0286 
0287   auto dummyProvider2 = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
0288 
0289   const edm::EventID eID_2(1, 1, 2);
0290   const edm::IOVSyncValue sync_2(eID_2);
0291   const edm::ValidityInterval definedInterval2(sync_2, edm::IOVSyncValue(edm::EventID(1, 1, 6)));
0292   dummyProvider2->setValidityInterval_forTesting(definedInterval2);
0293 
0294   const edm::ValidityInterval overlapInterval(std::max(definedInterval1.first(), definedInterval2.first()),
0295                                               std::min(definedInterval1.last(), definedInterval2.last()));
0296 
0297   const EventSetupRecordKey depRecordKey = DepRecord::keyForClass();
0298 
0299   DependentRecordIntervalFinder finder(depRecordKey);
0300   finder.addProviderWeAreDependentOn(dummyProvider1);
0301   finder.addProviderWeAreDependentOn(dummyProvider2);
0302 
0303   CPPUNIT_ASSERT(overlapInterval == finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 4))));
0304 }
0305 
0306 void testdependentrecord::testIncomparibleIOVAlgorithm() {
0307   const EventSetupRecordKey depRecordKey = DepRecord::keyForClass();
0308   DependentRecordIntervalFinder finder(depRecordKey);
0309 
0310   //test case where we have two providers, one synching on time the other on run/lumi/event
0311   auto dummyProviderEventID = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
0312   auto dummyProviderTime = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
0313 
0314   finder.addProviderWeAreDependentOn(dummyProviderEventID);
0315   finder.addProviderWeAreDependentOn(dummyProviderTime);
0316 
0317   {
0318     const edm::ValidityInterval iovEventID(edm::IOVSyncValue(edm::EventID(1, 1, 1)),
0319                                            edm::IOVSyncValue(edm::EventID(1, 1, 5)));
0320     dummyProviderEventID->setValidityInterval_forTesting(iovEventID);
0321 
0322     const edm::ValidityInterval iovTime(edm::IOVSyncValue(edm::Timestamp(1)), edm::IOVSyncValue(edm::Timestamp(6)));
0323     dummyProviderTime->setValidityInterval_forTesting(iovTime);
0324 
0325     const edm::ValidityInterval expectedIOV(iovTime.first(), edm::IOVSyncValue::invalidIOVSyncValue());
0326 
0327     // The algorithm selects incomparable IOVs from the two providers based on
0328     // the least estimated time difference from the start of changed IOVs.
0329     // The difference based on lumi numbers is zero in this case (assumes
0330     // 23 second lumis). The difference in times is also zero because it is
0331     // calculating in seconds and the lower 32 bits of the time argument to
0332     // the Timestamp constructor are dropped by the algorithm. So when finding
0333     // the closest both time and eventID estimates are zero. On a tie, the algorithm
0334     // selects the time IOV.
0335     CPPUNIT_ASSERT(expectedIOV ==
0336                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 4), edm::Timestamp(3))));
0337 
0338     // With IOVs that are not comparable we just continually get back the same
0339     // result when none of the IOVs changes. Next 3 just show that.
0340 
0341     //should give back same interval
0342     dummyProviderEventID->initializeForNewSyncValue();
0343     dummyProviderTime->initializeForNewSyncValue();
0344     CPPUNIT_ASSERT(expectedIOV ==
0345                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 4), edm::Timestamp(4))));
0346 
0347     //should give back same interval
0348     dummyProviderEventID->initializeForNewSyncValue();
0349     dummyProviderTime->initializeForNewSyncValue();
0350     CPPUNIT_ASSERT(expectedIOV ==
0351                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 2), edm::Timestamp(3))));
0352 
0353     //should give back same interval
0354     dummyProviderEventID->initializeForNewSyncValue();
0355     dummyProviderTime->initializeForNewSyncValue();
0356     CPPUNIT_ASSERT(expectedIOV ==
0357                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 1), edm::Timestamp(2))));
0358   }
0359   {
0360     //Change only run/lumi/event based provider. The algorithm picks
0361     //the closest of the IOVs that changed, so now gets the EventID based
0362     //IOV.
0363     const edm::ValidityInterval iovEventID(edm::IOVSyncValue(edm::EventID(1, 1, 6)),
0364                                            edm::IOVSyncValue(edm::EventID(1, 1, 10)));
0365     dummyProviderEventID->setValidityInterval_forTesting(iovEventID);
0366 
0367     const edm::ValidityInterval expectedIOV(iovEventID.first(), edm::IOVSyncValue::invalidIOVSyncValue());
0368 
0369     // Don't need to call initializeForNewSyncValue() if setValidityInterval_forTesting
0370     // was called.
0371     dummyProviderTime->initializeForNewSyncValue();
0372     CPPUNIT_ASSERT(expectedIOV ==
0373                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 6), edm::Timestamp(5))));
0374   }
0375   {
0376     //Change only time based provider
0377     const edm::ValidityInterval iovTime(edm::IOVSyncValue(edm::Timestamp(7)), edm::IOVSyncValue(edm::Timestamp(10)));
0378     dummyProviderTime->setValidityInterval_forTesting(iovTime);
0379 
0380     const edm::ValidityInterval expectedIOV(iovTime.first(), edm::IOVSyncValue::invalidIOVSyncValue());
0381 
0382     dummyProviderEventID->initializeForNewSyncValue();
0383     CPPUNIT_ASSERT(expectedIOV ==
0384                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 7), edm::Timestamp(7))));
0385   }
0386   //Change both but make run/lumi/event 'closer' by having same lumi
0387   {
0388     const edm::ValidityInterval iovEventID(edm::IOVSyncValue(edm::EventID(1, 2, 11)),
0389                                            edm::IOVSyncValue(edm::EventID(1, 3, 20)));
0390     dummyProviderEventID->setValidityInterval_forTesting(iovEventID);
0391 
0392     const edm::ValidityInterval iovTime(edm::IOVSyncValue(edm::Timestamp(1ULL << 32)),
0393                                         edm::IOVSyncValue(edm::Timestamp(5ULL << 32)));
0394     dummyProviderTime->setValidityInterval_forTesting(iovTime);
0395 
0396     const edm::ValidityInterval expectedIOV(iovEventID.first(), edm::IOVSyncValue::invalidIOVSyncValue());
0397     CPPUNIT_ASSERT(
0398         expectedIOV ==
0399         finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 2, 12), edm::Timestamp(3ULL << 32))));
0400   }
0401   //Change both but make time 'closer'
0402   {
0403     const edm::ValidityInterval iovEventID(edm::IOVSyncValue(edm::EventID(1, 3, 21)),
0404                                            edm::IOVSyncValue(edm::EventID(1, 10, 40)));
0405     dummyProviderEventID->setValidityInterval_forTesting(iovEventID);
0406 
0407     const edm::ValidityInterval iovTime(edm::IOVSyncValue(edm::Timestamp(7ULL << 32)),
0408                                         edm::IOVSyncValue(edm::Timestamp(10ULL << 32)));
0409     dummyProviderTime->setValidityInterval_forTesting(iovTime);
0410 
0411     const edm::ValidityInterval expectedIOV(iovTime.first(), edm::IOVSyncValue::invalidIOVSyncValue());
0412     CPPUNIT_ASSERT(
0413         expectedIOV ==
0414         finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 4, 30), edm::Timestamp(8ULL << 32))));
0415   }
0416   //Change both but make run/lumi/event 'closer'
0417   {
0418     const edm::ValidityInterval iovEventID(edm::IOVSyncValue(edm::EventID(1, 11, 41)),
0419                                            edm::IOVSyncValue(edm::EventID(1, 20, 60)));
0420     dummyProviderEventID->setValidityInterval_forTesting(iovEventID);
0421 
0422     const edm::ValidityInterval iovTime(edm::IOVSyncValue(edm::Timestamp(11ULL << 32)),
0423                                         edm::IOVSyncValue(edm::Timestamp(100ULL << 32)));
0424     dummyProviderTime->setValidityInterval_forTesting(iovTime);
0425 
0426     const edm::ValidityInterval expectedIOV(iovEventID.first(), edm::IOVSyncValue::invalidIOVSyncValue());
0427     CPPUNIT_ASSERT(
0428         expectedIOV ==
0429         finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 12, 50), edm::Timestamp(70ULL << 32))));
0430   }
0431 
0432   //Change both and make it ambiguous because of different run #
0433   {
0434     const edm::ValidityInterval iovEventID(edm::IOVSyncValue(edm::EventID(2, 1, 0)),
0435                                            edm::IOVSyncValue(edm::EventID(6, 0, 0)));
0436     dummyProviderEventID->setValidityInterval_forTesting(iovEventID);
0437 
0438     const edm::ValidityInterval iovTime(edm::IOVSyncValue(edm::Timestamp(200ULL << 32)),
0439                                         edm::IOVSyncValue(edm::Timestamp(500ULL << 32)));
0440     dummyProviderTime->setValidityInterval_forTesting(iovTime);
0441 
0442     const edm::ValidityInterval expectedIOV(iovTime.first(), edm::IOVSyncValue::invalidIOVSyncValue());
0443     CPPUNIT_ASSERT(
0444         expectedIOV ==
0445         finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(4, 12, 50), edm::Timestamp(400ULL << 32))));
0446   }
0447   {
0448     const edm::ValidityInterval iovEventID(edm::IOVSyncValue(edm::EventID(1, 1, 6)),
0449                                            edm::IOVSyncValue(edm::EventID(1, 1, 10)));
0450     dummyProviderEventID->setValidityInterval_forTesting(iovEventID);
0451 
0452     const edm::ValidityInterval iovTime(edm::IOVSyncValue(edm::Timestamp(7)), edm::IOVSyncValue(edm::Timestamp(10)));
0453     dummyProviderTime->setValidityInterval_forTesting(iovTime);
0454 
0455     const edm::ValidityInterval expectedIOV(iovTime.first(), edm::IOVSyncValue::invalidIOVSyncValue());
0456     CPPUNIT_ASSERT(expectedIOV ==
0457                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 7), edm::Timestamp(7))));
0458   }
0459 }
0460 
0461 void testdependentrecord::testInvalidIOVAlgorithm() {
0462   const EventSetupRecordKey depRecordKey = DepRecord::keyForClass();
0463   DependentRecordIntervalFinder finder(depRecordKey);
0464 
0465   auto dummyProviderEventID = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
0466   auto dummyProviderTime = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
0467 
0468   finder.addProviderWeAreDependentOn(dummyProviderEventID);
0469   finder.addProviderWeAreDependentOn(dummyProviderTime);
0470 
0471   {
0472     const edm::ValidityInterval iovEventID(edm::IOVSyncValue(edm::EventID(1, 1, 6)),
0473                                            edm::IOVSyncValue(edm::EventID(1, 1, 10)));
0474     dummyProviderEventID->setValidityInterval_forTesting(iovEventID);
0475 
0476     const edm::ValidityInterval iovTime(edm::IOVSyncValue(edm::Timestamp(7)), edm::IOVSyncValue(edm::Timestamp(10)));
0477     dummyProviderTime->setValidityInterval_forTesting(iovTime);
0478 
0479     const edm::ValidityInterval expectedIOV(iovTime.first(), edm::IOVSyncValue::invalidIOVSyncValue());
0480     CPPUNIT_ASSERT(expectedIOV ==
0481                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 7), edm::Timestamp(7))));
0482   }
0483 
0484   //check with invalid intervals
0485   const edm::ValidityInterval invalid(edm::IOVSyncValue::invalidIOVSyncValue(),
0486                                       edm::IOVSyncValue::invalidIOVSyncValue());
0487   {
0488     dummyProviderEventID->setValidityInterval_forTesting(invalid);
0489     dummyProviderTime->initializeForNewSyncValue();
0490     const edm::ValidityInterval expectedIOV(edm::IOVSyncValue(edm::Timestamp(7)),
0491                                             edm::IOVSyncValue::invalidIOVSyncValue());
0492     CPPUNIT_ASSERT(expectedIOV ==
0493                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 11), edm::Timestamp(8))));
0494   }
0495   {
0496     const edm::ValidityInterval iovEventID(edm::IOVSyncValue(edm::EventID(1, 1, 12)),
0497                                            edm::IOVSyncValue(edm::EventID(1, 1, 20)));
0498     dummyProviderEventID->setValidityInterval_forTesting(iovEventID);
0499     dummyProviderTime->setValidityInterval_forTesting(invalid);
0500     const edm::ValidityInterval expectedIOV(iovEventID.first(), edm::IOVSyncValue::invalidIOVSyncValue());
0501     CPPUNIT_ASSERT(expectedIOV ==
0502                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 13), edm::Timestamp(11))));
0503   }
0504   {
0505     dummyProviderEventID->setValidityInterval_forTesting(invalid);
0506     dummyProviderTime->setValidityInterval_forTesting(invalid);
0507 
0508     dummyProviderEventID->initializeForNewSyncValue();
0509     CPPUNIT_ASSERT(invalid ==
0510                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 13), edm::Timestamp(11))));
0511   }
0512 }
0513 
0514 void testdependentrecord::testInvalidIOVFirstTime() {
0515   const EventSetupRecordKey depRecordKey = DepRecord::keyForClass();
0516   DependentRecordIntervalFinder finder(depRecordKey);
0517 
0518   auto dummyProviderEventID = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
0519   auto dummyProviderTime = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
0520 
0521   finder.addProviderWeAreDependentOn(dummyProviderEventID);
0522   finder.addProviderWeAreDependentOn(dummyProviderTime);
0523 
0524   const edm::ValidityInterval invalid(edm::IOVSyncValue::invalidIOVSyncValue(),
0525                                       edm::IOVSyncValue::invalidIOVSyncValue());
0526   {
0527     //check for bug which only happens the first time we synchronize
0528     // have the second one invalid
0529     const edm::ValidityInterval iovEventID(edm::IOVSyncValue(edm::EventID(1, 1, 1)),
0530                                            edm::IOVSyncValue(edm::EventID(1, 1, 6)));
0531     dummyProviderEventID->setValidityInterval_forTesting(iovEventID);
0532 
0533     dummyProviderTime->setValidityInterval_forTesting(invalid);
0534 
0535     const edm::ValidityInterval expectedIOV(iovEventID.first(), edm::IOVSyncValue::invalidIOVSyncValue());
0536 
0537     CPPUNIT_ASSERT(expectedIOV ==
0538                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 4), edm::Timestamp(1))));
0539   }
0540   {
0541     const edm::ValidityInterval iovTime(edm::IOVSyncValue(edm::Timestamp(2)), edm::IOVSyncValue(edm::Timestamp(6)));
0542     dummyProviderTime->setValidityInterval_forTesting(iovTime);
0543 
0544     const edm::ValidityInterval expectedIOV(iovTime.first(), edm::IOVSyncValue::invalidIOVSyncValue());
0545 
0546     dummyProviderEventID->initializeForNewSyncValue();
0547     CPPUNIT_ASSERT(expectedIOV ==
0548                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 5), edm::Timestamp(3))));
0549   }
0550 }
0551 
0552 void testdependentrecord::testInvalidIOVFirstEventID() {
0553   const EventSetupRecordKey depRecordKey = DepRecord::keyForClass();
0554   DependentRecordIntervalFinder finder(depRecordKey);
0555 
0556   auto dummyProviderEventID = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
0557   auto dummyProviderTime = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
0558 
0559   finder.addProviderWeAreDependentOn(dummyProviderEventID);
0560   finder.addProviderWeAreDependentOn(dummyProviderTime);
0561 
0562   const edm::ValidityInterval invalid(edm::IOVSyncValue::invalidIOVSyncValue(),
0563                                       edm::IOVSyncValue::invalidIOVSyncValue());
0564   {
0565     //check for bug which only happens the first time we synchronize
0566     // have the  first one invalid
0567     dummyProviderEventID->setValidityInterval_forTesting(invalid);
0568 
0569     const edm::ValidityInterval iovTime(edm::IOVSyncValue(edm::Timestamp(1)), edm::IOVSyncValue(edm::Timestamp(6)));
0570     dummyProviderTime->setValidityInterval_forTesting(iovTime);
0571 
0572     const edm::ValidityInterval expectedIOV(iovTime.first(), edm::IOVSyncValue::invalidIOVSyncValue());
0573 
0574     CPPUNIT_ASSERT(expectedIOV ==
0575                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 4), edm::Timestamp(3))));
0576   }
0577   {
0578     const edm::ValidityInterval iovEventID(edm::IOVSyncValue(edm::EventID(1, 1, 5)),
0579                                            edm::IOVSyncValue(edm::EventID(1, 1, 10)));
0580     dummyProviderEventID->setValidityInterval_forTesting(iovEventID);
0581 
0582     const edm::ValidityInterval expectedIOV(edm::IOVSyncValue(edm::Timestamp(1)),
0583                                             edm::IOVSyncValue::invalidIOVSyncValue());
0584     dummyProviderTime->initializeForNewSyncValue();
0585     CPPUNIT_ASSERT(expectedIOV ==
0586                    finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 5), edm::Timestamp(4))));
0587   }
0588 }
0589 
0590 void testdependentrecord::timeAndRunTest() {
0591   edm::ParameterSet pset = createDummyPset();
0592   {
0593     SynchronousEventSetupsController controller;
0594     EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0595 
0596     std::shared_ptr<edm::eventsetup::DataProxyProvider> dummyProv = std::make_shared<DummyProxyProvider>();
0597     provider.add(dummyProv);
0598 
0599     std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
0600     dummyFinder->setInterval(
0601         edm::ValidityInterval(edm::IOVSyncValue(edm::EventID(1, 1, 1)), edm::IOVSyncValue(edm::EventID(1, 1, 5))));
0602     provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
0603 
0604     std::shared_ptr<edm::eventsetup::DataProxyProvider> depProv = std::make_shared<DepOn2RecordProxyProvider>();
0605     provider.add(depProv);
0606 
0607     std::shared_ptr<Dummy2RecordFinder> dummy2Finder = std::make_shared<Dummy2RecordFinder>();
0608     dummy2Finder->setInterval(
0609         edm::ValidityInterval(edm::IOVSyncValue(edm::Timestamp(1)), edm::IOVSyncValue(edm::Timestamp(5))));
0610     provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummy2Finder));
0611 
0612     {
0613       edm::ESParentContext parentC;
0614       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 1), edm::Timestamp(1)));
0615       const edm::EventSetup eventSetup1(provider.eventSetupImpl(), 0, nullptr, parentC);
0616       long long id1 = eventSetup1.get<DepOn2Record>().cacheIdentifier();
0617 
0618       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 1), edm::Timestamp(2)));
0619       const edm::EventSetup eventSetup2(provider.eventSetupImpl(), 0, nullptr, parentC);
0620       long long id2 = eventSetup2.get<DepOn2Record>().cacheIdentifier();
0621       CPPUNIT_ASSERT(id1 == id2);
0622 
0623       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 2), edm::Timestamp(2)));
0624       const edm::EventSetup eventSetup3(provider.eventSetupImpl(), 0, nullptr, parentC);
0625       long long id3 = eventSetup3.get<DepOn2Record>().cacheIdentifier();
0626       CPPUNIT_ASSERT(id1 == id3);
0627 
0628       dummy2Finder->setInterval(
0629           edm::ValidityInterval(edm::IOVSyncValue(edm::Timestamp(6)), edm::IOVSyncValue(edm::Timestamp(10))));
0630 
0631       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 4), edm::Timestamp(7)));
0632       const edm::EventSetup eventSetup4(provider.eventSetupImpl(), 0, nullptr, parentC);
0633       long long id4 = eventSetup4.get<DepOn2Record>().cacheIdentifier();
0634       CPPUNIT_ASSERT(id1 != id4);
0635 
0636       dummyFinder->setInterval(
0637           edm::ValidityInterval(edm::IOVSyncValue(edm::EventID(1, 1, 6)), edm::IOVSyncValue(edm::EventID(1, 1, 10))));
0638 
0639       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 7), edm::Timestamp(8)));
0640       const edm::EventSetup eventSetup5(provider.eventSetupImpl(), 0, nullptr, parentC);
0641       long long id5 = eventSetup5.get<DepOn2Record>().cacheIdentifier();
0642       CPPUNIT_ASSERT(id4 != id5);
0643     }
0644   }
0645 
0646   {
0647     //check that going all the way through EventSetup works properly
0648     // using two records with open ended IOVs
0649     SynchronousEventSetupsController controller;
0650     EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0651 
0652     std::shared_ptr<edm::eventsetup::DataProxyProvider> dummyProv = std::make_shared<DummyProxyProvider>();
0653     provider.add(dummyProv);
0654 
0655     std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
0656     dummyFinder->setInterval(
0657         edm::ValidityInterval(edm::IOVSyncValue(edm::EventID(1, 1, 1)), edm::IOVSyncValue::invalidIOVSyncValue()));
0658     provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
0659 
0660     std::shared_ptr<edm::eventsetup::DataProxyProvider> depProv = std::make_shared<DepOn2RecordProxyProvider>();
0661     provider.add(depProv);
0662 
0663     std::shared_ptr<Dummy2RecordFinder> dummy2Finder = std::make_shared<Dummy2RecordFinder>();
0664     dummy2Finder->setInterval(
0665         edm::ValidityInterval(edm::IOVSyncValue(edm::Timestamp(1)), edm::IOVSyncValue::invalidIOVSyncValue()));
0666     provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummy2Finder));
0667     {
0668       edm::ESParentContext parentC;
0669       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 1), edm::Timestamp(1)));
0670       const edm::EventSetup eventSetup1(provider.eventSetupImpl(), 0, nullptr, parentC);
0671       long long id1 = eventSetup1.get<DepOn2Record>().cacheIdentifier();
0672 
0673       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 1), edm::Timestamp(2)));
0674       const edm::EventSetup eventSetup2(provider.eventSetupImpl(), 0, nullptr, parentC);
0675       long long id2 = eventSetup2.get<DepOn2Record>().cacheIdentifier();
0676       CPPUNIT_ASSERT(id1 == id2);
0677 
0678       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 2), edm::Timestamp(2)));
0679       const edm::EventSetup eventSetup3(provider.eventSetupImpl(), 0, nullptr, parentC);
0680       long long id3 = eventSetup3.get<DepOn2Record>().cacheIdentifier();
0681       CPPUNIT_ASSERT(id1 == id3);
0682 
0683       dummy2Finder->setInterval(
0684           edm::ValidityInterval(edm::IOVSyncValue(edm::Timestamp(6)), edm::IOVSyncValue::invalidIOVSyncValue()));
0685       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 4), edm::Timestamp(7)));
0686       const edm::EventSetup eventSetup4(provider.eventSetupImpl(), 0, nullptr, parentC);
0687       long long id4 = eventSetup4.get<DepOn2Record>().cacheIdentifier();
0688       CPPUNIT_ASSERT(id1 != id4);
0689 
0690       dummyFinder->setInterval(
0691           edm::ValidityInterval(edm::IOVSyncValue(edm::EventID(1, 1, 6)), edm::IOVSyncValue::invalidIOVSyncValue()));
0692       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 7), edm::Timestamp(8)));
0693       const edm::EventSetup eventSetup5(provider.eventSetupImpl(), 0, nullptr, parentC);
0694       long long id5 = eventSetup5.get<DepOn2Record>().cacheIdentifier();
0695       CPPUNIT_ASSERT(id4 != id5);
0696     }
0697   }
0698 }
0699 
0700 void testdependentrecord::dependentSetproviderTest() {
0701   auto depProvider = std::make_unique<EventSetupRecordProvider>(DepRecord::keyForClass(), &activityRegistry);
0702 
0703   auto dummyProvider = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
0704 
0705   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
0706   dummyFinder->setInterval(
0707       edm::ValidityInterval(edm::IOVSyncValue(edm::EventID(1, 1, 1)), edm::IOVSyncValue(edm::EventID(1, 1, 3))));
0708   dummyProvider->addFinder(dummyFinder);
0709 
0710   CPPUNIT_ASSERT(*(depProvider->dependentRecords().begin()) == dummyProvider->key());
0711 
0712   std::vector<std::shared_ptr<EventSetupRecordProvider>> providers;
0713   providers.push_back(dummyProvider);
0714   depProvider->setDependentProviders(providers);
0715 }
0716 
0717 void testdependentrecord::getTest() {
0718   SynchronousEventSetupsController controller;
0719   edm::ParameterSet pset = createDummyPset();
0720   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0721 
0722   std::shared_ptr<edm::eventsetup::DataProxyProvider> dummyProv = std::make_shared<DummyProxyProvider>();
0723   provider.add(dummyProv);
0724 
0725   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
0726   dummyFinder->setInterval(
0727       edm::ValidityInterval(edm::IOVSyncValue(edm::EventID(1, 1, 1)), edm::IOVSyncValue(edm::EventID(1, 1, 3))));
0728   provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
0729 
0730   std::shared_ptr<edm::eventsetup::DataProxyProvider> depProv = std::make_shared<DepRecordProxyProvider>();
0731   provider.add(depProv);
0732   edm::ESParentContext parentC;
0733   {
0734     controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 1)));
0735     const edm::EventSetup eventSetup1(provider.eventSetupImpl(), 0, nullptr, parentC);
0736     const DepRecord& depRecord = eventSetup1.get<DepRecord>();
0737 
0738     depRecord.getRecord<DummyRecord>();
0739 
0740     auto dr = depRecord.tryToGetRecord<DummyRecord>();
0741     CPPUNIT_ASSERT(dr.has_value());
0742   }
0743   {
0744     controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 4)));
0745     const edm::EventSetup eventSetup2(provider.eventSetupImpl(), 0, nullptr, parentC);
0746     CPPUNIT_ASSERT_THROW(eventSetup2.get<DepRecord>(), edm::eventsetup::NoRecordException<DepRecord>);
0747   }
0748 }
0749 
0750 namespace {
0751   template <typename RECORD>
0752   struct DummyDataConsumer : public edm::EDConsumerBase {
0753     explicit DummyDataConsumer(edm::ESInputTag const& iTag)
0754         : m_token{esConsumes<edm::eventsetup::test::DummyData, RECORD>(iTag)} {}
0755 
0756     void prefetch(edm::EventSetupImpl const& iImpl) const {
0757       auto const& recs = this->esGetTokenRecordIndicesVector(edm::Transition::Event);
0758       auto const& proxies = this->esGetTokenIndicesVector(edm::Transition::Event);
0759       for (size_t i = 0; i != proxies.size(); ++i) {
0760         auto rec = iImpl.findImpl(recs[i]);
0761         if (rec) {
0762           oneapi::tbb::task_group group;
0763           edm::FinalWaitingTask waitTask{group};
0764           edm::ServiceToken token;
0765           rec->prefetchAsync(
0766               edm::WaitingTaskHolder(group, &waitTask), proxies[i], &iImpl, token, edm::ESParentContext{});
0767           waitTask.wait();
0768         }
0769       }
0770     }
0771     edm::ESGetToken<edm::eventsetup::test::DummyData, RECORD> m_token;
0772   };
0773 
0774   template <typename RECORD1, typename RECORD2>
0775   struct DummyDataConsumer2 : public edm::EDConsumerBase {
0776     explicit DummyDataConsumer2(edm::ESInputTag const& iTag1, edm::ESInputTag const& iTag2)
0777         : m_token1{esConsumes<edm::eventsetup::test::DummyData, RECORD1>(iTag1)},
0778           m_token2{esConsumes<edm::eventsetup::test::DummyData, RECORD2>(iTag2)} {}
0779 
0780     void prefetch(edm::EventSetupImpl const& iImpl) const {
0781       auto const& recs = this->esGetTokenRecordIndicesVector(edm::Transition::Event);
0782       auto const& proxies = this->esGetTokenIndicesVector(edm::Transition::Event);
0783       for (size_t i = 0; i != proxies.size(); ++i) {
0784         auto rec = iImpl.findImpl(recs[i]);
0785         if (rec) {
0786           oneapi::tbb::task_group group;
0787           edm::FinalWaitingTask waitTask{group};
0788           edm::ServiceToken token;
0789           rec->prefetchAsync(
0790               edm::WaitingTaskHolder(group, &waitTask), proxies[i], &iImpl, token, edm::ESParentContext{});
0791           waitTask.wait();
0792         }
0793       }
0794     }
0795 
0796     edm::ESGetToken<edm::eventsetup::test::DummyData, RECORD1> m_token1;
0797     edm::ESGetToken<edm::eventsetup::test::DummyData, RECORD2> m_token2;
0798   };
0799 }  // namespace
0800 
0801 void testdependentrecord::getDataWithESGetTokenTest() {
0802   using edm::eventsetup::test::DummyData;
0803   using edm::eventsetup::test::DummyProxyProvider;
0804   DummyData kGood{1};
0805   DummyData kBad{0};
0806 
0807   SynchronousEventSetupsController controller;
0808   edm::ParameterSet pset = createDummyPset();
0809   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0810 
0811   try {
0812     {
0813       edm::eventsetup::ComponentDescription description("DummyProxyProvider", "testOne", 0, true);
0814       edm::ParameterSet ps;
0815       ps.addParameter<std::string>("name", "test11");
0816       ps.registerIt();
0817       description.pid_ = ps.id();
0818       auto dummyProv = std::make_shared<DummyProxyProvider>(kBad);
0819       dummyProv->setDescription(description);
0820       provider.add(dummyProv);
0821     }
0822     {
0823       edm::eventsetup::ComponentDescription description("DepRecordProxyProviderWithData", "testTwo", 1, true);
0824       edm::ParameterSet ps;
0825       ps.addParameter<std::string>("name", "test22");
0826       ps.addParameter<std::string>("appendToDataLabel", "blah");
0827       ps.registerIt();
0828       description.pid_ = ps.id();
0829       auto dummyProv = std::make_shared<DepRecordProxyProviderWithData>(kGood);
0830       dummyProv->setDescription(description);
0831       dummyProv->setAppendToDataLabel(ps);
0832       provider.add(dummyProv);
0833     }
0834 
0835     std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
0836     dummyFinder->setInterval(
0837         edm::ValidityInterval(edm::IOVSyncValue(edm::EventID(1, 1, 1)), edm::IOVSyncValue(edm::EventID(1, 1, 3))));
0838     provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
0839 
0840     controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 1)));
0841     edm::ESParentContext parentC;
0842     {
0843       DummyDataConsumer<DepRecord> consumer{edm::ESInputTag{"", "blah"}};
0844       consumer.updateLookup(provider.recordsToProxyIndices());
0845       consumer.prefetch(provider.eventSetupImpl());
0846       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
0847                                        static_cast<unsigned int>(edm::Transition::Event),
0848                                        consumer.esGetTokenIndices(edm::Transition::Event),
0849                                        parentC};
0850       auto const& data = eventSetup.getData(consumer.m_token);
0851       CPPUNIT_ASSERT(kGood.value_ == data.value_);
0852     }
0853     {
0854       DummyDataConsumer<DummyRecord> consumer{edm::ESInputTag{"", ""}};
0855       consumer.updateLookup(provider.recordsToProxyIndices());
0856       consumer.prefetch(provider.eventSetupImpl());
0857       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
0858                                        static_cast<unsigned int>(edm::Transition::Event),
0859                                        consumer.esGetTokenIndices(edm::Transition::Event),
0860                                        parentC};
0861       auto const& data = eventSetup.getData(consumer.m_token);
0862       CPPUNIT_ASSERT(kBad.value_ == data.value_);
0863     }
0864     {
0865       DummyDataConsumer<DepRecord> consumer{edm::ESInputTag{"", "blah"}};
0866       consumer.updateLookup(provider.recordsToProxyIndices());
0867       consumer.prefetch(provider.eventSetupImpl());
0868       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
0869                                        static_cast<unsigned int>(edm::Transition::Event),
0870                                        consumer.esGetTokenIndices(edm::Transition::Event),
0871                                        parentC};
0872       auto const& depRecord = eventSetup.get<DepRecord>();
0873       auto const& data = depRecord.get(consumer.m_token);
0874       CPPUNIT_ASSERT(kGood.value_ == data.value_);
0875     }
0876     {
0877       DummyDataConsumer<DummyRecord> consumer{edm::ESInputTag{"", ""}};
0878       consumer.updateLookup(provider.recordsToProxyIndices());
0879       consumer.prefetch(provider.eventSetupImpl());
0880       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
0881                                        static_cast<unsigned int>(edm::Transition::Event),
0882                                        consumer.esGetTokenIndices(edm::Transition::Event),
0883                                        parentC};
0884       auto const& depRecord = eventSetup.get<DepRecord>();
0885 
0886       auto const& data = depRecord.get(consumer.m_token);
0887       CPPUNIT_ASSERT(kBad.value_ == data.value_);
0888     }
0889     {
0890       DummyDataConsumer<DepRecord> consumer{edm::ESInputTag{"", "blah"}};
0891       consumer.updateLookup(provider.recordsToProxyIndices());
0892       consumer.prefetch(provider.eventSetupImpl());
0893       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
0894                                        static_cast<unsigned int>(edm::Transition::Event),
0895                                        consumer.esGetTokenIndices(edm::Transition::Event),
0896                                        parentC};
0897       auto const& depRecord = eventSetup.get<DepRecord>();
0898 
0899       auto const& data = depRecord.get(consumer.m_token);
0900       CPPUNIT_ASSERT(kGood.value_ == data.value_);
0901     }
0902     {
0903       DummyDataConsumer2<DummyRecord, DepRecord> consumer{edm::ESInputTag{"", ""}, edm::ESInputTag{"", "blah"}};
0904       consumer.updateLookup(provider.recordsToProxyIndices());
0905       consumer.prefetch(provider.eventSetupImpl());
0906       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
0907                                        static_cast<unsigned int>(edm::Transition::Event),
0908                                        consumer.esGetTokenIndices(edm::Transition::Event),
0909                                        parentC};
0910       auto const& depRecord = eventSetup.get<DepRecord>();
0911 
0912       auto const& data1 = depRecord.get(consumer.m_token1);
0913       CPPUNIT_ASSERT(kBad.value_ == data1.value_);
0914 
0915       auto const& data2 = depRecord.get(consumer.m_token2);
0916       CPPUNIT_ASSERT(kGood.value_ == data2.value_);
0917     }
0918     {
0919       DummyDataConsumer<DummyRecord> consumer{edm::ESInputTag{"DoesNotExist", ""}};
0920       consumer.updateLookup(provider.recordsToProxyIndices());
0921       consumer.prefetch(provider.eventSetupImpl());
0922       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
0923                                        static_cast<unsigned int>(edm::Transition::Event),
0924                                        consumer.esGetTokenIndices(edm::Transition::Event),
0925                                        parentC};
0926       auto const& depRecord = eventSetup.get<DepRecord>();
0927 
0928       CPPUNIT_ASSERT_THROW(depRecord.get(consumer.m_token), cms::Exception);
0929     }
0930     {
0931       DummyDataConsumer<DepRecord> consumer{edm::ESInputTag{"DoesNotExist", "blah"}};
0932       consumer.updateLookup(provider.recordsToProxyIndices());
0933       consumer.prefetch(provider.eventSetupImpl());
0934       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
0935                                        static_cast<unsigned int>(edm::Transition::Event),
0936                                        consumer.esGetTokenIndices(edm::Transition::Event),
0937                                        parentC};
0938       auto const& depRecord = eventSetup.get<DepRecord>();
0939 
0940       CPPUNIT_ASSERT_THROW(depRecord.get(consumer.m_token), cms::Exception);
0941     }
0942   } catch (const cms::Exception& iException) {
0943     std::cout << "caught " << iException.explainSelf() << std::endl;
0944     throw;
0945   }
0946 }
0947 
0948 void testdependentrecord::getHandleWithESGetTokenTest() {
0949   using edm::eventsetup::test::DummyData;
0950   using edm::eventsetup::test::DummyProxyProvider;
0951   DummyData kGood{1};
0952   DummyData kBad{0};
0953 
0954   SynchronousEventSetupsController controller;
0955   edm::ParameterSet pset = createDummyPset();
0956   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0957 
0958   try {
0959     {
0960       edm::eventsetup::ComponentDescription description("DummyProxyProvider", "testOne", 0, true);
0961       edm::ParameterSet ps;
0962       ps.addParameter<std::string>("name", "test11");
0963       ps.registerIt();
0964       description.pid_ = ps.id();
0965       auto dummyProv = std::make_shared<DummyProxyProvider>(kBad);
0966       dummyProv->setDescription(description);
0967       provider.add(dummyProv);
0968     }
0969     {
0970       edm::eventsetup::ComponentDescription description("DepRecordProxyProviderWithData", "testTwo", 1, true);
0971       edm::ParameterSet ps;
0972       ps.addParameter<std::string>("name", "test22");
0973       ps.addParameter<std::string>("appendToDataLabel", "blah");
0974       ps.registerIt();
0975       description.pid_ = ps.id();
0976       auto dummyProv = std::make_shared<DepRecordProxyProviderWithData>(kGood);
0977       dummyProv->setDescription(description);
0978       dummyProv->setAppendToDataLabel(ps);
0979       provider.add(dummyProv);
0980     }
0981     std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
0982     dummyFinder->setInterval(
0983         edm::ValidityInterval(edm::IOVSyncValue(edm::EventID(1, 1, 1)), edm::IOVSyncValue(edm::EventID(1, 1, 3))));
0984     provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
0985 
0986     controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 1)));
0987 
0988     edm::ESParentContext parentC;
0989     {
0990       DummyDataConsumer<DepRecord> consumer{edm::ESInputTag{"", "blah"}};
0991       consumer.updateLookup(provider.recordsToProxyIndices());
0992       consumer.prefetch(provider.eventSetupImpl());
0993       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
0994                                        static_cast<unsigned int>(edm::Transition::Event),
0995                                        consumer.esGetTokenIndices(edm::Transition::Event),
0996                                        parentC};
0997       edm::ESHandle<DummyData> data = eventSetup.getHandle(consumer.m_token);
0998       CPPUNIT_ASSERT(kGood.value_ == data->value_);
0999       const edm::eventsetup::ComponentDescription* desc = data.description();
1000       CPPUNIT_ASSERT(desc->label_ == "testTwo");
1001     }
1002     {
1003       DummyDataConsumer<DummyRecord> consumer{edm::ESInputTag{"", ""}};
1004       consumer.updateLookup(provider.recordsToProxyIndices());
1005       consumer.prefetch(provider.eventSetupImpl());
1006       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1007                                        static_cast<unsigned int>(edm::Transition::Event),
1008                                        consumer.esGetTokenIndices(edm::Transition::Event),
1009                                        parentC};
1010       edm::ESHandle<DummyData> data = eventSetup.getHandle(consumer.m_token);
1011       CPPUNIT_ASSERT(kBad.value_ == data->value_);
1012       const edm::eventsetup::ComponentDescription* desc = data.description();
1013       CPPUNIT_ASSERT(desc->label_ == "testOne");
1014     }
1015     {
1016       DummyDataConsumer<DepRecord> consumer{edm::ESInputTag{"", "blah"}};
1017       consumer.updateLookup(provider.recordsToProxyIndices());
1018       consumer.prefetch(provider.eventSetupImpl());
1019       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1020                                        static_cast<unsigned int>(edm::Transition::Event),
1021                                        consumer.esGetTokenIndices(edm::Transition::Event),
1022                                        parentC};
1023       auto const& depRecord = eventSetup.get<DepRecord>();
1024 
1025       edm::ESHandle<DummyData> data = depRecord.getHandle(consumer.m_token);
1026       CPPUNIT_ASSERT(kGood.value_ == data->value_);
1027       const edm::eventsetup::ComponentDescription* desc = data.description();
1028       CPPUNIT_ASSERT(desc->label_ == "testTwo");
1029     }
1030     {
1031       DummyDataConsumer<DummyRecord> consumer{edm::ESInputTag{"", ""}};
1032       consumer.updateLookup(provider.recordsToProxyIndices());
1033       consumer.prefetch(provider.eventSetupImpl());
1034       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1035                                        static_cast<unsigned int>(edm::Transition::Event),
1036                                        consumer.esGetTokenIndices(edm::Transition::Event),
1037                                        parentC};
1038       auto const& depRecord = eventSetup.get<DepRecord>();
1039 
1040       edm::ESHandle<DummyData> data = depRecord.getHandle(consumer.m_token);
1041       CPPUNIT_ASSERT(kBad.value_ == data->value_);
1042       const edm::eventsetup::ComponentDescription* desc = data.description();
1043       CPPUNIT_ASSERT(desc->label_ == "testOne");
1044     }
1045     {
1046       DummyDataConsumer<DepRecord> consumer{edm::ESInputTag{"", "blah"}};
1047       consumer.updateLookup(provider.recordsToProxyIndices());
1048       consumer.prefetch(provider.eventSetupImpl());
1049       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1050                                        static_cast<unsigned int>(edm::Transition::Event),
1051                                        consumer.esGetTokenIndices(edm::Transition::Event),
1052                                        parentC};
1053       auto const& depRecord = eventSetup.get<DepRecord>();
1054 
1055       edm::ESHandle<DummyData> data = depRecord.getHandle(consumer.m_token);
1056       CPPUNIT_ASSERT(kGood.value_ == data->value_);
1057       const edm::eventsetup::ComponentDescription* desc = data.description();
1058       CPPUNIT_ASSERT(desc->label_ == "testTwo");
1059     }
1060     {
1061       DummyDataConsumer2<DummyRecord, DepRecord> consumer{edm::ESInputTag{"", ""}, edm::ESInputTag{"", "blah"}};
1062       consumer.updateLookup(provider.recordsToProxyIndices());
1063       consumer.prefetch(provider.eventSetupImpl());
1064       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1065                                        static_cast<unsigned int>(edm::Transition::Event),
1066                                        consumer.esGetTokenIndices(edm::Transition::Event),
1067                                        parentC};
1068       auto const& depRecord = eventSetup.get<DepRecord>();
1069 
1070       edm::ESHandle<DummyData> data1 = depRecord.getHandle(consumer.m_token1);
1071       CPPUNIT_ASSERT(kBad.value_ == data1->value_);
1072       const edm::eventsetup::ComponentDescription* desc = data1.description();
1073       CPPUNIT_ASSERT(desc->label_ == "testOne");
1074 
1075       edm::ESHandle<DummyData> data2 = depRecord.getHandle(consumer.m_token2);
1076       CPPUNIT_ASSERT(kGood.value_ == data2->value_);
1077       desc = data2.description();
1078       CPPUNIT_ASSERT(desc->label_ == "testTwo");
1079     }
1080     {
1081       DummyDataConsumer<DummyRecord> consumer{edm::ESInputTag{"DoesNotExist", ""}};
1082       consumer.updateLookup(provider.recordsToProxyIndices());
1083       consumer.prefetch(provider.eventSetupImpl());
1084       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1085                                        static_cast<unsigned int>(edm::Transition::Event),
1086                                        consumer.esGetTokenIndices(edm::Transition::Event),
1087                                        parentC};
1088       auto const& depRecord = eventSetup.get<DepRecord>();
1089 
1090       CPPUNIT_ASSERT(not depRecord.getHandle(consumer.m_token));
1091       CPPUNIT_ASSERT_THROW(*depRecord.getHandle(consumer.m_token), cms::Exception);
1092     }
1093     {
1094       DummyDataConsumer<DepRecord> consumer{edm::ESInputTag{"DoesNotExist", "blah"}};
1095       consumer.updateLookup(provider.recordsToProxyIndices());
1096       consumer.prefetch(provider.eventSetupImpl());
1097       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1098                                        static_cast<unsigned int>(edm::Transition::Event),
1099                                        consumer.esGetTokenIndices(edm::Transition::Event),
1100                                        parentC};
1101       auto const& depRecord = eventSetup.get<DepRecord>();
1102 
1103       CPPUNIT_ASSERT(not depRecord.getHandle(consumer.m_token));
1104       CPPUNIT_ASSERT_THROW(*depRecord.getHandle(consumer.m_token), cms::Exception);
1105     }
1106   } catch (const cms::Exception& iException) {
1107     std::cout << "caught " << iException.explainSelf() << std::endl;
1108     throw;
1109   }
1110 }
1111 
1112 void testdependentrecord::getTransientHandleWithESGetTokenTest() {
1113   using edm::eventsetup::test::DummyData;
1114   using edm::eventsetup::test::DummyProxyProvider;
1115   DummyData kGood{1};
1116   DummyData kBad{0};
1117 
1118   SynchronousEventSetupsController controller;
1119   edm::ParameterSet pset = createDummyPset();
1120   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
1121 
1122   try {
1123     {
1124       edm::eventsetup::ComponentDescription description("DummyProxyProvider", "testOne", 0, true);
1125       edm::ParameterSet ps;
1126       ps.addParameter<std::string>("name", "test11");
1127       ps.registerIt();
1128       description.pid_ = ps.id();
1129       auto dummyProv = std::make_shared<DummyProxyProvider>(kBad);
1130       dummyProv->setDescription(description);
1131       provider.add(dummyProv);
1132     }
1133     {
1134       edm::eventsetup::ComponentDescription description("DepRecordProxyProviderWithData", "testTwo", 1, true);
1135       edm::ParameterSet ps;
1136       ps.addParameter<std::string>("name", "test22");
1137       ps.addParameter<std::string>("appendToDataLabel", "blah");
1138       ps.registerIt();
1139       description.pid_ = ps.id();
1140       auto dummyProv = std::make_shared<DepRecordProxyProviderWithData>(kGood);
1141       dummyProv->setDescription(description);
1142       dummyProv->setAppendToDataLabel(ps);
1143       provider.add(dummyProv);
1144     }
1145     std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
1146     dummyFinder->setInterval(
1147         edm::ValidityInterval(edm::IOVSyncValue(edm::EventID(1, 1, 1)), edm::IOVSyncValue(edm::EventID(1, 1, 3))));
1148     provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
1149 
1150     controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 1)));
1151     edm::ESParentContext parentC;
1152     {
1153       DummyDataConsumer<DepRecord> consumer{edm::ESInputTag{"", "blah"}};
1154       consumer.updateLookup(provider.recordsToProxyIndices());
1155       consumer.prefetch(provider.eventSetupImpl());
1156       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1157                                        static_cast<unsigned int>(edm::Transition::Event),
1158                                        consumer.esGetTokenIndices(edm::Transition::Event),
1159                                        parentC};
1160       edm::ESTransientHandle<DummyData> data = eventSetup.getTransientHandle(consumer.m_token);
1161       CPPUNIT_ASSERT(kGood.value_ == data->value_);
1162       const edm::eventsetup::ComponentDescription* desc = data.description();
1163       CPPUNIT_ASSERT(desc->label_ == "testTwo");
1164     }
1165     {
1166       DummyDataConsumer<DummyRecord> consumer{edm::ESInputTag{"", ""}};
1167       consumer.updateLookup(provider.recordsToProxyIndices());
1168       consumer.prefetch(provider.eventSetupImpl());
1169       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1170                                        static_cast<unsigned int>(edm::Transition::Event),
1171                                        consumer.esGetTokenIndices(edm::Transition::Event),
1172                                        parentC};
1173       edm::ESTransientHandle<DummyData> data = eventSetup.getTransientHandle(consumer.m_token);
1174       CPPUNIT_ASSERT(kBad.value_ == data->value_);
1175       const edm::eventsetup::ComponentDescription* desc = data.description();
1176       CPPUNIT_ASSERT(desc->label_ == "testOne");
1177     }
1178     {
1179       DummyDataConsumer<DepRecord> consumer{edm::ESInputTag{"", "blah"}};
1180       consumer.updateLookup(provider.recordsToProxyIndices());
1181       consumer.prefetch(provider.eventSetupImpl());
1182       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1183                                        static_cast<unsigned int>(edm::Transition::Event),
1184                                        consumer.esGetTokenIndices(edm::Transition::Event),
1185                                        parentC};
1186       auto const& depRecord = eventSetup.get<DepRecord>();
1187 
1188       edm::ESTransientHandle<DummyData> data = depRecord.getTransientHandle(consumer.m_token);
1189       CPPUNIT_ASSERT(kGood.value_ == data->value_);
1190       const edm::eventsetup::ComponentDescription* desc = data.description();
1191       CPPUNIT_ASSERT(desc->label_ == "testTwo");
1192     }
1193     {
1194       DummyDataConsumer<DummyRecord> consumer{edm::ESInputTag{"", ""}};
1195       consumer.updateLookup(provider.recordsToProxyIndices());
1196       consumer.prefetch(provider.eventSetupImpl());
1197       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1198                                        static_cast<unsigned int>(edm::Transition::Event),
1199                                        consumer.esGetTokenIndices(edm::Transition::Event),
1200                                        parentC};
1201       auto const& depRecord = eventSetup.get<DepRecord>();
1202 
1203       edm::ESTransientHandle<DummyData> data = depRecord.getTransientHandle(consumer.m_token);
1204       CPPUNIT_ASSERT(kBad.value_ == data->value_);
1205       const edm::eventsetup::ComponentDescription* desc = data.description();
1206       CPPUNIT_ASSERT(desc->label_ == "testOne");
1207     }
1208     {
1209       DummyDataConsumer<DepRecord> consumer{edm::ESInputTag{"", "blah"}};
1210       consumer.updateLookup(provider.recordsToProxyIndices());
1211       consumer.prefetch(provider.eventSetupImpl());
1212       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1213                                        static_cast<unsigned int>(edm::Transition::Event),
1214                                        consumer.esGetTokenIndices(edm::Transition::Event),
1215                                        parentC};
1216       auto const& depRecord = eventSetup.get<DepRecord>();
1217 
1218       edm::ESTransientHandle<DummyData> data = depRecord.getTransientHandle(consumer.m_token);
1219       CPPUNIT_ASSERT(kGood.value_ == data->value_);
1220       const edm::eventsetup::ComponentDescription* desc = data.description();
1221       CPPUNIT_ASSERT(desc->label_ == "testTwo");
1222     }
1223     {
1224       DummyDataConsumer2<DummyRecord, DepRecord> consumer{edm::ESInputTag{"", ""}, edm::ESInputTag{"", "blah"}};
1225       consumer.updateLookup(provider.recordsToProxyIndices());
1226       consumer.prefetch(provider.eventSetupImpl());
1227       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1228                                        static_cast<unsigned int>(edm::Transition::Event),
1229                                        consumer.esGetTokenIndices(edm::Transition::Event),
1230                                        parentC};
1231       auto const& depRecord = eventSetup.get<DepRecord>();
1232 
1233       edm::ESTransientHandle<DummyData> data1 = depRecord.getTransientHandle(consumer.m_token1);
1234       CPPUNIT_ASSERT(kBad.value_ == data1->value_);
1235       const edm::eventsetup::ComponentDescription* desc = data1.description();
1236       CPPUNIT_ASSERT(desc->label_ == "testOne");
1237 
1238       edm::ESTransientHandle<DummyData> data2 = depRecord.getTransientHandle(consumer.m_token2);
1239       CPPUNIT_ASSERT(kGood.value_ == data2->value_);
1240       desc = data2.description();
1241       CPPUNIT_ASSERT(desc->label_ == "testTwo");
1242     }
1243     {
1244       DummyDataConsumer<DummyRecord> consumer{edm::ESInputTag{"DoesNotExist", ""}};
1245       consumer.updateLookup(provider.recordsToProxyIndices());
1246       consumer.prefetch(provider.eventSetupImpl());
1247       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1248                                        static_cast<unsigned int>(edm::Transition::Event),
1249                                        consumer.esGetTokenIndices(edm::Transition::Event),
1250                                        parentC};
1251       auto const& depRecord = eventSetup.get<DepRecord>();
1252 
1253       edm::ESTransientHandle<DummyData> data = depRecord.getTransientHandle(consumer.m_token);
1254       CPPUNIT_ASSERT(not data);
1255       CPPUNIT_ASSERT_THROW(*data, cms::Exception);
1256     }
1257     {
1258       DummyDataConsumer<DepRecord> consumer{edm::ESInputTag{"DoesNotExist", "blah"}};
1259       consumer.updateLookup(provider.recordsToProxyIndices());
1260       consumer.prefetch(provider.eventSetupImpl());
1261       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1262                                        static_cast<unsigned int>(edm::Transition::Event),
1263                                        consumer.esGetTokenIndices(edm::Transition::Event),
1264                                        parentC};
1265       auto const& depRecord = eventSetup.get<DepRecord>();
1266 
1267       edm::ESTransientHandle<DummyData> data = depRecord.getTransientHandle(consumer.m_token);
1268       CPPUNIT_ASSERT(not data);
1269       CPPUNIT_ASSERT_THROW(*data, cms::Exception);
1270     }
1271   } catch (const cms::Exception& iException) {
1272     std::cout << "caught " << iException.explainSelf() << std::endl;
1273     throw;
1274   }
1275 }
1276 
1277 void testdependentrecord::oneOfTwoRecordTest() {
1278   SynchronousEventSetupsController controller;
1279   edm::ParameterSet pset = createDummyPset();
1280   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
1281 
1282   std::shared_ptr<edm::eventsetup::DataProxyProvider> dummyProv = std::make_shared<DummyProxyProvider>();
1283   provider.add(dummyProv);
1284 
1285   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
1286   dummyFinder->setInterval(
1287       edm::ValidityInterval(edm::IOVSyncValue(edm::EventID(1, 1, 1)), edm::IOVSyncValue(edm::EventID(1, 1, 3))));
1288   provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
1289 
1290   std::shared_ptr<edm::eventsetup::DataProxyProvider> depProv = std::make_shared<DepOn2RecordProxyProvider>();
1291   provider.add(depProv);
1292   {
1293     edm::ESParentContext parentC;
1294     controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 1)));
1295     const edm::EventSetup eventSetup1(provider.eventSetupImpl(), 0, nullptr, parentC);
1296     const DepOn2Record& depRecord = eventSetup1.get<DepOn2Record>();
1297 
1298     depRecord.getRecord<DummyRecord>();
1299     CPPUNIT_ASSERT_THROW(depRecord.getRecord<Dummy2Record>(), edm::eventsetup::NoRecordException<Dummy2Record>);
1300 
1301     try {
1302       depRecord.getRecord<Dummy2Record>();
1303     } catch (edm::eventsetup::NoRecordException<Dummy2Record>& e) {
1304       //make sure that the record name appears in the error message.
1305       CPPUNIT_ASSERT(0 != strstr(e.what(), "DepOn2Record"));
1306       CPPUNIT_ASSERT(0 != strstr(e.what(), "Dummy2Record"));
1307       // std::cout<<e.what()<<std::endl;
1308     }
1309   }
1310 }
1311 
1312 void testdependentrecord::resetTest() {
1313   SynchronousEventSetupsController controller;
1314   edm::ParameterSet pset = createDummyPset();
1315   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
1316 
1317   std::shared_ptr<edm::eventsetup::DataProxyProvider> dummyProv = std::make_shared<DummyProxyProvider>();
1318   provider.add(dummyProv);
1319 
1320   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
1321   dummyFinder->setInterval(
1322       edm::ValidityInterval(edm::IOVSyncValue(edm::EventID(1, 1, 1)), edm::IOVSyncValue(edm::EventID(1, 1, 3))));
1323   provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
1324 
1325   std::shared_ptr<edm::eventsetup::DataProxyProvider> depProv = std::make_shared<DepRecordProxyProvider>();
1326   provider.add(depProv);
1327   {
1328     edm::ESParentContext parentC;
1329     controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 1)));
1330     const edm::EventSetup eventSetup1(provider.eventSetupImpl(), 0, nullptr, parentC);
1331     const DepRecord& depRecord = eventSetup1.get<DepRecord>();
1332     unsigned long long depCacheID = depRecord.cacheIdentifier();
1333     const DummyRecord& dummyRecord = depRecord.getRecord<DummyRecord>();
1334     unsigned long long dummyCacheID = dummyRecord.cacheIdentifier();
1335 
1336     provider.resetRecordPlusDependentRecords(dummyRecord.key());
1337     controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 1)));
1338     CPPUNIT_ASSERT(dummyCacheID != dummyRecord.cacheIdentifier());
1339     CPPUNIT_ASSERT(depCacheID != depRecord.cacheIdentifier());
1340   }
1341 }
1342 
1343 void testdependentrecord::alternateFinderTest() {
1344   auto dummyProvider = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
1345 
1346   const edm::EventID eID_1(1, 1, 1);
1347   const edm::IOVSyncValue sync_1(eID_1);
1348   const edm::EventID eID_3(1, 1, 3);
1349   const edm::IOVSyncValue sync_3(eID_3);
1350   const edm::EventID eID_4(1, 1, 4);
1351   const edm::ValidityInterval definedInterval(sync_1, edm::IOVSyncValue(eID_4));
1352   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
1353   dummyFinder->setInterval(definedInterval);
1354   dummyProvider->addFinder(dummyFinder);
1355 
1356   std::shared_ptr<DepRecordFinder> depFinder = std::make_shared<DepRecordFinder>();
1357   const edm::EventID eID_2(1, 1, 2);
1358   const edm::IOVSyncValue sync_2(eID_2);
1359   const edm::ValidityInterval depInterval(sync_1, sync_2);
1360   depFinder->setInterval(depInterval);
1361 
1362   const EventSetupRecordKey depRecordKey = DepRecord::keyForClass();
1363   DependentRecordIntervalFinder finder(depRecordKey);
1364   finder.setAlternateFinder(depFinder);
1365   finder.addProviderWeAreDependentOn(dummyProvider);
1366 
1367   CPPUNIT_ASSERT(depInterval == finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 1))));
1368 
1369   const edm::ValidityInterval dep2Interval(sync_3, edm::IOVSyncValue(eID_4));
1370   depFinder->setInterval(dep2Interval);
1371 
1372   /*const edm::ValidityInterval tempIOV = */
1373   finder.findIntervalFor(depRecordKey, sync_3);
1374   //std::cout <<  tempIOV.first().eventID()<<" to "<<tempIOV.last().eventID() <<std::endl;
1375   CPPUNIT_ASSERT(dep2Interval == finder.findIntervalFor(depRecordKey, sync_3));
1376 
1377   dummyFinder->setInterval(edm::ValidityInterval::invalidInterval());
1378   depFinder->setInterval(edm::ValidityInterval::invalidInterval());
1379 
1380   dummyProvider->initializeForNewSyncValue();
1381   CPPUNIT_ASSERT(edm::ValidityInterval::invalidInterval() ==
1382                  finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 5))));
1383 
1384   const edm::EventID eID_6(1, 1, 6);
1385   const edm::IOVSyncValue sync_6(eID_6);
1386   const edm::ValidityInterval unknownedEndInterval(sync_6, edm::IOVSyncValue::invalidIOVSyncValue());
1387   dummyFinder->setInterval(unknownedEndInterval);
1388 
1389   const edm::EventID eID_7(1, 1, 7);
1390   const edm::IOVSyncValue sync_7(eID_7);
1391   const edm::ValidityInterval iov6_7(sync_6, sync_7);
1392   depFinder->setInterval(iov6_7);
1393 
1394   dummyProvider->initializeForNewSyncValue();
1395   CPPUNIT_ASSERT(unknownedEndInterval == finder.findIntervalFor(depRecordKey, sync_6));
1396 
1397   //see if dependent record can override the finder
1398   dummyFinder->setInterval(depInterval);
1399   depFinder->setInterval(definedInterval);
1400   dummyProvider->initializeForNewSyncValue();
1401   CPPUNIT_ASSERT(depInterval == finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 1))));
1402 
1403   dummyFinder->setInterval(dep2Interval);
1404   dummyProvider->initializeForNewSyncValue();
1405   CPPUNIT_ASSERT(dep2Interval == finder.findIntervalFor(depRecordKey, sync_3));
1406 }
1407 
1408 void testdependentrecord::invalidRecordTest() {
1409   auto dummyProvider1 = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
1410 
1411   const edm::ValidityInterval invalid(edm::IOVSyncValue::invalidIOVSyncValue(),
1412                                       edm::IOVSyncValue::invalidIOVSyncValue());
1413 
1414   dummyProvider1->setValidityInterval_forTesting(invalid);
1415 
1416   auto dummyProvider2 = std::make_shared<EventSetupRecordProvider>(DummyRecord::keyForClass(), &activityRegistry);
1417   dummyProvider2->setValidityInterval_forTesting(invalid);
1418 
1419   const EventSetupRecordKey depRecordKey = DepRecord::keyForClass();
1420   DependentRecordIntervalFinder finder(depRecordKey);
1421   finder.addProviderWeAreDependentOn(dummyProvider1);
1422   finder.addProviderWeAreDependentOn(dummyProvider2);
1423 
1424   CPPUNIT_ASSERT(invalid == finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 2))));
1425 
1426   const edm::EventID eID_1(1, 1, 5);
1427   const edm::IOVSyncValue sync_1(eID_1);
1428   const edm::ValidityInterval definedInterval1(sync_1, edm::IOVSyncValue(edm::EventID(1, 1, 10)));
1429   const edm::EventID eID_2(1, 1, 2);
1430   const edm::IOVSyncValue sync_2(eID_2);
1431   const edm::ValidityInterval definedInterval2(sync_2, edm::IOVSyncValue(edm::EventID(1, 1, 6)));
1432   dummyProvider2->setValidityInterval_forTesting(definedInterval2);
1433 
1434   const edm::ValidityInterval openEnded1(definedInterval2.first(), edm::IOVSyncValue::invalidIOVSyncValue());
1435 
1436   dummyProvider1->initializeForNewSyncValue();
1437   dummyProvider2->initializeForNewSyncValue();
1438   CPPUNIT_ASSERT(openEnded1 == finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 4))));
1439 
1440   dummyProvider1->setValidityInterval_forTesting(definedInterval1);
1441 
1442   const edm::ValidityInterval overlapInterval(std::max(definedInterval1.first(), definedInterval2.first()),
1443                                               std::min(definedInterval1.last(), definedInterval2.last()));
1444 
1445   dummyProvider1->initializeForNewSyncValue();
1446   dummyProvider2->initializeForNewSyncValue();
1447   CPPUNIT_ASSERT(overlapInterval == finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 5))));
1448 
1449   dummyProvider2->setValidityInterval_forTesting(invalid);
1450   const edm::ValidityInterval openEnded2(definedInterval1.first(), edm::IOVSyncValue::invalidIOVSyncValue());
1451 
1452   dummyProvider1->initializeForNewSyncValue();
1453   dummyProvider2->initializeForNewSyncValue();
1454   CPPUNIT_ASSERT(openEnded2 == finder.findIntervalFor(depRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 7))));
1455 }
1456 
1457 void testdependentrecord::extendIOVTest() {
1458   SynchronousEventSetupsController controller;
1459   edm::ParameterSet pset = createDummyPset();
1460   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
1461 
1462   std::shared_ptr<edm::eventsetup::DataProxyProvider> dummyProv = std::make_shared<DummyProxyProvider>();
1463   provider.add(dummyProv);
1464 
1465   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
1466 
1467   edm::IOVSyncValue startSyncValue{edm::EventID{1, 1, 1}};
1468   dummyFinder->setInterval(edm::ValidityInterval{startSyncValue, edm::IOVSyncValue{edm::EventID{1, 1, 5}}});
1469   provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>{dummyFinder});
1470 
1471   std::shared_ptr<edm::eventsetup::DataProxyProvider> depProv = std::make_shared<DepOn2RecordProxyProvider>();
1472   provider.add(depProv);
1473 
1474   edm::ESParentContext parentC;
1475   std::shared_ptr<Dummy2RecordFinder> dummy2Finder = std::make_shared<Dummy2RecordFinder>();
1476   dummy2Finder->setInterval(edm::ValidityInterval{startSyncValue, edm::IOVSyncValue{edm::EventID{1, 1, 6}}});
1477   provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummy2Finder));
1478   {
1479     controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 1), edm::Timestamp(1)));
1480     const edm::EventSetup eventSetup1(provider.eventSetupImpl(), 0, nullptr, parentC);
1481     unsigned long long id1 = eventSetup1.get<DepOn2Record>().cacheIdentifier();
1482     CPPUNIT_ASSERT(id1 == eventSetup1.get<DummyRecord>().cacheIdentifier());
1483     CPPUNIT_ASSERT(id1 == eventSetup1.get<Dummy2Record>().cacheIdentifier());
1484 
1485     {
1486       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 5), edm::Timestamp(2)));
1487       const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, parentC);
1488       unsigned long long id = eventSetup.get<DepOn2Record>().cacheIdentifier();
1489       CPPUNIT_ASSERT(id1 == id);
1490       CPPUNIT_ASSERT(id1 == eventSetup.get<DummyRecord>().cacheIdentifier());
1491       CPPUNIT_ASSERT(id1 == eventSetup.get<Dummy2Record>().cacheIdentifier());
1492     }
1493     //extend the IOV DummyRecord while Dummy2Record still covers this range
1494     dummyFinder->setInterval(edm::ValidityInterval{startSyncValue, edm::IOVSyncValue{edm::EventID{1, 1, 7}}});
1495     {
1496       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 6), edm::Timestamp(7)));
1497       const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, parentC);
1498       unsigned long long id = eventSetup.get<DepOn2Record>().cacheIdentifier();
1499       CPPUNIT_ASSERT(id1 == id);
1500       CPPUNIT_ASSERT(id1 == eventSetup.get<DummyRecord>().cacheIdentifier());
1501       CPPUNIT_ASSERT(id1 == eventSetup.get<Dummy2Record>().cacheIdentifier());
1502     }
1503 
1504     //extend the IOV Dummy2Record while DummyRecord still covers this range
1505     dummy2Finder->setInterval(edm::ValidityInterval{startSyncValue, edm::IOVSyncValue{edm::EventID{1, 1, 7}}});
1506 
1507     {
1508       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 7), edm::Timestamp(7)));
1509       const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, parentC);
1510       unsigned long long id = eventSetup.get<DepOn2Record>().cacheIdentifier();
1511       CPPUNIT_ASSERT(id1 == id);
1512       CPPUNIT_ASSERT(id1 == eventSetup.get<DummyRecord>().cacheIdentifier());
1513       CPPUNIT_ASSERT(id1 == eventSetup.get<Dummy2Record>().cacheIdentifier());
1514     }
1515     //extend the both IOVs
1516     dummy2Finder->setInterval(edm::ValidityInterval{startSyncValue, edm::IOVSyncValue{edm::EventID{1, 1, 8}}});
1517 
1518     dummyFinder->setInterval(edm::ValidityInterval{startSyncValue, edm::IOVSyncValue{edm::EventID{1, 1, 8}}});
1519     {
1520       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 8), edm::Timestamp(7)));
1521       const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, parentC);
1522       unsigned long long id = eventSetup.get<DepOn2Record>().cacheIdentifier();
1523       CPPUNIT_ASSERT(id1 == id);
1524       CPPUNIT_ASSERT(id1 == eventSetup.get<DummyRecord>().cacheIdentifier());
1525       CPPUNIT_ASSERT(id1 == eventSetup.get<Dummy2Record>().cacheIdentifier());
1526     }
1527     //extend only one and create a new IOV for the other
1528     dummy2Finder->setInterval(edm::ValidityInterval{startSyncValue, edm::IOVSyncValue{edm::EventID{1, 1, 9}}});
1529 
1530     dummyFinder->setInterval(
1531         edm::ValidityInterval{edm::IOVSyncValue{edm::EventID{1, 1, 9}}, edm::IOVSyncValue{edm::EventID{1, 1, 9}}});
1532     {
1533       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 9), edm::Timestamp(7)));
1534       const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, parentC);
1535       unsigned long long id = eventSetup.get<DepOn2Record>().cacheIdentifier();
1536       CPPUNIT_ASSERT(id1 + 1 == id);
1537       CPPUNIT_ASSERT(id1 + 1 == eventSetup.get<DummyRecord>().cacheIdentifier());
1538       CPPUNIT_ASSERT(id1 == eventSetup.get<Dummy2Record>().cacheIdentifier());
1539     }
1540     //extend the otherone and create a new IOV for the other
1541     dummy2Finder->setInterval(
1542         edm::ValidityInterval{edm::IOVSyncValue{edm::EventID{1, 1, 10}}, edm::IOVSyncValue{edm::EventID{1, 1, 10}}});
1543 
1544     dummyFinder->setInterval(
1545         edm::ValidityInterval{edm::IOVSyncValue{edm::EventID{1, 1, 9}}, edm::IOVSyncValue{edm::EventID{1, 1, 10}}});
1546 
1547     {
1548       controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 10), edm::Timestamp(7)));
1549       const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, parentC);
1550       unsigned long long id = eventSetup.get<DepOn2Record>().cacheIdentifier();
1551       CPPUNIT_ASSERT(id1 + 2 == id);
1552       CPPUNIT_ASSERT(id1 + 1 == eventSetup.get<DummyRecord>().cacheIdentifier());
1553       CPPUNIT_ASSERT(id1 + 1 == eventSetup.get<Dummy2Record>().cacheIdentifier());
1554     }
1555   }
1556 }