Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-16 00:05:37

0001 // -*- C++ -*-
0002 //
0003 // Package:     Framework
0004 // Class  :     eventsetup_plugin_t
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Author:      Chris Jones
0010 // Created:     Thu May 26 11:01:19 EDT 2005
0011 // Changed:     Viji Sundararajan 28-Jun-2005
0012 //
0013 
0014 // system include files
0015 #include "cppunit/extensions/HelperMacros.h"
0016 // user include files
0017 #include "FWCore/PluginManager/interface/PluginManager.h"
0018 #include "FWCore/PluginManager/interface/standard.h"
0019 #include "FWCore/Utilities/interface/GetPassID.h"
0020 #include "FWCore/Version/interface/GetReleaseVersion.h"
0021 #include "FWCore/Framework/interface/SourceFactory.h"
0022 #include "FWCore/Framework/interface/ModuleFactory.h"
0023 #include "FWCore/Framework/interface/EventSetupProvider.h"
0024 #include "FWCore/Framework/interface/EventSetupsController.h"
0025 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0026 
0027 #include "DummyFinder.h"
0028 #include "DummyProxyProvider.h"
0029 #include "TestTypeResolvers.h"
0030 
0031 using namespace edm::eventsetup;
0032 
0033 namespace {
0034   edm::ActivityRegistry activityRegistry;
0035 }
0036 
0037 namespace edm::test {
0038   namespace other {
0039     class LoadableDummyFinderA : public DummyFinder {
0040     public:
0041       LoadableDummyFinderA(const edm::ParameterSet&) { ++count_; }
0042       static int count_;
0043     };
0044     int LoadableDummyFinderA::count_ = 0;
0045 
0046     class LoadableDummyProviderA : public edm::eventsetup::test::DummyProxyProvider {
0047     public:
0048       LoadableDummyProviderA(const edm::ParameterSet& iPSet)
0049           : DummyProxyProvider(edm::eventsetup::test::DummyData(iPSet.getUntrackedParameter<int>("value", 1))) {
0050         ++count_;
0051       }
0052       static int count_;
0053     };
0054     int LoadableDummyProviderA::count_ = 0;
0055 
0056     class LoadableDummyESSourceA : public edm::eventsetup::test::DummyProxyProvider, public DummyFinder {
0057     public:
0058       LoadableDummyESSourceA(const edm::ParameterSet& iPSet)
0059           : DummyProxyProvider(edm::eventsetup::test::DummyData(iPSet.getUntrackedParameter<int>("value", 2))) {
0060         setInterval(edm::ValidityInterval(edm::IOVSyncValue(edm::EventID(1, 0, 0)), edm::IOVSyncValue::endOfTime()));
0061         ++count_;
0062       }
0063       static int count_;
0064     };
0065     int LoadableDummyESSourceA::count_ = 0;
0066   }  // namespace other
0067   namespace cpu {
0068     class LoadableDummyFinderA : public DummyFinder {
0069     public:
0070       LoadableDummyFinderA(const edm::ParameterSet&) { ++count_; }
0071       static int count_;
0072     };
0073     int LoadableDummyFinderA::count_ = 0;
0074 
0075     class LoadableDummyProviderA : public edm::eventsetup::test::DummyProxyProvider {
0076     public:
0077       LoadableDummyProviderA(const edm::ParameterSet& iPSet)
0078           : DummyProxyProvider(edm::eventsetup::test::DummyData(iPSet.getUntrackedParameter<int>("value", 1))) {
0079         ++count_;
0080       }
0081       static int count_;
0082     };
0083     int LoadableDummyProviderA::count_ = 0;
0084     using LoadableDummyProviderB = LoadableDummyProviderA;
0085 
0086     class LoadableDummyESSourceA : public edm::eventsetup::test::DummyProxyProvider, public DummyFinder {
0087     public:
0088       LoadableDummyESSourceA(const edm::ParameterSet& iPSet)
0089           : DummyProxyProvider(edm::eventsetup::test::DummyData(iPSet.getUntrackedParameter<int>("value", 2))) {
0090         setInterval(edm::ValidityInterval(edm::IOVSyncValue(edm::EventID(1, 0, 0)), edm::IOVSyncValue::endOfTime()));
0091         ++count_;
0092       }
0093       static int count_;
0094     };
0095     int LoadableDummyESSourceA::count_ = 0;
0096     using LoadableDummyESSourceB = LoadableDummyESSourceA;
0097   }  // namespace cpu
0098 }  // namespace edm::test
0099 
0100 DEFINE_FWK_EVENTSETUP_SOURCE(edm::test::other::LoadableDummyFinderA);
0101 DEFINE_FWK_EVENTSETUP_SOURCE(edm::test::cpu::LoadableDummyFinderA);
0102 DEFINE_FWK_EVENTSETUP_SOURCE(edm::test::other::LoadableDummyESSourceA);
0103 DEFINE_FWK_EVENTSETUP_SOURCE(edm::test::cpu::LoadableDummyESSourceA);
0104 DEFINE_FWK_EVENTSETUP_SOURCE(edm::test::cpu::LoadableDummyESSourceB);
0105 DEFINE_FWK_EVENTSETUP_MODULE(edm::test::other::LoadableDummyProviderA);
0106 DEFINE_FWK_EVENTSETUP_MODULE(edm::test::cpu::LoadableDummyProviderA);
0107 DEFINE_FWK_EVENTSETUP_MODULE(edm::test::cpu::LoadableDummyProviderB);
0108 
0109 class testEventsetupplugin : public CppUnit::TestFixture {
0110   CPPUNIT_TEST_SUITE(testEventsetupplugin);
0111 
0112   CPPUNIT_TEST(finderTest);
0113   CPPUNIT_TEST(simpleResolverTest);
0114   CPPUNIT_TEST(complexResolverTest);
0115 
0116   CPPUNIT_TEST_SUITE_END();
0117 
0118 public:
0119   void setUp() {}
0120   void tearDown() {}
0121 
0122   void finderTest();
0123   void simpleResolverTest();
0124   void complexResolverTest();
0125 };
0126 
0127 ///registration of the test so that the runner can find it
0128 CPPUNIT_TEST_SUITE_REGISTRATION(testEventsetupplugin);
0129 
0130 static void doInit() {
0131   static bool firstTime = true;
0132   if (firstTime) {
0133     if (not edmplugin::PluginManager::isAvailable()) {
0134       edmplugin::PluginManager::configure(edmplugin::standard::config());
0135     }
0136     firstTime = false;
0137   }
0138 }
0139 
0140 void testEventsetupplugin::finderTest()
0141 
0142 {
0143   doInit();
0144   EventSetupsController esController;
0145   EventSetupProvider provider(&activityRegistry);
0146   edm::ModuleTypeResolverBase const* resolver = nullptr;
0147 
0148   edm::ParameterSet dummyFinderPSet;
0149   dummyFinderPSet.addParameter("@module_type", std::string("LoadableDummyFinder"));
0150   dummyFinderPSet.addParameter("@module_label", std::string(""));
0151   dummyFinderPSet.registerIt();
0152   SourceFactory::get()->addTo(esController, provider, dummyFinderPSet, resolver);
0153 
0154   ComponentDescription descFinder("LoadableDummyFinder", "", ComponentDescription::unknownID(), true);
0155   std::set<ComponentDescription> descriptions(provider.proxyProviderDescriptions());
0156   //should not be found since not a provider
0157   CPPUNIT_ASSERT(descriptions.find(descFinder) == descriptions.end());
0158 
0159   edm::ParameterSet dummyProviderPSet;
0160   dummyProviderPSet.addParameter("@module_type", std::string("LoadableDummyProvider"));
0161   dummyProviderPSet.addParameter("@module_label", std::string(""));
0162   dummyProviderPSet.registerIt();
0163   ModuleFactory::get()->addTo(esController, provider, dummyProviderPSet, resolver);
0164 
0165   ComponentDescription desc("LoadableDummyProvider", "", ComponentDescription::unknownID(), false);
0166   descriptions = provider.proxyProviderDescriptions();
0167   CPPUNIT_ASSERT(descriptions.find(desc) != descriptions.end());
0168   CPPUNIT_ASSERT(*(descriptions.find(desc)) == desc);
0169 
0170   edm::ParameterSet dummySourcePSet;
0171   dummySourcePSet.addParameter("@module_type", std::string("LoadableDummyESSource"));
0172   dummySourcePSet.addParameter("@module_label", std::string(""));
0173   dummySourcePSet.registerIt();
0174   SourceFactory::get()->addTo(esController, provider, dummySourcePSet, resolver);
0175 
0176   ComponentDescription descSource("LoadableDummyESSource", "", ComponentDescription::unknownID(), true);
0177   descriptions = provider.proxyProviderDescriptions();
0178   CPPUNIT_ASSERT(descriptions.find(descSource) != descriptions.end());
0179   CPPUNIT_ASSERT(*(descriptions.find(descSource)) == descSource);
0180 }
0181 
0182 void testEventsetupplugin::simpleResolverTest() {
0183   doInit();
0184 
0185   edm::test::SimpleTestTypeResolver resolver;
0186   EventSetupsController esController(&resolver);
0187   EventSetupProvider provider(&activityRegistry);
0188 
0189   edm::ParameterSet dummyFinderPSet;
0190   dummyFinderPSet.addParameter("@module_type", std::string("LoadableDummyFinder"));
0191   dummyFinderPSet.addParameter("@module_label", std::string(""));
0192   dummyFinderPSet.registerIt();
0193   SourceFactory::get()->addTo(esController, provider, dummyFinderPSet, &resolver);
0194 
0195   ComponentDescription descFinder("LoadableDummyFinder", "", ComponentDescription::unknownID(), true);
0196   std::set<ComponentDescription> descriptions(provider.proxyProviderDescriptions());
0197   //should not be found since not a provider
0198   CPPUNIT_ASSERT(descriptions.find(descFinder) == descriptions.end());
0199 
0200   edm::ParameterSet dummyProviderPSet;
0201   dummyProviderPSet.addParameter("@module_type", std::string("LoadableDummyProvider"));
0202   dummyProviderPSet.addParameter("@module_label", std::string(""));
0203   dummyProviderPSet.registerIt();
0204   ModuleFactory::get()->addTo(esController, provider, dummyProviderPSet, &resolver);
0205 
0206   ComponentDescription desc("LoadableDummyProvider", "", ComponentDescription::unknownID(), false);
0207   descriptions = provider.proxyProviderDescriptions();
0208   CPPUNIT_ASSERT(descriptions.find(desc) != descriptions.end());
0209   CPPUNIT_ASSERT(*(descriptions.find(desc)) == desc);
0210 
0211   edm::ParameterSet dummySourcePSet;
0212   dummySourcePSet.addParameter("@module_type", std::string("LoadableDummyESSource"));
0213   dummySourcePSet.addParameter("@module_label", std::string(""));
0214   dummySourcePSet.registerIt();
0215   SourceFactory::get()->addTo(esController, provider, dummySourcePSet, &resolver);
0216 
0217   ComponentDescription descSource("LoadableDummyESSource", "", ComponentDescription::unknownID(), true);
0218   descriptions = provider.proxyProviderDescriptions();
0219   CPPUNIT_ASSERT(descriptions.find(descSource) != descriptions.end());
0220   CPPUNIT_ASSERT(*(descriptions.find(descSource)) == descSource);
0221 }
0222 
0223 void testEventsetupplugin::complexResolverTest() {
0224   doInit();
0225 
0226   edm::test::ComplexTestTypeResolver resolver;
0227   EventSetupsController esController(&resolver);
0228   EventSetupProvider provider(&activityRegistry);
0229 
0230   edm::ParameterSet dummyFinderPSet;
0231   dummyFinderPSet.addParameter("@module_type", std::string("generic::LoadableDummyFinderA"));
0232   dummyFinderPSet.addParameter("@module_label", std::string(""));
0233   dummyFinderPSet.registerIt();
0234   SourceFactory::get()->addTo(esController, provider, dummyFinderPSet, &resolver);
0235 
0236   ComponentDescription descFinder("generic::LoadableDummyFinderA", "", ComponentDescription::unknownID(), true);
0237   std::set<ComponentDescription> descriptions(provider.proxyProviderDescriptions());
0238   //should not be found since not a provider
0239   CPPUNIT_ASSERT(descriptions.find(descFinder) == descriptions.end());
0240 
0241   // find other
0242   {
0243     CPPUNIT_ASSERT(edm::test::cpu::LoadableDummyProviderA::count_ == 0);
0244     CPPUNIT_ASSERT(edm::test::other::LoadableDummyProviderA::count_ == 0);
0245     edm::ParameterSet dummyProviderPSet;
0246     dummyProviderPSet.addParameter("@module_type", std::string("generic::LoadableDummyProviderA"));
0247     dummyProviderPSet.addParameter("@module_label", std::string(""));
0248     dummyProviderPSet.registerIt();
0249     ModuleFactory::get()->addTo(esController, provider, dummyProviderPSet, &resolver);
0250 
0251     ComponentDescription desc("generic::LoadableDummyProviderA", "", ComponentDescription::unknownID(), false);
0252     descriptions = provider.proxyProviderDescriptions();
0253     CPPUNIT_ASSERT(descriptions.find(desc) != descriptions.end());
0254     CPPUNIT_ASSERT(*(descriptions.find(desc)) == desc);
0255     CPPUNIT_ASSERT(edm::test::cpu::LoadableDummyProviderA::count_ == 0);
0256     CPPUNIT_ASSERT(edm::test::other::LoadableDummyProviderA::count_ == 1);
0257     edm::test::other::LoadableDummyProviderA::count_ = 0;
0258   }
0259 
0260   // find cpu
0261   {
0262     CPPUNIT_ASSERT(edm::test::cpu::LoadableDummyProviderB::count_ == 0);
0263     edm::ParameterSet dummyProviderPSet;
0264     dummyProviderPSet.addParameter("@module_type", std::string("generic::LoadableDummyProviderB"));
0265     dummyProviderPSet.addParameter("@module_label", std::string(""));
0266     dummyProviderPSet.registerIt();
0267     ModuleFactory::get()->addTo(esController, provider, dummyProviderPSet, &resolver);
0268 
0269     ComponentDescription desc("generic::LoadableDummyProviderB", "", ComponentDescription::unknownID(), false);
0270     descriptions = provider.proxyProviderDescriptions();
0271     CPPUNIT_ASSERT(descriptions.find(desc) != descriptions.end());
0272     CPPUNIT_ASSERT(*(descriptions.find(desc)) == desc);
0273     CPPUNIT_ASSERT(edm::test::cpu::LoadableDummyProviderB::count_ == 1);
0274     edm::test::cpu::LoadableDummyProviderB::count_ = 0;
0275   }
0276 
0277   // find other
0278   {
0279     CPPUNIT_ASSERT(edm::test::cpu::LoadableDummyESSourceA::count_ == 0);
0280     CPPUNIT_ASSERT(edm::test::other::LoadableDummyESSourceA::count_ == 0);
0281     edm::ParameterSet dummySourcePSet;
0282     dummySourcePSet.addParameter("@module_type", std::string("generic::LoadableDummyESSourceA"));
0283     dummySourcePSet.addParameter("@module_label", std::string(""));
0284     dummySourcePSet.registerIt();
0285     SourceFactory::get()->addTo(esController, provider, dummySourcePSet, &resolver);
0286 
0287     ComponentDescription descSource("generic::LoadableDummyESSourceA", "", ComponentDescription::unknownID(), true);
0288     descriptions = provider.proxyProviderDescriptions();
0289     CPPUNIT_ASSERT(descriptions.find(descSource) != descriptions.end());
0290     CPPUNIT_ASSERT(*(descriptions.find(descSource)) == descSource);
0291     CPPUNIT_ASSERT(edm::test::cpu::LoadableDummyESSourceA::count_ == 0);
0292     CPPUNIT_ASSERT(edm::test::other::LoadableDummyESSourceA::count_ == 1);
0293     edm::test::other::LoadableDummyESSourceA::count_ = 0;
0294   }
0295 
0296   // find cpu
0297   {
0298     CPPUNIT_ASSERT(edm::test::cpu::LoadableDummyESSourceB::count_ == 0);
0299     edm::ParameterSet dummySourcePSet;
0300     dummySourcePSet.addParameter("@module_type", std::string("generic::LoadableDummyESSourceB"));
0301     dummySourcePSet.addParameter("@module_label", std::string(""));
0302     dummySourcePSet.registerIt();
0303     SourceFactory::get()->addTo(esController, provider, dummySourcePSet, &resolver);
0304 
0305     ComponentDescription descSource("generic::LoadableDummyESSourceB", "", ComponentDescription::unknownID(), true);
0306     descriptions = provider.proxyProviderDescriptions();
0307     CPPUNIT_ASSERT(descriptions.find(descSource) != descriptions.end());
0308     CPPUNIT_ASSERT(*(descriptions.find(descSource)) == descSource);
0309     CPPUNIT_ASSERT(edm::test::cpu::LoadableDummyESSourceB::count_ == 1);
0310     edm::test::cpu::LoadableDummyESSourceB::count_ = 0;
0311   }
0312 }