Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18: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 
0043   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0044 
0045 private:
0046   void produce(edm::Event&, const edm::EventSetup&) override;
0047 
0048   // ----------member data ---------------------------
0049   bool doRefs_;
0050   edm::InputTag src_;
0051   edm::EDGetTokenT<l1t::JetBxCollection> token_;
0052 };
0053 
0054 //
0055 // constants, enums and typedefs
0056 //
0057 
0058 //
0059 // static data member definitions
0060 //
0061 
0062 //
0063 // constructors and destructor
0064 //
0065 TestBXVectorRefProducer::TestBXVectorRefProducer(const edm::ParameterSet& iConfig) {
0066   //now do what ever other initialization is needed
0067   src_ = iConfig.getParameter<edm::InputTag>("src");
0068   doRefs_ = iConfig.getParameter<bool>("doRefs");
0069   token_ = consumes<l1t::JetBxCollection>(src_);
0070 
0071   //register your products
0072   produces<vector<int>>("jetPt").setBranchAlias("jetPt");
0073 
0074   if (doRefs_) {
0075     produces<l1t::JetRefVector>("l1tJetRef").setBranchAlias("l1tJetRef");
0076   }
0077 }
0078 
0079 //
0080 // member functions
0081 //
0082 
0083 // ------------ method called to produce the data  ------------
0084 void TestBXVectorRefProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0085   using namespace edm;
0086 
0087   unique_ptr<vector<int>> jetMom(new vector<int>);
0088   unique_ptr<l1t::JetRefVector> jetRef(new l1t::JetRefVector);
0089 
0090   // retrieve the tracks
0091   Handle<l1t::JetBxCollection> jets;
0092   iEvent.getByToken(token_, jets);
0093   if (!jets.isValid())
0094     return;
0095 
0096   const int size = jets->size();
0097   jetMom->reserve(size);
0098 
0099   l1t::JetBxCollection::const_iterator iter;
0100 
0101   for (iter = jets->begin(0); iter != jets->end(0); ++iter) {
0102     jetMom->push_back(iter->pt());
0103 
0104     l1t::JetRef myref(jets, jets->key(iter));
0105     jetRef->push_back(myref);
0106 
0107   }  // end for
0108 
0109   iEvent.put(std::move(jetMom), "jetPt");
0110 
0111   if (doRefs_)
0112     iEvent.put(std::move(jetRef), "l1tJetRef");
0113 
0114   return;
0115 }
0116 
0117 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0118 void TestBXVectorRefProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0119   //The following says we do not know what parameters are allowed so do no validation
0120   // Please change this to state exactly what you do use, even if it is no parameters
0121   edm::ParameterSetDescription desc;
0122   desc.setUnknown();
0123   descriptions.addDefault(desc);
0124 }
0125 
0126 // declare this class as a framework plugin
0127 DEFINE_FWK_MODULE(TestBXVectorRefProducer);