CMS 3D CMS Logo

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  srcToken_(consumes<TColl>(cfg.template getParameter<edm::InputTag>("src"))),
73  converter_(cfg),
74  selector_(reco::modules::make<Selector>(cfg, consumesCollector())),
75  initialized_(false) {
76  produces<CColl>();
77  }
79  ~CandidateProducer() override { }
80 
81 private:
83  void beginRun(const edm::Run&, const edm::EventSetup& es) override {
84  if (!initialized_) {
85  converter_.beginFirstRun(es);
86  initialized_ = true;
87  }
88  }
90  void produce(edm::Event& evt, const edm::EventSetup& es) override {
92  evt.getByToken(srcToken_, src);
93  Init::init(selector_, evt, es);
95  std::unique_ptr<CColl> cands(new CColl);
96  if(!src->empty()) {
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(std::move(cands));
105  }
114 };
115 
116 #endif
size
Write out results.
type
Definition: HCALResponse.h:21
Master< F > master(const F &f)
Definition: FunctClone.h:68
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
Definition: helper.py:1
void produce(edm::Event &evt, const edm::EventSetup &es) override
process one event
def create(alignables, pedeDump, additionalData, outputFile, config)
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:508
bool initialized_
particles initialized?
CandidateProducer(const edm::ParameterSet &cfg)
constructor from parameter set
int init
Definition: HydjetWrapper.h:67
S make(const edm::ParameterSet &cfg)
static void create(size_t idx, CColl &cands, const Comp &components, Conv &converter)
Conv converter_
converter helper
Definition: CSCxTalk.h:5
size_t index(size_t i) const
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:520
Selector selector_
selector
Functor that operates on <T>
Definition: Selector.h:24
static void create(size_t idx, CColl &cands, const Comp &components, Conv &converter)
edm::EDGetTokenT< TColl > srcToken_
label of source collection and tag
fixed size matrix
HLT enums.
edm::OwnVector< Candidate > CandidateCollection
collection of Candidate objects
Definition: CandidateFwd.h:21
~CandidateProducer() override
destructor
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:43