CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastedRefProducer.h
Go to the documentation of this file.
1 #ifndef RecoTauTag_TauTagTools_CastedRefProducer_h
2 #define RecoTauTag_TauTagTools_CastedRefProducer_h
3 
4 /*
5  * Taking a View<BaseType> as input, create a output collection of Refs to the
6  * original collection with the desired type.
7  *
8  * Author: Evan K. Friis (UC Davis)
9  *
10  * Based on CommonTools/CandAlgos/interface/ShallowClone.h
11  *
12  */
13 
21 
22 namespace reco { namespace tautools {
23 
24 template<typename DerivedCollection, typename BaseType>
26  public:
32  explicit CastedRefProducer( const edm::ParameterSet& pset)
33  :src_(pset.template getParameter<edm::InputTag>("src")) {
34  produces<OutputCollection>();
35  }
39  virtual void produce(edm::Event& evt, const edm::EventSetup& es) {
40  // Output collection
41  std::auto_ptr<OutputCollection> coll(new OutputCollection());
42  // Get input
44  evt.getByLabel(src_, input);
45  // Get references to the base
46  for(size_t i = 0; i < input->size(); ++i) {
47  // Cast the base class to the derived class
48  base_ref base = input->refAt(i);
49  derived_ref derived = base.template castTo<derived_ref>();
50  coll->push_back(derived);
51  }
52  evt.put( coll );
53  }
54  private:
57 };
58 
59 }}
60 
61 #endif
tuple base
Main Program
Definition: newFWLiteAna.py:92
edm::Ref< DerivedCollection > derived_ref
int i
Definition: DBlmapReader.cc:9
edm::RefToBaseVector< BaseType > base_ref_vector
static std::string const input
Definition: EdmProvDump.cc:43
edm::RefVector< DerivedCollection > OutputCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
process an event
base_ref_vector::value_type base_ref
JetCorrectorParametersCollection coll
Definition: classes.h:10
edm::InputTag src_
labels of the collection to be converted
CastedRefProducer(const edm::ParameterSet &pset)
constructor from parameter set
def template
Definition: svgfig.py:520