CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CandidateSummaryTable.cc
Go to the documentation of this file.
1 //
2 //
3 
21 #include <iomanip>
22 
25 
26 namespace pat {
28  public:
29  explicit CandidateSummaryTable(const edm::ParameterSet & iConfig);
31 
32  virtual void analyze(const edm::Event & iEvent, const edm::EventSetup& iSetup) override;
33  virtual void endJob() override;
34 
35  private:
36  struct Record {
39  size_t present, empty, min, max, total;
40  Record(edm::InputTag tag, edm::ConsumesCollector && iC) : src(tag), srcToken(iC.consumes<edm::View<reco::Candidate> >(tag)), present(0), empty(0), min(0), max(0), total(0) {}
41 
42  void update(const edm::View<reco::Candidate> &items) {
43  present++;
44  size_t size = items.size();
45  if (size == 0) {
46  empty++;
47  } else {
48  if (min > size) min = size;
49  if (max < size) max = size;
50  }
51  total += size;
52  }
53  };
54  std::vector<Record> collections_;
55  size_t totalEvents_;
58  bool dumpItems_;
59  };
60 
61 } // namespace
62 
64  totalEvents_(0),
65  perEvent_(iConfig.getUntrackedParameter<bool>("perEvent", false)),
66  perJob_(iConfig.getUntrackedParameter<bool>("perJob", true)),
67  self_(iConfig.getParameter<std::string>("@module_label")),
68  logName_(iConfig.getUntrackedParameter<std::string>("logName")),
69  dumpItems_(iConfig.getUntrackedParameter<bool>("dumpItems", false))
70 {
71  std::vector<edm::InputTag> inputs = iConfig.getParameter<std::vector<edm::InputTag> >("candidates");
72  for (std::vector<edm::InputTag>::const_iterator it = inputs.begin(); it != inputs.end(); ++it) {
73  collections_.push_back(Record(*it, consumesCollector()));
74  }
75 }
76 
78 }
79 
80 void
82  using namespace edm;
83  using std::setw; using std::left; using std::right; using std::setprecision;
84 
86  if (perEvent_) {
87  LogInfo(logName_) << "Per Event Table " << logName_ <<
88  " (" << self_ << ", run:event " << iEvent.id().run() << ":" << iEvent.id().event() << ")";
89  }
90  totalEvents_++;
91  for (std::vector<Record>::iterator it = collections_.begin(), ed = collections_.end(); it != ed; ++it) {
92  iEvent.getByToken(it->srcToken, candidates);
93  if (!candidates.failedToGet()) it->update(*candidates);
94  if (perEvent_) {
95  LogVerbatim(logName_) << " " << setw(30) << left << it->src.encode() << right;
96  if (dumpItems_) {
97  size_t i = 0;
98  std::ostringstream oss;
99  for (View<reco::Candidate>::const_iterator cand = candidates->begin(), endc = candidates->end(); cand != endc; ++cand, ++i) {
100  oss << " [" << setw(3) << i << "]" <<
101  " pt " << setw(7) << setprecision(5) << cand->pt() <<
102  " eta " << setw(7) << setprecision(5) << cand->eta() <<
103  " phi " << setw(7) << setprecision(5) << cand->phi() <<
104  " et " << setw(7) << setprecision(5) << cand->et() <<
105  " phi " << setw(7) << setprecision(5) << cand->phi() <<
106  " charge " << setw(2) << cand->charge() <<
107  " id " << setw(7) << cand->pdgId() <<
108  " st " << setw(7) << cand->status() << "\n";
109  }
110  LogVerbatim(logName_) << oss.str();
111  }
112  }
113  }
114  if (perEvent_) LogInfo(logName_) << "" ; // add an empty line
115 }
116 
117 
118 void
120  using std::setw; using std::left; using std::right; using std::setprecision;
121  if (perJob_) {
122  std::ostringstream oss;
123  oss << "Summary Table " << logName_ << " (" << self_ << ", events total " << totalEvents_ << ")\n";
124  for (std::vector<Record>::iterator it = collections_.begin(), ed = collections_.end(); it != ed; ++it) {
125  oss << " " << setw(30) << left << it->src.encode() << right <<
126  " present " << setw(7) << it->present << " (" << setw(4) << setprecision(3) << (it->present*100.0/totalEvents_) << "%)" <<
127  " empty " << setw(7) << it->empty << " (" << setw(4) << setprecision(3) << (it->empty*100.0/totalEvents_) << "%)" <<
128  " min " << setw(7) << it->min <<
129  " max " << setw(7) << it->max <<
130  " total " << setw(7) << it->total <<
131  " avg " << setw(5) << setprecision(3) << (it->total/double(totalEvents_)) << "\n";
132  }
133  oss << "\n";
134  edm::LogVerbatim(logName_) << oss.str();
135  }
136 }
137 
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
int i
Definition: DBlmapReader.cc:9
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
CandidateSummaryTable(const edm::ParameterSet &iConfig)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
size_type size() const
edm::EDGetTokenT< edm::View< reco::Candidate > > srcToken
void update(const edm::View< reco::Candidate > &items)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:230
Record(edm::InputTag tag, edm::ConsumesCollector &&iC)
Produce a summary table of some candidate collections.
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
virtual void endJob() override
edm::EventID id() const
Definition: EventBase.h:60
volatile std::atomic< bool > shutdown_flag false
tuple size
Write out results.
std::vector< Record > collections_