CMS 3D CMS Logo

CandidateSummaryTable.cc
Go to the documentation of this file.
1 //
2 //
3 
20 #include <iomanip>
21 #include <atomic>
22 
25 
26 namespace pathelpers {
27  struct Record {
29  mutable std::atomic<size_t> present, empty, min, max, total;
30  Record(const edm::InputTag& tag) : src(tag), present(0), empty(0), min(0), max(0), total(0) {}
32  : src(other.src),
34  empty(other.empty.load()),
35  min(other.min.load()),
36  max(other.max.load()),
37  total(other.total.load()) {}
39  present++;
40  const size_t size = items.size();
41  if (size == 0) {
42  empty++;
43  } else {
44  auto previousMin = min.load();
45  while (previousMin > size and not min.compare_exchange_weak(previousMin, size)) {
46  }
47  auto previousMax = max.load();
48  while (previousMax < size and not max.compare_exchange_weak(previousMax, size)) {
49  }
50  }
51  total += size;
52  }
53  };
54 
55  struct RecordCache {
57  : perEvent_(iConfig.getUntrackedParameter<bool>("perEvent", false)),
58  perJob_(iConfig.getUntrackedParameter<bool>("perJob", true)),
59  self_(iConfig.getParameter<std::string>("@module_label")),
60  logName_(iConfig.getUntrackedParameter<std::string>("logName")),
61  dumpItems_(iConfig.getUntrackedParameter<bool>("dumpItems", false)),
62  totalEvents_(0) {
63  const std::vector<edm::InputTag>& tags = iConfig.getParameter<std::vector<edm::InputTag> >("candidates");
64  for (const auto& tag : tags) {
65  collections_.emplace_back(tag);
66  }
67  }
68  const bool perEvent_, perJob_;
70  const bool dumpItems_;
71  mutable std::atomic<size_t> totalEvents_;
72  std::vector<Record> collections_; // size of vector is never altered later! (atomics are in the class below)
73  };
74 
75 } // namespace pathelpers
76 
77 namespace pat {
78  class CandidateSummaryTable : public edm::stream::EDAnalyzer<edm::GlobalCache<pathelpers::RecordCache> > {
79  public:
80  explicit CandidateSummaryTable(const edm::ParameterSet& iConfig, const pathelpers::RecordCache*);
81  ~CandidateSummaryTable() override;
82 
83  static std::unique_ptr<pathelpers::RecordCache> initializeGlobalCache(edm::ParameterSet const& conf) {
84  return std::make_unique<pathelpers::RecordCache>(conf);
85  }
86 
87  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
88 
89  static void globalEndJob(const pathelpers::RecordCache*);
90 
91  private:
92  std::vector<std::pair<edm::InputTag, edm::EDGetTokenT<edm::View<reco::Candidate> > > > srcTokens;
93  };
94 } // namespace pat
95 
97  const std::vector<edm::InputTag>& inputs = iConfig.getParameter<std::vector<edm::InputTag> >("candidates");
98  for (std::vector<edm::InputTag>::const_iterator it = inputs.begin(); it != inputs.end(); ++it) {
99  srcTokens.emplace_back(*it, consumes<edm::View<reco::Candidate> >(*it));
100  }
101 }
102 
104 
106  using namespace edm;
107  using std::left;
108  using std::right;
109  using std::setprecision;
110  using std::setw;
111 
113  if (globalCache()->perEvent_) {
114  LogInfo(globalCache()->logName_) << "Per Event Table " << globalCache()->logName_ << " (" << globalCache()->self_
115  << ", run:event " << iEvent.id().run() << ":" << iEvent.id().event() << ")";
116  }
117  ++(globalCache()->totalEvents_);
118  auto& collections = globalCache()->collections_;
119  auto tags = srcTokens.cbegin();
120  for (auto it = collections.begin(), ed = collections.end(); it != ed; ++it, ++tags) {
121  iEvent.getByToken(tags->second, candidates);
122  if (!candidates.failedToGet())
123  it->update(*candidates);
124  if (globalCache()->perEvent_) {
125  LogVerbatim(globalCache()->logName_) << " " << setw(30) << left << it->src.encode() << right;
126  if (globalCache()->dumpItems_) {
127  size_t i = 0;
128  std::ostringstream oss;
129  for (View<reco::Candidate>::const_iterator cand = candidates->begin(), endc = candidates->end(); cand != endc;
130  ++cand, ++i) {
131  oss << " [" << setw(3) << i << "]"
132  << " pt " << setw(7) << setprecision(5) << cand->pt() << " eta " << setw(7) << setprecision(5)
133  << cand->eta() << " phi " << setw(7) << setprecision(5) << cand->phi() << " et " << setw(7)
134  << setprecision(5) << cand->et() << " phi " << setw(7) << setprecision(5) << cand->phi() << " charge "
135  << setw(2) << cand->charge() << " id " << setw(7) << cand->pdgId() << " st " << setw(7)
136  << cand->status() << "\n";
137  }
138  LogVerbatim(globalCache()->logName_) << oss.str();
139  }
140  }
141  }
142  if (globalCache()->perEvent_)
143  LogInfo(globalCache()->logName_) << ""; // add an empty line
144 }
145 
147  using std::left;
148  using std::right;
149  using std::setprecision;
150  using std::setw;
151  if (rcd->perJob_) {
152  std::ostringstream oss;
153  oss << "Summary Table " << rcd->logName_ << " (" << rcd->self_ << ", events total " << rcd->totalEvents_ << ")\n";
154  for (auto it = rcd->collections_.cbegin(), ed = rcd->collections_.cend(); it != ed; ++it) {
155  oss << " " << setw(30) << left << it->src.encode() << right << " present " << setw(7) << it->present << " ("
156  << setw(4) << setprecision(3) << (it->present * 100.0 / rcd->totalEvents_) << "%)"
157  << " empty " << setw(7) << it->empty << " (" << setw(4) << setprecision(3)
158  << (it->empty * 100.0 / rcd->totalEvents_) << "%)"
159  << " min " << setw(7) << it->min << " max " << setw(7) << it->max << " total " << setw(7) << it->total
160  << " avg " << setw(5) << setprecision(3) << (it->total / double(rcd->totalEvents_)) << "\n";
161  }
162  oss << "\n";
163  edm::LogVerbatim(rcd->logName_) << oss.str();
164  }
165 }
166 
pathelpers::Record::src
const edm::InputTag src
Definition: CandidateSummaryTable.cc:28
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
EDAnalyzer.h
pathelpers::Record
Definition: CandidateSummaryTable.cc:27
pathelpers::Record::Record
Record(const Record &other)
Definition: CandidateSummaryTable.cc:31
edm
HLT enums.
Definition: AlignableModifier.h:19
pathelpers::RecordCache::totalEvents_
std::atomic< size_t > totalEvents_
Definition: CandidateSummaryTable.cc:71
pat::CandidateSummaryTable::srcTokens
std::vector< std::pair< edm::InputTag, edm::EDGetTokenT< edm::View< reco::Candidate > > > > srcTokens
Definition: CandidateSummaryTable.cc:92
pathelpers::Record::update
void update(const edm::View< reco::Candidate > &items) const
Definition: CandidateSummaryTable.cc:38
pathelpers::Record::min
std::atomic< size_t > min
Definition: CandidateSummaryTable.cc:29
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
mps_monitormerge.items
list items
Definition: mps_monitormerge.py:29
pat::CandidateSummaryTable::CandidateSummaryTable
CandidateSummaryTable(const edm::ParameterSet &iConfig, const pathelpers::RecordCache *)
Definition: CandidateSummaryTable.cc:96
pathelpers::RecordCache::perJob_
const bool perJob_
Definition: CandidateSummaryTable.cc:68
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
pathelpers::Record::empty
std::atomic< size_t > empty
Definition: CandidateSummaryTable.cc:29
svgfig.load
def load(fileName)
Definition: svgfig.py:547
trackingPlots.other
other
Definition: trackingPlots.py:1467
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
oniaPATMuonsWithTrigger_cff.collections
collections
Definition: oniaPATMuonsWithTrigger_cff.py:37
edm::View
Definition: CaloClusterFwd.h:14
funct::true
true
Definition: Factorize.h:173
pathelpers::RecordCache::RecordCache
RecordCache(const edm::ParameterSet &iConfig)
Definition: CandidateSummaryTable.cc:56
edm::ParameterSet
Definition: ParameterSet.h:47
edm::stream::EDAnalyzer
Definition: EDAnalyzer.h:33
Event.h
cand
Definition: decayParser.h:32
iEvent
int iEvent
Definition: GenABIO.cc:224
PixelMapPlotter.inputs
inputs
Definition: PixelMapPlotter.py:490
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
pathelpers::RecordCache::dumpItems_
const bool dumpItems_
Definition: CandidateSummaryTable.cc:70
InputTag.h
pathelpers::Record::Record
Record(const edm::InputTag &tag)
Definition: CandidateSummaryTable.cc:30
pat::CandidateSummaryTable::globalEndJob
static void globalEndJob(const pathelpers::RecordCache *)
Definition: CandidateSummaryTable.cc:146
pathelpers::RecordCache::self_
const std::string self_
Definition: CandidateSummaryTable.cc:69
std
Definition: JetResolutionObject.h:76
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
pat::CandidateSummaryTable::initializeGlobalCache
static std::unique_ptr< pathelpers::RecordCache > initializeGlobalCache(edm::ParameterSet const &conf)
Definition: CandidateSummaryTable.cc:83
HLT_FULL_cff.candidates
candidates
Definition: HLT_FULL_cff.py:55051
pathelpers::RecordCache::logName_
const std::string logName_
Definition: CandidateSummaryTable.cc:69
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
pat::CandidateSummaryTable::analyze
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: CandidateSummaryTable.cc:105
triggerMatcherToHLTDebug_cfi.tags
tags
Definition: triggerMatcherToHLTDebug_cfi.py:9
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
pathelpers::Record::max
std::atomic< size_t > max
Definition: CandidateSummaryTable.cc:29
ConsumesCollector.h
Candidate.h
View.h
ParameterSet.h
pat::CandidateSummaryTable::~CandidateSummaryTable
~CandidateSummaryTable() override
Definition: CandidateSummaryTable.cc:103
pathelpers::Record::total
std::atomic< size_t > total
Definition: CandidateSummaryTable.cc:29
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:153
pathelpers::Record::present
std::atomic< size_t > present
Definition: CandidateSummaryTable.cc:29
edm::Event
Definition: Event.h:73
pathelpers::RecordCache
Definition: CandidateSummaryTable.cc:55
pathelpers::RecordCache::collections_
std::vector< Record > collections_
Definition: CandidateSummaryTable.cc:72
pathelpers
Definition: CandidateSummaryTable.cc:26
pathelpers::RecordCache::perEvent_
const bool perEvent_
Definition: CandidateSummaryTable.cc:68
edm::InputTag
Definition: InputTag.h:15
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
pat::CandidateSummaryTable
Produce a summary table of some candidate collections.
Definition: CandidateSummaryTable.cc:78