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  const base_ref_vector &baseRefs = input->refVector();
47  for(size_t i = 0; i < baseRefs.size(); ++i) {
48  // Cast the base class to the derived class
49  base_ref base = baseRefs.at(i);
50  derived_ref derived = base.template castTo<derived_ref>();
51  coll->push_back(derived);
52  }
53  evt.put( coll );
54  }
55  private:
58 };
59 
60 }}
61 
62 #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
value_type at(size_type idx) const
static std::string const input
Definition: EdmProvDump.cc:44
edm::RefVector< DerivedCollection > OutputCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
size_type size() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
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