Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:09:29

0001 // -*- C++ -*-
0002 //
0003 // Package:    HLTrigger/TestBXVectorRefProducer
0004 // Class:      TestBXVectorRefProducer
0005 //
0006 /**\class TestBXVectorRefProducer TestBXVectorRefProducer.cc HLTrigger/TestBXVectorRefProducer/plugins/TestBXVectorRefProducer.cc
0007 
0008  Description: Simple testing producer to test storing of Ref<BXVector>  (example of <l1t::JetRef>) in the Event.
0009 
0010  Implementation:
0011      Pick up the BXVector<l1t::Jet> from the event and try to store the Refs back into the Event.
0012 */
0013 //
0014 // Original Author:  Vladimir Rekovic
0015 //         Created:  Fri, 12 Feb 2016 09:56:04 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/stream/EDProducer.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/Utilities/interface/StreamID.h"
0031 
0032 //#include "DataFormats/L1Trigger/interface/BXVector.h"
0033 #include "DataFormats/L1Trigger/interface/Jet.h"
0034 
0035 //
0036 // class declaration
0037 //
0038 
0039 class TestBXVectorRefProducer : public edm::stream::EDProducer<> {
0040 public:
0041   explicit TestBXVectorRefProducer(const edm::ParameterSet&);
0042   ~TestBXVectorRefProducer() override;
0043 
0044   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045 
0046 private:
0047   void beginStream(edm::StreamID) override;
0048   void produce(edm::Event&, const edm::EventSetup&) override;
0049   void endStream() override;
0050 
0051   //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
0052   //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
0053   //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0054   //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0055 
0056   // ----------member data ---------------------------
0057   bool doRefs_;
0058   edm::InputTag src_;
0059   edm::EDGetTokenT<l1t::JetBxCollection> token_;
0060 };
0061 
0062 //
0063 // constants, enums and typedefs
0064 //
0065 
0066 //
0067 // static data member definitions
0068 //
0069 
0070 //
0071 // constructors and destructor
0072 //
0073 TestBXVectorRefProducer::TestBXVectorRefProducer(const edm::ParameterSet& iConfig) {
0074   //now do what ever other initialization is needed
0075   src_ = iConfig.getParameter<edm::InputTag>("src");
0076   doRefs_ = iConfig.getParameter<bool>("doRefs");
0077   token_ = consumes<l1t::JetBxCollection>(src_);
0078 
0079   //register your products
0080   produces<vector<int>>("jetPt").setBranchAlias("jetPt");
0081 
0082   if (doRefs_) {
0083     produces<l1t::JetRefVector>("l1tJetRef").setBranchAlias("l1tJetRef");
0084   }
0085 }
0086 
0087 TestBXVectorRefProducer::~TestBXVectorRefProducer() {
0088   // do anything here that needs to be done at destruction time
0089   // (e.g. close files, deallocate resources etc.)
0090 }
0091 
0092 //
0093 // member functions
0094 //
0095 
0096 // ------------ method called to produce the data  ------------
0097 void TestBXVectorRefProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0098   using namespace edm;
0099 
0100   unique_ptr<vector<int>> jetMom(new vector<int>);
0101   unique_ptr<l1t::JetRefVector> jetRef(new l1t::JetRefVector);
0102 
0103   // retrieve the tracks
0104   Handle<l1t::JetBxCollection> jets;
0105   iEvent.getByToken(token_, jets);
0106   if (!jets.isValid())
0107     return;
0108 
0109   const int size = jets->size();
0110   jetMom->reserve(size);
0111 
0112   l1t::JetBxCollection::const_iterator iter;
0113 
0114   for (iter = jets->begin(0); iter != jets->end(0); ++iter) {
0115     jetMom->push_back(iter->pt());
0116 
0117     l1t::JetRef myref(jets, jets->key(iter));
0118     jetRef->push_back(myref);
0119 
0120   }  // end for
0121 
0122   iEvent.put(std::move(jetMom), "jetPt");
0123 
0124   if (doRefs_)
0125     iEvent.put(std::move(jetRef), "l1tJetRef");
0126 
0127   return;
0128 }
0129 
0130 // ------------ method called once each stream before processing any runs, lumis or events  ------------
0131 void TestBXVectorRefProducer::beginStream(edm::StreamID) {}
0132 
0133 // ------------ method called once each stream after processing all runs, lumis and events  ------------
0134 void TestBXVectorRefProducer::endStream() {}
0135 
0136 // ------------ method called when starting to processes a run  ------------
0137 /*
0138 void
0139 TestBXVectorRefProducer::beginRun(edm::Run const&, edm::EventSetup const&)
0140 {
0141 }
0142 */
0143 
0144 // ------------ method called when ending the processing of a run  ------------
0145 /*
0146 void
0147 TestBXVectorRefProducer::endRun(edm::Run const&, edm::EventSetup const&)
0148 {
0149 }
0150 */
0151 
0152 // ------------ method called when starting to processes a luminosity block  ------------
0153 /*
0154 void
0155 TestBXVectorRefProducer::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0156 {
0157 }
0158 */
0159 
0160 // ------------ method called when ending the processing of a luminosity block  ------------
0161 /*
0162 void
0163 TestBXVectorRefProducer::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0164 {
0165 }
0166 */
0167 
0168 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0169 void TestBXVectorRefProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0170   //The following says we do not know what parameters are allowed so do no validation
0171   // Please change this to state exactly what you do use, even if it is no parameters
0172   edm::ParameterSetDescription desc;
0173   desc.setUnknown();
0174   descriptions.addDefault(desc);
0175 }
0176 
0177 // declare this class as a framework plugin
0178 DEFINE_FWK_MODULE(TestBXVectorRefProducer);