CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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  } // namespace helper
62 } // namespace converter
63 
64 template <typename TColl,
65  typename CColl,
66  typename Selector = AnySelector,
68  typename Creator = typename converter::helper::CandCreator<CColl>::type,
71 public:
74  : srcToken_(consumes<TColl>(cfg.template getParameter<edm::InputTag>("src"))),
75  converter_(cfg, consumesCollector()),
76  selector_(reco::modules::make<Selector>(cfg, consumesCollector())),
78  produces<CColl>();
79  }
81  ~CandidateProducer() override {}
82 
83 private:
85  void beginRun(const edm::Run&, const edm::EventSetup& es) override {
86  if (!initialized_) {
87  converter_.beginFirstRun(es);
88  initialized_ = true;
89  }
90  }
92  void produce(edm::Event& evt, const edm::EventSetup& es) override {
94  evt.getByToken(srcToken_, src);
95  Init::init(selector_, evt, es);
96  ::helper::MasterCollection<TColl> master(src, evt);
97  std::unique_ptr<CColl> cands(new CColl);
98  if (!src->empty()) {
99  size_t size = src->size();
100  cands->reserve(size);
101  for (size_t idx = 0; idx != size; ++idx) {
102  if (selector_((*src)[idx]))
103  Creator::create(master.index(idx), *cands, master, converter_);
104  }
105  }
106  evt.put(std::move(cands));
107  }
116 };
117 
118 #endif
Master< F > master(const F &f)
Definition: FunctClone.h:63
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const edm::EventSetup & c
tuple cfg
Definition: looper.py:296
void produce(edm::Event &evt, const edm::EventSetup &es) override
process one event
void beginRun(const edm::Run &, const edm::EventSetup &es) override
begin job (first run)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
bool initialized_
particles initialized?
CandidateProducer(const edm::ParameterSet &cfg)
constructor from parameter set
int init
Definition: HydjetWrapper.h:64
S make(const edm::ParameterSet &cfg)
static void create(size_t idx, CColl &cands, const Comp &components, Conv &converter)
Conv converter_
converter helper
def move
Definition: eostools.py:511
Selector selector_
selector
Functor that operates on &lt;T&gt;
Definition: Selector.h:22
static void create(size_t idx, CColl &cands, const Comp &components, Conv &converter)
edm::EDGetTokenT< TColl > srcToken_
label of source collection and tag
edm::OwnVector< Candidate > CandidateCollection
collection of Candidate objects
Definition: CandidateFwd.h:21
~CandidateProducer() override
destructor
tuple size
Write out results.
def template
Definition: svgfig.py:521
Definition: Run.h:45