Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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