Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-24 02:18:52

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