Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-18 22:30:24

0001 /*
0002  *  eventsetupscontroller_t.cc
0003  */
0004 
0005 #include "cppunit/extensions/HelperMacros.h"
0006 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0007 #include "FWCore/Framework/interface/EventSetupProvider.h"
0008 #include "FWCore/Framework/interface/EventSetupsController.h"
0009 #include "FWCore/Framework/interface/ParameterSetIDHolder.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/Framework/test/DummyFinder.h"
0012 #include "FWCore/Framework/test/DummyProxyProvider.h"
0013 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0014 #include "FWCore/Utilities/interface/Exception.h"
0015 
0016 #include <memory>
0017 #include <string>
0018 #include <vector>
0019 
0020 namespace {
0021   edm::ActivityRegistry activityRegistry;
0022 }
0023 
0024 class TestEventSetupsController : public CppUnit::TestFixture {
0025   CPPUNIT_TEST_SUITE(TestEventSetupsController);
0026 
0027   CPPUNIT_TEST(constructorTest);
0028   CPPUNIT_TEST(esProducerGetAndPutTest);
0029   CPPUNIT_TEST(esSourceGetAndPutTest);
0030 
0031   CPPUNIT_TEST_SUITE_END();
0032 
0033 public:
0034   void setUp() {}
0035   void tearDown() {}
0036 
0037   void constructorTest();
0038   void esProducerGetAndPutTest();
0039   void esSourceGetAndPutTest();
0040 };
0041 
0042 ///registration of the test so that the runner can find it
0043 CPPUNIT_TEST_SUITE_REGISTRATION(TestEventSetupsController);
0044 
0045 void TestEventSetupsController::constructorTest() {
0046   edm::eventsetup::EventSetupsController esController;
0047 
0048   CPPUNIT_ASSERT(esController.providers().empty());
0049   CPPUNIT_ASSERT(esController.esproducers().empty());
0050   CPPUNIT_ASSERT(esController.essources().empty());
0051   CPPUNIT_ASSERT(esController.mustFinishConfiguration() == true);
0052 
0053   edm::ParameterSet pset;
0054   std::vector<std::string> emptyVStrings;
0055   pset.addParameter<std::vector<std::string> >("@all_esprefers", emptyVStrings);
0056   pset.addParameter<std::vector<std::string> >("@all_essources", emptyVStrings);
0057   pset.addParameter<std::vector<std::string> >("@all_esmodules", emptyVStrings);
0058 
0059   esController.makeProvider(pset, &activityRegistry);
0060   esController.makeProvider(pset, &activityRegistry);
0061   esController.makeProvider(pset, &activityRegistry);
0062 
0063   CPPUNIT_ASSERT(esController.providers().size() == 3);
0064   CPPUNIT_ASSERT(esController.providers()[0]->subProcessIndex() == 0);
0065   CPPUNIT_ASSERT(esController.providers()[1]->subProcessIndex() == 1);
0066   CPPUNIT_ASSERT(esController.providers()[2]->subProcessIndex() == 2);
0067 }
0068 
0069 void TestEventSetupsController::esProducerGetAndPutTest() {
0070   edm::eventsetup::EventSetupsController esController;
0071 
0072   edm::ParameterSet pset1;
0073   pset1.registerIt();
0074   std::shared_ptr<edm::eventsetup::test::DummyProxyProvider> proxyProvider1 =
0075       std::make_shared<edm::eventsetup::test::DummyProxyProvider>();
0076 
0077   edm::ParameterSet pset2;
0078   pset2.addUntrackedParameter<int>("p1", 1);
0079   pset2.registerIt();
0080   std::shared_ptr<edm::eventsetup::test::DummyProxyProvider> proxyProvider2 =
0081       std::make_shared<edm::eventsetup::test::DummyProxyProvider>();
0082   CPPUNIT_ASSERT(pset2.id() == pset1.id());
0083 
0084   edm::ParameterSet pset3;
0085   pset3.addUntrackedParameter<int>("p1", 2);
0086   pset3.registerIt();
0087   std::shared_ptr<edm::eventsetup::test::DummyProxyProvider> proxyProvider3 =
0088       std::make_shared<edm::eventsetup::test::DummyProxyProvider>();
0089   CPPUNIT_ASSERT(pset3.id() == pset1.id());
0090 
0091   edm::ParameterSet pset4;
0092   pset4.addParameter<int>("p1", 1);
0093   pset4.registerIt();
0094   std::shared_ptr<edm::eventsetup::test::DummyProxyProvider> proxyProvider4 =
0095       std::make_shared<edm::eventsetup::test::DummyProxyProvider>();
0096   CPPUNIT_ASSERT(pset4.id() != pset1.id());
0097 
0098   edm::eventsetup::ParameterSetIDHolder psetIDHolder1(pset1.id());
0099   edm::eventsetup::ParameterSetIDHolder psetIDHolder1a(pset1.id());
0100   edm::eventsetup::ParameterSetIDHolder psetIDHolder4(pset4.id());
0101   CPPUNIT_ASSERT(pset1.id() == psetIDHolder1.psetID());
0102   CPPUNIT_ASSERT(psetIDHolder1 == psetIDHolder1a);
0103   CPPUNIT_ASSERT(!(psetIDHolder1 == psetIDHolder4));
0104   CPPUNIT_ASSERT((pset1.id() < pset4.id()) == (psetIDHolder1 < psetIDHolder4));
0105 
0106   std::shared_ptr<edm::eventsetup::DataProxyProvider> ptrFromGet =
0107       esController.getESProducerAndRegisterProcess(pset1, 0);
0108   CPPUNIT_ASSERT(!ptrFromGet);
0109   esController.putESProducer(pset1, proxyProvider1, 0);
0110 
0111   ptrFromGet = esController.getESProducerAndRegisterProcess(pset2, 0);
0112   CPPUNIT_ASSERT(!ptrFromGet);
0113   esController.putESProducer(pset2, proxyProvider2, 0);
0114 
0115   ptrFromGet = esController.getESProducerAndRegisterProcess(pset3, 0);
0116   CPPUNIT_ASSERT(!ptrFromGet);
0117   esController.putESProducer(pset3, proxyProvider3, 0);
0118 
0119   ptrFromGet = esController.getESProducerAndRegisterProcess(pset4, 0);
0120   CPPUNIT_ASSERT(!ptrFromGet);
0121   esController.putESProducer(pset4, proxyProvider4, 0);
0122 
0123   ptrFromGet = esController.getESProducerAndRegisterProcess(pset1, 1);
0124   CPPUNIT_ASSERT(ptrFromGet);
0125   CPPUNIT_ASSERT(ptrFromGet == proxyProvider1);
0126 
0127   ptrFromGet = esController.getESProducerAndRegisterProcess(pset2, 2);
0128   CPPUNIT_ASSERT(ptrFromGet);
0129   CPPUNIT_ASSERT(ptrFromGet == proxyProvider2);
0130 
0131   ptrFromGet = esController.getESProducerAndRegisterProcess(pset3, 3);
0132   CPPUNIT_ASSERT(ptrFromGet);
0133   CPPUNIT_ASSERT(ptrFromGet == proxyProvider3);
0134 
0135   ptrFromGet = esController.getESProducerAndRegisterProcess(pset4, 4);
0136   CPPUNIT_ASSERT(ptrFromGet);
0137   CPPUNIT_ASSERT(ptrFromGet == proxyProvider4);
0138 
0139   ptrFromGet = esController.getESProducerAndRegisterProcess(pset4, 5);
0140   CPPUNIT_ASSERT(ptrFromGet);
0141   CPPUNIT_ASSERT(ptrFromGet == proxyProvider4);
0142 
0143   std::multimap<edm::ParameterSetID, edm::eventsetup::ESProducerInfo> const& esproducers = esController.esproducers();
0144   bool isPresent1 = false;
0145   bool isPresent2 = false;
0146   bool isPresent3 = false;
0147   bool isPresent4 = false;
0148 
0149   CPPUNIT_ASSERT(esproducers.size() == 4);
0150   for (auto const& esproducer : esproducers) {
0151     if (esproducer.second.pset() == &pset1) {
0152       isPresent1 = true;
0153       CPPUNIT_ASSERT(esproducer.first == pset1.id());
0154       CPPUNIT_ASSERT(esproducer.second.providerGet() ==
0155                      static_cast<edm::eventsetup::DataProxyProvider*>(proxyProvider1.get()));
0156       edm::eventsetup::ESProducerInfo const& info = esproducer.second;
0157       CPPUNIT_ASSERT(info.subProcessIndexes().size() == 2);
0158       CPPUNIT_ASSERT(info.subProcessIndexes()[0] == 0);
0159       CPPUNIT_ASSERT(info.subProcessIndexes()[1] == 1);
0160     }
0161     if (esproducer.second.pset() == &pset2) {
0162       isPresent2 = true;
0163       CPPUNIT_ASSERT(esproducer.first == pset1.id());
0164       CPPUNIT_ASSERT(esproducer.second.providerGet() ==
0165                      static_cast<edm::eventsetup::DataProxyProvider*>(proxyProvider2.get()));
0166       edm::eventsetup::ESProducerInfo const& info = esproducer.second;
0167       CPPUNIT_ASSERT(info.subProcessIndexes().size() == 2);
0168       CPPUNIT_ASSERT(info.subProcessIndexes()[0] == 0);
0169       CPPUNIT_ASSERT(info.subProcessIndexes()[1] == 2);
0170     }
0171     if (esproducer.second.pset() == &pset3) {
0172       isPresent3 = true;
0173       CPPUNIT_ASSERT(esproducer.first == pset3.id());
0174       CPPUNIT_ASSERT(esproducer.second.providerGet() ==
0175                      static_cast<edm::eventsetup::DataProxyProvider*>(proxyProvider3.get()));
0176       edm::eventsetup::ESProducerInfo const& info = esproducer.second;
0177       CPPUNIT_ASSERT(info.subProcessIndexes().size() == 2);
0178       CPPUNIT_ASSERT(info.subProcessIndexes()[0] == 0);
0179       CPPUNIT_ASSERT(info.subProcessIndexes()[1] == 3);
0180     }
0181     if (esproducer.second.pset() == &pset4) {
0182       isPresent4 = true;
0183       CPPUNIT_ASSERT(esproducer.first == pset4.id());
0184       CPPUNIT_ASSERT(esproducer.second.providerGet() ==
0185                      static_cast<edm::eventsetup::DataProxyProvider*>(proxyProvider4.get()));
0186       edm::eventsetup::ESProducerInfo const& info = esproducer.second;
0187       CPPUNIT_ASSERT(info.subProcessIndexes().size() == 3);
0188       CPPUNIT_ASSERT(info.subProcessIndexes()[0] == 0);
0189       CPPUNIT_ASSERT(info.subProcessIndexes()[1] == 4);
0190       CPPUNIT_ASSERT(info.subProcessIndexes()[2] == 5);
0191     }
0192   }
0193   CPPUNIT_ASSERT(isPresent1 && isPresent2 && isPresent3 && isPresent4);
0194 
0195   bool firstProcessWithThisPSet = false;
0196   bool precedingHasMatchingPSet = false;
0197 
0198   esController.lookForMatches(pset4.id(), 0, 0, firstProcessWithThisPSet, precedingHasMatchingPSet);
0199   CPPUNIT_ASSERT(firstProcessWithThisPSet == true);
0200   CPPUNIT_ASSERT(precedingHasMatchingPSet == false);
0201 
0202   esController.lookForMatches(pset4.id(), 4, 0, firstProcessWithThisPSet, precedingHasMatchingPSet);
0203   CPPUNIT_ASSERT(firstProcessWithThisPSet == false);
0204   CPPUNIT_ASSERT(precedingHasMatchingPSet == true);
0205 
0206   esController.lookForMatches(pset4.id(), 4, 1, firstProcessWithThisPSet, precedingHasMatchingPSet);
0207   CPPUNIT_ASSERT(firstProcessWithThisPSet == false);
0208   CPPUNIT_ASSERT(precedingHasMatchingPSet == false);
0209 
0210   CPPUNIT_ASSERT_THROW(
0211       esController.lookForMatches(pset4.id(), 6, 0, firstProcessWithThisPSet, precedingHasMatchingPSet),
0212       cms::Exception);
0213 
0214   CPPUNIT_ASSERT(esController.isFirstMatch(pset4.id(), 5, 0));
0215   CPPUNIT_ASSERT(!esController.isFirstMatch(pset4.id(), 5, 4));
0216   CPPUNIT_ASSERT_THROW(esController.isFirstMatch(pset4.id(), 6, 4), cms::Exception);
0217   CPPUNIT_ASSERT_THROW(esController.isFirstMatch(pset4.id(), 5, 1), cms::Exception);
0218 
0219   CPPUNIT_ASSERT(!esController.isLastMatch(pset4.id(), 5, 0));
0220   CPPUNIT_ASSERT(esController.isLastMatch(pset4.id(), 5, 4));
0221   CPPUNIT_ASSERT_THROW(esController.isLastMatch(pset4.id(), 6, 4), cms::Exception);
0222   CPPUNIT_ASSERT_THROW(esController.isLastMatch(pset4.id(), 5, 1), cms::Exception);
0223 
0224   CPPUNIT_ASSERT(esController.isMatchingESProducer(pset4.id(), 5, 0));
0225   CPPUNIT_ASSERT(esController.isMatchingESProducer(pset4.id(), 5, 4));
0226   CPPUNIT_ASSERT(!esController.isMatchingESProducer(pset4.id(), 5, 2));
0227   CPPUNIT_ASSERT_THROW(esController.isMatchingESProducer(pset4.id(), 6, 4), cms::Exception);
0228 
0229   CPPUNIT_ASSERT(esController.getESProducerPSet(pset1.id(), 0) == &pset1);
0230   CPPUNIT_ASSERT(esController.getESProducerPSet(pset2.id(), 2) == &pset2);
0231   CPPUNIT_ASSERT(esController.getESProducerPSet(pset3.id(), 3) == &pset3);
0232   CPPUNIT_ASSERT(esController.getESProducerPSet(pset4.id(), 5) == &pset4);
0233   CPPUNIT_ASSERT_THROW(esController.getESProducerPSet(pset4.id(), 6), cms::Exception);
0234 
0235   esController.clearComponents();
0236   CPPUNIT_ASSERT(esController.esproducers().empty());
0237   CPPUNIT_ASSERT(esController.essources().empty());
0238 }
0239 
0240 void TestEventSetupsController::esSourceGetAndPutTest() {
0241   edm::eventsetup::EventSetupsController esController;
0242 
0243   edm::ParameterSet pset1;
0244   pset1.registerIt();
0245   std::shared_ptr<DummyFinder> finder1 = std::make_shared<DummyFinder>();
0246 
0247   edm::ParameterSet pset2;
0248   pset2.addUntrackedParameter<int>("p1", 1);
0249   pset2.registerIt();
0250   std::shared_ptr<DummyFinder> finder2 = std::make_shared<DummyFinder>();
0251   CPPUNIT_ASSERT(pset2.id() == pset1.id());
0252 
0253   edm::ParameterSet pset3;
0254   pset3.addUntrackedParameter<int>("p1", 2);
0255   pset3.registerIt();
0256   std::shared_ptr<DummyFinder> finder3 = std::make_shared<DummyFinder>();
0257   CPPUNIT_ASSERT(pset3.id() == pset1.id());
0258 
0259   edm::ParameterSet pset4;
0260   pset4.addParameter<int>("p1", 1);
0261   pset4.registerIt();
0262   std::shared_ptr<DummyFinder> finder4 = std::make_shared<DummyFinder>();
0263   CPPUNIT_ASSERT(pset4.id() != pset1.id());
0264 
0265   std::shared_ptr<edm::EventSetupRecordIntervalFinder> ptrFromGet =
0266       esController.getESSourceAndRegisterProcess(pset1, 0);
0267   CPPUNIT_ASSERT(!ptrFromGet);
0268   esController.putESSource(pset1, finder1, 0);
0269 
0270   ptrFromGet = esController.getESSourceAndRegisterProcess(pset2, 0);
0271   CPPUNIT_ASSERT(!ptrFromGet);
0272   esController.putESSource(pset2, finder2, 0);
0273 
0274   ptrFromGet = esController.getESSourceAndRegisterProcess(pset3, 0);
0275   CPPUNIT_ASSERT(!ptrFromGet);
0276   esController.putESSource(pset3, finder3, 0);
0277 
0278   ptrFromGet = esController.getESSourceAndRegisterProcess(pset4, 0);
0279   CPPUNIT_ASSERT(!ptrFromGet);
0280   esController.putESSource(pset4, finder4, 0);
0281 
0282   ptrFromGet = esController.getESSourceAndRegisterProcess(pset1, 1);
0283   CPPUNIT_ASSERT(ptrFromGet);
0284   CPPUNIT_ASSERT(ptrFromGet == finder1);
0285 
0286   ptrFromGet = esController.getESSourceAndRegisterProcess(pset2, 2);
0287   CPPUNIT_ASSERT(ptrFromGet);
0288   CPPUNIT_ASSERT(ptrFromGet == finder2);
0289 
0290   ptrFromGet = esController.getESSourceAndRegisterProcess(pset3, 3);
0291   CPPUNIT_ASSERT(ptrFromGet);
0292   CPPUNIT_ASSERT(ptrFromGet == finder3);
0293 
0294   ptrFromGet = esController.getESSourceAndRegisterProcess(pset4, 4);
0295   CPPUNIT_ASSERT(ptrFromGet);
0296   CPPUNIT_ASSERT(ptrFromGet == finder4);
0297 
0298   ptrFromGet = esController.getESSourceAndRegisterProcess(pset4, 5);
0299   CPPUNIT_ASSERT(ptrFromGet);
0300   CPPUNIT_ASSERT(ptrFromGet == finder4);
0301 
0302   std::multimap<edm::ParameterSetID, edm::eventsetup::ESSourceInfo> const& essources = esController.essources();
0303   bool isPresent1 = false;
0304   bool isPresent2 = false;
0305   bool isPresent3 = false;
0306   bool isPresent4 = false;
0307 
0308   CPPUNIT_ASSERT(essources.size() == 4);
0309   for (auto const& essource : essources) {
0310     if (essource.second.pset() == &pset1) {
0311       isPresent1 = true;
0312       CPPUNIT_ASSERT(essource.first == pset1.id());
0313       CPPUNIT_ASSERT(essource.second.finderGet() ==
0314                      static_cast<edm::EventSetupRecordIntervalFinder const*>(finder1.get()));
0315       edm::eventsetup::ESSourceInfo const& info = essource.second;
0316       CPPUNIT_ASSERT(info.subProcessIndexes().size() == 2);
0317       CPPUNIT_ASSERT(info.subProcessIndexes()[0] == 0);
0318       CPPUNIT_ASSERT(info.subProcessIndexes()[1] == 1);
0319     }
0320     if (essource.second.pset() == &pset2) {
0321       isPresent2 = true;
0322       CPPUNIT_ASSERT(essource.first == pset1.id());
0323       CPPUNIT_ASSERT(essource.second.finderGet() ==
0324                      static_cast<edm::EventSetupRecordIntervalFinder const*>(finder2.get()));
0325       edm::eventsetup::ESSourceInfo const& info = essource.second;
0326       CPPUNIT_ASSERT(info.subProcessIndexes().size() == 2);
0327       CPPUNIT_ASSERT(info.subProcessIndexes()[0] == 0);
0328       CPPUNIT_ASSERT(info.subProcessIndexes()[1] == 2);
0329     }
0330     if (essource.second.pset() == &pset3) {
0331       isPresent3 = true;
0332       CPPUNIT_ASSERT(essource.first == pset3.id());
0333       CPPUNIT_ASSERT(essource.second.finderGet() ==
0334                      static_cast<edm::EventSetupRecordIntervalFinder const*>(finder3.get()));
0335       edm::eventsetup::ESSourceInfo const& info = essource.second;
0336       CPPUNIT_ASSERT(info.subProcessIndexes().size() == 2);
0337       CPPUNIT_ASSERT(info.subProcessIndexes()[0] == 0);
0338       CPPUNIT_ASSERT(info.subProcessIndexes()[1] == 3);
0339     }
0340     if (essource.second.pset() == &pset4) {
0341       isPresent4 = true;
0342       CPPUNIT_ASSERT(essource.first == pset4.id());
0343       CPPUNIT_ASSERT(essource.second.finderGet() ==
0344                      static_cast<edm::EventSetupRecordIntervalFinder const*>(finder4.get()));
0345       edm::eventsetup::ESSourceInfo const& info = essource.second;
0346       CPPUNIT_ASSERT(info.subProcessIndexes().size() == 3);
0347       CPPUNIT_ASSERT(info.subProcessIndexes()[0] == 0);
0348       CPPUNIT_ASSERT(info.subProcessIndexes()[1] == 4);
0349       CPPUNIT_ASSERT(info.subProcessIndexes()[2] == 5);
0350     }
0351   }
0352   CPPUNIT_ASSERT(isPresent1 && isPresent2 && isPresent3 && isPresent4);
0353 
0354   CPPUNIT_ASSERT(esController.isMatchingESSource(pset4.id(), 5, 0));
0355   CPPUNIT_ASSERT(esController.isMatchingESSource(pset4.id(), 5, 4));
0356   CPPUNIT_ASSERT(!esController.isMatchingESSource(pset4.id(), 5, 2));
0357   CPPUNIT_ASSERT_THROW(esController.isMatchingESSource(pset4.id(), 6, 4), cms::Exception);
0358 
0359   esController.clearComponents();
0360   CPPUNIT_ASSERT(esController.esproducers().empty());
0361   CPPUNIT_ASSERT(esController.essources().empty());
0362 }