CMS 3D CMS Logo

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:
33  :src_(pset.template getParameter<edm::InputTag>("src")) {
34  produces<OutputCollection>();
35  }
37  ~CastedRefProducer() override{};
39  void produce(edm::Event& evt, const edm::EventSetup& es) override {
40  // Output collection
41  auto coll = std::make_unique<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(std::move(coll));
53  }
54  private:
57 };
58 
59 }}
60 
61 #endif
edm::Ref< DerivedCollection > derived_ref
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
~CastedRefProducer() override
destructor
void push_back(key_type i, value_type const &j, label_type const &flav="")
edm::RefToBaseVector< BaseType > base_ref_vector
static std::string const input
Definition: EdmProvDump.cc:44
edm::RefVector< DerivedCollection > OutputCollection
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:520
base
Make Sure CMSSW is Setup ##.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:464
base_ref_vector::value_type base_ref
JetCorrectorParametersCollection coll
Definition: classes.h:10
fixed size matrix
HLT enums.
void produce(edm::Event &evt, const edm::EventSetup &es) override
process an event
edm::InputTag src_
labels of the collection to be converted
CastedRefProducer(const edm::ParameterSet &pset)
constructor from parameter set
def move(src, dest)
Definition: eostools.py:510