File indexing completed on 2025-01-31 02:19:30
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <iostream>
0010 #include "cppunit/extensions/HelperMacros.h"
0011 #include <memory>
0012 #include "FWCore/Utilities/interface/GetPassID.h"
0013 #include "FWCore/Version/interface/GetReleaseVersion.h"
0014
0015 #include "FWCore/Framework/interface/SignallingProductRegistry.h"
0016 #include "FWCore/Framework/interface/PreallocationConfiguration.h"
0017
0018 #include "FWCore/Framework/interface/global/EDProducer.h"
0019 #include "FWCore/Framework/interface/ExceptionActions.h"
0020 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0021 #include "DataFormats/Provenance/interface/ProcessConfiguration.h"
0022 #include "FWCore/Framework/interface/maker/WorkerMaker.h"
0023 #include "FWCore/Framework/interface/maker/MakeModuleParams.h"
0024 #include "FWCore/Framework/interface/maker/WorkerT.h"
0025
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027
0028 #include "FWCore/Utilities/interface/TypeID.h"
0029
0030 class testEDProducerProductRegistryCallback : public CppUnit::TestFixture {
0031 CPPUNIT_TEST_SUITE(testEDProducerProductRegistryCallback);
0032
0033 CPPUNIT_TEST_EXCEPTION(testCircularRef, cms::Exception);
0034 CPPUNIT_TEST_EXCEPTION(testCircularRef2, cms::Exception);
0035 CPPUNIT_TEST(testTwoListeners);
0036
0037 CPPUNIT_TEST_SUITE_END();
0038
0039 public:
0040 void setUp() {}
0041 void tearDown() {}
0042 void testCircularRef();
0043 void testCircularRef2();
0044 void testTwoListeners();
0045 };
0046
0047
0048 CPPUNIT_TEST_SUITE_REGISTRATION(testEDProducerProductRegistryCallback);
0049
0050 using namespace edm;
0051
0052 namespace {
0053 class TestMod : public global::EDProducer<> {
0054 public:
0055 explicit TestMod(ParameterSet const& p);
0056
0057 void produce(StreamID, Event& e, EventSetup const&) const override;
0058
0059 void listen(ProductDescription const&);
0060 };
0061
0062 TestMod::TestMod(ParameterSet const&) { produces<int>(); }
0063
0064 void TestMod::produce(StreamID, Event&, EventSetup const&) const {}
0065
0066 class ListenMod : public global::EDProducer<> {
0067 public:
0068 explicit ListenMod(ParameterSet const&);
0069 void produce(StreamID, Event& e, EventSetup const&) const override;
0070 void listen(ProductDescription const&);
0071 };
0072
0073 ListenMod::ListenMod(ParameterSet const&) {
0074 callWhenNewProductsRegistered(
0075 [this](ProductDescription const& productDescription) { this->listen(productDescription); });
0076 }
0077 void ListenMod::produce(StreamID, Event&, EventSetup const&) const {}
0078
0079 void ListenMod::listen(ProductDescription const& iDesc) {
0080 edm::TypeID intType(typeid(int));
0081
0082 if (iDesc.friendlyClassName() == intType.friendlyClassName()) {
0083 produces<int>(iDesc.moduleLabel() + "-" + iDesc.productInstanceName());
0084
0085 }
0086 }
0087
0088 class ListenFloatMod : public global::EDProducer<> {
0089 public:
0090 explicit ListenFloatMod(ParameterSet const&);
0091 void produce(StreamID, Event& e, EventSetup const&) const;
0092 void listen(ProductDescription const&);
0093 };
0094
0095 ListenFloatMod::ListenFloatMod(ParameterSet const&) {
0096 callWhenNewProductsRegistered(
0097 [this](ProductDescription const& productDescription) { this->listen(productDescription); });
0098 }
0099 void ListenFloatMod::produce(StreamID, Event&, EventSetup const&) const {}
0100
0101 void ListenFloatMod::listen(ProductDescription const& iDesc) {
0102 edm::TypeID intType(typeid(int));
0103
0104 if (iDesc.friendlyClassName() == intType.friendlyClassName()) {
0105 produces<float>(iDesc.moduleLabel() + "-" + iDesc.productInstanceName());
0106
0107 }
0108 }
0109 }
0110
0111 void testEDProducerProductRegistryCallback::testCircularRef() {
0112 using namespace edm;
0113
0114 SignallingProductRegistry preg;
0115
0116 std::unique_ptr<Maker> f = std::make_unique<WorkerMaker<TestMod>>();
0117
0118 ParameterSet p1;
0119 p1.addParameter("@module_type", std::string("TestMod"));
0120 p1.addParameter("@module_label", std::string("t1"));
0121 p1.addParameter("@module_edm_type", std::string("EDProducer"));
0122 p1.registerIt();
0123
0124 ParameterSet p2;
0125 p2.addParameter("@module_type", std::string("TestMod"));
0126 p2.addParameter("@module_label", std::string("t2"));
0127 p2.addParameter("@module_edm_type", std::string("EDProducer"));
0128 p2.registerIt();
0129
0130 edm::ExceptionToActionTable table;
0131 edm::PreallocationConfiguration prealloc;
0132
0133 edm::ParameterSet dummyProcessPset;
0134 dummyProcessPset.registerIt();
0135 auto pc =
0136 std::make_shared<ProcessConfiguration>("PROD", dummyProcessPset.id(), edm::getReleaseVersion(), edm::getPassID());
0137
0138 edm::MakeModuleParams params1(&p1, preg, &prealloc, pc);
0139 edm::MakeModuleParams params2(&p2, preg, &prealloc, pc);
0140
0141 std::unique_ptr<Maker> lM = std::make_unique<WorkerMaker<ListenMod>>();
0142 ParameterSet l1;
0143 l1.addParameter("@module_type", std::string("ListenMod"));
0144 l1.addParameter("@module_label", std::string("l1"));
0145 l1.addParameter("@module_edm_type", std::string("EDProducer"));
0146 l1.registerIt();
0147
0148 ParameterSet l2;
0149 l2.addParameter("@module_type", std::string("ListenMod"));
0150 l2.addParameter("@module_label", std::string("l2"));
0151 l2.addParameter("@module_edm_type", std::string("EDProducer"));
0152 l2.registerIt();
0153
0154 edm::MakeModuleParams paramsl1(&l1, preg, &prealloc, pc);
0155 edm::MakeModuleParams paramsl2(&l2, preg, &prealloc, pc);
0156
0157 signalslot::Signal<void(const ModuleDescription&)> aSignal;
0158
0159 auto m1 = f->makeModule(params1, aSignal, aSignal);
0160 std::unique_ptr<Worker> w1 = m1->makeWorker(&table);
0161 auto ml1 = lM->makeModule(paramsl1, aSignal, aSignal);
0162 std::unique_ptr<Worker> wl1 = ml1->makeWorker(&table);
0163 auto ml2 = lM->makeModule(paramsl2, aSignal, aSignal);
0164 std::unique_ptr<Worker> wl2 = ml2->makeWorker(&table);
0165 auto m2 = f->makeModule(params2, aSignal, aSignal);
0166 std::unique_ptr<Worker> w2 = m2->makeWorker(&table);
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180 CPPUNIT_ASSERT(10 == preg.size());
0181 }
0182
0183 void testEDProducerProductRegistryCallback::testCircularRef2() {
0184 using namespace edm;
0185
0186 SignallingProductRegistry preg;
0187
0188 std::unique_ptr<Maker> f = std::make_unique<WorkerMaker<TestMod>>();
0189
0190 ParameterSet p1;
0191 p1.addParameter("@module_type", std::string("TestMod"));
0192 p1.addParameter("@module_label", std::string("t1"));
0193 p1.addParameter("@module_edm_type", std::string("EDProducer"));
0194 p1.registerIt();
0195
0196 ParameterSet p2;
0197 p2.addParameter("@module_type", std::string("TestMod"));
0198 p2.addParameter("@module_label", std::string("t2"));
0199 p2.addParameter("@module_edm_type", std::string("EDProducer"));
0200 p2.registerIt();
0201
0202 edm::ExceptionToActionTable table;
0203 edm::PreallocationConfiguration prealloc;
0204
0205 edm::ParameterSet dummyProcessPset;
0206 dummyProcessPset.registerIt();
0207 auto pc =
0208 std::make_shared<ProcessConfiguration>("PROD", dummyProcessPset.id(), edm::getReleaseVersion(), edm::getPassID());
0209
0210 edm::MakeModuleParams params1(&p1, preg, &prealloc, pc);
0211 edm::MakeModuleParams params2(&p2, preg, &prealloc, pc);
0212
0213 std::unique_ptr<Maker> lM = std::make_unique<WorkerMaker<ListenMod>>();
0214 ParameterSet l1;
0215 l1.addParameter("@module_type", std::string("ListenMod"));
0216 l1.addParameter("@module_label", std::string("l1"));
0217 l1.addParameter("@module_edm_type", std::string("EDProducer"));
0218 l1.registerIt();
0219
0220 ParameterSet l2;
0221 l2.addParameter("@module_type", std::string("ListenMod"));
0222 l2.addParameter("@module_label", std::string("l2"));
0223 l2.addParameter("@module_edm_type", std::string("EDProducer"));
0224 l2.registerIt();
0225
0226 edm::MakeModuleParams paramsl1(&l1, preg, &prealloc, pc);
0227 edm::MakeModuleParams paramsl2(&l2, preg, &prealloc, pc);
0228
0229 signalslot::Signal<void(const ModuleDescription&)> aSignal;
0230 auto ml1 = lM->makeModule(paramsl1, aSignal, aSignal);
0231 std::unique_ptr<Worker> wl1 = ml1->makeWorker(&table);
0232 auto ml2 = lM->makeModule(paramsl2, aSignal, aSignal);
0233 std::unique_ptr<Worker> wl2 = ml2->makeWorker(&table);
0234 auto m1 = f->makeModule(params1, aSignal, aSignal);
0235 std::unique_ptr<Worker> w1 = m1->makeWorker(&table);
0236 auto m2 = f->makeModule(params2, aSignal, aSignal);
0237 std::unique_ptr<Worker> w2 = m2->makeWorker(&table);
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251 CPPUNIT_ASSERT(10 == preg.size());
0252 }
0253
0254 void testEDProducerProductRegistryCallback::testTwoListeners() {
0255 using namespace edm;
0256
0257 SignallingProductRegistry preg;
0258
0259 std::unique_ptr<Maker> f = std::make_unique<WorkerMaker<TestMod>>();
0260
0261 ParameterSet p1;
0262 p1.addParameter("@module_type", std::string("TestMod"));
0263 p1.addParameter("@module_label", std::string("t1"));
0264 p1.addParameter("@module_edm_type", std::string("EDProducer"));
0265 p1.registerIt();
0266
0267 ParameterSet p2;
0268 p2.addParameter("@module_type", std::string("TestMod"));
0269 p2.addParameter("@module_label", std::string("t2"));
0270 p2.addParameter("@module_edm_type", std::string("EDProducer"));
0271 p2.registerIt();
0272
0273 edm::ExceptionToActionTable table;
0274 edm::PreallocationConfiguration prealloc;
0275
0276 edm::ParameterSet dummyProcessPset;
0277 dummyProcessPset.registerIt();
0278 auto pc =
0279 std::make_shared<ProcessConfiguration>("PROD", dummyProcessPset.id(), edm::getReleaseVersion(), edm::getPassID());
0280
0281 edm::MakeModuleParams params1(&p1, preg, &prealloc, pc);
0282 edm::MakeModuleParams params2(&p2, preg, &prealloc, pc);
0283
0284 std::unique_ptr<Maker> lM = std::make_unique<WorkerMaker<ListenMod>>();
0285 ParameterSet l1;
0286 l1.addParameter("@module_type", std::string("ListenMod"));
0287 l1.addParameter("@module_label", std::string("l1"));
0288 l1.addParameter("@module_edm_type", std::string("EDProducer"));
0289 l1.registerIt();
0290
0291 std::unique_ptr<Maker> lFM = std::make_unique<WorkerMaker<ListenFloatMod>>();
0292 ParameterSet l2;
0293 l2.addParameter("@module_type", std::string("ListenMod"));
0294 l2.addParameter("@module_label", std::string("l2"));
0295 l2.addParameter("@module_edm_type", std::string("EDProducer"));
0296 l2.registerIt();
0297
0298 edm::MakeModuleParams paramsl1(&l1, preg, &prealloc, pc);
0299 edm::MakeModuleParams paramsl2(&l2, preg, &prealloc, pc);
0300
0301 signalslot::Signal<void(const ModuleDescription&)> aSignal;
0302 auto m1 = f->makeModule(params1, aSignal, aSignal);
0303 std::unique_ptr<Worker> w1 = m1->makeWorker(&table);
0304 auto ml1 = lM->makeModule(paramsl1, aSignal, aSignal);
0305 std::unique_ptr<Worker> wl1 = ml1->makeWorker(&table);
0306 auto ml2 = lFM->makeModule(paramsl2, aSignal, aSignal);
0307 std::unique_ptr<Worker> wl2 = ml2->makeWorker(&table);
0308 auto m2 = f->makeModule(params2, aSignal, aSignal);
0309 std::unique_ptr<Worker> w2 = m2->makeWorker(&table);
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321 CPPUNIT_ASSERT(8 == preg.size());
0322 }