File indexing completed on 2024-04-06 12:12:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <atomic>
0011 #include <memory>
0012 #include <tuple>
0013 #include <vector>
0014
0015 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0016 #include "FWCore/Framework/interface/CacheHandle.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/LuminosityBlock.h"
0019 #include "FWCore/Framework/interface/MakerMacros.h"
0020 #include "FWCore/Framework/interface/moduleAbilities.h"
0021 #include "FWCore/Framework/interface/one/EDProducer.h"
0022 #include "FWCore/Framework/interface/ProcessBlock.h"
0023 #include "FWCore/Framework/interface/Run.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/Utilities/interface/BranchType.h"
0026 #include "FWCore/Utilities/interface/EDMException.h"
0027 #include "FWCore/Utilities/interface/EDGetToken.h"
0028 #include "FWCore/Utilities/interface/InputTag.h"
0029
0030 namespace edmtest {
0031 namespace one {
0032
0033 class SharedResourcesProducer : public edm::one::EDProducer<edm::one::SharedResources> {
0034 public:
0035 explicit SharedResourcesProducer(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {
0036 produces<int>();
0037 usesResource("foo");
0038 }
0039 const unsigned int trans_;
0040 unsigned int m_count = 0;
0041
0042 void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0043
0044 ~SharedResourcesProducer() noexcept(false) {
0045 if (m_count != trans_) {
0046 throw cms::Exception("transitions")
0047 << "SharedResourcesProducer transitions " << m_count << " but it was supposed to be " << trans_;
0048 }
0049 }
0050 };
0051
0052 class WatchRunsProducer : public edm::one::EDProducer<edm::one::WatchRuns> {
0053 public:
0054 explicit WatchRunsProducer(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {
0055 produces<int>();
0056 }
0057 bool br = false;
0058 bool er = false;
0059 const unsigned int trans_;
0060 unsigned int m_count = 0;
0061
0062 void produce(edm::Event&, edm::EventSetup const&) override {
0063 ++m_count;
0064 if (!br || er) {
0065 throw cms::Exception("out of sequence") << " produce before beginRun or after endRun";
0066 }
0067 }
0068
0069 void beginRun(edm::Run const&, edm::EventSetup const&) override {
0070 ++m_count;
0071 if (br) {
0072 throw cms::Exception("out of sequence") << " beginRun seen multiple times";
0073 }
0074 br = true;
0075 er = false;
0076 }
0077
0078 void endRun(edm::Run const&, edm::EventSetup const&) override {
0079 ++m_count;
0080 if (!br) {
0081 throw cms::Exception("out of sequence") << " endRun before beginRun";
0082 }
0083 br = false;
0084 er = true;
0085 }
0086
0087 ~WatchRunsProducer() noexcept(false) {
0088 if (m_count != trans_) {
0089 throw cms::Exception("transitions")
0090 << "WatchRunsProducer transitions " << m_count << " but it was supposed to be " << trans_;
0091 }
0092 }
0093 };
0094
0095 class WatchLumiBlocksProducer : public edm::one::EDProducer<edm::one::WatchLuminosityBlocks> {
0096 public:
0097 explicit WatchLumiBlocksProducer(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {
0098 produces<int>();
0099 }
0100 const unsigned int trans_;
0101 bool bl = false;
0102 bool el = false;
0103 unsigned int m_count = 0;
0104
0105 void produce(edm::Event&, edm::EventSetup const&) override {
0106 ++m_count;
0107 if (!bl || el) {
0108 throw cms::Exception("out of sequence") << " produce before beginLumiBlock or after endLumiBlock";
0109 }
0110 }
0111
0112 void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {
0113 ++m_count;
0114 if (bl) {
0115 throw cms::Exception("out of sequence") << " beginLumiBlock seen mutiple times";
0116 }
0117 bl = true;
0118 el = false;
0119 }
0120
0121 void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {
0122 ++m_count;
0123 if (!bl) {
0124 throw cms::Exception("out of sequence") << " endLumiBlock before beginLumiBlock";
0125 }
0126 bl = false;
0127 el = true;
0128 }
0129
0130 ~WatchLumiBlocksProducer() noexcept(false) {
0131 if (m_count != trans_) {
0132 throw cms::Exception("transitions")
0133 << "WatchLumiBlockProducer transitions " << m_count << " but it was supposed to be " << trans_;
0134 }
0135 }
0136 };
0137
0138 namespace prdr {
0139 struct Cache {
0140 bool begin = true;
0141 bool end = false;
0142 };
0143 }
0144 class RunCacheProducer : public edm::one::EDProducer<edm::RunCache<prdr::Cache>> {
0145 public:
0146 explicit RunCacheProducer(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {
0147 produces<int>();
0148 }
0149 const unsigned int trans_;
0150 mutable std::atomic<unsigned int> m_count = 0;
0151
0152 void produce(edm::Event& iEvent, edm::EventSetup const&) override {
0153 ++m_count;
0154 auto c = runCache(iEvent.getRun().index());
0155 if (nullptr == c) {
0156 throw cms::Exception("Missing cache") << " no cache in analyze";
0157 }
0158
0159 if (!c->begin || c->end) {
0160 throw cms::Exception("out of sequence") << " produce before beginRun or after endRun";
0161 }
0162 }
0163
0164 std::shared_ptr<prdr::Cache> globalBeginRun(edm::Run const&, edm::EventSetup const&) const final {
0165 ++m_count;
0166 return std::make_shared<prdr::Cache>();
0167 }
0168
0169 void globalEndRun(edm::Run const& iRun, edm::EventSetup const&) final {
0170 ++m_count;
0171 auto c = runCache(iRun.index());
0172 if (nullptr == c) {
0173 throw cms::Exception("Missing cache") << " no cache in globalEndRun";
0174 }
0175 if (!c->begin) {
0176 throw cms::Exception("out of sequence") << " endRun before beginRun";
0177 }
0178 c->begin = false;
0179 c->end = true;
0180 }
0181
0182 ~RunCacheProducer() {
0183 if (m_count != trans_) {
0184 throw cms::Exception("transitions")
0185 << "WatchRunsAnalyzer transitions " << m_count << " but it was supposed to be " << trans_;
0186 }
0187 }
0188 };
0189
0190 class LumiBlockCacheProducer : public edm::one::EDProducer<edm::LuminosityBlockCache<prdr::Cache>> {
0191 public:
0192 explicit LumiBlockCacheProducer(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {
0193 produces<int>();
0194 }
0195 const unsigned int trans_;
0196 mutable std::atomic<unsigned int> m_count = 0;
0197
0198 void produce(edm::Event& iEvent, edm::EventSetup const&) override {
0199 ++m_count;
0200
0201 auto c = luminosityBlockCache(iEvent.getLuminosityBlock().index());
0202 if (nullptr == c) {
0203 throw cms::Exception("Missing cache") << " no cache in analyze";
0204 }
0205
0206 if (!c->begin || c->end) {
0207 throw cms::Exception("out of sequence") << " produce before beginLumiBlock or after endLumiBlock";
0208 }
0209 }
0210
0211 std::shared_ptr<prdr::Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
0212 edm::EventSetup const&) const final {
0213 ++m_count;
0214 return std::make_shared<prdr::Cache>();
0215 }
0216
0217 void globalEndLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const&) override {
0218 ++m_count;
0219 auto c = luminosityBlockCache(iLumi.index());
0220 if (!c->begin) {
0221 throw cms::Exception("out of sequence") << " endLumiBlock before beginLumiBlock";
0222 }
0223 c->begin = false;
0224 c->end = true;
0225 }
0226
0227 ~LumiBlockCacheProducer() {
0228 if (m_count != trans_) {
0229 throw cms::Exception("transitions")
0230 << "WatchLumiBlocksAnalyzer transitions " << m_count << " but it was supposed to be " << trans_;
0231 }
0232 }
0233 };
0234
0235 class ProcessBlockIntProducer : public edm::one::EDProducer<edm::WatchProcessBlock> {
0236 public:
0237 explicit ProcessBlockIntProducer(edm::ParameterSet const& pset) : trans_(pset.getParameter<int>("transitions")) {
0238 produces<unsigned int>();
0239
0240 {
0241 auto tag = pset.getParameter<edm::InputTag>("consumesBeginProcessBlock");
0242 if (not tag.label().empty()) {
0243 getTokenBegin_ = consumes<unsigned int, edm::InProcess>(tag);
0244 }
0245 }
0246 {
0247 auto tag = pset.getParameter<edm::InputTag>("consumesEndProcessBlock");
0248 if (not tag.label().empty()) {
0249 getTokenEnd_ = consumes<unsigned int, edm::InProcess>(tag);
0250 }
0251 }
0252 }
0253
0254 void beginProcessBlock(edm::ProcessBlock const& processBlock) override {
0255 if (m_count != 0) {
0256 throw cms::Exception("transitions")
0257 << "ProcessBlockIntProducer::begin transitions " << m_count << " but it was supposed to be " << 0;
0258 }
0259 ++m_count;
0260
0261 const unsigned int valueToGet = 11;
0262 if (not getTokenBegin_.isUninitialized()) {
0263 if (processBlock.get(getTokenBegin_) != valueToGet) {
0264 throw cms::Exception("BadValue")
0265 << "expected " << valueToGet << " but got " << processBlock.get(getTokenBegin_);
0266 }
0267 }
0268 }
0269
0270 void produce(edm::Event&, edm::EventSetup const&) override {
0271 if (m_count < 1u) {
0272 throw cms::Exception("out of sequence") << "produce before beginProcessBlock " << m_count;
0273 }
0274 ++m_count;
0275 }
0276
0277 void endProcessBlock(edm::ProcessBlock const& processBlock) override {
0278 ++m_count;
0279 if (m_count != trans_) {
0280 throw cms::Exception("transitions")
0281 << "ProcessBlockIntProducer::end transitions " << m_count << " but it was supposed to be " << trans_;
0282 }
0283
0284 {
0285 const unsigned int valueToGet = 11;
0286 if (not getTokenBegin_.isUninitialized()) {
0287 if (processBlock.get(getTokenBegin_) != valueToGet) {
0288 throw cms::Exception("BadValue")
0289 << "expected " << valueToGet << " but got " << processBlock.get(getTokenBegin_);
0290 }
0291 }
0292 }
0293 {
0294 const unsigned int valueToGet = 21;
0295 if (not getTokenEnd_.isUninitialized()) {
0296 if (processBlock.get(getTokenEnd_) != valueToGet) {
0297 throw cms::Exception("BadValue")
0298 << "expected " << valueToGet << " but got " << processBlock.get(getTokenEnd_);
0299 }
0300 }
0301 }
0302 }
0303
0304 ~ProcessBlockIntProducer() {
0305 if (m_count != trans_) {
0306 throw cms::Exception("transitions")
0307 << "ProcessBlockIntProducer transitions " << m_count << " but it was supposed to be " << trans_;
0308 }
0309 }
0310
0311 private:
0312 const unsigned int trans_;
0313 mutable std::atomic<unsigned int> m_count{0};
0314 edm::EDGetTokenT<unsigned int> getTokenBegin_;
0315 edm::EDGetTokenT<unsigned int> getTokenEnd_;
0316 };
0317
0318 class TestBeginProcessBlockProducer : public edm::one::EDProducer<edm::BeginProcessBlockProducer> {
0319 public:
0320 explicit TestBeginProcessBlockProducer(edm::ParameterSet const& pset)
0321 : trans_(pset.getParameter<int>("transitions")),
0322 token_(produces<unsigned int, edm::Transition::BeginProcessBlock>("begin")) {
0323 produces<unsigned int>();
0324
0325 auto tag = pset.getParameter<edm::InputTag>("consumesBeginProcessBlock");
0326 if (not tag.label().empty()) {
0327 getToken_ = consumes<unsigned int, edm::InProcess>(tag);
0328 }
0329 }
0330
0331 void beginProcessBlockProduce(edm::ProcessBlock& processBlock) override {
0332 if (m_count != 0) {
0333 throw cms::Exception("transitions")
0334 << "TestBeginProcessBlockProducer transitions " << m_count << " but it was supposed to be " << 0;
0335 }
0336 ++m_count;
0337
0338 const unsigned int valueToPutAndGet = 11;
0339 processBlock.emplace(token_, valueToPutAndGet);
0340
0341 if (not getToken_.isUninitialized()) {
0342 if (processBlock.get(getToken_) != valueToPutAndGet) {
0343 throw cms::Exception("BadValue")
0344 << "expected " << valueToPutAndGet << " but got " << processBlock.get(getToken_);
0345 }
0346 }
0347 }
0348
0349 void produce(edm::Event&, edm::EventSetup const&) override {
0350 if (m_count < 1u) {
0351 throw cms::Exception("out of sequence") << "produce before beginProcessBlockProduce " << m_count;
0352 }
0353 ++m_count;
0354 }
0355
0356 ~TestBeginProcessBlockProducer() {
0357 if (m_count != trans_) {
0358 throw cms::Exception("transitions")
0359 << "TestBeginProcessBlockProducer transitions " << m_count << " but it was supposed to be " << trans_;
0360 }
0361 }
0362
0363 private:
0364 const unsigned int trans_;
0365 mutable std::atomic<unsigned int> m_count{0};
0366 edm::EDPutTokenT<unsigned int> token_;
0367 edm::EDGetTokenT<unsigned int> getToken_;
0368 };
0369
0370 class TestEndProcessBlockProducer : public edm::one::EDProducer<edm::EndProcessBlockProducer> {
0371 public:
0372 explicit TestEndProcessBlockProducer(edm::ParameterSet const& pset)
0373 : trans_(pset.getParameter<int>("transitions")),
0374 token_(produces<unsigned int, edm::Transition::EndProcessBlock>("end")) {
0375 produces<unsigned int>();
0376
0377 auto tag = pset.getParameter<edm::InputTag>("consumesEndProcessBlock");
0378 if (not tag.label().empty()) {
0379 getToken_ = consumes<unsigned int, edm::InProcess>(tag);
0380 }
0381 }
0382
0383 void produce(edm::Event&, edm::EventSetup const&) override { ++m_count; }
0384
0385 void endProcessBlockProduce(edm::ProcessBlock& processBlock) override {
0386 ++m_count;
0387 if (m_count != trans_) {
0388 throw cms::Exception("transitions")
0389 << "TestEndProcessBlockProducer transitions " << m_count << " but it was supposed to be " << trans_;
0390 }
0391
0392 const unsigned int valueToPutAndGet = 21;
0393 processBlock.emplace(token_, valueToPutAndGet);
0394 if (not getToken_.isUninitialized()) {
0395 if (processBlock.get(getToken_) != valueToPutAndGet) {
0396 throw cms::Exception("BadValue")
0397 << "expected " << valueToPutAndGet << " but got " << processBlock.get(getToken_);
0398 }
0399 }
0400 }
0401
0402 ~TestEndProcessBlockProducer() {
0403 if (m_count != trans_) {
0404 throw cms::Exception("transitions")
0405 << "~TestEndProcessBlockProducer transitions " << m_count << " but it was supposed to be " << trans_;
0406 }
0407 }
0408
0409 private:
0410 const unsigned int trans_;
0411 mutable std::atomic<unsigned int> m_count{0};
0412 edm::EDPutTokenT<unsigned int> token_;
0413 edm::EDGetTokenT<unsigned int> getToken_;
0414 };
0415
0416 class TestBeginRunProducer : public edm::one::EDProducer<edm::one::WatchRuns, edm::BeginRunProducer> {
0417 public:
0418 explicit TestBeginRunProducer(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {
0419 produces<int>();
0420 produces<unsigned int, edm::Transition::BeginRun>("a");
0421 }
0422 const unsigned int trans_;
0423 unsigned int m_count = 0;
0424 bool p = false;
0425
0426 void beginRun(edm::Run const&, edm::EventSetup const&) override { p = false; }
0427
0428 void produce(edm::Event&, edm::EventSetup const&) override {
0429 ++m_count;
0430 p = true;
0431 }
0432
0433 void beginRunProduce(edm::Run&, edm::EventSetup const&) override {
0434 if (p) {
0435 throw cms::Exception("out of sequence") << "produce before beginRunProduce";
0436 }
0437 ++m_count;
0438 }
0439
0440 void endRun(edm::Run const&, edm::EventSetup const&) override {}
0441
0442 ~TestBeginRunProducer() noexcept(false) {
0443 if (m_count != trans_) {
0444 throw cms::Exception("transitions")
0445 << "TestBeginRunProducer transitions " << m_count << " but it was supposed to be " << trans_;
0446 }
0447 }
0448 };
0449
0450 class TestBeginLumiBlockProducer
0451 : public edm::one::EDProducer<edm::one::WatchLuminosityBlocks, edm::BeginLuminosityBlockProducer> {
0452 public:
0453 explicit TestBeginLumiBlockProducer(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {
0454 produces<int>();
0455 produces<unsigned int, edm::Transition::BeginLuminosityBlock>("a");
0456 }
0457 const unsigned int trans_;
0458 unsigned int m_count = 0;
0459 bool p = false;
0460
0461 void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override { p = false; }
0462
0463 void produce(edm::Event&, edm::EventSetup const&) override {
0464 ++m_count;
0465 p = true;
0466 }
0467
0468 void beginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) override {
0469 ++m_count;
0470 if (p) {
0471 throw cms::Exception("out of sequence") << "produce before beginLuminosityBlockProduce";
0472 }
0473 }
0474
0475 void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {}
0476
0477 ~TestBeginLumiBlockProducer() noexcept(false) {
0478 if (m_count != trans_) {
0479 throw cms::Exception("transitions")
0480 << "TestBeginLumiBlockProducer transitions " << m_count << " but it was supposed to be " << trans_;
0481 }
0482 }
0483 };
0484
0485 class TestEndRunProducer : public edm::one::EDProducer<edm::one::WatchRuns, edm::EndRunProducer> {
0486 public:
0487 explicit TestEndRunProducer(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {
0488 produces<int>();
0489 produces<unsigned int, edm::Transition::EndRun>("a");
0490 }
0491 const unsigned int trans_;
0492 bool erp = false;
0493
0494 void beginRun(edm::Run const&, edm::EventSetup const&) override { erp = false; }
0495
0496 unsigned int m_count = 0;
0497
0498 void produce(edm::Event&, edm::EventSetup const&) override {
0499 ++m_count;
0500 if (erp) {
0501 throw cms::Exception("out of sequence") << "endRunProduce before produce";
0502 }
0503 }
0504
0505 void endRunProduce(edm::Run&, edm::EventSetup const&) override {
0506 ++m_count;
0507 erp = true;
0508 }
0509
0510 void endRun(edm::Run const&, edm::EventSetup const&) override {}
0511
0512 ~TestEndRunProducer() noexcept(false) {
0513 if (m_count != trans_) {
0514 throw cms::Exception("transitions")
0515 << "TestEndRunProducer transitions " << m_count << " but it was supposed to be " << trans_;
0516 }
0517 }
0518 };
0519
0520 class TestEndLumiBlockProducer
0521 : public edm::one::EDProducer<edm::one::WatchLuminosityBlocks, edm::EndLuminosityBlockProducer> {
0522 public:
0523 explicit TestEndLumiBlockProducer(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {
0524 produces<int>();
0525 produces<unsigned int, edm::Transition::EndLuminosityBlock>("a");
0526 }
0527 const unsigned int trans_;
0528 bool elbp = false;
0529 unsigned int m_count = 0;
0530
0531 void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override { elbp = false; }
0532
0533 void produce(edm::Event&, edm::EventSetup const&) override {
0534 ++m_count;
0535 if (elbp) {
0536 throw cms::Exception("out of sequence") << "endLumiBlockProduce before produce";
0537 }
0538 }
0539
0540 void endLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) override {
0541 ++m_count;
0542 elbp = true;
0543 }
0544
0545 void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {}
0546
0547 ~TestEndLumiBlockProducer() noexcept(false) {
0548 if (m_count != trans_) {
0549 throw cms::Exception("transitions")
0550 << "TestEndLumiBlockProducer transitions " << m_count << " but it was supposed to be " << trans_;
0551 }
0552 }
0553 };
0554
0555 class TestAccumulator : public edm::one::EDProducer<edm::Accumulator, edm::EndLuminosityBlockProducer> {
0556 public:
0557 explicit TestAccumulator(edm::ParameterSet const& p)
0558 : m_expectedCount(p.getParameter<unsigned int>("expectedCount")),
0559 m_putToken(produces<unsigned int, edm::Transition::EndLuminosityBlock>()) {}
0560
0561 void accumulate(edm::Event const&, edm::EventSetup const&) override { ++m_count; }
0562
0563 void endLuminosityBlockProduce(edm::LuminosityBlock& l, edm::EventSetup const&) override {
0564 l.emplace(m_putToken, m_count.load());
0565 }
0566
0567 ~TestAccumulator() {
0568 if (m_count.load() != m_expectedCount) {
0569 throw cms::Exception("TestCount")
0570 << "TestAccumulator counter was " << m_count << " but it was supposed to be " << m_expectedCount;
0571 }
0572 }
0573
0574 mutable std::atomic<unsigned int> m_count{0};
0575 const unsigned int m_expectedCount;
0576 const edm::EDPutTokenT<unsigned int> m_putToken;
0577 };
0578
0579 class TestInputProcessBlockCache {
0580 public:
0581 long long int value_ = 0;
0582 };
0583
0584 class TestInputProcessBlockCache1 {
0585 public:
0586 long long int value_ = 0;
0587 };
0588
0589 class InputProcessBlockIntProducer
0590 : public edm::one::EDProducer<
0591 edm::InputProcessBlockCache<int, TestInputProcessBlockCache, TestInputProcessBlockCache1>> {
0592 public:
0593 explicit InputProcessBlockIntProducer(edm::ParameterSet const& pset) {
0594 expectedTransitions_ = pset.getParameter<int>("transitions");
0595 expectedByRun_ = pset.getParameter<std::vector<int>>("expectedByRun");
0596 expectedSum_ = pset.getParameter<int>("expectedSum");
0597 {
0598 auto tag = pset.getParameter<edm::InputTag>("consumesBeginProcessBlock");
0599 if (not tag.label().empty()) {
0600 getTokenBegin_ = consumes<IntProduct, edm::InProcess>(tag);
0601 }
0602 }
0603 {
0604 auto tag = pset.getParameter<edm::InputTag>("consumesEndProcessBlock");
0605 if (not tag.label().empty()) {
0606 getTokenEnd_ = consumes<IntProduct, edm::InProcess>(tag);
0607 }
0608 }
0609 {
0610 auto tag = pset.getParameter<edm::InputTag>("consumesBeginProcessBlockM");
0611 if (not tag.label().empty()) {
0612 getTokenBeginM_ = consumes<IntProduct, edm::InProcess>(tag);
0613 }
0614 }
0615 {
0616 auto tag = pset.getParameter<edm::InputTag>("consumesEndProcessBlockM");
0617 if (not tag.label().empty()) {
0618 getTokenEndM_ = consumes<IntProduct, edm::InProcess>(tag);
0619 }
0620 }
0621 registerProcessBlockCacheFiller<int>(
0622 getTokenBegin_, [this](edm::ProcessBlock const& processBlock, std::shared_ptr<int> const& previousCache) {
0623 auto returnValue = std::make_shared<int>(0);
0624 *returnValue += processBlock.get(getTokenBegin_).value;
0625 *returnValue += processBlock.get(getTokenEnd_).value;
0626 ++transitions_;
0627 return returnValue;
0628 });
0629 registerProcessBlockCacheFiller<1>(getTokenBegin_,
0630 [this](edm::ProcessBlock const& processBlock,
0631 std::shared_ptr<TestInputProcessBlockCache> const& previousCache) {
0632 auto returnValue = std::make_shared<TestInputProcessBlockCache>();
0633 returnValue->value_ += processBlock.get(getTokenBegin_).value;
0634 returnValue->value_ += processBlock.get(getTokenEnd_).value;
0635 ++transitions_;
0636 return returnValue;
0637 });
0638 registerProcessBlockCacheFiller<TestInputProcessBlockCache1>(
0639 getTokenBegin_,
0640 [this](edm::ProcessBlock const& processBlock,
0641 std::shared_ptr<TestInputProcessBlockCache1> const& previousCache) {
0642 auto returnValue = std::make_shared<TestInputProcessBlockCache1>();
0643 returnValue->value_ += processBlock.get(getTokenBegin_).value;
0644 returnValue->value_ += processBlock.get(getTokenEnd_).value;
0645 ++transitions_;
0646 return returnValue;
0647 });
0648 }
0649
0650 void accessInputProcessBlock(edm::ProcessBlock const& processBlock) override {
0651 if (processBlock.processName() == "PROD1") {
0652 sum_ += processBlock.get(getTokenBegin_).value;
0653 sum_ += processBlock.get(getTokenEnd_).value;
0654 }
0655 if (processBlock.processName() == "MERGE") {
0656 sum_ += processBlock.get(getTokenBeginM_).value;
0657 sum_ += processBlock.get(getTokenEndM_).value;
0658 }
0659 ++transitions_;
0660 }
0661
0662 void produce(edm::Event& event, edm::EventSetup const&) override {
0663 auto cacheTuple = processBlockCaches(event);
0664 if (!expectedByRun_.empty()) {
0665 if (expectedByRun_.at(event.run() - 1) != *std::get<edm::CacheHandle<int>>(cacheTuple)) {
0666 throw cms::Exception("UnexpectedValue")
0667 << "InputProcessBlockIntProducer::produce cached value was "
0668 << *std::get<edm::CacheHandle<int>>(cacheTuple) << " but it was supposed to be "
0669 << expectedByRun_.at(event.run() - 1);
0670 }
0671 if (expectedByRun_.at(event.run() - 1) != std::get<1>(cacheTuple)->value_) {
0672 throw cms::Exception("UnexpectedValue")
0673 << "InputProcessBlockIntProducer::produce second cached value was " << std::get<1>(cacheTuple)->value_
0674 << " but it was supposed to be " << expectedByRun_.at(event.run() - 1);
0675 }
0676 if (expectedByRun_.at(event.run() - 1) !=
0677 std::get<edm::CacheHandle<TestInputProcessBlockCache1>>(cacheTuple)->value_) {
0678 throw cms::Exception("UnexpectedValue")
0679 << "InputProcessBlockIntProducer::produce third cached value was "
0680 << std::get<edm::CacheHandle<TestInputProcessBlockCache1>>(cacheTuple)->value_
0681 << " but it was supposed to be " << expectedByRun_.at(event.run() - 1);
0682 }
0683 }
0684 ++transitions_;
0685 }
0686
0687 void endJob() override {
0688 if (transitions_ != expectedTransitions_) {
0689 throw cms::Exception("transitions") << "InputProcessBlockIntProducer transitions " << transitions_
0690 << " but it was supposed to be " << expectedTransitions_;
0691 }
0692 if (sum_ != expectedSum_) {
0693 throw cms::Exception("UnexpectedValue")
0694 << "InputProcessBlockIntProducer sum " << sum_ << " but it was supposed to be " << expectedSum_;
0695 }
0696 if (cacheSize() > 0u) {
0697 throw cms::Exception("UnexpectedValue")
0698 << "InputProcessBlockIntProducer cache size not zero at endJob " << cacheSize();
0699 }
0700 }
0701
0702 private:
0703 edm::EDGetTokenT<IntProduct> getTokenBegin_;
0704 edm::EDGetTokenT<IntProduct> getTokenEnd_;
0705 edm::EDGetTokenT<IntProduct> getTokenBeginM_;
0706 edm::EDGetTokenT<IntProduct> getTokenEndM_;
0707 mutable std::atomic<unsigned int> transitions_{0};
0708 int sum_{0};
0709 unsigned int expectedTransitions_{0};
0710 std::vector<int> expectedByRun_;
0711 int expectedSum_{0};
0712 };
0713
0714 }
0715 }
0716
0717 DEFINE_FWK_MODULE(edmtest::one::SharedResourcesProducer);
0718 DEFINE_FWK_MODULE(edmtest::one::WatchRunsProducer);
0719 DEFINE_FWK_MODULE(edmtest::one::WatchLumiBlocksProducer);
0720 DEFINE_FWK_MODULE(edmtest::one::RunCacheProducer);
0721 DEFINE_FWK_MODULE(edmtest::one::LumiBlockCacheProducer);
0722 DEFINE_FWK_MODULE(edmtest::one::ProcessBlockIntProducer);
0723 DEFINE_FWK_MODULE(edmtest::one::TestBeginProcessBlockProducer);
0724 DEFINE_FWK_MODULE(edmtest::one::TestEndProcessBlockProducer);
0725 DEFINE_FWK_MODULE(edmtest::one::TestBeginRunProducer);
0726 DEFINE_FWK_MODULE(edmtest::one::TestBeginLumiBlockProducer);
0727 DEFINE_FWK_MODULE(edmtest::one::TestEndRunProducer);
0728 DEFINE_FWK_MODULE(edmtest::one::TestEndLumiBlockProducer);
0729 DEFINE_FWK_MODULE(edmtest::one::TestAccumulator);
0730 DEFINE_FWK_MODULE(edmtest::one::InputProcessBlockIntProducer);