1 |
dgele |
1.1 |
#ifndef RecoAlgos_CandidateProducer_h
|
2 |
|
|
#define RecoAlgos_CandidateProducer_h
|
3 |
|
|
/** \class CandidateProducer
|
4 |
|
|
*
|
5 |
|
|
* Framework module that produces a collection
|
6 |
|
|
* of candidates from generic compoment
|
7 |
|
|
*
|
8 |
|
|
* \author Luca Lista, INFN
|
9 |
|
|
*
|
10 |
|
|
* \version $Revision: 1.4 $
|
11 |
|
|
*
|
12 |
|
|
* $Id: CandidateProducer.h,v 1.4 2008/01/17 13:29:37 llista Exp $
|
13 |
|
|
*
|
14 |
|
|
*/
|
15 |
|
|
#include "FWCore/ParameterSet/interface/InputTag.h"
|
16 |
|
|
#include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
|
17 |
|
|
#include "FWCore/Framework/interface/EDProducer.h"
|
18 |
|
|
#include "FWCore/Framework/interface/Event.h"
|
19 |
|
|
#include "DataFormats/Common/interface/Handle.h"
|
20 |
|
|
#include "DataFormats/Candidate/interface/CandidateFwd.h"
|
21 |
|
|
#include "PhysicsTools/UtilAlgos/interface/MasterCollectionHelper.h"
|
22 |
|
|
#include "PhysicsTools/UtilAlgos/interface/AnySelector.h"
|
23 |
|
|
#include "PhysicsTools/UtilAlgos/interface/EventSetupInitTrait.h"
|
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;
|
34 |
|
|
typedef edm::Ref<std::vector<typename Conv::value_type> > ref_type;
|
35 |
|
|
ref_type ref = components.template getConcreteRef<ref_type>(idx);
|
36 |
|
|
converter.convert(ref, c);
|
37 |
|
|
cands.push_back(c);
|
38 |
|
|
}
|
39 |
|
|
};
|
40 |
|
|
|
41 |
|
|
struct PolymorphicCreator {
|
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;
|
45 |
|
|
typedef edm::Ref<std::vector<typename Conv::value_type> > ref_type;
|
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 {
|
54 |
|
|
typedef ConcreteCreator type;
|
55 |
|
|
};
|
56 |
|
|
|
57 |
|
|
template<>
|
58 |
|
|
struct CandCreator<reco::CandidateCollection> {
|
59 |
|
|
typedef PolymorphicCreator type;
|
60 |
|
|
};
|
61 |
|
|
}
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
template<typename TColl, typename CColl, typename Selector = AnySelector,
|
65 |
|
|
typename Conv = typename converter::helper::CandConverter<typename TColl::value_type>::type,
|
66 |
|
|
typename Creator = typename converter::helper::CandCreator<CColl>::type,
|
67 |
|
|
typename Init = typename ::reco::modules::EventSetupInit<Selector>::type>
|
68 |
|
|
class CandidateProducer : public edm::EDProducer {
|
69 |
|
|
public:
|
70 |
|
|
/// constructor from parameter set
|
71 |
|
|
CandidateProducer(const edm::ParameterSet & cfg) :
|
72 |
|
|
src_(cfg.template getParameter<edm::InputTag>("src")),
|
73 |
|
|
converter_(cfg),
|
74 |
|
|
selector_(reco::modules::make<Selector>(cfg)){
|
75 |
|
|
produces<CColl>();
|
76 |
|
|
}
|
77 |
|
|
/// destructor
|
78 |
|
|
~CandidateProducer() { }
|
79 |
|
|
|
80 |
|
|
private:
|
81 |
|
|
/// begin job
|
82 |
|
|
void beginJob(const edm::EventSetup& es) { converter_.beginJob(es); }
|
83 |
|
|
/// process one event
|
84 |
|
|
void produce(edm::Event& evt, const edm::EventSetup& es) {
|
85 |
|
|
edm::Handle<TColl> src;
|
86 |
|
|
evt.getByLabel(src_, src);
|
87 |
|
|
Init::init(selector_, evt, es);
|
88 |
|
|
::helper::MasterCollection<TColl> master(src);
|
89 |
|
|
std::auto_ptr<CColl> cands(new CColl);
|
90 |
|
|
if(src->size()!= 0) {
|
91 |
|
|
size_t size = src->size();
|
92 |
|
|
cands->reserve(size);
|
93 |
|
|
for(size_t idx = 0; idx != size; ++ idx) {
|
94 |
|
|
if(selector_((*src)[idx]))
|
95 |
|
|
Creator::create(master.index(idx), *cands, master, converter_);
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
evt.put(cands);
|
99 |
|
|
}
|
100 |
|
|
/// label of source collection and tag
|
101 |
|
|
edm::InputTag src_;
|
102 |
|
|
/// converter helper
|
103 |
|
|
Conv converter_;
|
104 |
|
|
/// selector
|
105 |
|
|
Selector selector_;
|
106 |
|
|
};
|
107 |
|
|
|
108 |
|
|
#endif
|