Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  *  stream_producer_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/EDProducer.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 testStreamProducer : public CppUnit::TestFixture {
0053   CPPUNIT_TEST_SUITE(testStreamProducer);
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   testStreamProducer();
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::EDProducer<> {
0144   public:
0145     static unsigned int m_count;
0146 
0147     BasicProd(edm::ParameterSet const&) {}
0148 
0149     void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0150   };
0151 
0152   class GlobalProd : public edm::stream::EDProducer<edm::GlobalCache<int>> {
0153   public:
0154     static unsigned int m_count;
0155 
0156     static std::unique_ptr<int> initializeGlobalCache(edm::ParameterSet const&) { return std::make_unique<int>(1); }
0157     GlobalProd(edm::ParameterSet const&, const int* iGlobal) { CPPUNIT_ASSERT(*iGlobal == 1); }
0158 
0159     void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0160 
0161     static void globalEndJob(int* iGlobal) {
0162       CPPUNIT_ASSERT(1 == *iGlobal);
0163       ++m_count;
0164     }
0165   };
0166   class GlobalProdWithBeginJob : public edm::stream::EDProducer<edm::GlobalCache<int>> {
0167   public:
0168     static unsigned int m_count;
0169 
0170     static std::unique_ptr<int> initializeGlobalCache(edm::ParameterSet const&) { return std::make_unique<int>(1); }
0171     GlobalProdWithBeginJob(edm::ParameterSet const&, const int* iGlobal) { CPPUNIT_ASSERT(*iGlobal == 1); }
0172 
0173     static void globalBeginJob(int* iGlobal) {
0174       CPPUNIT_ASSERT(1 == *iGlobal);
0175       *iGlobal = 2;
0176       ++m_count;
0177     }
0178 
0179     void beginStream(edm::StreamID) override {
0180       int* iGlobal = const_cast<int*>(globalCache());
0181       CPPUNIT_ASSERT(2 == *iGlobal);
0182       *iGlobal = 3;
0183       ++m_count;
0184     }
0185 
0186     void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0187 
0188     static void globalEndJob(int* iGlobal) {
0189       CPPUNIT_ASSERT(3 == *iGlobal);
0190       ++m_count;
0191     }
0192   };
0193   class RunProd : public edm::stream::EDProducer<edm::RunCache<int>> {
0194   public:
0195     static unsigned int m_count;
0196     RunProd(edm::ParameterSet const&) {}
0197     void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0198 
0199     static std::shared_ptr<int> globalBeginRun(edm::Run const&, edm::EventSetup const&, GlobalCache const*) {
0200       ++m_count;
0201       return std::shared_ptr<int>{};
0202     }
0203 
0204     static void globalEndRun(edm::Run const&, edm::EventSetup const&, RunProd::RunContext const*) { ++m_count; }
0205   };
0206 
0207   class LumiProd : public edm::stream::EDProducer<edm::LuminosityBlockCache<int>> {
0208   public:
0209     static unsigned int m_count;
0210     LumiProd(edm::ParameterSet const&) {}
0211     void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0212 
0213     static std::shared_ptr<int> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
0214                                                            edm::EventSetup const&,
0215                                                            RunContext const*) {
0216       ++m_count;
0217       return std::shared_ptr<int>{};
0218     }
0219 
0220     static void globalEndLuminosityBlock(edm::LuminosityBlock const&,
0221                                          edm::EventSetup const&,
0222                                          LuminosityBlockContext const*) {
0223       ++m_count;
0224     }
0225   };
0226 
0227   class RunSummaryProd : public edm::stream::EDProducer<edm::RunSummaryCache<int>> {
0228   public:
0229     static unsigned int m_count;
0230     RunSummaryProd(edm::ParameterSet const&) {}
0231     void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0232 
0233     static std::shared_ptr<int> globalBeginRunSummary(edm::Run const&, edm::EventSetup const&, GlobalCache const*) {
0234       ++m_count;
0235       return std::shared_ptr<int>{};
0236     }
0237 
0238     void endRunSummary(edm::Run const&, edm::EventSetup const&, int*) const override { ++m_count; }
0239 
0240     static void globalEndRunSummary(edm::Run const&, edm::EventSetup const&, RunContext const*, int*) { ++m_count; }
0241   };
0242 
0243   class LumiSummaryProd : public edm::stream::EDProducer<edm::LuminosityBlockSummaryCache<int>> {
0244   public:
0245     static unsigned int m_count;
0246     LumiSummaryProd(edm::ParameterSet const&) {}
0247     void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0248 
0249     static std::shared_ptr<int> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const&,
0250                                                                   edm::EventSetup const&,
0251                                                                   LuminosityBlockContext const*) {
0252       ++m_count;
0253       return std::shared_ptr<int>{};
0254     }
0255 
0256     void endLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&, int*) const override {
0257       ++m_count;
0258     }
0259 
0260     static void globalEndLuminosityBlockSummary(edm::LuminosityBlock const&,
0261                                                 edm::EventSetup const&,
0262                                                 LuminosityBlockContext const*,
0263                                                 int*) {
0264       ++m_count;
0265     }
0266   };
0267 
0268   class BeginRunProd : public edm::stream::EDProducer<edm::BeginRunProducer> {
0269   public:
0270     static unsigned int m_count;
0271     BeginRunProd(edm::ParameterSet const&) {}
0272 
0273     void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0274 
0275     static void globalBeginRunProduce(edm::Run&, edm::EventSetup const&, RunContext const*) { ++m_count; }
0276   };
0277 
0278   class BeginLumiProd : public edm::stream::EDProducer<edm::BeginLuminosityBlockProducer> {
0279   public:
0280     static unsigned int m_count;
0281     BeginLumiProd(edm::ParameterSet const&) {}
0282 
0283     void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0284 
0285     static void globalBeginLuminosityBlockProduce(edm::LuminosityBlock&,
0286                                                   edm::EventSetup const&,
0287                                                   LuminosityBlockContext const*) {
0288       ++m_count;
0289     }
0290   };
0291 
0292   class EndRunProd : public edm::stream::EDProducer<edm::EndRunProducer> {
0293   public:
0294     static unsigned int m_count;
0295     EndRunProd(edm::ParameterSet const&) {}
0296 
0297     void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0298 
0299     static void globalEndRunProduce(edm::Run&, edm::EventSetup const&, RunContext const*) { ++m_count; }
0300   };
0301 
0302   class EndLumiProd : public edm::stream::EDProducer<edm::EndLuminosityBlockProducer> {
0303   public:
0304     static unsigned int m_count;
0305     EndLumiProd(edm::ParameterSet const&) {}
0306 
0307     void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0308 
0309     static void globalEndLuminosityBlockProduce(edm::LuminosityBlock&,
0310                                                 edm::EventSetup const&,
0311                                                 LuminosityBlockContext const*) {
0312       ++m_count;
0313     }
0314   };
0315 
0316   class EndRunSummaryProd : public edm::stream::EDProducer<edm::EndRunProducer, edm::RunSummaryCache<int>> {
0317   public:
0318     static unsigned int m_count;
0319     static bool m_globalEndRunSummaryCalled;
0320     EndRunSummaryProd(edm::ParameterSet const&) {}
0321 
0322     void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0323 
0324     static std::shared_ptr<int> globalBeginRunSummary(edm::Run const&, edm::EventSetup const&, RunContext const*) {
0325       ++m_count;
0326       return std::shared_ptr<int>{};
0327     }
0328 
0329     void endRunSummary(edm::Run const&, edm::EventSetup const&, int*) const override { ++m_count; }
0330 
0331     static void globalEndRunSummary(edm::Run const&, edm::EventSetup const&, RunContext const*, int*) {
0332       ++m_count;
0333       CPPUNIT_ASSERT(m_globalEndRunSummaryCalled == false);
0334       m_globalEndRunSummaryCalled = true;
0335     }
0336 
0337     static void globalEndRunProduce(edm::Run&, edm::EventSetup const&, RunContext const*, int const*) {
0338       ++m_count;
0339       CPPUNIT_ASSERT(m_globalEndRunSummaryCalled == true);
0340       m_globalEndRunSummaryCalled = false;
0341     }
0342   };
0343 
0344   class EndLumiSummaryProd
0345       : public edm::stream::EDProducer<edm::EndLuminosityBlockProducer, edm::LuminosityBlockSummaryCache<int>> {
0346   public:
0347     static unsigned int m_count;
0348     static bool m_globalEndLuminosityBlockSummaryCalled;
0349     EndLumiSummaryProd(edm::ParameterSet const&) {}
0350 
0351     void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0352 
0353     static std::shared_ptr<int> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const&,
0354                                                                   edm::EventSetup const&,
0355                                                                   LuminosityBlockContext const*) {
0356       ++m_count;
0357       return std::shared_ptr<int>{};
0358     }
0359 
0360     void endLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&, int*) const override {
0361       ++m_count;
0362     }
0363 
0364     static void globalEndLuminosityBlockSummary(edm::LuminosityBlock const&,
0365                                                 edm::EventSetup const&,
0366                                                 LuminosityBlockContext const*,
0367                                                 int*) {
0368       ++m_count;
0369       CPPUNIT_ASSERT(m_globalEndLuminosityBlockSummaryCalled == false);
0370       m_globalEndLuminosityBlockSummaryCalled = true;
0371     }
0372 
0373     static void globalEndLuminosityBlockProduce(edm::LuminosityBlock&,
0374                                                 edm::EventSetup const&,
0375                                                 LuminosityBlockContext const*,
0376                                                 int const*) {
0377       ++m_count;
0378       CPPUNIT_ASSERT(m_globalEndLuminosityBlockSummaryCalled == true);
0379       m_globalEndLuminosityBlockSummaryCalled = false;
0380     }
0381   };
0382 };
0383 unsigned int testStreamProducer::BasicProd::m_count = 0;
0384 unsigned int testStreamProducer::GlobalProd::m_count = 0;
0385 unsigned int testStreamProducer::GlobalProdWithBeginJob::m_count = 0;
0386 unsigned int testStreamProducer::RunProd::m_count = 0;
0387 unsigned int testStreamProducer::LumiProd::m_count = 0;
0388 unsigned int testStreamProducer::RunSummaryProd::m_count = 0;
0389 unsigned int testStreamProducer::LumiSummaryProd::m_count = 0;
0390 unsigned int testStreamProducer::BeginRunProd::m_count = 0;
0391 unsigned int testStreamProducer::EndRunProd::m_count = 0;
0392 unsigned int testStreamProducer::BeginLumiProd::m_count = 0;
0393 unsigned int testStreamProducer::EndLumiProd::m_count = 0;
0394 unsigned int testStreamProducer::EndRunSummaryProd::m_count = 0;
0395 bool testStreamProducer::EndRunSummaryProd::m_globalEndRunSummaryCalled = false;
0396 unsigned int testStreamProducer::EndLumiSummaryProd::m_count = 0;
0397 bool testStreamProducer::EndLumiSummaryProd::m_globalEndLuminosityBlockSummaryCalled = false;
0398 ///registration of the test so that the runner can find it
0399 CPPUNIT_TEST_SUITE_REGISTRATION(testStreamProducer);
0400 
0401 testStreamProducer::testStreamProducer()
0402     : m_prodReg(new edm::ProductRegistry{}),
0403       m_idHelper(new edm::BranchIDListHelper{}),
0404       m_associationsHelper(new edm::ThinnedAssociationsHelper{}),
0405       m_ep() {
0406   //Setup the principals
0407   m_prodReg->setFrozen();
0408   m_idHelper->updateFromRegistry(*m_prodReg);
0409   edm::EventID eventID = edm::EventID::firstValidEvent();
0410 
0411   std::string uuid = edm::createGlobalIdentifier();
0412   edm::Timestamp now(1234567UL);
0413   auto runAux = std::make_shared<edm::RunAuxiliary>(eventID.run(), now, now);
0414   m_rp.reset(new edm::RunPrincipal(runAux, m_prodReg, m_procConfig, &historyAppender_, 0));
0415   auto lumiAux = std::make_shared<edm::LuminosityBlockAuxiliary>(m_rp->run(), 1, now, now);
0416   m_lbp.reset(new edm::LuminosityBlockPrincipal(m_prodReg, m_procConfig, &historyAppender_, 0));
0417   m_lbp->setAux(*lumiAux);
0418   m_lbp->setRunPrincipal(m_rp);
0419   edm::EventAuxiliary eventAux(eventID, uuid, now, true);
0420 
0421   //Only an EventProcessor or SubProcess is allowed to create a StreamID but I need one
0422   ShadowStreamID shadowID;
0423   shadowID.value = 0;
0424   edm::StreamID* pID = reinterpret_cast<edm::StreamID*>(&shadowID);
0425   assert(pID->value() == 0);
0426 
0427   m_ep.reset(new edm::EventPrincipal(m_prodReg, m_idHelper, m_associationsHelper, m_procConfig, nullptr, *pID));
0428   m_ep->fillEventPrincipal(eventAux, nullptr);
0429   m_ep->setLuminosityBlockPrincipal(m_lbp.get());
0430   m_actReg.reset(new edm::ActivityRegistry);
0431 
0432   //For each transition, bind a lambda which will call the proper method of the Worker
0433   m_transToFunc[Trans::kBeginJob] = [](edm::Worker* iBase) { iBase->beginJob(); };
0434   m_transToFunc[Trans::kBeginStream] = [](edm::Worker* iBase) {
0435     edm::StreamContext streamContext(s_streamID0, nullptr);
0436     iBase->beginStream(s_streamID0, streamContext);
0437   };
0438 
0439   m_transToFunc[Trans::kGlobalBeginRun] = [this](edm::Worker* iBase) {
0440     typedef edm::OccurrenceTraits<edm::RunPrincipal, edm::BranchActionGlobalBegin> Traits;
0441     edm::ParentContext parentContext;
0442     edm::RunTransitionInfo info(*m_rp, *m_es);
0443     doWork<Traits>(iBase, info, parentContext);
0444   };
0445   m_transToFunc[Trans::kStreamBeginRun] = [this](edm::Worker* iBase) {
0446     typedef edm::OccurrenceTraits<edm::RunPrincipal, edm::BranchActionStreamBegin> Traits;
0447     edm::ParentContext parentContext;
0448     edm::RunTransitionInfo info(*m_rp, *m_es);
0449     doWork<Traits>(iBase, info, parentContext);
0450   };
0451 
0452   m_transToFunc[Trans::kGlobalBeginLuminosityBlock] = [this](edm::Worker* iBase) {
0453     typedef edm::OccurrenceTraits<edm::LuminosityBlockPrincipal, edm::BranchActionGlobalBegin> Traits;
0454     edm::ParentContext parentContext;
0455     edm::LumiTransitionInfo info(*m_lbp, *m_es);
0456     doWork<Traits>(iBase, info, parentContext);
0457   };
0458   m_transToFunc[Trans::kStreamBeginLuminosityBlock] = [this](edm::Worker* iBase) {
0459     typedef edm::OccurrenceTraits<edm::LuminosityBlockPrincipal, edm::BranchActionStreamBegin> Traits;
0460     edm::ParentContext parentContext;
0461     edm::LumiTransitionInfo info(*m_lbp, *m_es);
0462     doWork<Traits>(iBase, info, parentContext);
0463   };
0464 
0465   m_transToFunc[Trans::kEvent] = [this](edm::Worker* iBase) {
0466     typedef edm::OccurrenceTraits<edm::EventPrincipal, edm::BranchActionStreamBegin> Traits;
0467     edm::StreamContext streamContext(s_streamID0, nullptr);
0468     edm::ParentContext parentContext(&streamContext);
0469     iBase->setActivityRegistry(m_actReg);
0470     edm::EventTransitionInfo info(*m_ep, *m_es);
0471     doWork<Traits>(iBase, info, parentContext);
0472   };
0473 
0474   m_transToFunc[Trans::kStreamEndLuminosityBlock] = [this](edm::Worker* iBase) {
0475     typedef edm::OccurrenceTraits<edm::LuminosityBlockPrincipal, edm::BranchActionStreamEnd> Traits;
0476     edm::ParentContext parentContext;
0477     edm::LumiTransitionInfo info(*m_lbp, *m_es);
0478     doWork<Traits>(iBase, info, parentContext);
0479   };
0480   m_transToFunc[Trans::kGlobalEndLuminosityBlock] = [this](edm::Worker* iBase) {
0481     typedef edm::OccurrenceTraits<edm::LuminosityBlockPrincipal, edm::BranchActionGlobalEnd> Traits;
0482     edm::ParentContext parentContext;
0483     edm::LumiTransitionInfo info(*m_lbp, *m_es);
0484     doWork<Traits>(iBase, info, parentContext);
0485   };
0486 
0487   m_transToFunc[Trans::kStreamEndRun] = [this](edm::Worker* iBase) {
0488     typedef edm::OccurrenceTraits<edm::RunPrincipal, edm::BranchActionStreamEnd> Traits;
0489     edm::ParentContext parentContext;
0490     edm::RunTransitionInfo info(*m_rp, *m_es);
0491     doWork<Traits>(iBase, info, parentContext);
0492   };
0493   m_transToFunc[Trans::kGlobalEndRun] = [this](edm::Worker* iBase) {
0494     typedef edm::OccurrenceTraits<edm::RunPrincipal, edm::BranchActionGlobalEnd> Traits;
0495     edm::ParentContext parentContext;
0496     edm::RunTransitionInfo info(*m_rp, *m_es);
0497     doWork<Traits>(iBase, info, parentContext);
0498   };
0499 
0500   m_transToFunc[Trans::kEndStream] = [](edm::Worker* iBase) {
0501     edm::StreamContext streamContext(s_streamID0, nullptr);
0502     iBase->endStream(s_streamID0, streamContext);
0503   };
0504   m_transToFunc[Trans::kEndJob] = [](edm::Worker* iBase) { iBase->endJob(); };
0505 }
0506 
0507 namespace {
0508   template <typename T>
0509   std::shared_ptr<edm::stream::EDProducerAdaptorBase> createModule() {
0510     edm::ParameterSet pset;
0511     std::shared_ptr<edm::stream::EDProducerAdaptorBase> retValue =
0512         std::make_shared<edm::stream::EDProducerAdaptor<T>>(pset);
0513     edm::maker::ModuleHolderT<edm::stream::EDProducerAdaptorBase> h(retValue, nullptr);
0514     h.preallocate(edm::PreallocationConfiguration{});
0515     return retValue;
0516   }
0517   template <typename T>
0518   void testTransition(edm::Worker* iWorker,
0519                       testStreamProducer::Trans iTrans,
0520                       testStreamProducer::Expectations const& iExpect,
0521                       std::function<void(edm::Worker*)> iFunc) {
0522     assert(0 == T::m_count);
0523     iFunc(iWorker);
0524     auto count = std::count(iExpect.begin(), iExpect.end(), iTrans);
0525     if (count != T::m_count) {
0526       std::cout << "For trans " << static_cast<std::underlying_type<testStreamProducer::Trans>::type>(iTrans)
0527                 << " expected " << count << " and got " << T::m_count << std::endl;
0528     }
0529     CPPUNIT_ASSERT(T::m_count == count);
0530     T::m_count = 0;
0531     iWorker->reset();
0532   }
0533 }  // namespace
0534 
0535 template <typename T, typename U>
0536 void testStreamProducer::testTransitions(std::shared_ptr<U> iMod, Expectations const& iExpect) {
0537   oneapi::tbb::global_control control(oneapi::tbb::global_control::max_allowed_parallelism, 1);
0538 
0539   edm::WorkerT<edm::stream::EDProducerAdaptorBase> w{iMod, m_desc, nullptr};
0540   for (auto& keyVal : m_transToFunc) {
0541     testTransition<T>(&w, keyVal.first, iExpect, keyVal.second);
0542   }
0543 }
0544 template <typename T>
0545 void testStreamProducer::runTest(Expectations const& iExpect) {
0546   auto mod = createModule<T>();
0547   CPPUNIT_ASSERT(0 == T::m_count);
0548   testTransitions<T>(mod, iExpect);
0549 }
0550 
0551 void testStreamProducer::basicTest() { runTest<BasicProd>({Trans::kEvent}); }
0552 
0553 void testStreamProducer::globalTest() {
0554   runTest<GlobalProd>({Trans::kEvent, Trans::kEndJob});
0555   runTest<GlobalProdWithBeginJob>({Trans::kBeginJob, Trans::kBeginStream, Trans::kEvent, Trans::kEndJob});
0556 }
0557 
0558 void testStreamProducer::runTest() { runTest<RunProd>({Trans::kGlobalBeginRun, Trans::kEvent, Trans::kGlobalEndRun}); }
0559 
0560 void testStreamProducer::runSummaryTest() {
0561   runTest<RunSummaryProd>({Trans::kGlobalBeginRun, Trans::kEvent, Trans::kStreamEndRun, Trans::kGlobalEndRun});
0562 }
0563 
0564 void testStreamProducer::lumiTest() {
0565   runTest<LumiProd>({Trans::kGlobalBeginLuminosityBlock, Trans::kEvent, Trans::kGlobalEndLuminosityBlock});
0566 }
0567 
0568 void testStreamProducer::lumiSummaryTest() {
0569   runTest<LumiSummaryProd>({Trans::kGlobalBeginLuminosityBlock,
0570                             Trans::kEvent,
0571                             Trans::kStreamEndLuminosityBlock,
0572                             Trans::kGlobalEndLuminosityBlock});
0573 }
0574 
0575 void testStreamProducer::beginRunProdTest() { runTest<BeginRunProd>({Trans::kGlobalBeginRun, Trans::kEvent}); }
0576 
0577 void testStreamProducer::beginLumiProdTest() {
0578   runTest<BeginLumiProd>({Trans::kGlobalBeginLuminosityBlock, Trans::kEvent});
0579 }
0580 
0581 void testStreamProducer::endRunProdTest() { runTest<EndRunProd>({Trans::kGlobalEndRun, Trans::kEvent}); }
0582 
0583 void testStreamProducer::endLumiProdTest() { runTest<EndLumiProd>({Trans::kGlobalEndLuminosityBlock, Trans::kEvent}); }
0584 
0585 void testStreamProducer::endRunSummaryProdTest() {
0586   runTest<EndRunSummaryProd>(
0587       {Trans::kGlobalEndRun, Trans::kEvent, Trans::kGlobalBeginRun, Trans::kStreamEndRun, Trans::kGlobalEndRun});
0588 }
0589 
0590 void testStreamProducer::endLumiSummaryProdTest() {
0591   runTest<EndLumiSummaryProd>({Trans::kGlobalEndLuminosityBlock,
0592                                Trans::kEvent,
0593                                Trans::kGlobalBeginLuminosityBlock,
0594                                Trans::kStreamEndLuminosityBlock,
0595                                Trans::kGlobalEndLuminosityBlock});
0596 }