Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-19 01:43:57

0001 
0002 /*----------------------------------------------------------------------
0003 
0004 Toy edm::one::EDFilter modules of
0005 edm::one cache classes and edm::*Producer classes
0006 for testing purposes only.
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/EDFilter.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 SharedResourcesFilter : public edm::one::EDFilter<edm::one::SharedResources> {
0034     public:
0035       explicit SharedResourcesFilter(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {
0036         produces<int>();
0037         usesResource();
0038       }
0039       const unsigned int trans_;
0040       mutable std::atomic<unsigned int> m_count{0};
0041       bool filter(edm::Event&, edm::EventSetup const&) override {
0042         ++m_count;
0043         return true;
0044       }
0045 
0046       ~SharedResourcesFilter() {
0047         if (m_count != trans_) {
0048           throw cms::Exception("transitions")
0049               << "SharedResourcesFilter transitions " << m_count << " but it was supposed to be " << trans_;
0050         }
0051       }
0052     };
0053 
0054     class WatchRunsFilter : public edm::one::EDFilter<edm::one::WatchRuns> {
0055     public:
0056       explicit WatchRunsFilter(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {}
0057       bool br = false;
0058       bool er = false;
0059       const unsigned int trans_;
0060       unsigned int m_count = 0;
0061 
0062       bool filter(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         return true;
0068       }
0069 
0070       void beginRun(edm::Run const&, edm::EventSetup const&) override {
0071         ++m_count;
0072         if (br) {
0073           throw cms::Exception("out of sequence") << " beginRun seen multiple times";
0074         }
0075         br = true;
0076         er = false;
0077       }
0078 
0079       void endRun(edm::Run const&, edm::EventSetup const&) override {
0080         ++m_count;
0081         if (!br) {
0082           throw cms::Exception("out of sequence") << " endRun before beginRun";
0083         }
0084         br = false;
0085         er = true;
0086       }
0087 
0088       ~WatchRunsFilter() {
0089         if (m_count != trans_) {
0090           throw cms::Exception("transitions")
0091               << "WatchRunsFilter transitions " << m_count << " but it was supposed to be " << trans_;
0092         }
0093       }
0094     };
0095 
0096     class WatchLumiBlocksFilter : public edm::one::EDFilter<edm::one::WatchLuminosityBlocks> {
0097     public:
0098       explicit WatchLumiBlocksFilter(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {}
0099       const unsigned int trans_;
0100       bool bl = false;
0101       bool el = false;
0102       unsigned int m_count = 0;
0103 
0104       bool filter(edm::Event&, edm::EventSetup const&) override {
0105         ++m_count;
0106         if (!bl || el) {
0107           throw cms::Exception("out of sequence") << " produce before beginLumiBlock or after endLumiBlock";
0108         }
0109         return true;
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       ~WatchLumiBlocksFilter() {
0131         if (m_count != trans_) {
0132           throw cms::Exception("transitions")
0133               << "WatchLumiBlocksFilter transitions " << m_count << " but it was supposed to be " << trans_;
0134         }
0135       }
0136     };
0137 
0138     namespace fltr {
0139       struct Cache {
0140         bool begin = true;
0141         bool end = false;
0142       };
0143     }  // namespace fltr
0144     class RunCacheFilter : public edm::one::EDFilter<edm::RunCache<fltr::Cache>> {
0145     public:
0146       explicit RunCacheFilter(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {}
0147       const unsigned int trans_;
0148       mutable std::atomic<unsigned int> m_count = 0;
0149 
0150       bool filter(edm::Event& iEvent, edm::EventSetup const&) override {
0151         ++m_count;
0152         auto c = runCache(iEvent.getRun().index());
0153         if (nullptr == c) {
0154           throw cms::Exception("Missing cache") << " no cache in analyze";
0155         }
0156 
0157         if (!c->begin || c->end) {
0158           throw cms::Exception("out of sequence") << " produce before beginRun or after endRun";
0159         }
0160 
0161         return true;
0162       }
0163 
0164       std::shared_ptr<fltr::Cache> globalBeginRun(edm::Run const&, edm::EventSetup const&) const final {
0165         ++m_count;
0166         return std::make_shared<fltr::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       ~RunCacheFilter() {
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 LumiBlockCacheFilter : public edm::one::EDFilter<edm::LuminosityBlockCache<fltr::Cache>> {
0191     public:
0192       explicit LumiBlockCacheFilter(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {}
0193       const unsigned int trans_;
0194       mutable std::atomic<unsigned int> m_count = 0;
0195 
0196       bool filter(edm::Event& iEvent, edm::EventSetup const&) override {
0197         ++m_count;
0198 
0199         auto c = luminosityBlockCache(iEvent.getLuminosityBlock().index());
0200         if (nullptr == c) {
0201           throw cms::Exception("Missing cache") << " no cache in analyze";
0202         }
0203 
0204         if (!c->begin || c->end) {
0205           throw cms::Exception("out of sequence") << " produce before beginLumiBlock or after endLumiBlock";
0206         }
0207         return true;
0208       }
0209 
0210       std::shared_ptr<fltr::Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
0211                                                               edm::EventSetup const&) const final {
0212         ++m_count;
0213         return std::make_shared<fltr::Cache>();
0214       }
0215 
0216       void globalEndLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const&) override {
0217         ++m_count;
0218         auto c = luminosityBlockCache(iLumi.index());
0219         if (!c->begin) {
0220           throw cms::Exception("out of sequence") << " endLumiBlock before beginLumiBlock";
0221         }
0222         c->begin = false;
0223         c->end = true;
0224       }
0225 
0226       ~LumiBlockCacheFilter() {
0227         if (m_count != trans_) {
0228           throw cms::Exception("transitions")
0229               << "WatchLumiBlocksAnalyzer transitions " << m_count << " but it was supposed to be " << trans_;
0230         }
0231       }
0232     };
0233 
0234     class ProcessBlockIntFilter : public edm::one::EDFilter<edm::WatchProcessBlock> {
0235     public:
0236       explicit ProcessBlockIntFilter(edm::ParameterSet const& pset) : trans_(pset.getParameter<int>("transitions")) {
0237         produces<unsigned int>();
0238 
0239         {
0240           auto tag = pset.getParameter<edm::InputTag>("consumesBeginProcessBlock");
0241           if (not tag.label().empty()) {
0242             getTokenBegin_ = consumes<unsigned int, edm::InProcess>(tag);
0243           }
0244         }
0245         {
0246           auto tag = pset.getParameter<edm::InputTag>("consumesEndProcessBlock");
0247           if (not tag.label().empty()) {
0248             getTokenEnd_ = consumes<unsigned int, edm::InProcess>(tag);
0249           }
0250         }
0251       }
0252 
0253       void beginProcessBlock(edm::ProcessBlock const& processBlock) override {
0254         if (m_count != 0) {
0255           throw cms::Exception("transitions")
0256               << "ProcessBlockIntFilter::begin transitions " << m_count << " but it was supposed to be " << 0;
0257         }
0258         ++m_count;
0259 
0260         const unsigned int valueToGet = 31;
0261         if (not getTokenBegin_.isUninitialized()) {
0262           if (processBlock.get(getTokenBegin_) != valueToGet) {
0263             throw cms::Exception("BadValue")
0264                 << "expected " << valueToGet << " but got " << processBlock.get(getTokenBegin_);
0265           }
0266         }
0267       }
0268 
0269       bool filter(edm::Event&, edm::EventSetup const&) override {
0270         if (m_count < 1u) {
0271           throw cms::Exception("out of sequence") << "produce before beginProcessBlock " << m_count;
0272         }
0273         ++m_count;
0274         return true;
0275       }
0276 
0277       void endProcessBlock(edm::ProcessBlock const& processBlock) override {
0278         ++m_count;
0279         if (m_count != trans_) {
0280           throw cms::Exception("transitions")
0281               << "ProcessBlockIntFilter::end transitions " << m_count << " but it was supposed to be " << trans_;
0282         }
0283 
0284         {
0285           const unsigned int valueToGet = 31;
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 = 41;
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       ~ProcessBlockIntFilter() {
0305         if (m_count != trans_) {
0306           throw cms::Exception("transitions")
0307               << "ProcessBlockIntFilter 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 TestBeginProcessBlockFilter : public edm::one::EDFilter<edm::BeginProcessBlockProducer> {
0319     public:
0320       explicit TestBeginProcessBlockFilter(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               << "TestBeginProcessBlockFilter transitions " << m_count << " but it was supposed to be " << 0;
0335         }
0336         ++m_count;
0337 
0338         const unsigned int valueToPutAndGet = 31;
0339         processBlock.emplace(token_, valueToPutAndGet);
0340         if (not getToken_.isUninitialized()) {
0341           if (processBlock.get(getToken_) != valueToPutAndGet) {
0342             throw cms::Exception("BadValue")
0343                 << "expected " << valueToPutAndGet << " but got " << processBlock.get(getToken_);
0344           }
0345         }
0346       }
0347 
0348       bool filter(edm::Event&, edm::EventSetup const&) override {
0349         if (m_count < 1u) {
0350           throw cms::Exception("out of sequence") << "produce before beginProcessBlockProduce " << m_count;
0351         }
0352         ++m_count;
0353         return true;
0354       }
0355 
0356       ~TestBeginProcessBlockFilter() {
0357         if (m_count != trans_) {
0358           throw cms::Exception("transitions")
0359               << "TestBeginProcessBlockFilter 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 TestEndProcessBlockFilter : public edm::one::EDFilter<edm::EndProcessBlockProducer> {
0371     public:
0372       explicit TestEndProcessBlockFilter(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       bool filter(edm::Event&, edm::EventSetup const&) override {
0384         ++m_count;
0385         return true;
0386       }
0387 
0388       void endProcessBlockProduce(edm::ProcessBlock& processBlock) override {
0389         ++m_count;
0390         if (m_count != trans_) {
0391           throw cms::Exception("transitions")
0392               << "TestEndProcessBlockFilter transitions " << m_count << " but it was supposed to be " << trans_;
0393         }
0394 
0395         const unsigned int valueToPutAndGet = 41;
0396         processBlock.emplace(token_, valueToPutAndGet);
0397         if (not getToken_.isUninitialized()) {
0398           if (processBlock.get(getToken_) != valueToPutAndGet) {
0399             throw cms::Exception("BadValue")
0400                 << "expected " << valueToPutAndGet << " but got " << processBlock.get(getToken_);
0401           }
0402         }
0403       }
0404 
0405       ~TestEndProcessBlockFilter() {
0406         if (m_count != trans_) {
0407           throw cms::Exception("transitions")
0408               << "~TestEndProcessBlockFilter transitions " << m_count << " but it was supposed to be " << trans_;
0409         }
0410       }
0411 
0412     private:
0413       const unsigned int trans_;
0414       mutable std::atomic<unsigned int> m_count{0};
0415       edm::EDPutTokenT<unsigned int> token_;
0416       edm::EDGetTokenT<unsigned int> getToken_;
0417     };
0418 
0419     class BeginRunFilter : public edm::one::EDFilter<edm::one::WatchRuns, edm::BeginRunProducer> {
0420     public:
0421       explicit BeginRunFilter(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {
0422         produces<int>();
0423         produces<unsigned int, edm::Transition::BeginRun>("a");
0424       }
0425       const unsigned int trans_;
0426       unsigned int m_count = 0;
0427       bool p = false;
0428 
0429       void beginRun(edm::Run const&, edm::EventSetup const&) override { p = false; }
0430 
0431       bool filter(edm::Event&, edm::EventSetup const&) override {
0432         ++m_count;
0433         p = true;
0434         return true;
0435       }
0436 
0437       void beginRunProduce(edm::Run&, edm::EventSetup const&) override {
0438         if (p) {
0439           throw cms::Exception("out of sequence") << "produce before beginRunProduce";
0440         }
0441         ++m_count;
0442       }
0443 
0444       void endRun(edm::Run const&, edm::EventSetup const&) override {}
0445 
0446       ~BeginRunFilter() {
0447         if (m_count != trans_) {
0448           throw cms::Exception("transitions")
0449               << "BeginRunFilter transitions " << m_count << " but it was supposed to be " << trans_;
0450         }
0451       }
0452     };
0453 
0454     class BeginLumiBlockFilter
0455         : public edm::one::EDFilter<edm::one::WatchLuminosityBlocks, edm::BeginLuminosityBlockProducer> {
0456     public:
0457       explicit BeginLumiBlockFilter(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {
0458         produces<unsigned int, edm::Transition::BeginLuminosityBlock>("a");
0459       }
0460       const unsigned int trans_;
0461       unsigned int m_count = 0;
0462       bool p = false;
0463 
0464       void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override { p = false; }
0465 
0466       bool filter(edm::Event&, edm::EventSetup const&) override {
0467         ++m_count;
0468         p = true;
0469         return true;
0470       }
0471 
0472       void beginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) override {
0473         ++m_count;
0474         if (p) {
0475           throw cms::Exception("out of sequence") << "produce before beginLuminosityBlockProduce";
0476         }
0477       }
0478 
0479       void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {}
0480 
0481       ~BeginLumiBlockFilter() {
0482         if (m_count != trans_) {
0483           throw cms::Exception("transitions")
0484               << "BeginLumiBlockFilter transitions " << m_count << " but it was supposed to be " << trans_;
0485         }
0486       }
0487     };
0488 
0489     class EndRunFilter : public edm::one::EDFilter<edm::one::WatchRuns, edm::EndRunProducer> {
0490     public:
0491       explicit EndRunFilter(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {
0492         produces<unsigned int, edm::Transition::EndRun>("a");
0493       }
0494       const unsigned int trans_;
0495       bool erp = false;
0496       unsigned int m_count = 0;
0497 
0498       void beginRun(edm::Run const&, edm::EventSetup const&) override { erp = false; }
0499 
0500       bool filter(edm::Event&, edm::EventSetup const&) override {
0501         ++m_count;
0502         if (erp) {
0503           throw cms::Exception("out of sequence") << "endRunProduce before produce";
0504         }
0505         return true;
0506       }
0507 
0508       void endRunProduce(edm::Run&, edm::EventSetup const&) override { ++m_count; }
0509 
0510       void endRun(edm::Run const&, edm::EventSetup const&) override {}
0511 
0512       ~EndRunFilter() {
0513         if (m_count != trans_) {
0514           throw cms::Exception("transitions")
0515               << "EndRunFilter transitions " << m_count << " but it was supposed to be " << trans_;
0516         }
0517       }
0518     };
0519 
0520     class EndLumiBlockFilter
0521         : public edm::one::EDFilter<edm::one::WatchLuminosityBlocks, edm::EndLuminosityBlockProducer> {
0522     public:
0523       explicit EndLumiBlockFilter(edm::ParameterSet const& p) : trans_(p.getParameter<int>("transitions")) {
0524         produces<unsigned int, edm::Transition::EndLuminosityBlock>("a");
0525       }
0526       const unsigned int trans_;
0527       bool elbp = false;
0528       unsigned int m_count = 0;
0529 
0530       void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override { elbp = false; }
0531 
0532       bool filter(edm::Event&, edm::EventSetup const&) override {
0533         ++m_count;
0534         if (elbp) {
0535           throw cms::Exception("out of sequence") << "endLumiBlockProduce before produce";
0536         }
0537         return true;
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       ~EndLumiBlockFilter() {
0548         if (m_count != trans_) {
0549           throw cms::Exception("transitions")
0550               << "EndLumiBlockFilter transitions " << m_count << " but it was supposed to be " << trans_;
0551         }
0552       }
0553     };
0554 
0555     class TestInputProcessBlockCache {
0556     public:
0557       long long int value_ = 0;
0558     };
0559 
0560     class TestInputProcessBlockCache1 {
0561     public:
0562       long long int value_ = 0;
0563     };
0564 
0565     class InputProcessBlockIntFilter
0566         : public edm::one::EDFilter<
0567               edm::InputProcessBlockCache<int, TestInputProcessBlockCache, TestInputProcessBlockCache1>> {
0568     public:
0569       explicit InputProcessBlockIntFilter(edm::ParameterSet const& pset) {
0570         expectedTransitions_ = pset.getParameter<int>("transitions");
0571         expectedByRun_ = pset.getParameter<std::vector<int>>("expectedByRun");
0572         expectedSum_ = pset.getParameter<int>("expectedSum");
0573         {
0574           auto tag = pset.getParameter<edm::InputTag>("consumesBeginProcessBlock");
0575           if (not tag.label().empty()) {
0576             getTokenBegin_ = consumes<IntProduct, edm::InProcess>(tag);
0577           }
0578         }
0579         {
0580           auto tag = pset.getParameter<edm::InputTag>("consumesEndProcessBlock");
0581           if (not tag.label().empty()) {
0582             getTokenEnd_ = consumes<IntProduct, edm::InProcess>(tag);
0583           }
0584         }
0585         {
0586           auto tag = pset.getParameter<edm::InputTag>("consumesBeginProcessBlockM");
0587           if (not tag.label().empty()) {
0588             getTokenBeginM_ = consumes<IntProduct, edm::InProcess>(tag);
0589           }
0590         }
0591         {
0592           auto tag = pset.getParameter<edm::InputTag>("consumesEndProcessBlockM");
0593           if (not tag.label().empty()) {
0594             getTokenEndM_ = consumes<IntProduct, edm::InProcess>(tag);
0595           }
0596         }
0597         registerProcessBlockCacheFiller<int>(
0598             getTokenBegin_, [this](edm::ProcessBlock const& processBlock, std::shared_ptr<int> const& previousCache) {
0599               auto returnValue = std::make_shared<int>(0);
0600               *returnValue += processBlock.get(getTokenBegin_).value;
0601               *returnValue += processBlock.get(getTokenEnd_).value;
0602               ++transitions_;
0603               return returnValue;
0604             });
0605         registerProcessBlockCacheFiller<1>(getTokenBegin_,
0606                                            [this](edm::ProcessBlock const& processBlock,
0607                                                   std::shared_ptr<TestInputProcessBlockCache> const& previousCache) {
0608                                              auto returnValue = std::make_shared<TestInputProcessBlockCache>();
0609                                              returnValue->value_ += processBlock.get(getTokenBegin_).value;
0610                                              returnValue->value_ += processBlock.get(getTokenEnd_).value;
0611                                              ++transitions_;
0612                                              return returnValue;
0613                                            });
0614         registerProcessBlockCacheFiller<TestInputProcessBlockCache1>(
0615             getTokenBegin_,
0616             [this](edm::ProcessBlock const& processBlock,
0617                    std::shared_ptr<TestInputProcessBlockCache1> const& previousCache) {
0618               auto returnValue = std::make_shared<TestInputProcessBlockCache1>();
0619               returnValue->value_ += processBlock.get(getTokenBegin_).value;
0620               returnValue->value_ += processBlock.get(getTokenEnd_).value;
0621               ++transitions_;
0622               return returnValue;
0623             });
0624       }
0625 
0626       void accessInputProcessBlock(edm::ProcessBlock const& processBlock) override {
0627         if (processBlock.processName() == "PROD1") {
0628           sum_ += processBlock.get(getTokenBegin_).value;
0629           sum_ += processBlock.get(getTokenEnd_).value;
0630         }
0631         if (processBlock.processName() == "MERGE") {
0632           sum_ += processBlock.get(getTokenBeginM_).value;
0633           sum_ += processBlock.get(getTokenEndM_).value;
0634         }
0635         ++transitions_;
0636       }
0637 
0638       bool filter(edm::Event& event, edm::EventSetup const&) override {
0639         auto cacheTuple = processBlockCaches(event);
0640         if (!expectedByRun_.empty()) {
0641           if (expectedByRun_.at(event.run() - 1) != *std::get<edm::CacheHandle<int>>(cacheTuple)) {
0642             throw cms::Exception("UnexpectedValue")
0643                 << "InputProcessBlockIntFilter::filter cached value was "
0644                 << *std::get<edm::CacheHandle<int>>(cacheTuple) << " but it was supposed to be "
0645                 << expectedByRun_.at(event.run() - 1);
0646           }
0647           if (expectedByRun_.at(event.run() - 1) != std::get<1>(cacheTuple)->value_) {
0648             throw cms::Exception("UnexpectedValue")
0649                 << "InputProcessBlockIntFilter::filter second cached value was " << std::get<1>(cacheTuple)->value_
0650                 << " but it was supposed to be " << expectedByRun_.at(event.run() - 1);
0651           }
0652           if (expectedByRun_.at(event.run() - 1) !=
0653               std::get<edm::CacheHandle<TestInputProcessBlockCache1>>(cacheTuple)->value_) {
0654             throw cms::Exception("UnexpectedValue")
0655                 << "InputProcessBlockIntFilter::filter third cached value was "
0656                 << std::get<edm::CacheHandle<TestInputProcessBlockCache1>>(cacheTuple)->value_
0657                 << " but it was supposed to be " << expectedByRun_.at(event.run() - 1);
0658           }
0659         }
0660         ++transitions_;
0661         return true;
0662       }
0663 
0664       void endJob() override {
0665         if (transitions_ != expectedTransitions_) {
0666           throw cms::Exception("transitions") << "InputProcessBlockIntFilter transitions " << transitions_
0667                                               << " but it was supposed to be " << expectedTransitions_;
0668         }
0669         if (sum_ != expectedSum_) {
0670           throw cms::Exception("UnexpectedValue")
0671               << "InputProcessBlockIntFilter sum " << sum_ << " but it was supposed to be " << expectedSum_;
0672         }
0673         if (cacheSize() > 0u) {
0674           throw cms::Exception("UnexpectedValue")
0675               << "InputProcessBlockIntFilter cache size not zero at endJob " << cacheSize();
0676         }
0677       }
0678 
0679     private:
0680       edm::EDGetTokenT<IntProduct> getTokenBegin_;
0681       edm::EDGetTokenT<IntProduct> getTokenEnd_;
0682       edm::EDGetTokenT<IntProduct> getTokenBeginM_;
0683       edm::EDGetTokenT<IntProduct> getTokenEndM_;
0684       mutable std::atomic<unsigned int> transitions_{0};
0685       int sum_{0};
0686       unsigned int expectedTransitions_{0};
0687       std::vector<int> expectedByRun_;
0688       int expectedSum_{0};
0689     };
0690 
0691   }  // namespace one
0692 }  // namespace edmtest
0693 
0694 DEFINE_FWK_MODULE(edmtest::one::SharedResourcesFilter);
0695 DEFINE_FWK_MODULE(edmtest::one::WatchRunsFilter);
0696 DEFINE_FWK_MODULE(edmtest::one::WatchLumiBlocksFilter);
0697 DEFINE_FWK_MODULE(edmtest::one::RunCacheFilter);
0698 DEFINE_FWK_MODULE(edmtest::one::LumiBlockCacheFilter);
0699 DEFINE_FWK_MODULE(edmtest::one::ProcessBlockIntFilter);
0700 DEFINE_FWK_MODULE(edmtest::one::TestBeginProcessBlockFilter);
0701 DEFINE_FWK_MODULE(edmtest::one::TestEndProcessBlockFilter);
0702 DEFINE_FWK_MODULE(edmtest::one::BeginRunFilter);
0703 DEFINE_FWK_MODULE(edmtest::one::BeginLumiBlockFilter);
0704 DEFINE_FWK_MODULE(edmtest::one::EndRunFilter);
0705 DEFINE_FWK_MODULE(edmtest::one::EndLumiBlockFilter);
0706 DEFINE_FWK_MODULE(edmtest::one::InputProcessBlockIntFilter);