CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/HLTrigger/btau/src/HLTCollectionProducer.h

Go to the documentation of this file.
00001 #ifndef HLTCollectionProducer_h
00002 #define HLTCollectionProducer_h
00003 
00004 //
00005 // Package:    HLTCollectionProducer
00006 // Class:      HLTCollectionProducer
00007 // 
00014 //
00015 // Original Author:  Ian Tomalin
00016 //
00017 
00018 // user include files
00019 #include "FWCore/Framework/interface/EDProducer.h"
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00023 #include "FWCore/Utilities/interface/InputTag.h"
00024 #include "DataFormats/Common/interface/RefVector.h"
00025 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00026 
00027 #include <typeinfo>
00028 #include <string>
00029 #include <vector>
00030 
00031 //
00032 // class declaration
00033 //
00034 
00035 template <typename T> 
00036 class HLTCollectionProducer : public edm::EDProducer {
00037 
00038   public:
00039     explicit HLTCollectionProducer(const edm::ParameterSet&);
00040     virtual ~HLTCollectionProducer();
00041     static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
00042     virtual void produce(edm::Event&, const edm::EventSetup&);
00043   
00044   private:
00045     edm::InputTag    hltObject_;
00046     std::vector<int> triggerTypes_;
00047 };
00048 
00049 
00050 //
00051 // constructors and destructor
00052 //
00053 template <typename T>
00054 HLTCollectionProducer<T>::HLTCollectionProducer(const edm::ParameterSet& iConfig) :
00055   hltObject_    ( iConfig.getParameter<edm::InputTag>("HLTObject") ),
00056   triggerTypes_ ( iConfig.getParameter<std::vector<int> >("TriggerTypes") )
00057 {
00058   produces< std::vector<T> >();
00059 }
00060 
00061 template <typename T>
00062 HLTCollectionProducer<T>::~HLTCollectionProducer() {}
00063 
00064 template<typename T>
00065 void 
00066 HLTCollectionProducer<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00067   edm::ParameterSetDescription desc;
00068   desc.add<edm::InputTag> ("HLTObject", edm::InputTag("TriggerFilterObjectWithRefs"));
00069   std::vector<int> triggerTypes;
00070   desc.add<std::vector<int> > ("TriggerTypes",triggerTypes);
00071   descriptions.add(std::string("hlt")+std::string(typeid(HLTCollectionProducer<T>).name()), desc);
00072 }
00073 
00074 //
00075 // member functions
00076 //
00077 
00078 // ------------ method called to produce the data  ------------
00079 template <typename T>
00080 void
00081 HLTCollectionProducer<T>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00082 {
00083 
00084   std::auto_ptr<std::vector<T> > collection ( new std::vector<T>() );
00085 
00086   // get hold of collection of TriggerFilterObjectsWithRefs
00087   edm::Handle<trigger::TriggerFilterObjectWithRefs> hltObject;
00088   iEvent.getByLabel(hltObject_, hltObject);
00089   std::vector<edm::Ref<std::vector<T> > > objectRefs;
00090 
00091   for (size_t t=0; t<triggerTypes_.size(); ++t) {
00092     objectRefs.clear();
00093     hltObject->getObjects( triggerTypes_[t], objectRefs );
00094     for (size_t i = 0; i < objectRefs.size(); ++i) {
00095       collection->push_back(*objectRefs[i]);
00096     }
00097   }
00098   
00099   iEvent.put(collection);
00100 
00101 }
00102 
00103 #endif // HLTCollectionProducer_h