CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CandidateProducer.h
Go to the documentation of this file.
1 #ifndef RecoAlgos_CandidateProducer_h
2 #define RecoAlgos_CandidateProducer_h
3 
24 
25 namespace converter {
26  namespace helper {
27  template<typename T>
28  struct CandConverter { };
29 
30  struct ConcreteCreator {
31  template<typename CColl, typename Comp, typename Conv>
32  static void create(size_t idx, CColl & cands, const Comp & components, Conv & converter) {
33  typename Conv::Candidate c;
35  ref_type ref = components.template getConcreteRef<ref_type>(idx);
36  converter.convert(ref, c);
37  cands.push_back(c);
38  }
39  };
40 
42  template<typename CColl, typename Comp, typename Conv>
43  static void create(size_t idx, CColl & cands, const Comp & components, Conv & converter) {
44  typename Conv::Candidate * c = new typename Conv::Candidate;
46  ref_type ref = components.template getConcreteRef<ref_type>(idx);
47  converter.convert(ref, * c);
48  cands.push_back(c);
49  }
50  };
51 
52  template<typename CColl>
53  struct CandCreator {
55  };
56 
57  template<>
60  };
61  }
62 }
63 
64 template<typename TColl, typename CColl, typename Selector = AnySelector,
66  typename Creator = typename converter::helper::CandCreator<CColl>::type,
69 public:
72  src_(cfg.template getParameter<edm::InputTag>("src")),
73  converter_(cfg),
74  selector_(reco::modules::make<Selector>(cfg)),
76  produces<CColl>();
77  }
80 
81 private:
83  void beginRun(edm::Run&, const edm::EventSetup& es) {
84  if (!initialized_) {
85  converter_.beginFirstRun(es);
86  initialized_ = true;
87  }
88  }
90  void produce(edm::Event& evt, const edm::EventSetup& es) {
92  evt.getByLabel(src_, src);
93  Init::init(selector_, evt, es);
95  std::auto_ptr<CColl> cands(new CColl);
96  if(src->size()!= 0) {
97  size_t size = src->size();
98  cands->reserve(size);
99  for(size_t idx = 0; idx != size; ++ idx) {
100  if(selector_((*src)[idx]))
101  Creator::create(master.index(idx), *cands, master, converter_);
102  }
103  }
104  evt.put(cands);
105  }
114 };
115 
116 #endif
type
Definition: HCALResponse.h:22
Master< F > master(const F &f)
Definition: FunctClone.h:68
edm::InputTag src_
label of source collection and tag
bool initialized_
particles initialized?
CandidateProducer(const edm::ParameterSet &cfg)
constructor from parameter set
int init
Definition: HydjetWrapper.h:63
S make(const edm::ParameterSet &cfg)
static void create(size_t idx, CColl &cands, const Comp &components, Conv &converter)
void produce(edm::Event &evt, const edm::EventSetup &es)
process one event
Conv converter_
converter helper
Definition: CSCxTalk.h:5
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
size_t index(size_t i) const
void beginRun(edm::Run &, const edm::EventSetup &es)
begin job (first run)
Selector selector_
selector
Functor that operates on &lt;T&gt;
Definition: Selector.h:25
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
static void create(size_t idx, CColl &cands, const Comp &components, Conv &converter)
~CandidateProducer()
destructor
edm::OwnVector< Candidate > CandidateCollection
collection of Candidate objects
Definition: CandidateFwd.h:21
SurfaceDeformation * create(int type, const std::vector< double > &params)
tuple size
Write out results.
def template
Definition: svgfig.py:520
Definition: Run.h:33