Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-23 22:47:54

0001 /*
0002  *  eventsetup_t.cc
0003  *  EDMProto
0004  *
0005  *  Created by Chris Jones on 3/24/05.
0006  *  Changed by Viji Sundararajan on 24-Jun-05.
0007  *
0008  */
0009 
0010 // Note that repeatedly in this test we add the modules directly to
0011 // the EventSetupProvider instead of having the controller use the
0012 // plugin system and ModuleFactory to add the modules. This works OK
0013 // in tests as long as there are no SubProcesses, otherwise this needs
0014 // to be done as in a real job where the modules are added as plugins
0015 // through the parameter set passed to the controller.
0016 
0017 #include "DataFormats/Provenance/interface/EventID.h"
0018 #include "DataFormats/Provenance/interface/Timestamp.h"
0019 #include "FWCore/Framework/interface/ComponentDescription.h"
0020 #include "FWCore/Framework/interface/ESProductResolverProvider.h"
0021 #include "FWCore/Framework/interface/EDConsumerBase.h"
0022 #include "FWCore/Framework/interface/ConsumesCollector.h"
0023 #include "FWCore/Framework/interface/ESHandle.h"
0024 #include "FWCore/Framework/interface/ESTransientHandle.h"
0025 #include "FWCore/Framework/interface/ESRecordsToProductResolverIndices.h"
0026 #include "FWCore/Framework/interface/EventSetupImpl.h"
0027 #include "FWCore/Framework/interface/EventSetupProvider.h"
0028 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0029 #include "FWCore/Framework/interface/IOVSyncValue.h"
0030 #include "FWCore/Framework/interface/NoProductResolverException.h"
0031 #include "FWCore/Framework/interface/RecordDependencyRegister.h"
0032 #include "FWCore/Framework/interface/NoRecordException.h"
0033 #include "FWCore/Framework/interface/MakeDataException.h"
0034 #include "FWCore/Framework/interface/ValidityInterval.h"
0035 
0036 #include "FWCore/Framework/src/SynchronousEventSetupsController.h"
0037 
0038 #include "FWCore/Framework/test/DummyData.h"
0039 #include "FWCore/Framework/test/DummyEventSetupRecordRetriever.h"
0040 #include "FWCore/Framework/test/DummyESProductResolverProvider.h"
0041 #include "FWCore/Framework/test/DummyRecord.h"
0042 
0043 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0044 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0045 #include "FWCore/Utilities/interface/Exception.h"
0046 #include "FWCore/Utilities/interface/ESProductTag.h"
0047 #include "FWCore/Concurrency/interface/ThreadsController.h"
0048 #include "FWCore/Concurrency/interface/FinalWaitingTask.h"
0049 
0050 #include "cppunit/extensions/HelperMacros.h"
0051 
0052 #include <memory>
0053 #include <optional>
0054 #include <string>
0055 #include <vector>
0056 
0057 using namespace edm;
0058 using namespace edm::eventsetup;
0059 using edm::eventsetup::test::DummyData;
0060 using edm::eventsetup::test::DummyESProductResolverProvider;
0061 
0062 namespace {
0063 
0064   bool non_null(const void* iPtr) { return iPtr != nullptr; }
0065 
0066   edm::ParameterSet createDummyPset() {
0067     edm::ParameterSet pset;
0068     std::vector<std::string> emptyVStrings;
0069     pset.addParameter<std::vector<std::string>>("@all_esprefers", emptyVStrings);
0070     pset.addParameter<std::vector<std::string>>("@all_essources", emptyVStrings);
0071     pset.addParameter<std::vector<std::string>>("@all_esmodules", emptyVStrings);
0072     return pset;
0073   }
0074 }  // namespace
0075 
0076 class testEventsetup : public CppUnit::TestFixture {
0077   CPPUNIT_TEST_SUITE(testEventsetup);
0078 
0079   CPPUNIT_TEST(constructTest);
0080   CPPUNIT_TEST(getTest);
0081   CPPUNIT_TEST(tryToGetTest);
0082   CPPUNIT_TEST_EXCEPTION(getExcTest, edm::eventsetup::NoRecordException<DummyRecord>);
0083   CPPUNIT_TEST(provenanceTest);
0084   CPPUNIT_TEST(getDataWithESGetTokenTest);
0085   CPPUNIT_TEST(getHandleWithESGetTokenTest);
0086   CPPUNIT_TEST(getTransientHandleWithESGetTokenTest);
0087   CPPUNIT_TEST(recordValidityTest);
0088   CPPUNIT_TEST_EXCEPTION(recordValidityExcTest, edm::eventsetup::NoRecordException<DummyRecord>);
0089   CPPUNIT_TEST(recordValidityNoFinderTest);
0090   CPPUNIT_TEST_EXCEPTION(recordValidityNoFinderExcTest, edm::eventsetup::NoRecordException<DummyRecord>);
0091   CPPUNIT_TEST(recordValidityResolverNoFinderTest);
0092   CPPUNIT_TEST_EXCEPTION(recordValidityResolverNoFinderExcTest, edm::eventsetup::NoRecordException<DummyRecord>);
0093 
0094   CPPUNIT_TEST_EXCEPTION(producerConflictTest, cms::Exception);
0095   CPPUNIT_TEST_EXCEPTION(sourceConflictTest, cms::Exception);
0096   CPPUNIT_TEST(twoSourceTest);
0097   CPPUNIT_TEST(sourceProducerResolutionTest);
0098   CPPUNIT_TEST(preferTest);
0099 
0100   CPPUNIT_TEST(introspectionTest);
0101 
0102   CPPUNIT_TEST(iovExtensionTest);
0103   CPPUNIT_TEST(resetResolversTest);
0104 
0105   CPPUNIT_TEST_SUITE_END();
0106 
0107 public:
0108   void setUp() { m_scheduler = std::make_unique<edm::ThreadsController>(1); }
0109   void tearDown() {}
0110 
0111   void constructTest();
0112   void getTest();
0113   void tryToGetTest();
0114   void getExcTest();
0115   void recordValidityTest();
0116   void recordValidityExcTest();
0117   void recordValidityNoFinderTest();
0118   void recordValidityNoFinderExcTest();
0119   void recordValidityResolverNoFinderTest();
0120   void recordValidityResolverNoFinderExcTest();
0121   void provenanceTest();
0122   void getDataWithESGetTokenTest();
0123   void getHandleWithESGetTokenTest();
0124   void getTransientHandleWithESGetTokenTest();
0125 
0126   void producerConflictTest();
0127   void sourceConflictTest();
0128   void twoSourceTest();
0129   void sourceProducerResolutionTest();
0130   void preferTest();
0131 
0132   void introspectionTest();
0133 
0134   void iovExtensionTest();
0135   void resetResolversTest();
0136 
0137 private:
0138   edm::propagate_const<std::unique_ptr<edm::ThreadsController>> m_scheduler;
0139 
0140   DummyData kGood{1};
0141   DummyData kBad{0};
0142 };
0143 
0144 ///registration of the test so that the runner can find it
0145 CPPUNIT_TEST_SUITE_REGISTRATION(testEventsetup);
0146 
0147 namespace {
0148   edm::ActivityRegistry activityRegistry;
0149 }
0150 
0151 void testEventsetup::constructTest() {
0152   eventsetup::EventSetupProvider provider(&activityRegistry);
0153   const Timestamp time(1);
0154   const IOVSyncValue timestamp(time);
0155   bool newEventSetupImpl = false;
0156   auto eventSetupImpl = provider.eventSetupForInstance(timestamp, newEventSetupImpl);
0157   CPPUNIT_ASSERT(non_null(eventSetupImpl.get()));
0158   edm::ESParentContext pc;
0159   const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, pc);
0160 }
0161 
0162 // Note there is a similar test in dependentrecord_t.cppunit.cc
0163 // named getTest() that tests get and tryToGet using an EventSetupProvider.
0164 // No need to repeat that test here. The next two just test EventSetupImpl
0165 // at the lowest level.
0166 
0167 void testEventsetup::getTest() {
0168   EventSetupImpl eventSetupImpl;
0169   std::vector<eventsetup::EventSetupRecordKey> keys;
0170   EventSetupRecordKey key = EventSetupRecordKey::makeKey<DummyRecord>();
0171   keys.push_back(key);
0172   eventSetupImpl.setKeyIters(keys.begin(), keys.end());
0173   EventSetupRecordImpl dummyRecordImpl{key, &activityRegistry};
0174   eventSetupImpl.addRecordImpl(dummyRecordImpl);
0175   edm::ESParentContext pc;
0176   const edm::EventSetup eventSetup(eventSetupImpl, 0, nullptr, pc);
0177   const DummyRecord& gottenRecord = eventSetup.get<DummyRecord>();
0178   CPPUNIT_ASSERT(&dummyRecordImpl == gottenRecord.impl_);
0179 }
0180 
0181 void testEventsetup::tryToGetTest() {
0182   EventSetupImpl eventSetupImpl;
0183   std::vector<eventsetup::EventSetupRecordKey> keys;
0184   EventSetupRecordKey key = EventSetupRecordKey::makeKey<DummyRecord>();
0185   keys.push_back(key);
0186   eventSetupImpl.setKeyIters(keys.begin(), keys.end());
0187   EventSetupRecordImpl dummyRecordImpl{key, &activityRegistry};
0188   eventSetupImpl.addRecordImpl(dummyRecordImpl);
0189   edm::ESParentContext pc;
0190   const edm::EventSetup eventSetup(eventSetupImpl, 0, nullptr, pc);
0191   std::optional<DummyRecord> gottenRecord = eventSetup.tryToGet<DummyRecord>();
0192   CPPUNIT_ASSERT(gottenRecord);
0193   CPPUNIT_ASSERT(&dummyRecordImpl == gottenRecord.value().impl_);
0194 }
0195 
0196 void testEventsetup::getExcTest() {
0197   SynchronousEventSetupsController controller;
0198   edm::ParameterSet pset = createDummyPset();
0199   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0200   controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 1), edm::Timestamp(1)));
0201   edm::ESParentContext pc;
0202   const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, pc);
0203   eventSetup.get<DummyRecord>();
0204 }
0205 
0206 class DummyFinder : public EventSetupRecordIntervalFinder {
0207 public:
0208   DummyFinder() : EventSetupRecordIntervalFinder(), interval_() { this->findingRecord<DummyRecord>(); }
0209 
0210   void setInterval(const ValidityInterval& iInterval) { interval_ = iInterval; }
0211 
0212 protected:
0213   virtual void setIntervalFor(const eventsetup::EventSetupRecordKey&,
0214                               const IOVSyncValue& iTime,
0215                               ValidityInterval& iInterval) {
0216     if (interval_.validFor(iTime)) {
0217       iInterval = interval_;
0218     } else {
0219       iInterval = ValidityInterval();
0220     }
0221   }
0222 
0223 private:
0224   ValidityInterval interval_;
0225 };
0226 
0227 void testEventsetup::recordValidityTest() {
0228   SynchronousEventSetupsController controller;
0229   edm::ParameterSet pset = createDummyPset();
0230   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0231 
0232   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
0233 
0234   // Note this manner of adding finders works OK in tests as long as there
0235   // are no SubProcesses, otherwise this needs to be done as in a real
0236   // job where they are added as plugins through the pset passed to the controller.
0237   provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
0238 
0239   Timestamp time_1(1);
0240   controller.eventSetupForInstance(IOVSyncValue(time_1));
0241   edm::ESParentContext pc;
0242   const edm::EventSetup eventSetup1(provider.eventSetupImpl(), 0, nullptr, pc);
0243   CPPUNIT_ASSERT(!eventSetup1.tryToGet<DummyRecord>().has_value());
0244 
0245   const Timestamp time_2(2);
0246   dummyFinder->setInterval(ValidityInterval(IOVSyncValue(time_2), IOVSyncValue(Timestamp(3))));
0247   {
0248     controller.eventSetupForInstance(IOVSyncValue(time_2));
0249     edm::ESParentContext pc;
0250     const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, pc);
0251     eventSetup.get<DummyRecord>();
0252     CPPUNIT_ASSERT(eventSetup.tryToGet<DummyRecord>().has_value());
0253   }
0254 
0255   {
0256     controller.eventSetupForInstance(IOVSyncValue(Timestamp(3)));
0257     edm::ESParentContext pc;
0258     const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, pc);
0259     eventSetup.get<DummyRecord>();
0260     CPPUNIT_ASSERT(eventSetup.tryToGet<DummyRecord>().has_value());
0261   }
0262   {
0263     controller.eventSetupForInstance(IOVSyncValue(Timestamp(4)));
0264     edm::ESParentContext pc;
0265     const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, pc);
0266     CPPUNIT_ASSERT(!eventSetup.tryToGet<DummyRecord>().has_value());
0267   }
0268 }
0269 
0270 void testEventsetup::recordValidityExcTest() {
0271   SynchronousEventSetupsController controller;
0272   edm::ParameterSet pset = createDummyPset();
0273   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0274 
0275   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
0276 
0277   // Note this manner of adding finders works OK in tests as long as there
0278   // are no SubProcesses, otherwise this needs to be done as in a real
0279   // job where they are added as plugins through the pset passed to the controller.
0280   provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
0281 
0282   Timestamp time_1(1);
0283   controller.eventSetupForInstance(IOVSyncValue(time_1));
0284   edm::ESParentContext pc;
0285   const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, pc);
0286   eventSetup.get<DummyRecord>();
0287 }
0288 
0289 void testEventsetup::recordValidityNoFinderTest() {
0290   SynchronousEventSetupsController controller;
0291   edm::ParameterSet pset = createDummyPset();
0292   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0293 
0294   Timestamp time_1(1);
0295   controller.eventSetupForInstance(IOVSyncValue(time_1));
0296   edm::ESParentContext pc;
0297   const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, pc);
0298   CPPUNIT_ASSERT(!eventSetup.tryToGet<DummyRecord>().has_value());
0299 }
0300 
0301 void testEventsetup::recordValidityNoFinderExcTest() {
0302   SynchronousEventSetupsController controller;
0303   edm::ParameterSet pset = createDummyPset();
0304   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0305 
0306   Timestamp time_1(1);
0307   controller.eventSetupForInstance(IOVSyncValue(time_1));
0308   edm::ESParentContext pc;
0309   const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, pc);
0310   eventSetup.get<DummyRecord>();
0311 }
0312 
0313 //create an instance of the register
0314 static eventsetup::RecordDependencyRegister<DummyRecord> s_factory;
0315 
0316 void testEventsetup::recordValidityResolverNoFinderTest() {
0317   SynchronousEventSetupsController controller;
0318   edm::ParameterSet pset = createDummyPset();
0319   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0320 
0321   provider.add(std::make_shared<DummyESProductResolverProvider>());
0322 
0323   Timestamp time_1(1);
0324   controller.eventSetupForInstance(IOVSyncValue(time_1));
0325   edm::ESParentContext pc;
0326   const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, pc);
0327   CPPUNIT_ASSERT(!eventSetup.tryToGet<DummyRecord>().has_value());
0328 }
0329 
0330 void testEventsetup::recordValidityResolverNoFinderExcTest() {
0331   SynchronousEventSetupsController controller;
0332   edm::ParameterSet pset = createDummyPset();
0333   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0334 
0335   provider.add(std::make_shared<DummyESProductResolverProvider>());
0336 
0337   Timestamp time_1(1);
0338   controller.eventSetupForInstance(IOVSyncValue(time_1));
0339   edm::ESParentContext pc;
0340   const edm::EventSetup eventSetup(provider.eventSetupImpl(), 0, nullptr, pc);
0341   eventSetup.get<DummyRecord>();
0342 }
0343 
0344 void testEventsetup::producerConflictTest() {
0345   SynchronousEventSetupsController controller;
0346   edm::ParameterSet pset = createDummyPset();
0347   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0348 
0349   edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "", 0, false);
0350 
0351   {
0352     auto dummyProv = std::make_shared<DummyESProductResolverProvider>();
0353     dummyProv->setDescription(description);
0354     provider.add(dummyProv);
0355   }
0356   {
0357     auto dummyProv = std::make_shared<DummyESProductResolverProvider>();
0358     dummyProv->setDescription(description);
0359     provider.add(dummyProv);
0360   }
0361   //checking for conflicts is delayed until first eventSetupForInstance
0362   controller.eventSetupForInstance(IOVSyncValue::invalidIOVSyncValue());
0363 }
0364 
0365 void testEventsetup::sourceConflictTest() {
0366   SynchronousEventSetupsController controller;
0367   edm::ParameterSet pset = createDummyPset();
0368   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0369 
0370   edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "", 0, true);
0371 
0372   {
0373     auto dummyProv = std::make_shared<DummyESProductResolverProvider>();
0374     dummyProv->setDescription(description);
0375     provider.add(dummyProv);
0376   }
0377   {
0378     auto dummyProv = std::make_shared<DummyESProductResolverProvider>();
0379     dummyProv->setDescription(description);
0380     provider.add(dummyProv);
0381   }
0382   //checking for conflicts is delayed until first eventSetupForInstance
0383   controller.eventSetupForInstance(IOVSyncValue::invalidIOVSyncValue());
0384 }
0385 
0386 void testEventsetup::twoSourceTest() {
0387   SynchronousEventSetupsController controller;
0388   edm::ParameterSet pset = createDummyPset();
0389   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0390 
0391   edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "", 0, true);
0392   {
0393     auto dummyProv = std::make_shared<DummyESProductResolverProvider>();
0394     dummyProv->setDescription(description);
0395     provider.add(dummyProv);
0396   }
0397   {
0398     auto dummyProv = std::make_shared<edm::DummyEventSetupRecordRetriever>();
0399     std::shared_ptr<eventsetup::ESProductResolverProvider> providerPtr(dummyProv);
0400     std::shared_ptr<edm::EventSetupRecordIntervalFinder> finderPtr(dummyProv);
0401     edm::eventsetup::ComponentDescription description2("DummyEventSetupRecordRetriever", "", 0, true);
0402     dummyProv->setDescription(description2);
0403     provider.add(providerPtr);
0404     provider.add(finderPtr);
0405   }
0406   //checking for conflicts is delayed until first eventSetupForInstance
0407   edm::ESParentContext pc;
0408   controller.eventSetupForInstance(IOVSyncValue::invalidIOVSyncValue());
0409   const edm::EventSetup eventSetup3(provider.eventSetupImpl(), 0, nullptr, pc);
0410   CPPUNIT_ASSERT(!eventSetup3.tryToGet<DummyRecord>().has_value());
0411   CPPUNIT_ASSERT(!eventSetup3.tryToGet<DummyEventSetupRecord>().has_value());
0412   controller.eventSetupForInstance(IOVSyncValue(Timestamp(3)));
0413   const edm::EventSetup eventSetup4(provider.eventSetupImpl(), 0, nullptr, pc);
0414   CPPUNIT_ASSERT(!eventSetup4.tryToGet<DummyRecord>().has_value());
0415   CPPUNIT_ASSERT(eventSetup4.tryToGet<DummyEventSetupRecord>().has_value());
0416   eventSetup4.get<DummyEventSetupRecord>();
0417 }
0418 
0419 namespace {
0420   struct DummyDataConsumer : public EDConsumerBase {
0421     explicit DummyDataConsumer(ESInputTag const& iTag) : m_token{esConsumes(iTag)} {}
0422 
0423     void prefetch(edm::EventSetupImpl const& iImpl) const {
0424       auto const& recs = this->esGetTokenRecordIndicesVector(edm::Transition::Event);
0425       auto const& resolvers = this->esGetTokenIndicesVector(edm::Transition::Event);
0426       for (size_t i = 0; i != resolvers.size(); ++i) {
0427         auto rec = iImpl.findImpl(recs[i]);
0428         if (rec) {
0429           oneapi::tbb::task_group group;
0430           edm::FinalWaitingTask waitTask{group};
0431           rec->prefetchAsync(
0432               WaitingTaskHolder(group, &waitTask), resolvers[i], &iImpl, edm::ServiceToken{}, edm::ESParentContext{});
0433           waitTask.wait();
0434         }
0435       }
0436     }
0437 
0438     ESGetToken<edm::eventsetup::test::DummyData, edm::DefaultRecord> m_token;
0439     ESGetToken<edm::eventsetup::test::DummyData, edm::DefaultRecord> m_tokenUninitialized;
0440   };
0441 }  // namespace
0442 
0443 void testEventsetup::provenanceTest() {
0444   SynchronousEventSetupsController controller;
0445   edm::ParameterSet pset = createDummyPset();
0446   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0447 
0448   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
0449   dummyFinder->setInterval(ValidityInterval(IOVSyncValue(Timestamp(2)), IOVSyncValue(Timestamp(3))));
0450   provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
0451 
0452   try {
0453     {
0454       edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "", 0, true);
0455       edm::ParameterSet ps;
0456       ps.addParameter<std::string>("name", "test11");
0457       ps.registerIt();
0458       description.pid_ = ps.id();
0459       auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kBad);
0460       dummyProv->setDescription(description);
0461       provider.add(dummyProv);
0462     }
0463     {
0464       edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "testLabel", 1, false);
0465       edm::ParameterSet ps;
0466       ps.addParameter<std::string>("name", "test22");
0467       ps.registerIt();
0468       description.pid_ = ps.id();
0469       auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kGood);
0470       dummyProv->setDescription(description);
0471       provider.add(dummyProv);
0472     }
0473     controller.eventSetupForInstance(IOVSyncValue(Timestamp(2)));
0474     DummyDataConsumer consumer{edm::ESInputTag("", "")};
0475     consumer.updateLookup(provider.recordsToResolverIndices());
0476     consumer.prefetch(provider.eventSetupImpl());
0477     edm::ESParentContext pc;
0478     const edm::EventSetup eventSetup(provider.eventSetupImpl(),
0479                                      static_cast<unsigned int>(edm::Transition::Event),
0480                                      consumer.esGetTokenIndices(edm::Transition::Event),
0481                                      pc);
0482     edm::ESHandle<DummyData> data = eventSetup.getHandle(consumer.m_token);
0483 
0484     CPPUNIT_ASSERT(kGood.value_ == data->value_);
0485     const edm::eventsetup::ComponentDescription* desc = data.description();
0486     CPPUNIT_ASSERT(desc->label_ == "testLabel");
0487   } catch (const cms::Exception& iException) {
0488     std::cout << "caught " << iException.explainSelf() << std::endl;
0489     throw;
0490   }
0491 }
0492 
0493 namespace {
0494   //This just tests that the constructs will properly compile
0495   class [[maybe_unused]] EDConsumesCollectorConsumer : public edm::EDConsumerBase {
0496     EDConsumesCollectorConsumer() {
0497       using edm::eventsetup::test::DummyData;
0498       {
0499         [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token1(
0500             consumesCollector().esConsumes<DummyData, edm::DefaultRecord>());
0501         [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token2(
0502             consumesCollector().esConsumes<DummyData, edm::DefaultRecord>(edm::ESInputTag("Blah")));
0503         [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token3(
0504             consumesCollector().esConsumes<DummyData, edm::DefaultRecord, edm::Transition::BeginRun>());
0505         [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token4(
0506             consumesCollector().esConsumes<DummyData, edm::DefaultRecord, edm::Transition::BeginRun>(
0507                 edm::ESInputTag("Blah")));
0508       }
0509       {
0510         [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token1(consumesCollector().esConsumes());
0511         [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token2(
0512             consumesCollector().esConsumes(edm::ESInputTag("Blah")));
0513         [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token3(
0514             consumesCollector().esConsumes<edm::Transition::BeginRun>());
0515         [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token4(
0516             consumesCollector().esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("Blah")));
0517       }
0518       {
0519         [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token1;
0520         token1 = consumesCollector().esConsumes();
0521         [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token2;
0522         token2 = consumesCollector().esConsumes(edm::ESInputTag("Blah"));
0523         [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token3;
0524         token3 = consumesCollector().esConsumes<edm::Transition::BeginRun>();
0525         [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token4;
0526         token4 = consumesCollector().esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("Blah"));
0527       }
0528 
0529     }  // namespace
0530   };
0531 
0532   class ConsumesProducer : public ESProducer {
0533   public:
0534     ConsumesProducer() : token_{setWhatProduced(this, "consumes").consumes<edm::eventsetup::test::DummyData>()} {}
0535     std::unique_ptr<edm::eventsetup::test::DummyData> produce(const DummyRecord& iRecord) {
0536       auto const& data = iRecord.get(token_);
0537       return std::make_unique<edm::eventsetup::test::DummyData>(data);
0538     }
0539 
0540   private:
0541     edm::ESGetToken<edm::eventsetup::test::DummyData, DummyRecord> token_;
0542   };
0543 
0544   class ConsumesFromProducer : public ESProducer {
0545   public:
0546     ConsumesFromProducer()
0547         : token_{setWhatProduced(this, "consumesFrom").consumesFrom<edm::eventsetup::test::DummyData, DummyRecord>()} {}
0548     std::unique_ptr<edm::eventsetup::test::DummyData> produce(const DummyRecord& iRecord) {
0549       auto const& data = iRecord.get(token_);
0550       return std::make_unique<edm::eventsetup::test::DummyData>(data);
0551     }
0552 
0553   private:
0554     edm::ESGetToken<edm::eventsetup::test::DummyData, DummyRecord> token_;
0555   };
0556 
0557   //This is used only to test compilation
0558   class [[maybe_unused]] ESConsumesCollectorProducer : public ESProducer {
0559   public:
0560     struct Helper {
0561       Helper(ESConsumesCollector iCollector) {
0562         using edm::eventsetup::test::DummyData;
0563         {
0564           [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token1(
0565               iCollector.consumesFrom<DummyData, edm::DefaultRecord>());
0566           [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token2(
0567               iCollector.consumesFrom<DummyData, edm::DefaultRecord>(edm::ESInputTag("Blah")));
0568         }
0569         {
0570           [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token1(iCollector.consumes());
0571           [[maybe_unused]] edm::ESGetToken<DummyData, edm::DefaultRecord> token2(
0572               iCollector.consumes(edm::ESInputTag("Blah")));
0573         }
0574       }
0575     };
0576 
0577     ESConsumesCollectorProducer() : helper_(setWhatProduced(this, "consumesCollector")) {}
0578 
0579     std::unique_ptr<edm::eventsetup::test::DummyData> produce(const DummyRecord& iRecord) {
0580       return std::unique_ptr<edm::eventsetup::test::DummyData>();
0581     }
0582 
0583   private:
0584     Helper helper_;
0585   };
0586 
0587   class SetMayConsumeProducer : public ESProducer {
0588   public:
0589     SetMayConsumeProducer(bool iSucceed,
0590                           char const* conditionalModuleLabel,
0591                           char const* conditionalProductLabel,
0592                           char const* producedProductLabel)
0593         : succeed_(iSucceed),
0594           conditionalModuleLabel_(conditionalModuleLabel),
0595           conditionalProductLabel_(conditionalProductLabel),
0596           producedProductLabel_(producedProductLabel) {
0597       setWhatProduced(this, producedProductLabel)
0598           .setMayConsume(
0599               token_,
0600               [this](auto& get, edm::ESTransientHandle<edm::eventsetup::test::DummyData> const& handle) {
0601                 if (succeed_) {
0602                   return get(conditionalModuleLabel_, conditionalProductLabel_);
0603                 }
0604                 return get.nothing();
0605               },
0606               edm::ESProductTag<edm::eventsetup::test::DummyData, DummyRecord>("", ""));
0607     }
0608     std::unique_ptr<edm::eventsetup::test::DummyData> produce(const DummyRecord& iRecord) {
0609       auto const& data = iRecord.getHandle(token_);
0610       if (succeed_) {
0611         return std::make_unique<edm::eventsetup::test::DummyData>(*data);
0612       }
0613       CPPUNIT_ASSERT(!data.isValid());
0614       return std::unique_ptr<edm::eventsetup::test::DummyData>();
0615     }
0616 
0617   private:
0618     edm::ESGetToken<edm::eventsetup::test::DummyData, DummyRecord> token_;
0619     bool succeed_;
0620     char const* conditionalModuleLabel_;
0621     char const* conditionalProductLabel_;
0622     char const* producedProductLabel_;
0623   };
0624 
0625 }  // namespace
0626 
0627 void testEventsetup::getDataWithESGetTokenTest() {
0628   SynchronousEventSetupsController controller;
0629   edm::ParameterSet pset = createDummyPset();
0630   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0631 
0632   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
0633   dummyFinder->setInterval(ValidityInterval(IOVSyncValue(Timestamp(2)), IOVSyncValue(Timestamp(3))));
0634   provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
0635 
0636   try {
0637     {
0638       edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "testOne", 0, true);
0639       edm::ParameterSet ps;
0640       ps.addParameter<std::string>("name", "test11");
0641       ps.registerIt();
0642       description.pid_ = ps.id();
0643       auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kBad);
0644       dummyProv->setDescription(description);
0645       provider.add(dummyProv);
0646     }
0647     {
0648       edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "testTwo", 1, false);
0649       edm::ParameterSet ps;
0650       ps.addParameter<std::string>("name", "test22");
0651       ps.addParameter<std::string>("appendToDataLabel", "blah");
0652       ps.registerIt();
0653       description.pid_ = ps.id();
0654       auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kGood);
0655       dummyProv->setDescription(description);
0656       dummyProv->setAppendToDataLabel(ps);
0657       provider.add(dummyProv);
0658     }
0659     {
0660       edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "", 100, false);
0661       edm::ParameterSet ps;
0662       ps.addParameter<std::string>("name", "test22");
0663       ps.addParameter<std::string>("appendToDataLabel", "blahblah");
0664       ps.registerIt();
0665       description.pid_ = ps.id();
0666       auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kGood);
0667       dummyProv->setDescription(description);
0668       dummyProv->setAppendToDataLabel(ps);
0669       provider.add(dummyProv);
0670     }
0671     {
0672       edm::eventsetup::ComponentDescription description("ConsumesProducer", "consumes", 2, false);
0673       edm::ParameterSet ps;
0674       ps.addParameter<std::string>("name", "consumes");
0675       ps.registerIt();
0676       description.pid_ = ps.id();
0677       auto dummyProv = std::make_shared<ConsumesProducer>();
0678       dummyProv->setDescription(description);
0679       dummyProv->setAppendToDataLabel(ps);
0680       provider.add(dummyProv);
0681     }
0682     {
0683       edm::eventsetup::ComponentDescription description("ConsumesFromProducer", "consumesFrom", 3, false);
0684       edm::ParameterSet ps;
0685       ps.addParameter<std::string>("name", "consumesFrom");
0686       ps.registerIt();
0687       description.pid_ = ps.id();
0688       auto dummyProv = std::make_shared<ConsumesFromProducer>();
0689       dummyProv->setDescription(description);
0690       dummyProv->setAppendToDataLabel(ps);
0691       provider.add(dummyProv);
0692     }
0693     {
0694       edm::eventsetup::ComponentDescription description("SetMayConsumeProducer", "setMayConsumeSuceed", 4, false);
0695       edm::ParameterSet ps;
0696       ps.addParameter<std::string>("name", "setMayConsumeSuceed");
0697       ps.registerIt();
0698       description.pid_ = ps.id();
0699       auto dummyProv = std::make_shared<SetMayConsumeProducer>(true, "", "", "setMayConsumeSucceed");
0700       dummyProv->setDescription(description);
0701       dummyProv->setAppendToDataLabel(ps);
0702       provider.add(dummyProv);
0703     }
0704     {
0705       edm::eventsetup::ComponentDescription description("SetMayConsumeProducer", "setMayConsumeFail", 5, false);
0706       edm::ParameterSet ps;
0707       ps.addParameter<std::string>("name", "setMayConsumeFail");
0708       ps.registerIt();
0709       description.pid_ = ps.id();
0710       auto dummyProv = std::make_shared<SetMayConsumeProducer>(false, "", "", "setMayConsumeFail");
0711       dummyProv->setDescription(description);
0712       dummyProv->setAppendToDataLabel(ps);
0713       provider.add(dummyProv);
0714     }
0715     {
0716       edm::eventsetup::ComponentDescription description(
0717           "SetMayConsumeProducer", "setMayConsumeWithModuleLabel", 5, false);
0718       edm::ParameterSet ps;
0719       ps.addParameter<std::string>("name", "thisIsNotUsed");
0720       ps.registerIt();
0721       description.pid_ = ps.id();
0722       auto dummyProv =
0723           std::make_shared<SetMayConsumeProducer>(true, "testTwo", "blah", "productLabelForProducerWithModuleLabel");
0724       dummyProv->setDescription(description);
0725       dummyProv->setAppendToDataLabel(ps);
0726       provider.add(dummyProv);
0727     }
0728     {
0729       edm::eventsetup::ComponentDescription description(
0730           "SetMayConsumeProducer", "setMayConsumeWithModuleLabelThatDoesntExist", 5, false);
0731       edm::ParameterSet ps;
0732       ps.addParameter<std::string>("name", "thisIsNotUsed");
0733       ps.registerIt();
0734       description.pid_ = ps.id();
0735       auto dummyProv = std::make_shared<SetMayConsumeProducer>(
0736           true, "doesNotExist", "blah", "productLabelForProducerWithModuleLabelThatDoesntExist");
0737       dummyProv->setDescription(description);
0738       dummyProv->setAppendToDataLabel(ps);
0739       provider.add(dummyProv);
0740     }
0741     {
0742       edm::eventsetup::ComponentDescription description(
0743           "SetMayConsumeProducer", "setMayConsumeWithProductLabelThatDoesntExist", 5, false);
0744       edm::ParameterSet ps;
0745       ps.addParameter<std::string>("name", "thisIsNotUsed");
0746       ps.registerIt();
0747       description.pid_ = ps.id();
0748       auto dummyProv = std::make_shared<SetMayConsumeProducer>(
0749           true, "testTwo", "doesNotExist", "productLabelForProducerWithProductLabelThatDoesntExist");
0750       dummyProv->setDescription(description);
0751       dummyProv->setAppendToDataLabel(ps);
0752       provider.add(dummyProv);
0753     }
0754     {
0755       edm::eventsetup::ComponentDescription description(
0756           "SetMayConsumeProducer", "setMayConsumeWithUnlabeledModuleLabel", 101, false);
0757       edm::ParameterSet ps;
0758       ps.addParameter<std::string>("name", "thisIsNotUsed");
0759       ps.registerIt();
0760       description.pid_ = ps.id();
0761       auto dummyProv = std::make_shared<SetMayConsumeProducer>(
0762           true, "DummyESProductResolverProvider", "blahblah", "productLabelForProducerWithMayConsumesUnlabeledCase");
0763       dummyProv->setDescription(description);
0764       dummyProv->setAppendToDataLabel(ps);
0765       provider.add(dummyProv);
0766     }
0767     {
0768       edm::eventsetup::ComponentDescription description(
0769           "SetMayConsumeProducer", "setMayConsumeWithUnlabeledModuleLabel", 102, false);
0770       edm::ParameterSet ps;
0771       ps.addParameter<std::string>("name", "thisIsNotUsed");
0772       ps.registerIt();
0773       description.pid_ = ps.id();
0774       auto dummyProv = std::make_shared<SetMayConsumeProducer>(
0775           true, "doesNotExist", "blahblah", "productLabelForProducerWithMayConsumesUnlabeledCaseNonexistent");
0776       dummyProv->setDescription(description);
0777       dummyProv->setAppendToDataLabel(ps);
0778       provider.add(dummyProv);
0779     }
0780 
0781     edm::ESParentContext pc;
0782     controller.eventSetupForInstance(IOVSyncValue(Timestamp(2)));
0783     {
0784       DummyDataConsumer consumer{edm::ESInputTag("", "blah")};
0785       consumer.updateLookup(provider.recordsToResolverIndices());
0786       consumer.prefetch(provider.eventSetupImpl());
0787       EventSetup eventSetup{provider.eventSetupImpl(),
0788                             static_cast<unsigned int>(edm::Transition::Event),
0789                             consumer.esGetTokenIndices(edm::Transition::Event),
0790                             pc};
0791       auto const& data = eventSetup.getData(consumer.m_token);
0792       CPPUNIT_ASSERT(kGood.value_ == data.value_);
0793       bool uninitializedTokenThrewException = false;
0794       try {
0795         (void)eventSetup.getData(consumer.m_tokenUninitialized);
0796       } catch (cms::Exception& ex) {
0797         uninitializedTokenThrewException = true;
0798         CPPUNIT_ASSERT(ex.category() == "InvalidESGetToken");
0799       }
0800       CPPUNIT_ASSERT(uninitializedTokenThrewException);
0801     }
0802 
0803     {
0804       DummyDataConsumer consumer{edm::ESInputTag("", "")};
0805       consumer.updateLookup(provider.recordsToResolverIndices());
0806       consumer.prefetch(provider.eventSetupImpl());
0807       EventSetup eventSetup{provider.eventSetupImpl(),
0808                             static_cast<unsigned int>(edm::Transition::Event),
0809                             consumer.esGetTokenIndices(edm::Transition::Event),
0810                             pc};
0811       const DummyData& data = eventSetup.getData(consumer.m_token);
0812       CPPUNIT_ASSERT(kBad.value_ == data.value_);
0813     }
0814 
0815     {
0816       DummyDataConsumer consumer{edm::ESInputTag("testTwo", "blah")};
0817       consumer.updateLookup(provider.recordsToResolverIndices());
0818       consumer.prefetch(provider.eventSetupImpl());
0819       EventSetup eventSetup{provider.eventSetupImpl(),
0820                             static_cast<unsigned int>(edm::Transition::Event),
0821                             consumer.esGetTokenIndices(edm::Transition::Event),
0822                             pc};
0823       auto const& data = eventSetup.getData(consumer.m_token);
0824       CPPUNIT_ASSERT(kGood.value_ == data.value_);
0825     }
0826 
0827     {
0828       DummyDataConsumer consumer{edm::ESInputTag("testTwo", "DoesNotExist")};
0829       consumer.updateLookup(provider.recordsToResolverIndices());
0830       consumer.prefetch(provider.eventSetupImpl());
0831       EventSetup eventSetup{provider.eventSetupImpl(),
0832                             static_cast<unsigned int>(edm::Transition::Event),
0833                             consumer.esGetTokenIndices(edm::Transition::Event),
0834                             pc};
0835       CPPUNIT_ASSERT_THROW(eventSetup.getData(consumer.m_token), edm::eventsetup::NoProductResolverException);
0836     }
0837 
0838     {
0839       DummyDataConsumer consumer{edm::ESInputTag("DoesNotExist", "blah")};
0840       consumer.updateLookup(provider.recordsToResolverIndices());
0841       consumer.prefetch(provider.eventSetupImpl());
0842       EventSetup eventSetup{provider.eventSetupImpl(),
0843                             static_cast<unsigned int>(edm::Transition::Event),
0844                             consumer.esGetTokenIndices(edm::Transition::Event),
0845                             pc};
0846       CPPUNIT_ASSERT_THROW(eventSetup.getData(consumer.m_token), cms::Exception);
0847     }
0848 
0849     {
0850       DummyDataConsumer consumer{edm::ESInputTag("", "consumes")};
0851       consumer.updateLookup(provider.recordsToResolverIndices());
0852       consumer.prefetch(provider.eventSetupImpl());
0853       EventSetup eventSetup{provider.eventSetupImpl(),
0854                             static_cast<unsigned int>(edm::Transition::Event),
0855                             consumer.esGetTokenIndices(edm::Transition::Event),
0856                             pc};
0857       const DummyData& data = eventSetup.getData(consumer.m_token);
0858       CPPUNIT_ASSERT(kBad.value_ == data.value_);
0859     }
0860 
0861     {
0862       DummyDataConsumer consumer{edm::ESInputTag("", "consumesFrom")};
0863       consumer.updateLookup(provider.recordsToResolverIndices());
0864       consumer.prefetch(provider.eventSetupImpl());
0865       EventSetup eventSetup{provider.eventSetupImpl(),
0866                             static_cast<unsigned int>(edm::Transition::Event),
0867                             consumer.esGetTokenIndices(edm::Transition::Event),
0868                             pc};
0869       const DummyData& data = eventSetup.getData(consumer.m_token);
0870       CPPUNIT_ASSERT(kBad.value_ == data.value_);
0871     }
0872 
0873     {
0874       DummyDataConsumer consumer{edm::ESInputTag("", "setMayConsumeFail")};
0875       consumer.updateLookup(provider.recordsToResolverIndices());
0876       consumer.prefetch(provider.eventSetupImpl());
0877       EventSetup eventSetup{provider.eventSetupImpl(),
0878                             static_cast<unsigned int>(edm::Transition::Event),
0879                             consumer.esGetTokenIndices(edm::Transition::Event),
0880                             pc};
0881       CPPUNIT_ASSERT_THROW(eventSetup.getData(consumer.m_token), edm::eventsetup::MakeDataException);
0882     }
0883     {
0884       DummyDataConsumer consumer{edm::ESInputTag("", "setMayConsumeSucceed")};
0885       consumer.updateLookup(provider.recordsToResolverIndices());
0886       consumer.prefetch(provider.eventSetupImpl());
0887       EventSetup eventSetup{provider.eventSetupImpl(),
0888                             static_cast<unsigned int>(edm::Transition::Event),
0889                             consumer.esGetTokenIndices(edm::Transition::Event),
0890                             pc};
0891       const DummyData& data = eventSetup.getData(consumer.m_token);
0892       CPPUNIT_ASSERT(kBad.value_ == data.value_);
0893     }
0894 
0895     {
0896       DummyDataConsumer consumer{edm::ESInputTag("", "productLabelForProducerWithModuleLabel")};
0897       consumer.updateLookup(provider.recordsToResolverIndices());
0898       consumer.prefetch(provider.eventSetupImpl());
0899       EventSetup eventSetup{provider.eventSetupImpl(),
0900                             static_cast<unsigned int>(edm::Transition::Event),
0901                             consumer.esGetTokenIndices(edm::Transition::Event),
0902                             pc};
0903       const DummyData& data = eventSetup.getData(consumer.m_token);
0904       CPPUNIT_ASSERT(kGood.value_ == data.value_);
0905     }
0906 
0907     {
0908       DummyDataConsumer consumer{edm::ESInputTag("", "productLabelForProducerWithModuleLabelThatDoesntExist")};
0909       consumer.updateLookup(provider.recordsToResolverIndices());
0910       CPPUNIT_ASSERT_THROW(consumer.prefetch(provider.eventSetupImpl()), edm::eventsetup::NoProductResolverException);
0911     }
0912 
0913     {
0914       DummyDataConsumer consumer{edm::ESInputTag("", "productLabelForProducerWithProductLabelThatDoesntExist")};
0915       consumer.updateLookup(provider.recordsToResolverIndices());
0916       CPPUNIT_ASSERT_THROW(consumer.prefetch(provider.eventSetupImpl()), edm::eventsetup::NoProductResolverException);
0917     }
0918 
0919     {
0920       DummyDataConsumer consumer{edm::ESInputTag("", "productLabelForProducerWithMayConsumesUnlabeledCase")};
0921       consumer.updateLookup(provider.recordsToResolverIndices());
0922       consumer.prefetch(provider.eventSetupImpl());
0923       EventSetup eventSetup{provider.eventSetupImpl(),
0924                             static_cast<unsigned int>(edm::Transition::Event),
0925                             consumer.esGetTokenIndices(edm::Transition::Event),
0926                             pc};
0927       const DummyData& data = eventSetup.getData(consumer.m_token);
0928       CPPUNIT_ASSERT(kGood.value_ == data.value_);
0929     }
0930 
0931     {
0932       DummyDataConsumer consumer{edm::ESInputTag("", "productLabelForProducerWithMayConsumesUnlabeledCaseNonexistent")};
0933       consumer.updateLookup(provider.recordsToResolverIndices());
0934       CPPUNIT_ASSERT_THROW(consumer.prefetch(provider.eventSetupImpl()), edm::eventsetup::NoProductResolverException);
0935     }
0936 
0937   } catch (const cms::Exception& iException) {
0938     std::cout << "caught " << iException.explainSelf() << std::endl;
0939     throw;
0940   }
0941 }
0942 
0943 void testEventsetup::getHandleWithESGetTokenTest() {
0944   SynchronousEventSetupsController controller;
0945   edm::ParameterSet pset = createDummyPset();
0946   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0947 
0948   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
0949   dummyFinder->setInterval(ValidityInterval(IOVSyncValue(Timestamp(2)), IOVSyncValue(Timestamp(3))));
0950   provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
0951 
0952   edm::ESParentContext pc;
0953   try {
0954     {
0955       edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "testOne", 0, true);
0956       edm::ParameterSet ps;
0957       ps.addParameter<std::string>("name", "test11");
0958       ps.registerIt();
0959       description.pid_ = ps.id();
0960       auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kBad);
0961       dummyProv->setDescription(description);
0962       provider.add(dummyProv);
0963     }
0964     {
0965       edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "testTwo", 1, false);
0966       edm::ParameterSet ps;
0967       ps.addParameter<std::string>("name", "test22");
0968       ps.addParameter<std::string>("appendToDataLabel", "blah");
0969       ps.registerIt();
0970       description.pid_ = ps.id();
0971       auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kGood);
0972       dummyProv->setDescription(description);
0973       dummyProv->setAppendToDataLabel(ps);
0974       provider.add(dummyProv);
0975     }
0976     controller.eventSetupForInstance(IOVSyncValue(Timestamp(2)));
0977     {
0978       DummyDataConsumer consumer{edm::ESInputTag("", "blah")};
0979       consumer.updateLookup(provider.recordsToResolverIndices());
0980       consumer.prefetch(provider.eventSetupImpl());
0981 
0982       EventSetup eventSetup{provider.eventSetupImpl(),
0983                             static_cast<unsigned int>(edm::Transition::Event),
0984                             consumer.esGetTokenIndices(edm::Transition::Event),
0985                             pc};
0986       edm::ESHandle<DummyData> data = eventSetup.getHandle(consumer.m_token);
0987       CPPUNIT_ASSERT(kGood.value_ == data->value_);
0988       const edm::eventsetup::ComponentDescription* desc = data.description();
0989       CPPUNIT_ASSERT(desc->label_ == "testTwo");
0990     }
0991 
0992     {
0993       DummyDataConsumer consumer{edm::ESInputTag("", "")};
0994       consumer.updateLookup(provider.recordsToResolverIndices());
0995       consumer.prefetch(provider.eventSetupImpl());
0996       EventSetup eventSetup{provider.eventSetupImpl(),
0997                             static_cast<unsigned int>(edm::Transition::Event),
0998                             consumer.esGetTokenIndices(edm::Transition::Event),
0999                             pc};
1000       edm::ESHandle<DummyData> data = eventSetup.getHandle(consumer.m_token);
1001       CPPUNIT_ASSERT(kBad.value_ == data->value_);
1002       const edm::eventsetup::ComponentDescription* desc = data.description();
1003       CPPUNIT_ASSERT(desc->label_ == "testOne");
1004     }
1005 
1006     {
1007       DummyDataConsumer consumer{edm::ESInputTag("testTwo", "blah")};
1008       consumer.updateLookup(provider.recordsToResolverIndices());
1009       consumer.prefetch(provider.eventSetupImpl());
1010       EventSetup eventSetup{provider.eventSetupImpl(),
1011                             static_cast<unsigned int>(edm::Transition::Event),
1012                             consumer.esGetTokenIndices(edm::Transition::Event),
1013                             pc};
1014       edm::ESHandle<DummyData> data = eventSetup.getHandle(consumer.m_token);
1015       CPPUNIT_ASSERT(kGood.value_ == data->value_);
1016       const edm::eventsetup::ComponentDescription* desc = data.description();
1017       CPPUNIT_ASSERT(desc->label_ == "testTwo");
1018     }
1019 
1020     {
1021       DummyDataConsumer consumer{edm::ESInputTag("DoesNotExist", "blah")};
1022       consumer.updateLookup(provider.recordsToResolverIndices());
1023       consumer.prefetch(provider.eventSetupImpl());
1024       EventSetup eventSetup{provider.eventSetupImpl(),
1025                             static_cast<unsigned int>(edm::Transition::Event),
1026                             consumer.esGetTokenIndices(edm::Transition::Event),
1027                             pc};
1028       CPPUNIT_ASSERT(not eventSetup.getHandle(consumer.m_token));
1029       CPPUNIT_ASSERT_THROW(*eventSetup.getHandle(consumer.m_token), cms::Exception);
1030     }
1031 
1032   } catch (const cms::Exception& iException) {
1033     std::cout << "caught " << iException.explainSelf() << std::endl;
1034     throw;
1035   }
1036 }
1037 
1038 void testEventsetup::getTransientHandleWithESGetTokenTest() {
1039   using edm::eventsetup::test::DummyData;
1040   using edm::eventsetup::test::DummyESProductResolverProvider;
1041   DummyData kGood{1};
1042   DummyData kBad{0};
1043 
1044   SynchronousEventSetupsController controller;
1045   edm::ParameterSet pset = createDummyPset();
1046   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
1047 
1048   edm::ESParentContext pc;
1049   try {
1050     {
1051       edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "testOne", 0, true);
1052       edm::ParameterSet ps;
1053       ps.addParameter<std::string>("name", "test11");
1054       ps.registerIt();
1055       description.pid_ = ps.id();
1056       auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kBad);
1057       dummyProv->setDescription(description);
1058       provider.add(dummyProv);
1059     }
1060     {
1061       edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "testTwo", 1, false);
1062       edm::ParameterSet ps;
1063       ps.addParameter<std::string>("name", "test22");
1064       ps.addParameter<std::string>("appendToDataLabel", "blah");
1065       ps.registerIt();
1066       description.pid_ = ps.id();
1067       auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kGood);
1068       dummyProv->setDescription(description);
1069       dummyProv->setAppendToDataLabel(ps);
1070       provider.add(dummyProv);
1071     }
1072     std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
1073     dummyFinder->setInterval(
1074         edm::ValidityInterval(edm::IOVSyncValue(edm::EventID(1, 1, 1)), edm::IOVSyncValue(edm::EventID(1, 1, 3))));
1075     provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
1076 
1077     controller.eventSetupForInstance(edm::IOVSyncValue(edm::EventID(1, 1, 1)));
1078     {
1079       DummyDataConsumer consumer{edm::ESInputTag("", "blah")};
1080       consumer.updateLookup(provider.recordsToResolverIndices());
1081       consumer.prefetch(provider.eventSetupImpl());
1082       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1083                                        static_cast<unsigned int>(edm::Transition::Event),
1084                                        consumer.esGetTokenIndices(edm::Transition::Event),
1085                                        pc};
1086       edm::ESTransientHandle<DummyData> data = eventSetup.getTransientHandle(consumer.m_token);
1087       CPPUNIT_ASSERT(kGood.value_ == data->value_);
1088       const edm::eventsetup::ComponentDescription* desc = data.description();
1089       CPPUNIT_ASSERT(desc->label_ == "testTwo");
1090     }
1091 
1092     {
1093       DummyDataConsumer consumer{edm::ESInputTag("", "")};
1094       consumer.updateLookup(provider.recordsToResolverIndices());
1095       consumer.prefetch(provider.eventSetupImpl());
1096       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1097                                        static_cast<unsigned int>(edm::Transition::Event),
1098                                        consumer.esGetTokenIndices(edm::Transition::Event),
1099                                        pc};
1100       edm::ESTransientHandle<DummyData> data = eventSetup.getTransientHandle(consumer.m_token);
1101       CPPUNIT_ASSERT(kBad.value_ == data->value_);
1102       const edm::eventsetup::ComponentDescription* desc = data.description();
1103       CPPUNIT_ASSERT(desc->label_ == "testOne");
1104     }
1105 
1106     {
1107       DummyDataConsumer consumer{edm::ESInputTag("testTwo", "blah")};
1108       consumer.updateLookup(provider.recordsToResolverIndices());
1109       consumer.prefetch(provider.eventSetupImpl());
1110       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1111                                        static_cast<unsigned int>(edm::Transition::Event),
1112                                        consumer.esGetTokenIndices(edm::Transition::Event),
1113                                        pc};
1114       edm::ESTransientHandle<DummyData> data = eventSetup.getTransientHandle(consumer.m_token);
1115       CPPUNIT_ASSERT(kGood.value_ == data->value_);
1116       const edm::eventsetup::ComponentDescription* desc = data.description();
1117       CPPUNIT_ASSERT(desc->label_ == "testTwo");
1118     }
1119 
1120     {
1121       DummyDataConsumer consumer{edm::ESInputTag("DoesNotExist", "blah")};
1122       consumer.updateLookup(provider.recordsToResolverIndices());
1123       consumer.prefetch(provider.eventSetupImpl());
1124       const edm::EventSetup eventSetup{provider.eventSetupImpl(),
1125                                        static_cast<unsigned int>(edm::Transition::Event),
1126                                        consumer.esGetTokenIndices(edm::Transition::Event),
1127                                        pc};
1128       edm::ESTransientHandle<DummyData> data = eventSetup.getTransientHandle(consumer.m_token);
1129       CPPUNIT_ASSERT(not data);
1130       CPPUNIT_ASSERT_THROW(*data, cms::Exception);
1131     }
1132 
1133   } catch (const cms::Exception& iException) {
1134     std::cout << "caught " << iException.explainSelf() << std::endl;
1135     throw;
1136   }
1137 }
1138 
1139 void testEventsetup::sourceProducerResolutionTest() {
1140   {
1141     SynchronousEventSetupsController controller;
1142     edm::ParameterSet pset = createDummyPset();
1143     EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
1144 
1145     std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
1146     dummyFinder->setInterval(ValidityInterval(IOVSyncValue(Timestamp(2)), IOVSyncValue(Timestamp(3))));
1147     provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
1148 
1149     edm::ESParentContext pc;
1150     {
1151       edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "", 0, true);
1152       auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kBad);
1153       dummyProv->setDescription(description);
1154       provider.add(dummyProv);
1155     }
1156     {
1157       edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "", 1, false);
1158       auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kGood);
1159       dummyProv->setDescription(description);
1160       provider.add(dummyProv);
1161     }
1162     controller.eventSetupForInstance(IOVSyncValue(Timestamp(2)));
1163     DummyDataConsumer consumer{edm::ESInputTag("", "")};
1164     consumer.updateLookup(provider.recordsToResolverIndices());
1165     consumer.prefetch(provider.eventSetupImpl());
1166     const EventSetup eventSetup{provider.eventSetupImpl(),
1167                                 static_cast<unsigned int>(edm::Transition::Event),
1168                                 consumer.esGetTokenIndices(edm::Transition::Event),
1169                                 pc};
1170     edm::ESHandle<DummyData> data = eventSetup.getHandle(consumer.m_token);
1171     CPPUNIT_ASSERT(kGood.value_ == data->value_);
1172   }
1173 
1174   //reverse order
1175   {
1176     SynchronousEventSetupsController controller;
1177     edm::ParameterSet pset = createDummyPset();
1178     EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
1179 
1180     std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
1181     dummyFinder->setInterval(ValidityInterval(IOVSyncValue(Timestamp(2)), IOVSyncValue(Timestamp(3))));
1182     provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
1183     {
1184       edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "", 0, false);
1185       auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kGood);
1186       dummyProv->setDescription(description);
1187       provider.add(dummyProv);
1188     }
1189     {
1190       edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "", 1, true);
1191       auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kBad);
1192       dummyProv->setDescription(description);
1193       provider.add(dummyProv);
1194     }
1195     controller.eventSetupForInstance(IOVSyncValue(Timestamp(2)));
1196     ESParentContext pc;
1197     DummyDataConsumer consumer{edm::ESInputTag("", "")};
1198     consumer.updateLookup(provider.recordsToResolverIndices());
1199     consumer.prefetch(provider.eventSetupImpl());
1200     EventSetup eventSetup{provider.eventSetupImpl(),
1201                           static_cast<unsigned int>(edm::Transition::Event),
1202                           consumer.esGetTokenIndices(edm::Transition::Event),
1203                           pc};
1204     edm::ESHandle<DummyData> data = eventSetup.getHandle(consumer.m_token);
1205     CPPUNIT_ASSERT(kGood.value_ == data->value_);
1206   }
1207 }
1208 
1209 void testEventsetup::preferTest() {
1210   edm::ParameterSet pset = createDummyPset();
1211 
1212   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
1213   dummyFinder->setInterval(ValidityInterval(IOVSyncValue(Timestamp(2)), IOVSyncValue(Timestamp(3))));
1214 
1215   edm::ESParentContext pc;
1216   try {
1217     {
1218       SynchronousEventSetupsController controller;
1219       EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
1220       provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
1221 
1222       EventSetupProvider::PreferredProviderInfo preferInfo;
1223       EventSetupProvider::RecordToDataMap recordToData;
1224       //default means use all resolvers
1225       preferInfo[ComponentDescription("DummyESProductResolverProvider", "", ComponentDescription::unknownID(), false)] =
1226           recordToData;
1227       provider.setPreferredProviderInfo(preferInfo);
1228       {
1229         edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "bad", 0, false);
1230         auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kBad);
1231         dummyProv->setDescription(description);
1232         provider.add(dummyProv);
1233       }
1234       {
1235         edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "", 1, false);
1236         auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kGood);
1237         dummyProv->setDescription(description);
1238         provider.add(dummyProv);
1239       }
1240       controller.eventSetupForInstance(IOVSyncValue(Timestamp(2)));
1241       DummyDataConsumer consumer{edm::ESInputTag("", "")};
1242       consumer.updateLookup(provider.recordsToResolverIndices());
1243       consumer.prefetch(provider.eventSetupImpl());
1244       EventSetup eventSetup{provider.eventSetupImpl(),
1245                             static_cast<unsigned int>(edm::Transition::Event),
1246                             consumer.esGetTokenIndices(edm::Transition::Event),
1247                             pc};
1248       edm::ESHandle<DummyData> data = eventSetup.getHandle(consumer.m_token);
1249       CPPUNIT_ASSERT(kGood.value_ == data->value_);
1250     }
1251 
1252     //sources
1253     {
1254       SynchronousEventSetupsController controller;
1255       EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
1256       provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
1257 
1258       EventSetupProvider::PreferredProviderInfo preferInfo;
1259       EventSetupProvider::RecordToDataMap recordToData;
1260       //default means use all resolvers
1261       preferInfo[ComponentDescription("DummyESProductResolverProvider", "", ComponentDescription::unknownID(), false)] =
1262           recordToData;
1263       provider.setPreferredProviderInfo(preferInfo);
1264       {
1265         edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "", 0, true);
1266         auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kGood);
1267         dummyProv->setDescription(description);
1268         provider.add(dummyProv);
1269       }
1270       {
1271         edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "bad", 1, true);
1272         auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kBad);
1273         dummyProv->setDescription(description);
1274         provider.add(dummyProv);
1275       }
1276       controller.eventSetupForInstance(IOVSyncValue(Timestamp(2)));
1277       DummyDataConsumer consumer{edm::ESInputTag("", "")};
1278       consumer.updateLookup(provider.recordsToResolverIndices());
1279       consumer.prefetch(provider.eventSetupImpl());
1280       EventSetup eventSetup{provider.eventSetupImpl(),
1281                             static_cast<unsigned int>(edm::Transition::Event),
1282                             consumer.esGetTokenIndices(edm::Transition::Event),
1283                             pc};
1284       edm::ESHandle<DummyData> data = eventSetup.getHandle(consumer.m_token);
1285       CPPUNIT_ASSERT(kGood.value_ == data->value_);
1286     }
1287 
1288     //specific name
1289     {
1290       SynchronousEventSetupsController controller;
1291       EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
1292       provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
1293 
1294       EventSetupProvider::PreferredProviderInfo preferInfo;
1295       EventSetupProvider::RecordToDataMap recordToData;
1296       recordToData.insert(
1297           std::make_pair(std::string("DummyRecord"), std::make_pair(std::string("DummyData"), std::string())));
1298       preferInfo[ComponentDescription("DummyESProductResolverProvider", "", ComponentDescription::unknownID(), false)] =
1299           recordToData;
1300       provider.setPreferredProviderInfo(preferInfo);
1301       {
1302         edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "", 0, true);
1303         auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kGood);
1304         dummyProv->setDescription(description);
1305         provider.add(dummyProv);
1306       }
1307       {
1308         edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "bad", 1, true);
1309         auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kBad);
1310         dummyProv->setDescription(description);
1311         provider.add(dummyProv);
1312       }
1313       controller.eventSetupForInstance(IOVSyncValue(Timestamp(2)));
1314       DummyDataConsumer consumer{edm::ESInputTag("", "")};
1315       consumer.updateLookup(provider.recordsToResolverIndices());
1316       consumer.prefetch(provider.eventSetupImpl());
1317       EventSetup eventSetup{provider.eventSetupImpl(),
1318                             static_cast<unsigned int>(edm::Transition::Event),
1319                             consumer.esGetTokenIndices(edm::Transition::Event),
1320                             pc};
1321       edm::ESHandle<DummyData> data = eventSetup.getHandle(consumer.m_token);
1322       CPPUNIT_ASSERT(kGood.value_ == data->value_);
1323     }
1324 
1325   } catch (const cms::Exception& iException) {
1326     std::cout << "caught " << iException.explainSelf() << std::endl;
1327     throw;
1328   }
1329 }
1330 
1331 void testEventsetup::introspectionTest() {
1332   SynchronousEventSetupsController controller;
1333   edm::ParameterSet pset = createDummyPset();
1334   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
1335 
1336   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
1337   dummyFinder->setInterval(ValidityInterval(IOVSyncValue(Timestamp(2)), IOVSyncValue(Timestamp(3))));
1338   provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(dummyFinder));
1339 
1340   edm::ESParentContext pc;
1341   try {
1342     {
1343       edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "", 0, true);
1344       edm::ParameterSet ps;
1345       ps.addParameter<std::string>("name", "test11");
1346       ps.registerIt();
1347       description.pid_ = ps.id();
1348       auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kBad);
1349       dummyProv->setDescription(description);
1350       provider.add(dummyProv);
1351     }
1352     EventSetupRecordKey dummyRecordKey = EventSetupRecordKey::makeKey<DummyRecord>();
1353     controller.eventSetupForInstance(IOVSyncValue(Timestamp(2)));
1354     {
1355       EventSetup eventSetup{provider.eventSetupImpl(), 0, nullptr, pc};
1356 
1357       CPPUNIT_ASSERT(eventSetup.recordIsProvidedByAModule(dummyRecordKey));
1358       std::vector<edm::eventsetup::EventSetupRecordKey> recordKeys;
1359       eventSetup.fillAvailableRecordKeys(recordKeys);
1360       CPPUNIT_ASSERT(1 == recordKeys.size());
1361       CPPUNIT_ASSERT(dummyRecordKey == recordKeys[0]);
1362       auto record = eventSetup.find(recordKeys[0]);
1363       CPPUNIT_ASSERT(record.has_value());
1364     }
1365     // Intentionally an out of range sync value so the IOV is invalid
1366     // to test the find function with a record that exists in the
1367     // EventSetupImpl but has a null pointer.
1368     controller.eventSetupForInstance(IOVSyncValue(Timestamp(4)));
1369     {
1370       EventSetup eventSetup{provider.eventSetupImpl(), 0, nullptr, pc};
1371 
1372       CPPUNIT_ASSERT(eventSetup.recordIsProvidedByAModule(dummyRecordKey));
1373       std::vector<edm::eventsetup::EventSetupRecordKey> recordKeys;
1374       eventSetup.fillAvailableRecordKeys(recordKeys);
1375       CPPUNIT_ASSERT(0 == recordKeys.size());
1376       auto record = eventSetup.find(dummyRecordKey);
1377       CPPUNIT_ASSERT(!record.has_value());
1378 
1379       // Just to try all cases test find with a record type not in the EventSetupImpl
1380       // at all.
1381       EventSetupRecordKey dummyRecordKey1 = EventSetupRecordKey::makeKey<DummyEventSetupRecord>();
1382       auto record1 = eventSetup.find(dummyRecordKey1);
1383       CPPUNIT_ASSERT(!record1.has_value());
1384     }
1385   } catch (const cms::Exception& iException) {
1386     std::cout << "caught " << iException.explainSelf() << std::endl;
1387     throw;
1388   }
1389 }
1390 
1391 void testEventsetup::iovExtensionTest() {
1392   SynchronousEventSetupsController controller;
1393   edm::ParameterSet pset = createDummyPset();
1394   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
1395 
1396   std::shared_ptr<DummyFinder> finder = std::make_shared<DummyFinder>();
1397   finder->setInterval(ValidityInterval(IOVSyncValue(Timestamp(2)), IOVSyncValue(Timestamp(3))));
1398   provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(finder));
1399 
1400   edm::ESParentContext pc;
1401   {
1402     controller.eventSetupForInstance(IOVSyncValue{Timestamp(2)});
1403     EventSetup eventSetup{provider.eventSetupImpl(), 0, nullptr, pc};
1404     CPPUNIT_ASSERT(2 == eventSetup.get<DummyRecord>().cacheIdentifier());
1405   }
1406   {
1407     controller.eventSetupForInstance(IOVSyncValue{Timestamp(3)});
1408     EventSetup eventSetup{provider.eventSetupImpl(), 0, nullptr, pc};
1409     eventSetup.get<DummyRecord>();
1410     CPPUNIT_ASSERT(2 == eventSetup.get<DummyRecord>().cacheIdentifier());
1411   }
1412   //extending the IOV should not cause the cache to be reset
1413   finder->setInterval(ValidityInterval(IOVSyncValue{Timestamp{2}}, IOVSyncValue{Timestamp{4}}));
1414   {
1415     controller.eventSetupForInstance(IOVSyncValue{Timestamp(4)});
1416     EventSetup eventSetup{provider.eventSetupImpl(), 0, nullptr, pc};
1417     CPPUNIT_ASSERT(2 == eventSetup.get<DummyRecord>().cacheIdentifier());
1418   }
1419 
1420   //this is a new IOV so should get cache reset
1421   finder->setInterval(ValidityInterval(IOVSyncValue{Timestamp{5}}, IOVSyncValue{Timestamp{6}}));
1422   {
1423     controller.eventSetupForInstance(IOVSyncValue{Timestamp(5)});
1424     EventSetup eventSetup{provider.eventSetupImpl(), 0, nullptr, pc};
1425     CPPUNIT_ASSERT(3 == eventSetup.get<DummyRecord>().cacheIdentifier());
1426   }
1427 }
1428 
1429 void testEventsetup::resetResolversTest() {
1430   SynchronousEventSetupsController controller;
1431   edm::ParameterSet pset = createDummyPset();
1432   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
1433 
1434   std::shared_ptr<DummyFinder> finder = std::make_shared<DummyFinder>();
1435   finder->setInterval(ValidityInterval(IOVSyncValue(Timestamp(2)), IOVSyncValue(Timestamp(3))));
1436   provider.add(std::shared_ptr<edm::EventSetupRecordIntervalFinder>(finder));
1437 
1438   ComponentDescription description("DummyESProductResolverProvider", "", 0, true);
1439   ParameterSet ps;
1440   ps.addParameter<std::string>("name", "test11");
1441   ps.registerIt();
1442   description.pid_ = ps.id();
1443   DummyData kOne{1};
1444   auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kOne);
1445   dummyProv->setDescription(description);
1446   provider.add(dummyProv);
1447 
1448   edm::ESParentContext pc;
1449   {
1450     controller.eventSetupForInstance(IOVSyncValue{Timestamp(2)});
1451     DummyDataConsumer consumer{edm::ESInputTag("", "")};
1452     consumer.updateLookup(provider.recordsToResolverIndices());
1453     consumer.prefetch(provider.eventSetupImpl());
1454     EventSetup eventSetup{provider.eventSetupImpl(),
1455                           static_cast<unsigned int>(edm::Transition::Event),
1456                           consumer.esGetTokenIndices(edm::Transition::Event),
1457                           pc};
1458     CPPUNIT_ASSERT(2 == eventSetup.get<DummyRecord>().cacheIdentifier());
1459     edm::ESHandle<DummyData> data = eventSetup.getHandle(consumer.m_token);
1460     CPPUNIT_ASSERT(data->value_ == 1);
1461   }
1462   provider.forceCacheClear();
1463   {
1464     controller.eventSetupForInstance(IOVSyncValue{Timestamp(2)});
1465     DummyDataConsumer consumer{edm::ESInputTag("", "")};
1466     consumer.updateLookup(provider.recordsToResolverIndices());
1467     consumer.prefetch(provider.eventSetupImpl());
1468     EventSetup eventSetup{provider.eventSetupImpl(),
1469                           static_cast<unsigned int>(edm::Transition::Event),
1470                           consumer.esGetTokenIndices(edm::Transition::Event),
1471                           pc};
1472     eventSetup.get<DummyRecord>();
1473     CPPUNIT_ASSERT(3 == eventSetup.get<DummyRecord>().cacheIdentifier());
1474     dummyProv->incrementData();
1475     edm::ESHandle<DummyData> data = eventSetup.getHandle(consumer.m_token);
1476     CPPUNIT_ASSERT(data->value_ == 2);
1477   }
1478 }