Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-04 04:34:56

0001 /*
0002  *  proxyfactoryproducer_t.cc
0003  *  EDMProto
0004  *
0005  *  Created by Chris Jones on 4/8/05.
0006  *  Changed by Viji Sundararajan on 28-Jun-05
0007  */
0008 #include <iostream>
0009 #include <atomic>
0010 #include <vector>
0011 #include <map>
0012 #include <functional>
0013 #include "oneapi/tbb/global_control.h"
0014 #include "FWCore/Framework/interface/limited/EDFilter.h"
0015 #include "FWCore/Framework/interface/maker/WorkerT.h"
0016 #include "FWCore/Framework/interface/maker/ModuleHolder.h"
0017 #include "FWCore/Framework/interface/PreallocationConfiguration.h"
0018 #include "FWCore/Framework/interface/TransitionInfoTypes.h"
0019 #include "FWCore/Framework/interface/OccurrenceTraits.h"
0020 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0021 #include "DataFormats/Provenance/interface/BranchIDListHelper.h"
0022 #include "DataFormats/Provenance/interface/ThinnedAssociationsHelper.h"
0023 #include "FWCore/Framework/interface/HistoryAppender.h"
0024 #include "FWCore/ServiceRegistry/interface/ParentContext.h"
0025 #include "FWCore/ServiceRegistry/interface/StreamContext.h"
0026 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0027 #include "FWCore/Concurrency/interface/FinalWaitingTask.h"
0028 #include "FWCore/Utilities/interface/GlobalIdentifier.h"
0029 
0030 #include "FWCore/Utilities/interface/Exception.h"
0031 
0032 #include "cppunit/extensions/HelperMacros.h"
0033 
0034 namespace {
0035   edm::ParameterSet makePSet() {
0036     edm::ParameterSet pset;
0037     const unsigned int kLimit = 1;
0038     pset.addUntrackedParameter("concurrencyLimit", kLimit);
0039     return pset;
0040   }
0041 
0042   const edm::ParameterSet s_pset = makePSet();
0043 }  // namespace
0044 
0045 namespace {
0046   struct ShadowStreamID {
0047     constexpr ShadowStreamID() : value(0) {}
0048     unsigned int value;
0049   };
0050 
0051   union IDUnion {
0052     IDUnion() : m_shadow() {}
0053     ShadowStreamID m_shadow;
0054     edm::StreamID m_id;
0055   };
0056 }  // namespace
0057 static edm::StreamID makeID() {
0058   IDUnion u;
0059   assert(u.m_id.value() == 0);
0060   return u.m_id;
0061 }
0062 static const edm::StreamID s_streamID0 = makeID();
0063 
0064 class testLimitedFilter : public CppUnit::TestFixture {
0065   CPPUNIT_TEST_SUITE(testLimitedFilter);
0066 
0067   CPPUNIT_TEST(basicTest);
0068   CPPUNIT_TEST(streamTest);
0069   CPPUNIT_TEST(runTest);
0070   CPPUNIT_TEST(runSummaryTest);
0071   CPPUNIT_TEST(lumiTest);
0072   CPPUNIT_TEST(lumiSummaryTest);
0073   CPPUNIT_TEST(beginRunProdTest);
0074   CPPUNIT_TEST(beginLumiProdTest);
0075   CPPUNIT_TEST(endRunProdTest);
0076   CPPUNIT_TEST(endLumiProdTest);
0077   CPPUNIT_TEST(endRunSummaryProdTest);
0078   CPPUNIT_TEST(endLumiSummaryProdTest);
0079 
0080   CPPUNIT_TEST_SUITE_END();
0081 
0082 public:
0083   testLimitedFilter();
0084 
0085   void setUp() {}
0086   void tearDown() {}
0087 
0088   void basicTest();
0089   void streamTest();
0090   void runTest();
0091   void runSummaryTest();
0092   void lumiTest();
0093   void lumiSummaryTest();
0094   void beginRunProdTest();
0095   void beginLumiProdTest();
0096   void endRunProdTest();
0097   void endLumiProdTest();
0098   void endRunSummaryProdTest();
0099   void endLumiSummaryProdTest();
0100 
0101   enum class Trans {
0102     kBeginJob,
0103     kBeginStream,
0104     kGlobalBeginRun,
0105     kGlobalBeginRunProduce,
0106     kStreamBeginRun,
0107     kGlobalBeginLuminosityBlock,
0108     kStreamBeginLuminosityBlock,
0109     kEvent,
0110     kStreamEndLuminosityBlock,
0111     kGlobalEndLuminosityBlock,
0112     kStreamEndRun,
0113     kGlobalEndRun,
0114     kEndStream,
0115     kEndJob
0116   };
0117   typedef std::vector<Trans> Expectations;
0118 
0119 private:
0120   std::map<Trans, std::function<void(edm::Worker*)>> m_transToFunc;
0121 
0122   edm::ProcessConfiguration m_procConfig;
0123   std::shared_ptr<edm::ProductRegistry> m_prodReg;
0124   std::shared_ptr<edm::BranchIDListHelper> m_idHelper;
0125   std::shared_ptr<edm::ThinnedAssociationsHelper> m_associationsHelper;
0126   std::unique_ptr<edm::EventPrincipal> m_ep;
0127   edm::HistoryAppender historyAppender_;
0128   std::shared_ptr<edm::LuminosityBlockPrincipal> m_lbp;
0129   std::shared_ptr<edm::RunPrincipal> m_rp;
0130   std::shared_ptr<edm::ActivityRegistry>
0131       m_actReg;  // We do not use propagate_const because the registry itself is mutable.
0132   edm::EventSetupImpl* m_es = nullptr;
0133   edm::ModuleDescription m_desc = {"Dummy", "dummy"};
0134 
0135   template <typename T>
0136   void testTransitions(std::shared_ptr<T> iMod, Expectations const& iExpect);
0137 
0138   template <typename Traits, typename Info>
0139   void doWork(edm::Worker* iBase, Info const& info, edm::ParentContext const& iContext) {
0140     oneapi::tbb::task_group group;
0141     edm::FinalWaitingTask task{group};
0142     edm::ServiceToken token;
0143     iBase->doWorkAsync<Traits>(edm::WaitingTaskHolder(group, &task), info, token, s_streamID0, iContext, nullptr);
0144     task.wait();
0145   }
0146 
0147   class BasicProd : public edm::limited::EDFilter<> {
0148   public:
0149     BasicProd() : edm::limited::EDFilterBase(s_pset), edm::limited::EDFilter<>(s_pset) {}
0150     mutable unsigned int m_count = 0;  //[[cms-thread-safe]]
0151 
0152     bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {
0153       ++m_count;
0154       return true;
0155     }
0156   };
0157   class StreamProd : public edm::limited::EDFilter<edm::StreamCache<int>> {
0158   public:
0159     StreamProd() : edm::limited::EDFilterBase(s_pset), edm::limited::EDFilter<edm::StreamCache<int>>(s_pset) {}
0160     mutable unsigned int m_count = 0;
0161     bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {
0162       ++m_count;
0163       return true;
0164     }
0165 
0166     std::unique_ptr<int> beginStream(edm::StreamID) const override {
0167       ++m_count;
0168       return std::unique_ptr<int>{};
0169     }
0170 
0171     virtual void streamBeginRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const override { ++m_count; }
0172     virtual void streamBeginLuminosityBlock(edm::StreamID,
0173                                             edm::LuminosityBlock const&,
0174                                             edm::EventSetup const&) const override {
0175       ++m_count;
0176     }
0177     virtual void streamEndLuminosityBlock(edm::StreamID,
0178                                           edm::LuminosityBlock const&,
0179                                           edm::EventSetup const&) const override {
0180       ++m_count;
0181     }
0182     virtual void streamEndRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const override { ++m_count; }
0183     void endStream(edm::StreamID) const override { ++m_count; }
0184   };
0185 
0186   class RunProd : public edm::limited::EDFilter<edm::RunCache<int>> {
0187   public:
0188     RunProd() : edm::limited::EDFilterBase(s_pset), edm::limited::EDFilter<edm::RunCache<int>>(s_pset) {}
0189     mutable unsigned int m_count = 0;
0190     bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {
0191       ++m_count;
0192       return true;
0193     }
0194 
0195     std::shared_ptr<int> globalBeginRun(edm::Run const&, edm::EventSetup const&) const override {
0196       ++m_count;
0197       return std::shared_ptr<int>{};
0198     }
0199 
0200     void globalEndRun(edm::Run const&, edm::EventSetup const&) const override { ++m_count; }
0201   };
0202 
0203   class LumiProd : public edm::limited::EDFilter<edm::LuminosityBlockCache<int>> {
0204   public:
0205     LumiProd() : edm::limited::EDFilterBase(s_pset), edm::limited::EDFilter<edm::LuminosityBlockCache<int>>(s_pset) {}
0206     mutable unsigned int m_count = 0;
0207     bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {
0208       ++m_count;
0209       return true;
0210     }
0211 
0212     std::shared_ptr<int> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
0213                                                     edm::EventSetup const&) const override {
0214       ++m_count;
0215       return std::shared_ptr<int>{};
0216     }
0217 
0218     void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const override { ++m_count; }
0219   };
0220 
0221   class RunSummaryProd : public edm::limited::EDFilter<edm::RunSummaryCache<int>> {
0222   public:
0223     RunSummaryProd() : edm::limited::EDFilterBase(s_pset), edm::limited::EDFilter<edm::RunSummaryCache<int>>(s_pset) {}
0224     mutable unsigned int m_count = 0;
0225     bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {
0226       ++m_count;
0227       return true;
0228     }
0229 
0230     std::shared_ptr<int> globalBeginRunSummary(edm::Run const&, edm::EventSetup const&) const override {
0231       ++m_count;
0232       return std::shared_ptr<int>{};
0233     }
0234 
0235     void streamEndRunSummary(edm::StreamID, edm::Run const&, edm::EventSetup const&, int*) const override { ++m_count; }
0236 
0237     void globalEndRunSummary(edm::Run const&, edm::EventSetup const&, int*) const override { ++m_count; }
0238   };
0239 
0240   class LumiSummaryProd : public edm::limited::EDFilter<edm::LuminosityBlockSummaryCache<int>> {
0241   public:
0242     LumiSummaryProd()
0243         : edm::limited::EDFilterBase(s_pset), edm::limited::EDFilter<edm::LuminosityBlockSummaryCache<int>>(s_pset) {}
0244     mutable unsigned int m_count = 0;
0245     bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {
0246       ++m_count;
0247       return true;
0248     }
0249 
0250     std::shared_ptr<int> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const&,
0251                                                            edm::EventSetup const&) const override {
0252       ++m_count;
0253       return std::shared_ptr<int>{};
0254     }
0255 
0256     void streamEndLuminosityBlockSummary(edm::StreamID,
0257                                          edm::LuminosityBlock const&,
0258                                          edm::EventSetup const&,
0259                                          int*) const override {
0260       ++m_count;
0261     }
0262 
0263     void globalEndLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&, int*) const override {
0264       ++m_count;
0265     }
0266   };
0267 
0268   class BeginRunProd : public edm::limited::EDFilter<edm::BeginRunProducer> {
0269   public:
0270     BeginRunProd() : edm::limited::EDFilterBase(s_pset), edm::limited::EDFilter<edm::BeginRunProducer>(s_pset) {}
0271     mutable unsigned int m_count = 0;
0272     bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {
0273       ++m_count;
0274       return true;
0275     }
0276 
0277     void globalBeginRunProduce(edm::Run&, edm::EventSetup const&) const override { ++m_count; }
0278   };
0279 
0280   class BeginLumiProd : public edm::limited::EDFilter<edm::BeginLuminosityBlockProducer> {
0281   public:
0282     BeginLumiProd()
0283         : edm::limited::EDFilterBase(s_pset), edm::limited::EDFilter<edm::BeginLuminosityBlockProducer>(s_pset) {}
0284     mutable unsigned int m_count = 0;
0285     bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {
0286       ++m_count;
0287       return true;
0288     }
0289 
0290     void globalBeginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const override { ++m_count; }
0291   };
0292 
0293   class EndRunProd : public edm::limited::EDFilter<edm::EndRunProducer> {
0294   public:
0295     EndRunProd() : edm::limited::EDFilterBase(s_pset), edm::limited::EDFilter<edm::EndRunProducer>(s_pset) {}
0296     mutable unsigned int m_count = 0;
0297     bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {
0298       ++m_count;
0299       return true;
0300     }
0301 
0302     void globalEndRunProduce(edm::Run&, edm::EventSetup const&) const override { ++m_count; }
0303   };
0304 
0305   class EndLumiProd : public edm::limited::EDFilter<edm::EndLuminosityBlockProducer> {
0306   public:
0307     EndLumiProd()
0308         : edm::limited::EDFilterBase(s_pset), edm::limited::EDFilter<edm::EndLuminosityBlockProducer>(s_pset) {}
0309     mutable unsigned int m_count = 0;
0310     bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {
0311       ++m_count;
0312       return true;
0313     }
0314 
0315     void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const override { ++m_count; }
0316   };
0317 
0318   class EndRunSummaryProd : public edm::limited::EDFilter<edm::EndRunProducer, edm::RunSummaryCache<int>> {
0319   public:
0320     EndRunSummaryProd()
0321         : edm::limited::EDFilterBase(s_pset),
0322           edm::limited::EDFilter<edm::EndRunProducer, edm::RunSummaryCache<int>>(s_pset) {}
0323     mutable unsigned int m_count = 0;
0324     mutable bool m_globalEndRunSummaryCalled = false;
0325     bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {
0326       ++m_count;
0327       return true;
0328     }
0329 
0330     std::shared_ptr<int> globalBeginRunSummary(edm::Run const&, edm::EventSetup const&) const override {
0331       ++m_count;
0332       return std::shared_ptr<int>{};
0333     }
0334 
0335     void streamEndRunSummary(edm::StreamID, edm::Run const&, edm::EventSetup const&, int*) const override { ++m_count; }
0336 
0337     void globalEndRunSummary(edm::Run const&, edm::EventSetup const&, int*) const override {
0338       ++m_count;
0339       CPPUNIT_ASSERT(m_globalEndRunSummaryCalled == false);
0340       m_globalEndRunSummaryCalled = true;
0341     }
0342 
0343     void globalEndRunProduce(edm::Run&, edm::EventSetup const&, int const*) const override {
0344       ++m_count;
0345       CPPUNIT_ASSERT(m_globalEndRunSummaryCalled == true);
0346       m_globalEndRunSummaryCalled = false;
0347     }
0348   };
0349 
0350   class EndLumiSummaryProd
0351       : public edm::limited::EDFilter<edm::EndLuminosityBlockProducer, edm::LuminosityBlockSummaryCache<int>> {
0352   public:
0353     EndLumiSummaryProd()
0354         : edm::limited::EDFilterBase(s_pset),
0355           edm::limited::EDFilter<edm::EndLuminosityBlockProducer, edm::LuminosityBlockSummaryCache<int>>(s_pset) {}
0356     mutable unsigned int m_count = 0;
0357     mutable bool m_globalEndLuminosityBlockSummaryCalled = false;
0358     bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {
0359       ++m_count;
0360       return true;
0361     }
0362 
0363     std::shared_ptr<int> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const&,
0364                                                            edm::EventSetup const&) const override {
0365       ++m_count;
0366       return std::shared_ptr<int>{};
0367     }
0368 
0369     void streamEndLuminosityBlockSummary(edm::StreamID,
0370                                          edm::LuminosityBlock const&,
0371                                          edm::EventSetup const&,
0372                                          int*) const override {
0373       ++m_count;
0374     }
0375 
0376     void globalEndLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&, int*) const override {
0377       ++m_count;
0378       CPPUNIT_ASSERT(m_globalEndLuminosityBlockSummaryCalled == false);
0379       m_globalEndLuminosityBlockSummaryCalled = true;
0380     }
0381 
0382     void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&, int const*) const override {
0383       ++m_count;
0384       CPPUNIT_ASSERT(m_globalEndLuminosityBlockSummaryCalled == true);
0385       m_globalEndLuminosityBlockSummaryCalled = false;
0386     }
0387   };
0388 
0389   class TransformProd : public edm::limited::EDFilter<edm::Transformer> {
0390   public:
0391     TransformProd(edm::ParameterSet const&)
0392         : edm::limited::EDFilterBase(s_pset), edm::limited::EDFilter<edm::Transformer>(s_pset) {
0393       token_ = produces<float>();
0394       registerTransform(token_, [](float iV) { return int(iV); });
0395     }
0396 
0397     bool filter(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const {
0398       //iEvent.emplace(token_, 3.625);
0399       return true;
0400     }
0401 
0402   private:
0403     edm::EDPutTokenT<float> token_;
0404   };
0405 };
0406 
0407 ///registration of the test so that the runner can find it
0408 CPPUNIT_TEST_SUITE_REGISTRATION(testLimitedFilter);
0409 
0410 testLimitedFilter::testLimitedFilter()
0411     : m_prodReg(new edm::ProductRegistry{}),
0412       m_idHelper(new edm::BranchIDListHelper{}),
0413       m_associationsHelper(new edm::ThinnedAssociationsHelper{}),
0414       m_ep() {
0415   //Setup the principals
0416   m_prodReg->setFrozen();
0417   m_idHelper->updateFromRegistry(*m_prodReg);
0418   edm::EventID eventID = edm::EventID::firstValidEvent();
0419 
0420   std::string uuid = edm::createGlobalIdentifier();
0421   edm::Timestamp now(1234567UL);
0422   m_rp.reset(new edm::RunPrincipal(m_prodReg, m_procConfig, &historyAppender_, 0));
0423   m_rp->setAux(edm::RunAuxiliary(eventID.run(), now, now));
0424   edm::LuminosityBlockAuxiliary lumiAux(m_rp->run(), 1, now, now);
0425   m_lbp.reset(new edm::LuminosityBlockPrincipal(m_prodReg, m_procConfig, &historyAppender_, 0));
0426   m_lbp->setAux(lumiAux);
0427   m_lbp->setRunPrincipal(m_rp);
0428   edm::EventAuxiliary eventAux(eventID, uuid, now, true);
0429 
0430   m_ep.reset(new edm::EventPrincipal(m_prodReg, m_idHelper, m_associationsHelper, m_procConfig, nullptr));
0431   m_ep->fillEventPrincipal(eventAux, nullptr);
0432   m_ep->setLuminosityBlockPrincipal(m_lbp.get());
0433   m_actReg.reset(new edm::ActivityRegistry);
0434 
0435   //For each transition, bind a lambda which will call the proper method of the Worker
0436   m_transToFunc[Trans::kBeginStream] = [](edm::Worker* iBase) {
0437     edm::StreamContext streamContext(s_streamID0, nullptr);
0438     iBase->beginStream(s_streamID0, streamContext);
0439   };
0440 
0441   m_transToFunc[Trans::kGlobalBeginRun] = [this](edm::Worker* iBase) {
0442     typedef edm::OccurrenceTraits<edm::RunPrincipal, edm::BranchActionGlobalBegin> Traits;
0443     edm::GlobalContext gc(edm::GlobalContext::Transition::kBeginRun, nullptr);
0444     edm::ParentContext nullParentContext(&gc);
0445     iBase->setActivityRegistry(m_actReg);
0446     edm::RunTransitionInfo info(*m_rp, *m_es);
0447     doWork<Traits>(iBase, info, nullParentContext);
0448   };
0449   m_transToFunc[Trans::kStreamBeginRun] = [this](edm::Worker* iBase) {
0450     typedef edm::OccurrenceTraits<edm::RunPrincipal, edm::BranchActionStreamBegin> Traits;
0451     edm::StreamContext streamContext(s_streamID0, nullptr);
0452     edm::ParentContext nullParentContext(&streamContext);
0453     iBase->setActivityRegistry(m_actReg);
0454     edm::RunTransitionInfo info(*m_rp, *m_es);
0455     doWork<Traits>(iBase, info, nullParentContext);
0456   };
0457 
0458   m_transToFunc[Trans::kGlobalBeginLuminosityBlock] = [this](edm::Worker* iBase) {
0459     typedef edm::OccurrenceTraits<edm::LuminosityBlockPrincipal, edm::BranchActionGlobalBegin> Traits;
0460     edm::GlobalContext gc(edm::GlobalContext::Transition::kBeginLuminosityBlock, nullptr);
0461     edm::ParentContext nullParentContext(&gc);
0462     iBase->setActivityRegistry(m_actReg);
0463     edm::LumiTransitionInfo info(*m_lbp, *m_es);
0464     doWork<Traits>(iBase, info, nullParentContext);
0465   };
0466   m_transToFunc[Trans::kStreamBeginLuminosityBlock] = [this](edm::Worker* iBase) {
0467     typedef edm::OccurrenceTraits<edm::LuminosityBlockPrincipal, edm::BranchActionStreamBegin> Traits;
0468     edm::StreamContext streamContext(s_streamID0, nullptr);
0469     edm::ParentContext nullParentContext(&streamContext);
0470     iBase->setActivityRegistry(m_actReg);
0471     edm::LumiTransitionInfo info(*m_lbp, *m_es);
0472     doWork<Traits>(iBase, info, nullParentContext);
0473   };
0474 
0475   m_transToFunc[Trans::kEvent] = [this](edm::Worker* iBase) {
0476     typedef edm::OccurrenceTraits<edm::EventPrincipal, edm::BranchActionStreamBegin> Traits;
0477     edm::StreamContext streamContext(s_streamID0, nullptr);
0478     edm::ParentContext nullParentContext(&streamContext);
0479     iBase->setActivityRegistry(m_actReg);
0480     edm::EventTransitionInfo info(*m_ep, *m_es);
0481     doWork<Traits>(iBase, info, nullParentContext);
0482   };
0483 
0484   m_transToFunc[Trans::kStreamEndLuminosityBlock] = [this](edm::Worker* iBase) {
0485     typedef edm::OccurrenceTraits<edm::LuminosityBlockPrincipal, edm::BranchActionStreamEnd> Traits;
0486     edm::StreamContext streamContext(s_streamID0, nullptr);
0487     edm::ParentContext nullParentContext(&streamContext);
0488     iBase->setActivityRegistry(m_actReg);
0489     edm::LumiTransitionInfo info(*m_lbp, *m_es);
0490     doWork<Traits>(iBase, info, nullParentContext);
0491   };
0492   m_transToFunc[Trans::kGlobalEndLuminosityBlock] = [this](edm::Worker* iBase) {
0493     typedef edm::OccurrenceTraits<edm::LuminosityBlockPrincipal, edm::BranchActionGlobalEnd> Traits;
0494     edm::GlobalContext gc(edm::GlobalContext::Transition::kEndLuminosityBlock, nullptr);
0495     edm::ParentContext nullParentContext(&gc);
0496     iBase->setActivityRegistry(m_actReg);
0497     edm::LumiTransitionInfo info(*m_lbp, *m_es);
0498     doWork<Traits>(iBase, info, nullParentContext);
0499   };
0500 
0501   m_transToFunc[Trans::kStreamEndRun] = [this](edm::Worker* iBase) {
0502     typedef edm::OccurrenceTraits<edm::RunPrincipal, edm::BranchActionStreamEnd> Traits;
0503     edm::StreamContext streamContext(s_streamID0, nullptr);
0504     edm::ParentContext nullParentContext(&streamContext);
0505     iBase->setActivityRegistry(m_actReg);
0506     edm::RunTransitionInfo info(*m_rp, *m_es);
0507     doWork<Traits>(iBase, info, nullParentContext);
0508   };
0509   m_transToFunc[Trans::kGlobalEndRun] = [this](edm::Worker* iBase) {
0510     typedef edm::OccurrenceTraits<edm::RunPrincipal, edm::BranchActionGlobalEnd> Traits;
0511     edm::GlobalContext gc(edm::GlobalContext::Transition::kEndRun, nullptr);
0512     edm::ParentContext nullParentContext(&gc);
0513     iBase->setActivityRegistry(m_actReg);
0514     edm::RunTransitionInfo info(*m_rp, *m_es);
0515     doWork<Traits>(iBase, info, nullParentContext);
0516   };
0517 
0518   m_transToFunc[Trans::kEndStream] = [](edm::Worker* iBase) {
0519     edm::StreamContext streamContext(s_streamID0, nullptr);
0520     iBase->endStream(s_streamID0, streamContext);
0521   };
0522 }
0523 
0524 namespace {
0525   template <typename T>
0526   void testTransition(std::shared_ptr<T> iMod,
0527                       edm::Worker* iWorker,
0528                       testLimitedFilter::Trans iTrans,
0529                       testLimitedFilter::Expectations const& iExpect,
0530                       std::function<void(edm::Worker*)> iFunc) {
0531     assert(0 == iMod->m_count);
0532     iFunc(iWorker);
0533     auto count = std::count(iExpect.begin(), iExpect.end(), iTrans);
0534     if (count != iMod->m_count) {
0535       std::cout << "For trans " << static_cast<std::underlying_type<testLimitedFilter::Trans>::type>(iTrans)
0536                 << " expected " << count << " and got " << iMod->m_count << std::endl;
0537     }
0538     CPPUNIT_ASSERT(iMod->m_count == count);
0539     iMod->m_count = 0;
0540     iWorker->reset();
0541   }
0542 }  // namespace
0543 
0544 template <typename T>
0545 void testLimitedFilter::testTransitions(std::shared_ptr<T> iMod, Expectations const& iExpect) {
0546   oneapi::tbb::global_control control(oneapi::tbb::global_control::max_allowed_parallelism, 1);
0547 
0548   edm::maker::ModuleHolderT<edm::limited::EDFilterBase> h(iMod, nullptr);
0549   h.preallocate(edm::PreallocationConfiguration{});
0550   edm::WorkerT<edm::limited::EDFilterBase> wOther{iMod, m_desc, nullptr};
0551   edm::WorkerT<edm::limited::EDFilterBase> wGlobalLumi{iMod, m_desc, nullptr};
0552   edm::WorkerT<edm::limited::EDFilterBase> wStreamLumi{iMod, m_desc, nullptr};
0553   edm::WorkerT<edm::limited::EDFilterBase> wGlobalRun{iMod, m_desc, nullptr};
0554   edm::WorkerT<edm::limited::EDFilterBase> wStreamRun{iMod, m_desc, nullptr};
0555   for (auto& keyVal : m_transToFunc) {
0556     edm::Worker* worker = &wOther;
0557     if (keyVal.first == Trans::kStreamBeginLuminosityBlock || keyVal.first == Trans::kStreamEndLuminosityBlock) {
0558       worker = &wStreamLumi;
0559     } else if (keyVal.first == Trans::kGlobalBeginLuminosityBlock || keyVal.first == Trans::kGlobalEndLuminosityBlock) {
0560       worker = &wGlobalLumi;
0561     } else if (keyVal.first == Trans::kStreamBeginRun || keyVal.first == Trans::kStreamEndRun) {
0562       worker = &wStreamRun;
0563     } else if (keyVal.first == Trans::kGlobalBeginRun || keyVal.first == Trans::kGlobalEndRun) {
0564       worker = &wGlobalRun;
0565     }
0566     testTransition(iMod, worker, keyVal.first, iExpect, keyVal.second);
0567   }
0568 }
0569 
0570 void testLimitedFilter::basicTest() {
0571   auto testProd = std::make_shared<BasicProd>();
0572 
0573   CPPUNIT_ASSERT(0 == testProd->m_count);
0574   testTransitions(testProd, {Trans::kEvent});
0575 }
0576 
0577 void testLimitedFilter::streamTest() {
0578   auto testProd = std::make_shared<StreamProd>();
0579 
0580   CPPUNIT_ASSERT(0 == testProd->m_count);
0581   testTransitions(testProd,
0582                   {Trans::kBeginStream,
0583                    Trans::kStreamBeginRun,
0584                    Trans::kStreamBeginLuminosityBlock,
0585                    Trans::kEvent,
0586                    Trans::kStreamEndLuminosityBlock,
0587                    Trans::kStreamEndRun,
0588                    Trans::kEndStream});
0589 }
0590 
0591 void testLimitedFilter::runTest() {
0592   auto testProd = std::make_shared<RunProd>();
0593 
0594   CPPUNIT_ASSERT(0 == testProd->m_count);
0595   testTransitions(testProd, {Trans::kGlobalBeginRun, Trans::kEvent, Trans::kGlobalEndRun});
0596 }
0597 
0598 void testLimitedFilter::runSummaryTest() {
0599   auto testProd = std::make_shared<RunSummaryProd>();
0600 
0601   CPPUNIT_ASSERT(0 == testProd->m_count);
0602   testTransitions(testProd, {Trans::kGlobalBeginRun, Trans::kEvent, Trans::kStreamEndRun, Trans::kGlobalEndRun});
0603 }
0604 
0605 void testLimitedFilter::lumiTest() {
0606   auto testProd = std::make_shared<LumiProd>();
0607 
0608   CPPUNIT_ASSERT(0 == testProd->m_count);
0609   testTransitions(testProd, {Trans::kGlobalBeginLuminosityBlock, Trans::kEvent, Trans::kGlobalEndLuminosityBlock});
0610 }
0611 
0612 void testLimitedFilter::lumiSummaryTest() {
0613   auto testProd = std::make_shared<LumiSummaryProd>();
0614 
0615   CPPUNIT_ASSERT(0 == testProd->m_count);
0616   testTransitions(testProd,
0617                   {Trans::kGlobalBeginLuminosityBlock,
0618                    Trans::kEvent,
0619                    Trans::kStreamEndLuminosityBlock,
0620                    Trans::kGlobalEndLuminosityBlock});
0621 }
0622 
0623 void testLimitedFilter::beginRunProdTest() {
0624   auto testProd = std::make_shared<BeginRunProd>();
0625 
0626   CPPUNIT_ASSERT(0 == testProd->m_count);
0627   testTransitions(testProd, {Trans::kGlobalBeginRun, Trans::kEvent});
0628 }
0629 
0630 void testLimitedFilter::beginLumiProdTest() {
0631   auto testProd = std::make_shared<BeginLumiProd>();
0632 
0633   CPPUNIT_ASSERT(0 == testProd->m_count);
0634   testTransitions(testProd, {Trans::kGlobalBeginLuminosityBlock, Trans::kEvent});
0635 }
0636 
0637 void testLimitedFilter::endRunProdTest() {
0638   auto testProd = std::make_shared<EndRunProd>();
0639 
0640   CPPUNIT_ASSERT(0 == testProd->m_count);
0641   testTransitions(testProd, {Trans::kGlobalEndRun, Trans::kEvent});
0642 }
0643 
0644 void testLimitedFilter::endLumiProdTest() {
0645   auto testProd = std::make_shared<EndLumiProd>();
0646 
0647   CPPUNIT_ASSERT(0 == testProd->m_count);
0648   testTransitions(testProd, {Trans::kGlobalEndLuminosityBlock, Trans::kEvent});
0649 }
0650 
0651 void testLimitedFilter::endRunSummaryProdTest() {
0652   auto testProd = std::make_shared<EndRunSummaryProd>();
0653 
0654   CPPUNIT_ASSERT(0 == testProd->m_count);
0655   testTransitions(
0656       testProd,
0657       {Trans::kGlobalEndRun, Trans::kEvent, Trans::kGlobalBeginRun, Trans::kStreamEndRun, Trans::kGlobalEndRun});
0658 }
0659 
0660 void testLimitedFilter::endLumiSummaryProdTest() {
0661   auto testProd = std::make_shared<EndLumiSummaryProd>();
0662 
0663   CPPUNIT_ASSERT(0 == testProd->m_count);
0664   testTransitions(testProd,
0665                   {Trans::kGlobalEndLuminosityBlock,
0666                    Trans::kEvent,
0667                    Trans::kGlobalBeginLuminosityBlock,
0668                    Trans::kStreamEndLuminosityBlock,
0669                    Trans::kGlobalEndLuminosityBlock});
0670 }