Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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