Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  *  full_chain_test.cc
0003  *  EDMProto
0004  *
0005  *  Created by Chris Jones on 4/3/05.
0006  *  Changed by Viji Sundararajan on 29-Jun-05.
0007  *
0008  */
0009 
0010 #include "DataFormats/Provenance/interface/Timestamp.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/Framework/interface/EventSetupProvider.h"
0013 #include "FWCore/Framework/interface/IOVSyncValue.h"
0014 #include "FWCore/Framework/interface/EDConsumerBase.h"
0015 #include "FWCore/Framework/interface/ESHandle.h"
0016 #include "FWCore/Framework/interface/ESRecordsToProxyIndices.h"
0017 #include "FWCore/Framework/interface/ValidityInterval.h"
0018 
0019 #include "FWCore/Framework/test/DummyData.h"
0020 #include "FWCore/Framework/test/DummyFinder.h"
0021 #include "FWCore/Framework/test/DummyProxyProvider.h"
0022 #include "FWCore/Framework/test/DummyRecord.h"
0023 #include "FWCore/Framework/src/SynchronousEventSetupsController.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0026 #include "FWCore/Concurrency/interface/ThreadsController.h"
0027 #include "FWCore/Concurrency/interface/FinalWaitingTask.h"
0028 
0029 #include "cppunit/extensions/HelperMacros.h"
0030 
0031 #include <memory>
0032 #include <string>
0033 #include <vector>
0034 
0035 using namespace edm;
0036 using namespace edm::eventsetup;
0037 using namespace edm::eventsetup::test;
0038 
0039 namespace {
0040   ActivityRegistry activityRegistry;
0041 
0042   ParameterSet createDummyPset() {
0043     ParameterSet pset;
0044     std::vector<std::string> emptyVStrings;
0045     pset.addParameter<std::vector<std::string>>("@all_esprefers", emptyVStrings);
0046     pset.addParameter<std::vector<std::string>>("@all_essources", emptyVStrings);
0047     pset.addParameter<std::vector<std::string>>("@all_esmodules", emptyVStrings);
0048     return pset;
0049   }
0050 
0051   struct DummyDataConsumer : public EDConsumerBase {
0052     explicit DummyDataConsumer() : m_token{esConsumes()} {}
0053 
0054     void prefetch(edm::EventSetupImpl const& iImpl) const {
0055       auto const& recs = this->esGetTokenRecordIndicesVector(edm::Transition::Event);
0056       auto const& proxies = this->esGetTokenIndicesVector(edm::Transition::Event);
0057       for (size_t i = 0; i != proxies.size(); ++i) {
0058         auto rec = iImpl.findImpl(recs[i]);
0059         if (rec) {
0060           oneapi::tbb::task_group group;
0061           edm::FinalWaitingTask waitTask{group};
0062           rec->prefetchAsync(
0063               WaitingTaskHolder(group, &waitTask), proxies[i], &iImpl, edm::ServiceToken{}, edm::ESParentContext{});
0064           waitTask.wait();
0065         }
0066       }
0067     }
0068 
0069     ESGetToken<edm::eventsetup::test::DummyData, edm::DefaultRecord> m_token;
0070   };
0071 }  // namespace
0072 
0073 class testfullChain : public CppUnit::TestFixture {
0074   CPPUNIT_TEST_SUITE(testfullChain);
0075 
0076   CPPUNIT_TEST(getfromDataproxyproviderTest);
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 getfromDataproxyproviderTest();
0085 
0086 private:
0087   edm::propagate_const<std::unique_ptr<edm::ThreadsController>> m_scheduler;
0088 };
0089 
0090 ///registration of the test so that the runner can find it
0091 CPPUNIT_TEST_SUITE_REGISTRATION(testfullChain);
0092 
0093 void testfullChain::getfromDataproxyproviderTest() {
0094   SynchronousEventSetupsController controller;
0095   ParameterSet pset = createDummyPset();
0096   EventSetupProvider& provider = *controller.makeProvider(pset, &activityRegistry);
0097 
0098   auto dummyFinder = std::make_shared<DummyFinder>();
0099   dummyFinder->setInterval(ValidityInterval(IOVSyncValue(Timestamp(1)), IOVSyncValue(Timestamp(5))));
0100   provider.add(dummyFinder);
0101 
0102   auto proxyProvider = std::make_shared<DummyProxyProvider>();
0103   provider.add(proxyProvider);
0104 
0105   edm::ESParentContext pc;
0106   for (unsigned int iTime = 1; iTime != 6; ++iTime) {
0107     const Timestamp time(iTime);
0108     controller.eventSetupForInstance(IOVSyncValue(time));
0109     DummyDataConsumer consumer;
0110     consumer.updateLookup(provider.recordsToProxyIndices());
0111     consumer.prefetch(provider.eventSetupImpl());
0112     EventSetup eventSetup(provider.eventSetupImpl(),
0113                           static_cast<unsigned int>(edm::Transition::Event),
0114                           consumer.esGetTokenIndices(edm::Transition::Event),
0115                           pc);
0116     ESHandle<DummyData> pDummy = eventSetup.getHandle(consumer.m_token);
0117     CPPUNIT_ASSERT(0 != pDummy.product());
0118 
0119     pDummy = eventSetup.getHandle(consumer.m_token);
0120     CPPUNIT_ASSERT(0 != pDummy.product());
0121   }
0122 }