File indexing completed on 2024-04-06 12:12:19
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/limited/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 limited {
0032
0033 namespace {
0034 struct Cache {
0035 Cache() : value(0), run(0), lumi(0), strm(0), work(0) {}
0036
0037 mutable std::atomic<unsigned int> value;
0038 mutable std::atomic<unsigned int> run;
0039 mutable std::atomic<unsigned int> lumi;
0040 mutable std::atomic<unsigned int> strm;
0041 mutable std::atomic<unsigned int> work;
0042 };
0043
0044 struct UnsafeCache {
0045 UnsafeCache() : value(0), run(0), lumi(0), strm(0), work(0) {}
0046 unsigned int value;
0047 unsigned int run;
0048 unsigned int lumi;
0049 unsigned int strm;
0050 unsigned int work;
0051 };
0052
0053 struct Dummy {};
0054
0055 }
0056
0057 class StreamIntProducer : public edm::limited::EDProducer<edm::StreamCache<UnsafeCache>> {
0058 public:
0059 explicit StreamIntProducer(edm::ParameterSet const& p)
0060 : edm::limited::EDProducerBase(p),
0061 edm::limited::EDProducer<edm::StreamCache<UnsafeCache>>(p),
0062 trans_(p.getParameter<int>("transitions")),
0063 nLumis_(p.getUntrackedParameter<unsigned int>("nLumis", 1)) {
0064 produces<unsigned int>();
0065 }
0066
0067 const unsigned int trans_;
0068 const unsigned int nLumis_;
0069 mutable std::atomic<unsigned int> m_count{0};
0070 mutable std::atomic<unsigned int> m_countStreams{0};
0071 mutable std::atomic<unsigned int> m_countStreamBeginLumiTransitions{0};
0072 mutable std::atomic<unsigned int> m_countStreamEndLumiTransitions{0};
0073
0074 std::unique_ptr<UnsafeCache> beginStream(edm::StreamID iID) const override {
0075 ++m_count;
0076 ++m_countStreams;
0077 auto sCache = std::make_unique<UnsafeCache>();
0078 ++(sCache->strm);
0079 sCache->value = iID.value();
0080 return sCache;
0081 }
0082
0083 void streamBeginRun(edm::StreamID iID, edm::Run const&, edm::EventSetup const&) const override {
0084 ++m_count;
0085 auto sCache = streamCache(iID);
0086 if (sCache->value != iID.value()) {
0087 throw cms::Exception("cache value")
0088 << "StreamIntProducer cache value " << (streamCache(iID))->value << " but it was supposed to be " << iID;
0089 }
0090 if (sCache->run != 0 || sCache->lumi != 0 || sCache->work != 0 || sCache->strm != 1) {
0091 throw cms::Exception("out of sequence") << "streamBeginRun out of sequence in Stream " << iID.value();
0092 }
0093 ++(sCache->run);
0094 }
0095
0096 void streamBeginLuminosityBlock(edm::StreamID iID,
0097 edm::LuminosityBlock const&,
0098 edm::EventSetup const&) const override {
0099 ++m_countStreamBeginLumiTransitions;
0100 auto sCache = streamCache(iID);
0101 if (sCache->lumi != 0 || sCache->work != 0) {
0102 throw cms::Exception("out of sequence")
0103 << "streamBeginLuminosityBlock out of sequence in Stream " << iID.value();
0104 }
0105 ++(sCache->lumi);
0106 }
0107
0108 void produce(edm::StreamID iID, edm::Event&, edm::EventSetup const&) const override {
0109 ++m_count;
0110 auto sCache = streamCache(iID);
0111 ++(sCache->work);
0112 if (sCache->lumi == 0 && sCache->run == 0) {
0113 throw cms::Exception("out of sequence") << "produce out of sequence in Stream " << iID.value();
0114 }
0115 }
0116
0117 void streamEndLuminosityBlock(edm::StreamID iID,
0118 edm::LuminosityBlock const&,
0119 edm::EventSetup const&) const override {
0120 ++m_countStreamEndLumiTransitions;
0121 auto sCache = streamCache(iID);
0122 --(sCache->lumi);
0123 sCache->work = 0;
0124 if (sCache->lumi != 0 || sCache->run == 0) {
0125 throw cms::Exception("out of sequence")
0126 << "streamEndLuminosityBlock out of sequence in Stream " << iID.value();
0127 }
0128 }
0129
0130 void streamEndRun(edm::StreamID iID, edm::Run const&, edm::EventSetup const&) const override {
0131 ++m_count;
0132 auto sCache = streamCache(iID);
0133 --(sCache->run);
0134 sCache->work = 0;
0135 if (sCache->run != 0 || sCache->lumi != 0) {
0136 throw cms::Exception("out of sequence") << "streamEndRun out of sequence in Stream " << iID.value();
0137 }
0138 }
0139
0140 void endStream(edm::StreamID iID) const override {
0141 ++m_count;
0142 auto sCache = streamCache(iID);
0143 --(sCache->strm);
0144 if (sCache->strm != 0 || sCache->run != 0 || sCache->lumi != 0) {
0145 throw cms::Exception("out of sequence") << "endStream out of sequence in Stream " << iID.value();
0146 }
0147 }
0148
0149 ~StreamIntProducer() {
0150 if (m_count != trans_) {
0151 throw cms::Exception("transitions")
0152 << "StreamIntProducer transitions " << m_count << " but it was supposed to be " << trans_;
0153 }
0154 unsigned int nStreamBeginLumiTransitions = m_countStreamBeginLumiTransitions.load();
0155 unsigned int nStreamEndLumiTransitions = m_countStreamEndLumiTransitions.load();
0156 unsigned int nStreams = m_countStreams.load();
0157 if (nStreamBeginLumiTransitions < nLumis_ || nStreamBeginLumiTransitions > (nLumis_ * nStreams)) {
0158 throw cms::Exception("transitions")
0159 << "StreamIntProducer stream begin lumi transitions " << nStreamBeginLumiTransitions
0160 << " but it was supposed to be between " << nLumis_ << " and " << nLumis_ * nStreams;
0161 }
0162 if (nStreamEndLumiTransitions != nStreamBeginLumiTransitions) {
0163 throw cms::Exception("transitions")
0164 << "StreamIntProducer stream end lumi transitions " << nStreamEndLumiTransitions
0165 << " does not equal stream begin lumi transitions " << nStreamBeginLumiTransitions;
0166 }
0167 }
0168 };
0169
0170 class RunIntProducer : public edm::limited::EDProducer<edm::StreamCache<UnsafeCache>, edm::RunCache<Cache>> {
0171 public:
0172 explicit RunIntProducer(edm::ParameterSet const& p)
0173 : edm::limited::EDProducerBase(p),
0174 edm::limited::EDProducer<edm::StreamCache<UnsafeCache>, edm::RunCache<Cache>>(p),
0175 trans_(p.getParameter<int>("transitions")),
0176 cvalue_(p.getParameter<int>("cachevalue")) {
0177 produces<unsigned int>();
0178 }
0179
0180 const unsigned int trans_;
0181 const unsigned int cvalue_;
0182 mutable std::atomic<unsigned int> m_count{0};
0183
0184 std::shared_ptr<Cache> globalBeginRun(edm::Run const& iRun, edm::EventSetup const&) const override {
0185 ++m_count;
0186 auto rCache = std::make_shared<Cache>();
0187 ++(rCache->run);
0188 return rCache;
0189 }
0190
0191 std::unique_ptr<UnsafeCache> beginStream(edm::StreamID) const override { return std::make_unique<UnsafeCache>(); }
0192
0193 void streamBeginRun(edm::StreamID iID, edm::Run const& iRun, edm::EventSetup const&) const override {
0194 auto rCache = runCache(iRun.index());
0195 if (rCache->run == 0) {
0196 throw cms::Exception("out of sequence") << "streamBeginRun before globalBeginRun in Stream " << iID.value();
0197 }
0198 }
0199
0200 void produce(edm::StreamID iID, edm::Event& iEvent, edm::EventSetup const&) const override {
0201 auto rCache = runCache(iEvent.getRun().index());
0202 ++(rCache->value);
0203 }
0204
0205 void streamEndRun(edm::StreamID iID, edm::Run const& iRun, edm::EventSetup const&) const override {
0206 auto rCache = runCache(iRun.index());
0207 if (rCache->run == 0) {
0208 throw cms::Exception("out of sequence") << "streamEndRun after globalEndRun in Stream " << iID.value();
0209 }
0210 }
0211
0212 void globalEndRun(edm::Run const& iRun, edm::EventSetup const&) const override {
0213 ++m_count;
0214 auto rCache = runCache(iRun.index());
0215 if (rCache->value != cvalue_) {
0216 throw cms::Exception("cache value")
0217 << "RunIntProducer cache value " << rCache->value << " but it was supposed to be " << cvalue_;
0218 }
0219 --(rCache->run);
0220 }
0221
0222 ~RunIntProducer() {
0223 if (m_count != trans_) {
0224 throw cms::Exception("transitions")
0225 << "RunIntProducer transitions " << m_count << " but it was supposed to be " << trans_;
0226 }
0227 }
0228 };
0229
0230 class LumiIntProducer
0231 : public edm::limited::EDProducer<edm::StreamCache<UnsafeCache>, edm::LuminosityBlockCache<Cache>> {
0232 public:
0233 explicit LumiIntProducer(edm::ParameterSet const& p)
0234 : edm::limited::EDProducerBase(p),
0235 edm::limited::EDProducer<edm::StreamCache<UnsafeCache>, edm::LuminosityBlockCache<Cache>>(p),
0236 trans_(p.getParameter<int>("transitions")),
0237 cvalue_(p.getParameter<int>("cachevalue")) {
0238 produces<unsigned int>();
0239 }
0240 const unsigned int trans_;
0241 const unsigned int cvalue_;
0242 mutable std::atomic<unsigned int> m_count{0};
0243
0244 std::shared_ptr<Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const& iLB,
0245 edm::EventSetup const&) const override {
0246 ++m_count;
0247 auto lCache = std::make_shared<Cache>();
0248 ++(lCache->lumi);
0249 return lCache;
0250 }
0251
0252 std::unique_ptr<UnsafeCache> beginStream(edm::StreamID) const override { return std::make_unique<UnsafeCache>(); }
0253
0254 void streamBeginLuminosityBlock(edm::StreamID iID,
0255 edm::LuminosityBlock const& iLB,
0256 edm::EventSetup const&) const override {
0257 auto lCache = luminosityBlockCache(iLB.index());
0258 if (lCache->lumi == 0) {
0259 throw cms::Exception("out of sequence")
0260 << "streamBeginLuminosityBlock seen before globalBeginLuminosityBlock in LuminosityBlock"
0261 << iLB.luminosityBlock();
0262 }
0263 }
0264
0265 void produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const override {
0266 auto lCache = luminosityBlockCache(iEvent.getLuminosityBlock().index());
0267 ++(lCache->value);
0268 }
0269
0270 void streamEndLuminosityBlock(edm::StreamID iID,
0271 edm::LuminosityBlock const& iLB,
0272 edm::EventSetup const&) const override {
0273 auto lCache = luminosityBlockCache(iLB.index());
0274 if (lCache->lumi == 0) {
0275 throw cms::Exception("out of sequence")
0276 << "streamEndLuminosityBlock seen before globalEndLuminosityBlock in LuminosityBlock"
0277 << iLB.luminosityBlock();
0278 }
0279 }
0280
0281 void globalEndLuminosityBlock(edm::LuminosityBlock const& iLB, edm::EventSetup const&) const override {
0282 ++m_count;
0283 auto lCache = luminosityBlockCache(iLB.index());
0284 --(lCache->lumi);
0285 if (lCache->lumi != 0) {
0286 throw cms::Exception("end out of sequence")
0287 << "globalEndLuminosityBlock seen before globalBeginLuminosityBlock in LuminosityBlock"
0288 << iLB.luminosityBlock();
0289 }
0290 if (lCache->value != cvalue_) {
0291 throw cms::Exception("cache value")
0292 << "LumiIntProducer cache value " << lCache->value << " but it was supposed to be " << cvalue_;
0293 }
0294 }
0295
0296 ~LumiIntProducer() {
0297 if (m_count != trans_) {
0298 throw cms::Exception("transitions")
0299 << "LumiIntProducer transitions " << m_count << " but it was supposed to be " << trans_;
0300 }
0301 }
0302 };
0303
0304 class RunSummaryIntProducer
0305 : public edm::limited::EDProducer<edm::StreamCache<UnsafeCache>, edm::RunSummaryCache<UnsafeCache>> {
0306 public:
0307 explicit RunSummaryIntProducer(edm::ParameterSet const& p)
0308 : edm::limited::EDProducerBase(p),
0309 edm::limited::EDProducer<edm::StreamCache<UnsafeCache>, edm::RunSummaryCache<UnsafeCache>>(p),
0310 trans_(p.getParameter<int>("transitions")),
0311 cvalue_(p.getParameter<int>("cachevalue")) {
0312 produces<unsigned int>();
0313 }
0314 const unsigned int trans_;
0315 const unsigned int cvalue_;
0316 mutable std::atomic<unsigned int> m_count{0};
0317
0318 std::unique_ptr<UnsafeCache> beginStream(edm::StreamID) const override { return std::make_unique<UnsafeCache>(); }
0319
0320 std::shared_ptr<UnsafeCache> globalBeginRunSummary(edm::Run const& iRun, edm::EventSetup const&) const override {
0321 ++m_count;
0322 auto gCache = std::make_shared<UnsafeCache>();
0323 ++(gCache->run);
0324 return gCache;
0325 }
0326
0327 void produce(edm::StreamID iID, edm::Event&, edm::EventSetup const&) const override {
0328 auto sCache = streamCache(iID);
0329 ++(sCache->value);
0330 }
0331
0332 void streamEndRunSummary(edm::StreamID iID,
0333 edm::Run const&,
0334 edm::EventSetup const&,
0335 UnsafeCache* gCache) const override {
0336 ++m_count;
0337 if (gCache->run == 0) {
0338 throw cms::Exception("out of sequence")
0339 << "streamEndRunSummary after globalEndRunSummary in Stream " << iID.value();
0340 }
0341 auto sCache = streamCache(iID);
0342 gCache->value += sCache->value;
0343 sCache->value = 0;
0344 }
0345
0346 void globalEndRunSummary(edm::Run const&, edm::EventSetup const&, UnsafeCache* gCache) const override {
0347 ++m_count;
0348 if (gCache->value != cvalue_) {
0349 throw cms::Exception("cache value")
0350 << "RunSummaryIntProducer cache value " << gCache->value << " but it was supposed to be " << cvalue_;
0351 }
0352 --(gCache->run);
0353 }
0354
0355 ~RunSummaryIntProducer() {
0356 if (m_count != trans_) {
0357 throw cms::Exception("transitions")
0358 << "RunSummaryIntProducer transitions " << m_count << " but it was supposed to be " << trans_;
0359 }
0360 }
0361 };
0362
0363 class LumiSummaryIntProducer
0364 : public edm::limited::EDProducer<edm::StreamCache<UnsafeCache>, edm::LuminosityBlockSummaryCache<UnsafeCache>> {
0365 public:
0366 explicit LumiSummaryIntProducer(edm::ParameterSet const& p)
0367 : edm::limited::EDProducerBase(p),
0368 edm::limited::EDProducer<edm::StreamCache<UnsafeCache>, edm::LuminosityBlockSummaryCache<UnsafeCache>>(p),
0369 trans_(p.getParameter<int>("transitions")),
0370 cvalue_(p.getParameter<int>("cachevalue")) {
0371 produces<unsigned int>();
0372 }
0373 const unsigned int trans_;
0374 const unsigned int cvalue_;
0375 mutable std::atomic<unsigned int> m_count{0};
0376 mutable std::atomic<unsigned int> m_countLumis{0};
0377 mutable std::atomic<unsigned int> m_countStreams{0};
0378 mutable std::atomic<unsigned int> m_countStreamLumiTransitions{0};
0379
0380 std::unique_ptr<UnsafeCache> beginStream(edm::StreamID) const override {
0381 ++m_count;
0382 ++m_countStreams;
0383 return std::make_unique<UnsafeCache>();
0384 }
0385
0386 std::shared_ptr<UnsafeCache> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const& iLB,
0387 edm::EventSetup const&) const override {
0388 ++m_count;
0389 ++m_countLumis;
0390 auto gCache = std::make_shared<UnsafeCache>();
0391 gCache->lumi = iLB.luminosityBlockAuxiliary().luminosityBlock();
0392 return gCache;
0393 }
0394
0395 void produce(edm::StreamID iID, edm::Event&, edm::EventSetup const&) const override {
0396 ++m_count;
0397 auto sCache = streamCache(iID);
0398 ++(sCache->value);
0399 }
0400
0401 void streamEndLuminosityBlockSummary(edm::StreamID iID,
0402 edm::LuminosityBlock const& iLB,
0403 edm::EventSetup const&,
0404 UnsafeCache* gCache) const override {
0405 ++m_countStreamLumiTransitions;
0406 if (gCache->lumi != iLB.luminosityBlockAuxiliary().luminosityBlock()) {
0407 throw cms::Exception("UnexpectedValue")
0408 << "streamEndLuminosityBlockSummary unexpected lumi number in Stream " << iID.value();
0409 }
0410 auto sCache = streamCache(iID);
0411 gCache->value += sCache->value;
0412 sCache->value = 0;
0413 }
0414
0415 void globalEndLuminosityBlockSummary(edm::LuminosityBlock const& iLB,
0416 edm::EventSetup const&,
0417 UnsafeCache* gCache) const override {
0418 ++m_count;
0419 if (gCache->lumi != iLB.luminosityBlockAuxiliary().luminosityBlock()) {
0420 throw cms::Exception("UnexpectedValue") << "globalEndLuminosityBlockSummary unexpected lumi number";
0421 }
0422 if (gCache->value != cvalue_) {
0423 throw cms::Exception("cache value")
0424 << "LumiSummaryIntProducer cache value " << gCache->value << " but it was supposed to be " << cvalue_;
0425 }
0426 }
0427
0428 ~LumiSummaryIntProducer() {
0429 if (m_count != trans_) {
0430 throw cms::Exception("transitions")
0431 << "LumiSummaryIntProducer transitions " << m_count << " but it was supposed to be " << trans_;
0432 }
0433 unsigned int nStreamLumiTransitions = m_countStreamLumiTransitions.load();
0434 unsigned int nLumis = m_countLumis.load();
0435 unsigned int nStreams = m_countStreams.load();
0436 if (nStreamLumiTransitions < nLumis || nStreamLumiTransitions > (nLumis * nStreams)) {
0437 throw cms::Exception("transitions")
0438 << "LumiSummaryIntProducer stream lumi transitions " << nStreamLumiTransitions
0439 << " but it was supposed to be between " << nLumis << " and " << nLumis * nStreams;
0440 }
0441 }
0442 };
0443
0444 class LumiSummaryLumiProducer : public edm::limited::EDProducer<edm::StreamCache<UnsafeCache>,
0445 edm::LuminosityBlockSummaryCache<UnsafeCache>,
0446 edm::EndLuminosityBlockProducer> {
0447 public:
0448 explicit LumiSummaryLumiProducer(edm::ParameterSet const& p)
0449 : edm::limited::EDProducerBase(p),
0450 edm::limited::EDProducer<edm::StreamCache<UnsafeCache>,
0451 edm::LuminosityBlockSummaryCache<UnsafeCache>,
0452 edm::EndLuminosityBlockProducer>(p),
0453 trans_(p.getParameter<int>("transitions")),
0454 cvalue_(p.getParameter<int>("cachevalue")) {
0455 produces<unsigned int>();
0456 }
0457 const unsigned int trans_;
0458 const unsigned int cvalue_;
0459 mutable std::atomic<unsigned int> m_count{0};
0460 mutable std::atomic<unsigned int> m_countLumis{0};
0461 mutable std::atomic<unsigned int> m_countStreams{0};
0462 mutable std::atomic<unsigned int> m_countStreamLumiTransitions{0};
0463
0464 std::unique_ptr<UnsafeCache> beginStream(edm::StreamID) const override {
0465 ++m_count;
0466 ++m_countStreams;
0467 return std::make_unique<UnsafeCache>();
0468 }
0469
0470 std::shared_ptr<UnsafeCache> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const& iLB,
0471 edm::EventSetup const&) const override {
0472 ++m_count;
0473 ++m_countLumis;
0474 auto gCache = std::make_shared<UnsafeCache>();
0475 gCache->lumi = iLB.luminosityBlockAuxiliary().luminosityBlock();
0476 return gCache;
0477 }
0478
0479 void produce(edm::StreamID iID, edm::Event&, edm::EventSetup const&) const override {
0480 auto sCache = streamCache(iID);
0481 ++(sCache->value);
0482 }
0483
0484 void streamEndLuminosityBlockSummary(edm::StreamID iID,
0485 edm::LuminosityBlock const& iLB,
0486 edm::EventSetup const&,
0487 UnsafeCache* gCache) const override {
0488 ++m_countStreamLumiTransitions;
0489 if (gCache->lumi != iLB.luminosityBlockAuxiliary().luminosityBlock()) {
0490 throw cms::Exception("UnexpectedValue")
0491 << "streamEndLuminosityBlockSummary unexpected lumi number in Stream " << iID.value();
0492 }
0493 auto sCache = streamCache(iID);
0494 gCache->value += sCache->value;
0495 sCache->value = 0;
0496 }
0497
0498 void globalEndLuminosityBlockSummary(edm::LuminosityBlock const& iLB,
0499 edm::EventSetup const&,
0500 UnsafeCache* gCache) const override {
0501 ++m_count;
0502 if (gCache->lumi != iLB.luminosityBlockAuxiliary().luminosityBlock()) {
0503 throw cms::Exception("UnexpectedValue") << "globalEndLuminosityBlockSummary unexpected lumi number";
0504 }
0505 if (gCache->value != cvalue_) {
0506 throw cms::Exception("cache value")
0507 << "LumiSummaryLumiProducer cache value " << gCache->value << " but it was supposed to be " << cvalue_;
0508 }
0509 }
0510
0511 void globalEndLuminosityBlockProduce(edm::LuminosityBlock& iLB,
0512 edm::EventSetup const&,
0513 UnsafeCache const* gCache) const override {
0514 ++m_count;
0515 if (gCache->lumi != iLB.luminosityBlockAuxiliary().luminosityBlock()) {
0516 throw cms::Exception("UnexpectedValue") << "globalEndLuminosityBlockProduce unexpected lumi number";
0517 }
0518 }
0519
0520 ~LumiSummaryLumiProducer() {
0521 if (m_count != trans_) {
0522 throw cms::Exception("transitions")
0523 << "LumiSummaryLumiProducer transitions " << m_count << " but it was supposed to be " << trans_;
0524 }
0525 unsigned int nStreamLumiTransitions = m_countStreamLumiTransitions.load();
0526 unsigned int nLumis = m_countLumis.load();
0527 unsigned int nStreams = m_countStreams.load();
0528 if (nStreamLumiTransitions < nLumis || nStreamLumiTransitions > (nLumis * nStreams)) {
0529 throw cms::Exception("transitions")
0530 << "LumiSummaryLumiProducer stream lumi transitions " << nStreamLumiTransitions
0531 << " but it was supposed to be between " << nLumis << " and " << nLumis * nStreams;
0532 }
0533 }
0534 };
0535
0536 class ProcessBlockIntProducer : public edm::limited::EDProducer<edm::WatchProcessBlock> {
0537 public:
0538 explicit ProcessBlockIntProducer(edm::ParameterSet const& pset)
0539 : edm::limited::EDProducerBase(pset),
0540 edm::limited::EDProducer<edm::WatchProcessBlock>(pset),
0541 trans_(pset.getParameter<int>("transitions")) {
0542 produces<unsigned int>();
0543
0544 {
0545 auto tag = pset.getParameter<edm::InputTag>("consumesBeginProcessBlock");
0546 if (not tag.label().empty()) {
0547 getTokenBegin_ = consumes<unsigned int, edm::InProcess>(tag);
0548 }
0549 }
0550 {
0551 auto tag = pset.getParameter<edm::InputTag>("consumesEndProcessBlock");
0552 if (not tag.label().empty()) {
0553 getTokenEnd_ = consumes<unsigned int, edm::InProcess>(tag);
0554 }
0555 }
0556 }
0557
0558 void beginProcessBlock(edm::ProcessBlock const& processBlock) override {
0559 if (m_count != 0) {
0560 throw cms::Exception("transitions")
0561 << "ProcessBlockIntProducer::begin transitions " << m_count << " but it was supposed to be " << 0;
0562 }
0563 ++m_count;
0564 const unsigned int valueToGet = 11;
0565 if (not getTokenBegin_.isUninitialized()) {
0566 if (processBlock.get(getTokenBegin_) != valueToGet) {
0567 throw cms::Exception("BadValue")
0568 << "expected " << valueToGet << " but got " << processBlock.get(getTokenBegin_);
0569 }
0570 }
0571 }
0572
0573 void produce(edm::StreamID iID, edm::Event&, edm::EventSetup const&) const override {
0574 if (m_count < 1u) {
0575 throw cms::Exception("out of sequence") << "produce before beginProcessBlock " << m_count;
0576 }
0577 ++m_count;
0578 }
0579
0580 void endProcessBlock(edm::ProcessBlock const& processBlock) override {
0581 ++m_count;
0582 if (m_count != trans_) {
0583 throw cms::Exception("transitions")
0584 << "ProcessBlockIntProducer::end transitions " << m_count << " but it was supposed to be " << trans_;
0585 }
0586 {
0587 const unsigned int valueToGet = 11;
0588 if (not getTokenBegin_.isUninitialized()) {
0589 if (processBlock.get(getTokenBegin_) != valueToGet) {
0590 throw cms::Exception("BadValue")
0591 << "expected " << valueToGet << " but got " << processBlock.get(getTokenBegin_);
0592 }
0593 }
0594 }
0595 {
0596 const unsigned int valueToGet = 21;
0597 if (not getTokenEnd_.isUninitialized()) {
0598 if (processBlock.get(getTokenEnd_) != valueToGet) {
0599 throw cms::Exception("BadValue")
0600 << "expected " << valueToGet << " but got " << processBlock.get(getTokenEnd_);
0601 }
0602 }
0603 }
0604 }
0605
0606 ~ProcessBlockIntProducer() {
0607 if (m_count != trans_) {
0608 throw cms::Exception("transitions")
0609 << "ProcessBlockIntProducer transitions " << m_count << " but it was supposed to be " << trans_;
0610 }
0611 }
0612
0613 private:
0614 const unsigned int trans_;
0615 mutable std::atomic<unsigned int> m_count{0};
0616 edm::EDGetTokenT<unsigned int> getTokenBegin_;
0617 edm::EDGetTokenT<unsigned int> getTokenEnd_;
0618 };
0619
0620 class TestBeginProcessBlockProducer : public edm::limited::EDProducer<edm::BeginProcessBlockProducer> {
0621 public:
0622 explicit TestBeginProcessBlockProducer(edm::ParameterSet const& pset)
0623 : edm::limited::EDProducerBase(pset),
0624 edm::limited::EDProducer<edm::BeginProcessBlockProducer>(pset),
0625 trans_(pset.getParameter<int>("transitions")),
0626 token_(produces<unsigned int, edm::Transition::BeginProcessBlock>("begin")) {
0627 produces<unsigned int>();
0628
0629 auto tag = pset.getParameter<edm::InputTag>("consumesBeginProcessBlock");
0630 if (not tag.label().empty()) {
0631 getToken_ = consumes<unsigned int, edm::InProcess>(tag);
0632 }
0633 }
0634
0635 void beginProcessBlockProduce(edm::ProcessBlock& processBlock) override {
0636 if (m_count != 0) {
0637 throw cms::Exception("transitions")
0638 << "TestBeginProcessBlockProducer transitions " << m_count << " but it was supposed to be " << 0;
0639 }
0640 ++m_count;
0641
0642 const unsigned int valueToPutAndGet = 11;
0643 processBlock.emplace(token_, valueToPutAndGet);
0644
0645 if (not getToken_.isUninitialized()) {
0646 if (processBlock.get(getToken_) != valueToPutAndGet) {
0647 throw cms::Exception("BadValue")
0648 << "expected " << valueToPutAndGet << " but got " << processBlock.get(getToken_);
0649 }
0650 }
0651 }
0652
0653 void produce(edm::StreamID iID, edm::Event&, edm::EventSetup const&) const override {
0654 if (m_count < 1u) {
0655 throw cms::Exception("out of sequence") << "produce before beginProcessBlockProduce " << m_count;
0656 }
0657 ++m_count;
0658 }
0659
0660 ~TestBeginProcessBlockProducer() {
0661 if (m_count != trans_) {
0662 throw cms::Exception("transitions")
0663 << "TestBeginProcessBlockProducer transitions " << m_count << " but it was supposed to be " << trans_;
0664 }
0665 }
0666
0667 private:
0668 const unsigned int trans_;
0669 mutable std::atomic<unsigned int> m_count{0};
0670 edm::EDPutTokenT<unsigned int> token_;
0671 edm::EDGetTokenT<unsigned int> getToken_;
0672 };
0673
0674 class TestEndProcessBlockProducer : public edm::limited::EDProducer<edm::EndProcessBlockProducer> {
0675 public:
0676 explicit TestEndProcessBlockProducer(edm::ParameterSet const& pset)
0677 : edm::limited::EDProducerBase(pset),
0678 edm::limited::EDProducer<edm::EndProcessBlockProducer>(pset),
0679 trans_(pset.getParameter<int>("transitions")),
0680 token_(produces<unsigned int, edm::Transition::EndProcessBlock>("end")) {
0681 produces<unsigned int>();
0682
0683 auto tag = pset.getParameter<edm::InputTag>("consumesEndProcessBlock");
0684 if (not tag.label().empty()) {
0685 getToken_ = consumes<unsigned int, edm::InProcess>(tag);
0686 }
0687 }
0688
0689 void produce(edm::StreamID iID, edm::Event&, edm::EventSetup const&) const override { ++m_count; }
0690
0691 void endProcessBlockProduce(edm::ProcessBlock& processBlock) override {
0692 ++m_count;
0693 if (m_count != trans_) {
0694 throw cms::Exception("transitions")
0695 << "TestEndProcessBlockProducer transitions " << m_count << " but it was supposed to be " << trans_;
0696 }
0697
0698 const unsigned int valueToPutAndGet = 21;
0699 processBlock.emplace(token_, valueToPutAndGet);
0700 if (not getToken_.isUninitialized()) {
0701 if (processBlock.get(getToken_) != valueToPutAndGet) {
0702 throw cms::Exception("BadValue")
0703 << "expected " << valueToPutAndGet << " but got " << processBlock.get(getToken_);
0704 }
0705 }
0706 }
0707
0708 ~TestEndProcessBlockProducer() {
0709 if (m_count != trans_) {
0710 throw cms::Exception("transitions")
0711 << "~TestEndProcessBlockProducer transitions " << m_count << " but it was supposed to be " << trans_;
0712 }
0713 }
0714
0715 private:
0716 const unsigned int trans_;
0717 mutable std::atomic<unsigned int> m_count{0};
0718 edm::EDPutTokenT<unsigned int> token_;
0719 edm::EDGetTokenT<unsigned int> getToken_;
0720 };
0721
0722 class TestBeginRunProducer : public edm::limited::EDProducer<edm::RunCache<Dummy>, edm::BeginRunProducer> {
0723 public:
0724 explicit TestBeginRunProducer(edm::ParameterSet const& p)
0725 : edm::limited::EDProducerBase(p),
0726 edm::limited::EDProducer<edm::RunCache<Dummy>, edm::BeginRunProducer>(p),
0727 trans_(p.getParameter<int>("transitions")) {
0728 produces<unsigned int>();
0729 produces<unsigned int, edm::Transition::BeginRun>("a");
0730 }
0731
0732 const unsigned int trans_;
0733 mutable std::atomic<unsigned int> m_count{0};
0734 mutable std::atomic<bool> brp{false};
0735
0736 std::shared_ptr<Dummy> globalBeginRun(edm::Run const& iRun, edm::EventSetup const&) const override {
0737 brp = false;
0738 return std::shared_ptr<Dummy>();
0739 }
0740
0741 void produce(edm::StreamID iID, edm::Event&, edm::EventSetup const&) const override {
0742 if (!brp) {
0743 throw cms::Exception("out of sequence") << "produce before globalBeginRunProduce in Stream " << iID.value();
0744 }
0745 }
0746
0747 void globalBeginRunProduce(edm::Run&, edm::EventSetup const&) const override {
0748 ++m_count;
0749 brp = true;
0750 }
0751
0752 void globalEndRun(edm::Run const& iRun, edm::EventSetup const&) const override {}
0753
0754 ~TestBeginRunProducer() {
0755 if (m_count != trans_) {
0756 throw cms::Exception("transitions")
0757 << "TestBeginRunProducer transitions " << m_count << " but it was supposed to be " << trans_;
0758 }
0759 }
0760 };
0761
0762 class TestEndRunProducer : public edm::limited::EDProducer<edm::RunCache<Dummy>, edm::EndRunProducer> {
0763 public:
0764 explicit TestEndRunProducer(edm::ParameterSet const& p)
0765 : edm::limited::EDProducerBase(p),
0766 edm::limited::EDProducer<edm::RunCache<Dummy>, edm::EndRunProducer>(p),
0767 trans_(p.getParameter<int>("transitions")) {
0768 produces<unsigned int>();
0769 produces<unsigned int, edm::Transition::EndRun>("a");
0770 }
0771 const unsigned int trans_;
0772 mutable std::atomic<unsigned int> m_count{0};
0773 mutable std::atomic<bool> p{false};
0774
0775 std::shared_ptr<Dummy> globalBeginRun(edm::Run const& iRun, edm::EventSetup const&) const override {
0776 p = false;
0777 return std::shared_ptr<Dummy>();
0778 }
0779
0780 void produce(edm::StreamID iID, edm::Event&, edm::EventSetup const&) const override { p = true; }
0781
0782 void globalEndRunProduce(edm::Run&, edm::EventSetup const&) const override {
0783 if (!p) {
0784 throw cms::Exception("out of sequence") << "endRunProduce before produce";
0785 }
0786 ++m_count;
0787 }
0788
0789 void globalEndRun(edm::Run const& iRun, edm::EventSetup const&) const override {}
0790
0791 ~TestEndRunProducer() {
0792 if (m_count != trans_) {
0793 throw cms::Exception("transitions")
0794 << "TestEndRunProducer transitions " << m_count << " but it was supposed to be " << trans_;
0795 }
0796 }
0797 };
0798
0799 class TestBeginLumiBlockProducer
0800 : public edm::limited::EDProducer<edm::LuminosityBlockCache<void>, edm::BeginLuminosityBlockProducer> {
0801 public:
0802 explicit TestBeginLumiBlockProducer(edm::ParameterSet const& p)
0803 : edm::limited::EDProducerBase(p),
0804 edm::limited::EDProducer<edm::LuminosityBlockCache<void>, edm::BeginLuminosityBlockProducer>(p),
0805 trans_(p.getParameter<int>("transitions")) {
0806 produces<unsigned int>();
0807 produces<unsigned int, edm::Transition::BeginLuminosityBlock>("a");
0808 }
0809 const unsigned int trans_;
0810 mutable std::atomic<unsigned int> m_count{0};
0811 mutable std::atomic<bool> gblp{false};
0812
0813 std::shared_ptr<void> globalBeginLuminosityBlock(edm::LuminosityBlock const& iLB,
0814 edm::EventSetup const&) const override {
0815 gblp = false;
0816 return std::shared_ptr<void>();
0817 }
0818
0819 void produce(edm::StreamID iID, edm::Event&, const edm::EventSetup&) const override {
0820 if (!gblp) {
0821 throw cms::Exception("out of sequence")
0822 << "produce before globalBeginLuminosityBlockProduce in Stream " << iID.value();
0823 }
0824 }
0825
0826 void globalBeginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const override {
0827 ++m_count;
0828 gblp = true;
0829 }
0830
0831 void globalEndLuminosityBlock(edm::LuminosityBlock const& iLB, edm::EventSetup const&) const override {}
0832
0833 ~TestBeginLumiBlockProducer() {
0834 if (m_count != trans_) {
0835 throw cms::Exception("transitions")
0836 << "TestBeginLumiBlockProducer transitions " << m_count << " but it was supposed to be " << trans_;
0837 }
0838 }
0839 };
0840
0841 class TestEndLumiBlockProducer
0842 : public edm::limited::EDProducer<edm::LuminosityBlockCache<void>, edm::EndLuminosityBlockProducer> {
0843 public:
0844 explicit TestEndLumiBlockProducer(edm::ParameterSet const& p)
0845 : edm::limited::EDProducerBase(p),
0846 edm::limited::EDProducer<edm::LuminosityBlockCache<void>, edm::EndLuminosityBlockProducer>(p),
0847 trans_(p.getParameter<int>("transitions")) {
0848 produces<unsigned int>();
0849 produces<unsigned int, edm::Transition::EndLuminosityBlock>("a");
0850 }
0851 const unsigned int trans_;
0852 mutable std::atomic<unsigned int> m_count{0};
0853 mutable std::atomic<bool> p{false};
0854
0855 std::shared_ptr<void> globalBeginLuminosityBlock(edm::LuminosityBlock const& iLB,
0856 edm::EventSetup const&) const override {
0857 p = false;
0858 return std::shared_ptr<void>();
0859 }
0860
0861 void produce(edm::StreamID iID, edm::Event&, edm::EventSetup const&) const override { p = true; }
0862
0863 void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const override {
0864 if (!p) {
0865 throw cms::Exception("out of sequence") << "endLumiBlockProduce before produce";
0866 }
0867 ++m_count;
0868 }
0869
0870 void globalEndLuminosityBlock(edm::LuminosityBlock const& iLB, edm::EventSetup const&) const override {}
0871
0872 ~TestEndLumiBlockProducer() {
0873 if (m_count != trans_) {
0874 throw cms::Exception("transitions")
0875 << "TestEndLumiBlockProducer transitions " << m_count << " but it was supposed to be " << trans_;
0876 }
0877 }
0878 };
0879
0880 class TestAccumulator : public edm::limited::EDProducer<edm::Accumulator, edm::EndLuminosityBlockProducer> {
0881 public:
0882 explicit TestAccumulator(edm::ParameterSet const& p)
0883 : edm::limited::EDProducerBase(p),
0884 edm::limited::EDProducer<edm::Accumulator, edm::EndLuminosityBlockProducer>(p),
0885 m_expectedCount(p.getParameter<unsigned int>("expectedCount")),
0886 m_putToken(produces<unsigned int, edm::Transition::EndLuminosityBlock>()) {}
0887
0888 void accumulate(edm::StreamID iID, edm::Event const&, edm::EventSetup const&) const override { ++m_count; }
0889
0890 void globalEndLuminosityBlockProduce(edm::LuminosityBlock& l, edm::EventSetup const&) const override {
0891 l.emplace(m_putToken, m_count.load());
0892 }
0893
0894 ~TestAccumulator() {
0895 if (m_count.load() != m_expectedCount) {
0896 throw cms::Exception("TestCount")
0897 << "TestAccumulator counter was " << m_count << " but it was supposed to be " << m_expectedCount;
0898 }
0899 }
0900
0901 mutable std::atomic<unsigned int> m_count{0};
0902 const unsigned int m_expectedCount;
0903 const edm::EDPutTokenT<unsigned int> m_putToken;
0904 };
0905
0906 class TestInputProcessBlockCache {
0907 public:
0908 long long int value_ = 0;
0909 };
0910
0911 class TestInputProcessBlockCache1 {
0912 public:
0913 long long int value_ = 0;
0914 };
0915
0916 class InputProcessBlockIntProducer
0917 : public edm::limited::EDProducer<
0918 edm::InputProcessBlockCache<int, TestInputProcessBlockCache, TestInputProcessBlockCache1>> {
0919 public:
0920 explicit InputProcessBlockIntProducer(edm::ParameterSet const& pset)
0921 : edm::limited::EDProducerBase(pset),
0922 edm::limited::EDProducer<
0923 edm::InputProcessBlockCache<int, TestInputProcessBlockCache, TestInputProcessBlockCache1>>(pset) {
0924 expectedTransitions_ = pset.getParameter<int>("transitions");
0925 expectedByRun_ = pset.getParameter<std::vector<int>>("expectedByRun");
0926 expectedSum_ = pset.getParameter<int>("expectedSum");
0927 {
0928 auto tag = pset.getParameter<edm::InputTag>("consumesBeginProcessBlock");
0929 if (not tag.label().empty()) {
0930 getTokenBegin_ = consumes<IntProduct, edm::InProcess>(tag);
0931 }
0932 }
0933 {
0934 auto tag = pset.getParameter<edm::InputTag>("consumesEndProcessBlock");
0935 if (not tag.label().empty()) {
0936 getTokenEnd_ = consumes<IntProduct, edm::InProcess>(tag);
0937 }
0938 }
0939 {
0940 auto tag = pset.getParameter<edm::InputTag>("consumesBeginProcessBlockM");
0941 if (not tag.label().empty()) {
0942 getTokenBeginM_ = consumes<IntProduct, edm::InProcess>(tag);
0943 }
0944 }
0945 {
0946 auto tag = pset.getParameter<edm::InputTag>("consumesEndProcessBlockM");
0947 if (not tag.label().empty()) {
0948 getTokenEndM_ = consumes<IntProduct, edm::InProcess>(tag);
0949 }
0950 }
0951 registerProcessBlockCacheFiller<int>(
0952 getTokenBegin_, [this](edm::ProcessBlock const& processBlock, std::shared_ptr<int> const& previousCache) {
0953 auto returnValue = std::make_shared<int>(0);
0954 *returnValue += processBlock.get(getTokenBegin_).value;
0955 *returnValue += processBlock.get(getTokenEnd_).value;
0956 ++transitions_;
0957 return returnValue;
0958 });
0959 registerProcessBlockCacheFiller<1>(getTokenBegin_,
0960 [this](edm::ProcessBlock const& processBlock,
0961 std::shared_ptr<TestInputProcessBlockCache> const& previousCache) {
0962 auto returnValue = std::make_shared<TestInputProcessBlockCache>();
0963 returnValue->value_ += processBlock.get(getTokenBegin_).value;
0964 returnValue->value_ += processBlock.get(getTokenEnd_).value;
0965 ++transitions_;
0966 return returnValue;
0967 });
0968 registerProcessBlockCacheFiller<TestInputProcessBlockCache1>(
0969 getTokenBegin_,
0970 [this](edm::ProcessBlock const& processBlock,
0971 std::shared_ptr<TestInputProcessBlockCache1> const& previousCache) {
0972 auto returnValue = std::make_shared<TestInputProcessBlockCache1>();
0973 returnValue->value_ += processBlock.get(getTokenBegin_).value;
0974 returnValue->value_ += processBlock.get(getTokenEnd_).value;
0975 ++transitions_;
0976 return returnValue;
0977 });
0978 }
0979
0980 void accessInputProcessBlock(edm::ProcessBlock const& processBlock) override {
0981 if (processBlock.processName() == "PROD1") {
0982 sum_ += processBlock.get(getTokenBegin_).value;
0983 sum_ += processBlock.get(getTokenEnd_).value;
0984 }
0985 if (processBlock.processName() == "MERGE") {
0986 sum_ += processBlock.get(getTokenBeginM_).value;
0987 sum_ += processBlock.get(getTokenEndM_).value;
0988 }
0989 ++transitions_;
0990 }
0991
0992 void produce(edm::StreamID, edm::Event& event, edm::EventSetup const&) const override {
0993 auto cacheTuple = processBlockCaches(event);
0994 if (!expectedByRun_.empty()) {
0995 if (expectedByRun_.at(event.run() - 1) != *std::get<edm::CacheHandle<int>>(cacheTuple)) {
0996 throw cms::Exception("UnexpectedValue")
0997 << "InputProcessBlockIntProducer::produce cached value was "
0998 << *std::get<edm::CacheHandle<int>>(cacheTuple) << " but it was supposed to be "
0999 << expectedByRun_.at(event.run() - 1);
1000 }
1001 if (expectedByRun_.at(event.run() - 1) != std::get<1>(cacheTuple)->value_) {
1002 throw cms::Exception("UnexpectedValue")
1003 << "InputProcessBlockIntProducer::produce second cached value was " << std::get<1>(cacheTuple)->value_
1004 << " but it was supposed to be " << expectedByRun_.at(event.run() - 1);
1005 }
1006 if (expectedByRun_.at(event.run() - 1) !=
1007 std::get<edm::CacheHandle<TestInputProcessBlockCache1>>(cacheTuple)->value_) {
1008 throw cms::Exception("UnexpectedValue")
1009 << "InputProcessBlockIntProducer::produce third cached value was "
1010 << std::get<edm::CacheHandle<TestInputProcessBlockCache1>>(cacheTuple)->value_
1011 << " but it was supposed to be " << expectedByRun_.at(event.run() - 1);
1012 }
1013 }
1014 ++transitions_;
1015 }
1016
1017 void endJob() override {
1018 if (transitions_ != expectedTransitions_) {
1019 throw cms::Exception("transitions") << "InputProcessBlockIntProducer transitions " << transitions_
1020 << " but it was supposed to be " << expectedTransitions_;
1021 }
1022 if (sum_ != expectedSum_) {
1023 throw cms::Exception("UnexpectedValue")
1024 << "InputProcessBlockIntProducer sum " << sum_ << " but it was supposed to be " << expectedSum_;
1025 }
1026 if (cacheSize() > 0u) {
1027 throw cms::Exception("UnexpectedValue")
1028 << "InputProcessBlockIntProducer cache size not zero at endJob " << cacheSize();
1029 }
1030 }
1031
1032 private:
1033 edm::EDGetTokenT<IntProduct> getTokenBegin_;
1034 edm::EDGetTokenT<IntProduct> getTokenEnd_;
1035 edm::EDGetTokenT<IntProduct> getTokenBeginM_;
1036 edm::EDGetTokenT<IntProduct> getTokenEndM_;
1037 mutable std::atomic<unsigned int> transitions_{0};
1038 int sum_{0};
1039 unsigned int expectedTransitions_{0};
1040 std::vector<int> expectedByRun_;
1041 int expectedSum_{0};
1042 };
1043
1044 }
1045 }
1046
1047 DEFINE_FWK_MODULE(edmtest::limited::StreamIntProducer);
1048 DEFINE_FWK_MODULE(edmtest::limited::RunIntProducer);
1049 DEFINE_FWK_MODULE(edmtest::limited::LumiIntProducer);
1050 DEFINE_FWK_MODULE(edmtest::limited::RunSummaryIntProducer);
1051 DEFINE_FWK_MODULE(edmtest::limited::LumiSummaryIntProducer);
1052 DEFINE_FWK_MODULE(edmtest::limited::LumiSummaryLumiProducer);
1053 DEFINE_FWK_MODULE(edmtest::limited::ProcessBlockIntProducer);
1054 DEFINE_FWK_MODULE(edmtest::limited::TestBeginProcessBlockProducer);
1055 DEFINE_FWK_MODULE(edmtest::limited::TestEndProcessBlockProducer);
1056 DEFINE_FWK_MODULE(edmtest::limited::TestBeginRunProducer);
1057 DEFINE_FWK_MODULE(edmtest::limited::TestEndRunProducer);
1058 DEFINE_FWK_MODULE(edmtest::limited::TestBeginLumiBlockProducer);
1059 DEFINE_FWK_MODULE(edmtest::limited::TestEndLumiBlockProducer);
1060 DEFINE_FWK_MODULE(edmtest::limited::TestAccumulator);
1061 DEFINE_FWK_MODULE(edmtest::limited::InputProcessBlockIntProducer);