ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/yiiyama/Toolset/Common/src/ObjectCounter.cc
Revision: 1.1
Committed: Fri Jun 1 11:10:17 2012 UTC (12 years, 11 months ago) by yiiyama
Content type: text/plain
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# Content
1 // -*- C++ -*-
2 //
3 // Package: ObjectCounter
4 // Class: ObjectCounter
5 //
6 /**\class ObjectCounter ObjectCounter.cc CommonTools/ObjectCounter/src/ObjectCounter.cc
7
8 Description: [one line class summary]
9
10 Implementation:
11 [Notes on implementation]
12 */
13 //
14 // Original Author: Yutaro Iiyama,512 1-005,+41227670489,
15 // Created: Fri Jun 1 11:20:59 CEST 2012
16 // $Id$
17 //
18 //
19
20
21 // system include files
22 #include <memory>
23
24 // user include files
25 #include "FWCore/Framework/interface/Frameworkfwd.h"
26 #include "FWCore/Framework/interface/EDFilter.h"
27
28 #include "FWCore/Framework/interface/Event.h"
29 #include "FWCore/Framework/interface/MakerMacros.h"
30
31 #include "FWCore/ParameterSet/interface/ParameterSet.h"
32
33 #include "FWCore/Utilities/interface/Exception.h"
34 #include "FWCore/Utilities/interface/InputTag.h"
35
36 #include "DataFormats/Common/interface/Handle.h"
37 #include "DataFormats/Common/interface/RefToBaseVector.h"
38
39 #include "DataFormats/Candidate/interface/Candidate.h"
40
41 //
42 // class declaration
43 //
44
45 class ObjectCounter : public edm::EDFilter {
46 public:
47 explicit ObjectCounter(const edm::ParameterSet&);
48 ~ObjectCounter();
49
50 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51
52 private:
53 virtual void beginJob() ;
54 virtual bool filter(edm::Event&, const edm::EventSetup&);
55 virtual void endJob() ;
56
57 virtual bool beginRun(edm::Run&, edm::EventSetup const&);
58 virtual bool endRun(edm::Run&, edm::EventSetup const&);
59 virtual bool beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
60 virtual bool endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
61
62 // ----------member data ---------------------------
63
64 edm::InputTag srcTag_;
65 unsigned threshold_;
66 };
67
68 //
69 // constants, enums and typedefs
70 //
71
72 //
73 // static data member definitions
74 //
75
76 //
77 // constructors and destructor
78 //
79 ObjectCounter::ObjectCounter(const edm::ParameterSet& iConfig) :
80 srcTag_(iConfig.getParameter<edm::InputTag>("src")),
81 threshold_(iConfig.getUntrackedParameter<int>("threshold", 1))
82 {
83 //now do what ever initialization is needed
84
85 }
86
87
88 ObjectCounter::~ObjectCounter()
89 {
90
91 // do anything here that needs to be done at desctruction time
92 // (e.g. close files, deallocate resources etc.)
93
94 }
95
96
97 //
98 // member functions
99 //
100
101 // ------------ method called on each new Event ------------
102 bool
103 ObjectCounter::filter(edm::Event& iEvent, const edm::EventSetup&)
104 {
105 using namespace edm;
106
107 Handle<RefToBaseVector<reco::Candidate> > collection;
108 if(!iEvent.getByLabel(srcTag_, collection))
109 throw cms::Exception("ProductNotFound") << srcTag_;
110
111 return collection->size() >= threshold_;
112 }
113
114 // ------------ method called once each job just before starting event loop ------------
115 void
116 ObjectCounter::beginJob()
117 {
118 }
119
120 // ------------ method called once each job just after ending the event loop ------------
121 void
122 ObjectCounter::endJob() {
123 }
124
125 // ------------ method called when starting to processes a run ------------
126 bool
127 ObjectCounter::beginRun(edm::Run&, edm::EventSetup const&)
128 {
129 return true;
130 }
131
132 // ------------ method called when ending the processing of a run ------------
133 bool
134 ObjectCounter::endRun(edm::Run&, edm::EventSetup const&)
135 {
136 return true;
137 }
138
139 // ------------ method called when starting to processes a luminosity block ------------
140 bool
141 ObjectCounter::beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&)
142 {
143 return true;
144 }
145
146 // ------------ method called when ending the processing of a luminosity block ------------
147 bool
148 ObjectCounter::endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&)
149 {
150 return true;
151 }
152
153 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
154 void
155 ObjectCounter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
156 //The following says we do not know what parameters are allowed so do no validation
157 // Please change this to state exactly what you do use, even if it is no parameters
158 edm::ParameterSetDescription desc;
159 desc.setUnknown();
160 descriptions.addDefault(desc);
161 }
162 //define this as a plug-in
163 DEFINE_FWK_MODULE(ObjectCounter);