Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-13 01:43:37

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