ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/ForwardAnalysis/Utilities/interface/OneToManySelector.h
Revision: 1.4
Committed: Fri Aug 5 07:21:57 2011 UTC (13 years, 9 months ago) by antoniov
Content type: text/plain
Branch: MAIN
CVS Tags: V01-01-01, V01-01-00, antoniov-forwardAnalysis-09Jul2012-v1, antoniov-forwardAnalysis-29Jun2012-v1, V01-00-00, antoniov-utilities-11Jun2012-v1, antoniov-forwardAnalysis-Oct072011-v1, sfonseca_10_04_2011, antoniov-forwardAnalysis-Sep182011-v1, antoniov-forwardAnalysis-Sep102011-v1, sfonseca_08_26_2011, forwardAnalysis-Aug232011-v1, forwardAnalysis-Aug172011-v1, forwardAnalysis-Aug052011-v1, HEAD
Changes since 1.3: +3 -1 lines
Log Message:
add selector function

File Contents

# Content
1 #ifndef ForwardAnalysis_Utilities_OneToManySelector_h
2 #define ForwardAnalysis_Utilities_OneToManySelector_h
3
4 #include "FWCore/Framework/interface/Event.h"
5 #include "FWCore/ParameterSet/interface/ParameterSet.h"
6 #include "FWCore/Utilities/interface/InputTag.h"
7 #include "CommonTools/UtilAlgos/interface/AnyPairSelector.h"
8 #include "CommonTools/UtilAlgos/interface/AnySelector.h"
9
10 namespace forwardAnalysis {
11
12 template <class Object, class Coll,
13 class PairSelector=AnyPairSelector, class S1=AnySelector, class S2=AnySelector>
14 class OneToManySelector {
15 public:
16 OneToManySelector(edm::ParameterSet const& pset):
17 src_( pset.template getParameter<edm::InputTag>("src") ),
18 selector_( reco::modules::make<PairSelector>(pset) ),
19 s1_( reco::modules::make<S1>(pset) ),
20 s2_( reco::modules::make<S2>(pset) ) {}
21
22 ~OneToManySelector() {}
23
24 bool operator() (Object const& obj, edm::Event const& event){
25 edm::Handle<Coll> source;
26 event.getByLabel(src_,source);
27 typename Coll::const_iterator cand = source->begin(), source_end = source->end();
28 bool result = true;
29 if( !s1_(obj) ) { result=false; return result; } // Use only objects passing selector S1
30 for(; cand != source_end; ++cand){
31 if( !s2_(*cand) ) continue; // Use only objects passing selector S2
32 if( !selector_(obj,*cand) ) { result = false; break; }
33 }
34 return result;
35 }
36
37 private:
38 edm::InputTag src_;
39 PairSelector selector_;
40 S1 s1_;
41 S2 s2_;
42 };
43
44 } // namespace
45
46 #endif