ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/GPetrucc/plugins/MaxEvents.cc
Revision: 1.1
Committed: Fri Mar 26 15:41:33 2010 UTC (15 years, 1 month ago) by gpetrucc
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Error occurred while calculating annotation data.
Log Message:
follow the express

File Contents

# Content
1 //
2 // $Id: MaxEvents.cc,v 1.1 2010/01/26 09:47:36 gpetrucc Exp $
3 //
4
5 /**
6 \class gMaxEvents PATMuonKinematics.h "PhysicsTools/PatAlgos/interface/PATMuonKinematics.h"
7 \brief Use StandAlone track to define the 4-momentum of a PAT Muon (normally the global one is used)
8
9 \author Giovanni Petrucciani
10 \version $Id: MaxEvents.cc,v 1.1 2010/01/26 09:47:36 gpetrucc Exp $
11 */
12
13
14 #include "FWCore/Framework/interface/EDFilter.h"
15 #include "FWCore/Framework/interface/Event.h"
16 #include "FWCore/Framework/interface/Run.h"
17 #include "FWCore/Framework/interface/LuminosityBlock.h"
18 #include "FWCore/ParameterSet/interface/ParameterSet.h"
19 #include "FWCore/ParameterSet/interface/InputTag.h"
20
21 #include "DataFormats/Common/interface/MergeableCounter.h"
22 #include <map>
23 #include <iostream>
24 #include <cstdio>
25 #include <boost/foreach.hpp>
26 #define foreach BOOST_FOREACH
27
28
29 class MaxEvents : public edm::EDFilter {
30 public:
31 explicit MaxEvents(const edm::ParameterSet & iConfig);
32 virtual ~MaxEvents() { }
33
34 virtual bool filter(edm::Event & iEvent, const edm::EventSetup & iSetup);
35 virtual bool beginLuminosityBlock(edm::LuminosityBlock &lumi, const edm::EventSetup &iSetup);
36 //virtual bool endLuminosityBlock(edm::LuminosityBlock &lumi, const edm::EventSetup &iSetup);
37 virtual void endJob();
38
39 private:
40 std::string myLabel_;
41 size_t maxPerLumi_, max_;
42
43 size_t nLumi_, nAll_;
44 //std::map<std::pair<uint32_t,uint32_t>, uint32_t> counters_;
45
46 struct Record {
47 uint32_t run, ls, event;
48 Record(const edm::EventID &ev) : run(ev.run()), ls(ev.luminosityBlock()), event(ev.event()) {}
49 bool operator<(const Record & other) const {
50 if (run != other.run) return run < other.run;
51 if (ls != other.ls ) return ls < other.ls ;
52 return event < other.event;
53 }
54 };
55 std::vector<Record> records_;
56 };
57
58 MaxEvents::MaxEvents(const edm::ParameterSet & iConfig) :
59 myLabel_(iConfig.getParameter<std::string>("@module_label")),
60 maxPerLumi_(iConfig.getParameter<uint32_t>("maxSavedEventsPerLumi")),
61 max_(iConfig.getParameter<uint32_t>("maxSavedEvents")),
62 nAll_(0)
63 {
64 //produces<edm::MergeableCounter, edm::InLumi>();
65 }
66
67
68 bool
69 MaxEvents::beginLuminosityBlock(edm::LuminosityBlock &lumi, const edm::EventSetup &iSetup) {
70 nLumi_ = 0;
71 return true;
72 }
73
74 /*
75 bool
76 MaxEvents::endLuminosityBlock(edm::LuminosityBlock &lumi, const edm::EventSetup &iSetup) {
77 counters_[std::pair<uint32_t,uint32_t>(lumi.run(), lumi.luminosityBlock())] = nLumi_;
78 std::auto_ptr<edm::MergeableCounter> counter(new edm::MergeableCounter());
79 counter->value = nLumi_;
80 lumi.put(counter);
81 return true;
82 }
83 */
84
85 void
86 MaxEvents::endJob() {
87 std::sort(records_.begin(), records_.end());
88 std::cerr << "\n" << myLabel_ << ": === REPORT FOR JOB === " << std::endl;
89 foreach (const Record &rec, records_) {
90 fprintf(stderr,"%s: Run %6d Lumi %5d Event %9d\n", myLabel_.c_str(), rec.run, rec.ls, rec.event);
91 }
92 /*
93 typedef std::pair<std::pair<uint32_t,uint32_t>, uint32_t> hitLumi;
94 foreach(const hitLumi &hit, counters_) {
95 fprintf(stderr,"%s: Run %6d LS %4d: events %7d\n", myLabel_.c_str(), hit.first.first, hit.first.second, hit.second);
96 }
97 std::cerr << std::endl;
98 */
99 }
100
101 bool
102 MaxEvents::filter(edm::Event & iEvent, const edm::EventSetup & iSetup) {
103 nAll_++; nLumi_++;
104 bool ok = ((maxPerLumi_ == 0) || (nLumi_ <= maxPerLumi_)) &&
105 ((max_ == 0) || (nAll_ <= max_));
106 if (ok) records_.push_back(Record(iEvent.id()));
107 return ok;
108 }
109
110
111 #include "FWCore/Framework/interface/MakerMacros.h"
112 DEFINE_FWK_MODULE(MaxEvents);