Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:30

0001 // -*- C++ -*-
0002 //
0003 // Package:    FWCore/Integration
0004 // Class:      ProducerUsingCollector
0005 //
0006 /**\class edmtest::ProducerUsingCollector
0007 
0008   Description: Used in tests of the ProducesCollector. It uses all
0009 the different functions in ProducesCollector for no reason other
0010 than to test them all.
0011 */
0012 // Original Author:  W. David Dagenhart
0013 //         Created:  26 September 2019
0014 
0015 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0016 #include "FWCore/Framework/interface/global/EDProducer.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/ProducesCollector.h"
0021 #include "FWCore/Framework/interface/Run.h"
0022 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0025 #include "FWCore/Utilities/interface/EDPutToken.h"
0026 #include "FWCore/Utilities/interface/Transition.h"
0027 #include "FWCore/Utilities/interface/TypeID.h"
0028 
0029 namespace edmtest {
0030 
0031   class ProducerHelperUsingCollector {
0032   public:
0033     ProducerHelperUsingCollector(edm::ProducesCollector&&);
0034     void putEventProducts(edm::Event&) const;
0035     void putBeginRunProducts(edm::Run&) const;
0036     void putEndRunProducts(edm::Run&) const;
0037     void putBeginLumiProducts(edm::LuminosityBlock&) const;
0038     void putEndLumiProducts(edm::LuminosityBlock&) const;
0039 
0040   private:
0041     edm::EDPutTokenT<IntProduct> eventToken_;
0042     edm::EDPutTokenT<IntProduct> eventWithInstanceToken_;
0043     edm::EDPutTokenT<UInt64Product> eventWithTransitionToken_;
0044     edm::EDPutToken eventUsingTypeIDToken_;
0045     edm::EDPutTokenT<IntProduct> brToken_;
0046     edm::EDPutTokenT<IntProduct> erToken_;
0047     edm::EDPutToken blToken_;
0048     edm::EDPutToken elToken_;
0049   };
0050 
0051   ProducerHelperUsingCollector::ProducerHelperUsingCollector(edm::ProducesCollector&& producesCollector)
0052       : eventToken_(producesCollector.produces<IntProduct>()),
0053         eventWithInstanceToken_(producesCollector.produces<IntProduct>("event")),
0054         eventWithTransitionToken_(producesCollector.produces<UInt64Product, edm::Transition::Event>()),
0055         eventUsingTypeIDToken_(producesCollector.produces(edm::TypeID(typeid(IntProduct)), "eventOther")),
0056         brToken_(producesCollector.produces<IntProduct, edm::Transition::BeginRun>("beginRun")),
0057         blToken_(producesCollector.produces<edm::Transition::BeginLuminosityBlock>(edm::TypeID(typeid(IntProduct)),
0058                                                                                    "beginLumi")) {
0059     edm::ProducesCollector copy(producesCollector);
0060     erToken_ = copy.produces<IntProduct, edm::Transition::EndRun>("endRun");
0061 
0062     copy = producesCollector;
0063     edm::ProducesCollector copy2(producesCollector);
0064     copy2 = std::move(copy);
0065     elToken_ = copy.produces<edm::Transition::EndLuminosityBlock>(edm::TypeID(typeid(IntProduct)), "endLumi");
0066   }
0067 
0068   void ProducerHelperUsingCollector::putEventProducts(edm::Event& event) const {
0069     event.emplace(eventToken_, 1);
0070     event.emplace(eventWithInstanceToken_, 2);
0071     event.emplace(eventWithTransitionToken_, 3);
0072     event.put(eventUsingTypeIDToken_, std::make_unique<IntProduct>(4));
0073   }
0074 
0075   void ProducerHelperUsingCollector::putBeginRunProducts(edm::Run& run) const { run.emplace(brToken_, 5); }
0076 
0077   void ProducerHelperUsingCollector::putEndRunProducts(edm::Run& run) const { run.emplace(erToken_, 6); }
0078 
0079   void ProducerHelperUsingCollector::putBeginLumiProducts(edm::LuminosityBlock& luminosityBlock) const {
0080     luminosityBlock.put(blToken_, std::make_unique<IntProduct>(7));
0081   }
0082 
0083   void ProducerHelperUsingCollector::putEndLumiProducts(edm::LuminosityBlock& luminosityBlock) const {
0084     luminosityBlock.put(elToken_, std::make_unique<IntProduct>(8));
0085   }
0086 
0087   class ProducerUsingCollector : public edm::global::EDProducer<edm::BeginRunProducer,
0088                                                                 edm::EndRunProducer,
0089                                                                 edm::EndLuminosityBlockProducer,
0090                                                                 edm::BeginLuminosityBlockProducer> {
0091   public:
0092     explicit ProducerUsingCollector(edm::ParameterSet const&);
0093 
0094     ~ProducerUsingCollector() override;
0095 
0096     void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0097 
0098     void globalBeginRunProduce(edm::Run&, edm::EventSetup const&) const override;
0099 
0100     void globalEndRunProduce(edm::Run&, edm::EventSetup const&) const override;
0101 
0102     void globalBeginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const override;
0103 
0104     void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const override;
0105 
0106     static void fillDescriptions(edm::ConfigurationDescriptions&);
0107 
0108   private:
0109     ProducerHelperUsingCollector helper_;
0110   };
0111 
0112   ProducerUsingCollector::ProducerUsingCollector(edm::ParameterSet const&) : helper_(producesCollector()) {}
0113 
0114   ProducerUsingCollector::~ProducerUsingCollector() {}
0115 
0116   void ProducerUsingCollector::produce(edm::StreamID, edm::Event& event, edm::EventSetup const&) const {
0117     helper_.putEventProducts(event);
0118   }
0119 
0120   void ProducerUsingCollector::globalBeginLuminosityBlockProduce(edm::LuminosityBlock& lb,
0121                                                                  edm::EventSetup const&) const {
0122     helper_.putBeginLumiProducts(lb);
0123   }
0124 
0125   void ProducerUsingCollector::globalEndLuminosityBlockProduce(edm::LuminosityBlock& lb, edm::EventSetup const&) const {
0126     helper_.putEndLumiProducts(lb);
0127   }
0128 
0129   void ProducerUsingCollector::globalBeginRunProduce(edm::Run& run, edm::EventSetup const&) const {
0130     helper_.putBeginRunProducts(run);
0131   }
0132 
0133   void ProducerUsingCollector::globalEndRunProduce(edm::Run& run, edm::EventSetup const&) const {
0134     helper_.putEndRunProducts(run);
0135   }
0136 
0137   void ProducerUsingCollector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0138     edm::ParameterSetDescription desc;
0139     descriptions.addDefault(desc);
0140   }
0141 
0142 }  // namespace edmtest
0143 using edmtest::ProducerUsingCollector;
0144 DEFINE_FWK_MODULE(ProducerUsingCollector);