Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:16

0001 // -*- C++ -*-
0002 //
0003 // Package:     test
0004 // Class  :     DeleteEarlyModules
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Tue Feb  7 15:36:37 CST 2012
0011 //
0012 
0013 // system include files
0014 #include <vector>
0015 #include <memory>
0016 
0017 // user include files
0018 #include "DataFormats/TestObjects/interface/DeleteEarly.h"
0019 #include "DataFormats/Common/interface/RefProd.h"
0020 #include "FWCore/Framework/interface/global/EDProducer.h"
0021 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0022 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0023 #include "FWCore/Utilities/interface/InputTag.h"
0024 #include "FWCore/Utilities/interface/Exception.h"
0025 #include "FWCore/Framework/interface/MakerMacros.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 #include "FWCore/Framework/interface/Event.h"
0028 
0029 namespace edmtest {
0030   class DeleteEarlyProducer : public edm::global::EDProducer<> {
0031   public:
0032     explicit DeleteEarlyProducer(edm::ParameterSet const& pset) { produces<DeleteEarly>(); }
0033 
0034     void beginJob() override {
0035       // Needed because DeleteEarly objects may be allocated and deleted in initialization
0036       edmtest::DeleteEarly::resetDeleteCount();
0037     }
0038 
0039     void produce(edm::StreamID, edm::Event& e, edm::EventSetup const&) const override {
0040       e.put(std::make_unique<DeleteEarly>());
0041     }
0042   };
0043 
0044   class DeleteEarlyRefProdProducer : public edm::global::EDProducer<> {
0045   public:
0046     explicit DeleteEarlyRefProdProducer(edm::ParameterSet const& pset)
0047         : m_token{consumes(pset.getParameter<edm::InputTag>("get"))} {
0048       m_put = produces<edm::RefProd<DeleteEarly>>();
0049     }
0050 
0051     void produce(edm::StreamID, edm::Event& e, edm::EventSetup const&) const override {
0052       auto h = e.getHandle(m_token);
0053       e.emplace(m_put, h);
0054     }
0055 
0056   private:
0057     const edm::EDGetTokenT<DeleteEarly> m_token;
0058     edm::EDPutTokenT<edm::RefProd<DeleteEarly>> m_put;
0059   };
0060 
0061   class DeleteEarlyReader : public edm::global::EDAnalyzer<> {
0062   public:
0063     DeleteEarlyReader(edm::ParameterSet const& pset)
0064         : getToken_(consumes(pset.getUntrackedParameter<edm::InputTag>("tag"))) {}
0065 
0066     void analyze(edm::StreamID, edm::Event const& e, edm::EventSetup const&) const override { e.get(getToken_); }
0067 
0068   private:
0069     edm::EDGetTokenT<DeleteEarly> getToken_;
0070   };
0071 
0072   class DeleteEarlyConsumer : public edm::global::EDAnalyzer<> {
0073   public:
0074     DeleteEarlyConsumer(edm::ParameterSet const& pset) {
0075       consumes<DeleteEarly>(pset.getUntrackedParameter<edm::InputTag>("tag"));
0076     }
0077 
0078     void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override {}
0079 
0080   private:
0081   };
0082 
0083   class DeleteEarlyRefProdReader : public edm::global::EDAnalyzer<> {
0084   public:
0085     DeleteEarlyRefProdReader(edm::ParameterSet const& pset)
0086         : getToken_(consumes(pset.getUntrackedParameter<edm::InputTag>("tag"))) {}
0087 
0088     void analyze(edm::StreamID, edm::Event const& e, edm::EventSetup const&) const override { e.get(getToken_).get(); }
0089 
0090   private:
0091     edm::EDGetTokenT<edm::RefProd<DeleteEarly>> getToken_;
0092   };
0093 
0094   class DeleteEarlyCheckDeleteAnalyzer : public edm::one::EDAnalyzer<> {
0095   public:
0096     DeleteEarlyCheckDeleteAnalyzer(edm::ParameterSet const& pset)
0097         : m_expectedValues(pset.getUntrackedParameter<std::vector<unsigned int>>("expectedValues")), m_index(0) {}
0098 
0099     void analyze(edm::Event const&, edm::EventSetup const&) override {
0100       if (DeleteEarly::nDeletes() != m_expectedValues.at(m_index)) {
0101         throw cms::Exception("DeleteEarlyError")
0102             << "On index " << m_index << " we expected " << m_expectedValues[m_index] << " deletes but we see "
0103             << DeleteEarly::nDeletes();
0104       }
0105       ++m_index;
0106     }
0107 
0108   private:
0109     std::vector<unsigned int> m_expectedValues;
0110     unsigned int m_index;
0111   };
0112 }  // namespace edmtest
0113 using namespace edmtest;
0114 DEFINE_FWK_MODULE(DeleteEarlyProducer);
0115 DEFINE_FWK_MODULE(DeleteEarlyRefProdProducer);
0116 DEFINE_FWK_MODULE(DeleteEarlyReader);
0117 DEFINE_FWK_MODULE(DeleteEarlyRefProdReader);
0118 DEFINE_FWK_MODULE(DeleteEarlyConsumer);
0119 DEFINE_FWK_MODULE(DeleteEarlyCheckDeleteAnalyzer);