CMS 3D CMS Logo

DQMStoreStats.h
Go to the documentation of this file.
1 #ifndef DQMStoreStats_H
2 #define DQMStoreStats_H
3 
13 #include <string>
14 #include <sstream>
15 #include <utility>
16 #include <vector>
17 #include <iostream>
18 #include <iomanip>
19 #include <utility>
20 #include <fstream>
21 #include <sstream>
22 
23 #include "TFile.h"
24 #include "TTree.h"
25 
29 
30 //
31 // class declarations
32 //
33 
36 
42 public:
44  totalHistos_ = 0;
45  totalBins_ = 0;
46  totalMemory_ = 0;
47  totalEmptyBins_ = 0;
48  }
50  unsigned int totalHistos_;
51  unsigned int totalBins_;
52  unsigned int totalEmptyBins_;
53  unsigned int totalMemory_;
54  void AddBinsF(unsigned int nBins, unsigned int nEmptyBins) {
55  ++totalHistos_;
56  totalBins_ += nBins;
57  totalEmptyBins_ += nEmptyBins;
58  totalMemory_ += (nBins *= sizeof(float));
59  }
60  void AddBinsS(unsigned int nBins, unsigned int nEmptyBins) {
61  ++totalHistos_;
62  totalBins_ += nBins;
63  totalEmptyBins_ += nEmptyBins;
64  totalMemory_ += (nBins *= sizeof(short));
65  }
66  void AddBinsD(unsigned int nBins, unsigned int nEmptyBins) {
67  ++totalHistos_;
68  totalBins_ += nBins;
69  totalEmptyBins_ += nEmptyBins;
70  totalMemory_ += (nBins *= sizeof(double));
71  }
72 };
73 
78 class DQMStoreStatsSubsystem : public std::vector<DQMStoreStatsSubfolder> {
79 public:
80  DQMStoreStatsSubsystem() = default;
82 };
83 
88 class DQMStoreStatsTopLevel : public std::vector<DQMStoreStatsSubsystem> {
89 public:
90  DQMStoreStatsTopLevel() = default;
91 };
92 
93 template <class Item>
94 class Iterator {
95 public:
96  virtual ~Iterator() = default;
97  virtual void First() = 0;
98  virtual void Next() = 0;
99  virtual bool IsDone() const = 0;
100  virtual Item CurrentItem() const = 0;
101 
102 protected:
103  Iterator() = default;
104 };
105 
106 template <class Item>
107 class VIterator : public Iterator<Item> {
108 public:
109  VIterator(const std::vector<Item>* aVector) : vector_(aVector), index(0) {}
110  ~VIterator() override = default;
111  void First() override { index = 0; }
112  void Next() override { ++index; }
113  virtual int size() { return vector_->size(); }
114  virtual int getIndex() { return (int)index; }
115 
116  bool IsDone() const override {
117  if (index < (unsigned int)vector_->size())
118  return false;
119  return true;
120  }
121 
122  Item CurrentItem() const override { return vector_->operator[](index); }
123 
124 private:
125  const std::vector<Item>* vector_;
126  unsigned int index;
127 };
128 
129 static unsigned int getId() {
130  static unsigned int id = 10;
131  return ++id;
132 }
133 
134 class Folder {
135 public:
137  : totalHistos_(0),
138  totalBins_(0),
139  totalEmptyBins_(0),
140  totalMemory_(0),
141  id_(10),
142  level_(0),
144  father_(nullptr) {}
145 
147  for (auto& subfolder : subfolders_)
148  delete subfolder;
149  }
150 
151  void setFather(Folder* e) { father_ = e; }
152  Folder* getFather() { return father_; }
153  const std::string& name() { return folderName_; }
154 
156  for (auto& subfolder : subfolders_)
157  if (subfolder->name() == name)
158  return subfolder;
159  auto* tmp = new Folder(name);
160  this->add(tmp);
161  return tmp;
162  }
163 
164  void setId(unsigned int id) { id_ = id; }
165  unsigned int id() { return id_; }
166  void setLevel(unsigned int value) { level_ = value; }
167  unsigned int level() { return level_; }
168 
169  void add(Folder* f) {
170  f->setFather(this);
171  subfolders_.push_back(f);
172  f->setLevel(level_ + 1);
173  f->setId(getId());
174  }
175 
176  unsigned int getHistos() {
177  unsigned int result = totalHistos_;
178  for (auto& subfolder : subfolders_)
179  result += subfolder->getHistos();
180  return result;
181  }
182  unsigned int getBins() {
183  unsigned int result = totalBins_;
184  for (auto& subfolder : subfolders_)
185  result += subfolder->getBins();
186  return result;
187  }
188  unsigned int getEmptyBins() {
189  unsigned int result = totalEmptyBins_;
190  for (auto& subfolder : subfolders_)
191  result += subfolder->getEmptyBins();
192  return result;
193  }
194  unsigned int getMemory() {
195  unsigned int result = totalMemory_;
196  for (auto& subfolder : subfolders_)
197  result += subfolder->getMemory();
198  return result;
199  }
200  void update(unsigned int bins, unsigned int empty, unsigned int memory) {
201  totalHistos_ += 1;
202  totalBins_ += bins;
204  totalMemory_ += memory;
205  }
207  indent.append(" ");
208  std::cout << indent << "I'm a " << name() << " whose father is " << getFather() << " with ID: " << id_
209  << " Histo: " << getHistos() << " Bins: " << getBins() << " EmptyBins: " << getEmptyBins()
210  << " Memory: " << getMemory() << " and my children are: " << std::endl;
211  for (auto& subfolder : subfolders_)
212  subfolder->dump(indent);
213  }
215 
216  void mainrows(std::string& sql_statement) {
217  std::stringstream s("");
218  s << "INSERT INTO mainrows(id, symbol_id, self_count, cumulative_count, kids, self_calls, total_calls, self_paths, "
219  "total_paths, pct)"
220  " VALUES("
221  << id_ << ", " << id_ << ", " << getMemory() << ", " << getMemory() << ", " << subfolders_.size() << ", "
222  << getBins() - getEmptyBins() << ", " << getBins() << ", " << getHistos() << ", " << getHistos() << ", 0.0);\n";
223  sql_statement.append(s.str());
224  for (auto& subfolder : subfolders_)
225  subfolder->mainrows(sql_statement);
226  }
227 
228  void symbols(std::string& sql_statement) {
229  unsigned int parentid = this->getFather() ? this->getFather()->id() : id_;
230  std::stringstream s("");
231  s << "INSERT INTO symbols(id, name, filename_id) VALUES (" << id_ << ",\"" << folderName_ << "\", " << parentid
232  << ");\n";
233  sql_statement.append(s.str());
234  for (auto& subfolder : subfolders_)
235  subfolder->symbols(sql_statement);
236  }
237 
238  void parents(std::string& sql_statement) {
239  unsigned int parentid = this->getFather() ? this->getFather()->id() : id_;
240  std::stringstream s("");
241  s << "INSERT INTO parents(self_id, child_id, to_child_count, to_child_calls, to_child_paths, pct) VALUES("
242  << parentid << "," << id_ << "," << totalMemory_ << "," << totalBins_ << "," << totalHistos_ << ",0"
243  << ");\n";
244  sql_statement.append(s.str());
245  for (auto& subfolder : subfolders_)
246  subfolder->parents(sql_statement);
247  }
248 
249  void children(std::string& sql_statement) {
250  unsigned int parentid = this->getFather() ? this->getFather()->id() : id_;
251  std::stringstream s("");
252  s << "INSERT INTO children(self_id, parent_id, from_parent_count, from_parent_calls, from_parent_paths, pct) "
253  "VALUES("
254  << id_ << "," << parentid << "," << getMemory() << "," << getBins() - getEmptyBins() << "," << totalHistos_
255  << ",0"
256  << ");\n";
257  sql_statement.append(s.str());
258  for (auto& subfolder : subfolders_)
259  subfolder->children(sql_statement);
260  }
261 
262  void mainrows_cumulative(std::string& sql_statement) {
263  std::stringstream s("");
264  s << "INSERT INTO mainrows(id, symbol_id, self_count, cumulative_count, kids, self_calls, total_calls, self_paths, "
265  "total_paths, pct)"
266  << " VALUES(" << id_ << "," << id_ << "," << 0 << "," << getMemory() << ", 0," << getBins() - getEmptyBins()
267  << "," << getBins() << ", 0, " << getHistos() << ", 0);\n";
268  sql_statement.append(s.str());
269  }
270 
271  void summary(std::string& sql_statement) {
272  std::stringstream s("");
273  s << "INSERT INTO summary(counter, total_count, total_freq, tick_period) VALUES (\"BINS_LIVE\"," << getMemory()
274  << "," << getBins() << ", 1);\n";
275  sql_statement.append(s.str());
276  }
277 
278  void files(std::string& sql_statement) {
279  std::stringstream s("");
280  s << "INSERT INTO files(id, name) VALUES(" << id_ << ",\"" << folderName_ << "\");\n";
281  sql_statement.append(s.str());
282  }
283 
284 private:
285  unsigned int totalHistos_;
286  unsigned int totalBins_;
287  unsigned int totalEmptyBins_;
288  unsigned int totalMemory_;
289  unsigned int id_;
290  unsigned int level_;
293  std::vector<Folder*> subfolders_;
294 };
295 
300 public:
302  ~DQMStoreStats() override;
303 
305 
306 protected:
307  // BeginJob
308  void beginJob() override;
309 
310  // BeginRun
311  void beginRun(const edm::Run& r, const edm::EventSetup& c) override;
312 
313  // Fake Analyze
314  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
315 
316  // DQM Client Diagnostic
317  void endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& c) override;
318 
319  // EndRun
320  void endRun(const edm::Run& r, const edm::EventSetup& c) override;
321 
322  // Endjob
323  void endJob() override;
324 
325 private:
326  int calcstats(int);
327  void calcIgProfDump(Folder&);
328  void dumpMemoryProfile();
329  std::pair<unsigned int, unsigned int> readMemoryEntry() const;
330  void print();
331 
334 
345 
348  int verbose_;
349 
350  std::vector<std::pair<time_t, unsigned int> > memoryHistoryVector_;
353  std::stringstream procFileName_;
354 
361 
362  // ---------- member data ----------
363 };
364 
365 #endif
DQMStoreStats::dumpMemHistory_
bool dumpMemHistory_
Definition: DQMStoreStats.h:359
DQMStoreStats::readMemoryEntry
std::pair< unsigned int, unsigned int > readMemoryEntry() const
Definition: DQMStoreStats.cc:628
Folder::totalEmptyBins_
unsigned int totalEmptyBins_
Definition: DQMStoreStats.h:287
DQMStoreStats::dbe_
DQMStore * dbe_
Definition: DQMStoreStats.h:332
Iterator::First
virtual void First()=0
VIterator::First
void First() override
Definition: DQMStoreStats.h:111
DQMStoreStats::endJob
void endJob() override
Definition: DQMStoreStats.cc:720
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
Folder::dump
void dump(std::string indent)
Definition: DQMStoreStats.h:206
Folder::level_
unsigned int level_
Definition: DQMStoreStats.h:290
DQMStoreStats::~DQMStoreStats
~DQMStoreStats() override
Iterator::Next
virtual void Next()=0
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
Iterator::Iterator
Iterator()=default
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
Folder::id
unsigned int id()
Definition: DQMStoreStats.h:165
edm::Run
Definition: Run.h:45
Folder::setFather
void setFather(Folder *e)
Definition: DQMStoreStats.h:151
Folder::summary
void summary(std::string &sql_statement)
Definition: DQMStoreStats.h:271
memory
Definition: HGCRecHitSoA.h:20
Folder::cd
Folder * cd(const std::string &name)
Definition: DQMStoreStats.h:155
gather_cfg.cout
cout
Definition: gather_cfg.py:144
DQMStoreStats::subsystem_
std::string subsystem_
Definition: DQMStoreStats.h:335
DQMStoreStats::endRun
void endRun(const edm::Run &r, const edm::EventSetup &c) override
Definition: DQMStoreStats.cc:709
Folder::totalHistos_
unsigned int totalHistos_
Definition: DQMStoreStats.h:285
Folder::~Folder
~Folder()
Definition: DQMStoreStats.h:146
DQMStore.h
DQMStoreStats::memoryHistoryVector_
std::vector< std::pair< time_t, unsigned int > > memoryHistoryVector_
Definition: DQMStoreStats.h:350
DQMStoreStatsSubfolder::totalMemory_
unsigned int totalMemory_
Definition: DQMStoreStats.h:53
Folder::getBins
unsigned int getBins()
Definition: DQMStoreStats.h:182
DQMStoreStatsSubfolder::AddBinsF
void AddBinsF(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:54
EDAnalyzer.h
DQMStoreStats::beginJob
void beginJob() override
Definition: DQMStoreStats.cc:655
Iterator
Definition: DQMStoreStats.h:94
Folder::name
const std::string & name()
Definition: DQMStoreStats.h:153
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
DQMStoreStats::nmeglobal_
int nmeglobal_
Definition: DQMStoreStats.h:339
VIterator::IsDone
bool IsDone() const override
Definition: DQMStoreStats.h:116
DQMStoreStats::startingTime_
time_t startingTime_
Definition: DQMStoreStats.h:351
DQMStoreStats::endLuminosityBlock
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
Definition: DQMStoreStats.cc:698
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
DQMStoreStatsSubfolder
Definition: DQMStoreStats.h:41
DQMStoreStatsTopLevel
Definition: DQMStoreStats.h:88
DQMStoreStats::statsMode
statsMode
Definition: DQMStoreStats.h:304
DQMStoreStats::DQMStoreStats
DQMStoreStats(const edm::ParameterSet &)
Definition: DQMStoreStats.cc:47
VIterator
Definition: DQMStoreStats.h:107
alignCSCRings.s
s
Definition: alignCSCRings.py:92
Folder::getMemory
unsigned int getMemory()
Definition: DQMStoreStats.h:194
DQMStoreStatsSubsystem
Definition: DQMStoreStats.h:78
dqm::legacy::DQMStore
Definition: DQMStore.h:727
Folder::files
void files(std::string &sql_statement)
Definition: DQMStoreStats.h:278
DQMStoreStatsSubfolder::totalHistos_
unsigned int totalHistos_
Definition: DQMStoreStats.h:50
DQMStoreStats::considerOnlyLumiProductME
Definition: DQMStoreStats.h:304
DQMStoreStatsSubfolder::DQMStoreStatsSubfolder
DQMStoreStatsSubfolder()
Definition: DQMStoreStats.h:43
Folder::Folder
Folder(std::string name)
Definition: DQMStoreStats.h:136
Iterator::~Iterator
virtual ~Iterator()=default
DQMStoreStats::isOpenProcFileSuccessful_
bool isOpenProcFileSuccessful_
Definition: DQMStoreStats.h:352
DQMStoreStats::runineventloop_
bool runineventloop_
Definition: DQMStoreStats.h:358
DQMStoreStats::analyze
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Definition: DQMStoreStats.cc:684
Folder::father_
Folder * father_
Definition: DQMStoreStats.h:292
seedmultiplicitymonitor_newtracking_cfi.nBins
nBins
Definition: seedmultiplicitymonitor_newtracking_cfi.py:8
DQMStoreStatsSubfolder::subfolderName_
std::string subfolderName_
Definition: DQMStoreStats.h:49
Folder::totalBins_
unsigned int totalBins_
Definition: DQMStoreStats.h:286
Folder::getEmptyBins
unsigned int getEmptyBins()
Definition: DQMStoreStats.h:188
DQMStoreStats::pathnamematch_
std::string pathnamematch_
Definition: DQMStoreStats.h:347
DQMStoreStats::dumpToFWJR_
bool dumpToFWJR_
Definition: DQMStoreStats.h:360
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DQMStoreStats
Definition: DQMStoreStats.h:299
DQMStoreStats::maxbinsmesubsys_
std::string maxbinsmesubsys_
Definition: DQMStoreStats.h:344
DQMStoreStats::print
void print()
Definition: DQMStoreStats.cc:614
DQMStoreStats::runonendjob_
bool runonendjob_
Definition: DQMStoreStats.h:356
Folder::parents
void parents(std::string &sql_statement)
Definition: DQMStoreStats.h:238
VIterator::vector_
const std::vector< Item > * vector_
Definition: DQMStoreStats.h:125
DQMStoreStats::maxbinsglobal_
int maxbinsglobal_
Definition: DQMStoreStats.h:341
Folder::folderName_
std::string folderName_
Definition: DQMStoreStats.h:291
Folder::mainrows
void mainrows(std::string &sql_statement)
Definition: DQMStoreStats.h:216
edm::ParameterSet
Definition: ParameterSet.h:47
Folder::totalMemory_
unsigned int totalMemory_
Definition: DQMStoreStats.h:288
Iterator::IsDone
virtual bool IsDone() const =0
Folder::setId
void setId(unsigned int id)
Definition: DQMStoreStats.h:164
DQMStoreStatsSubsystem::DQMStoreStatsSubsystem
DQMStoreStatsSubsystem()=default
DQMStoreStats::maxbinsmeglobal_
std::string maxbinsmeglobal_
Definition: DQMStoreStats.h:343
Folder::children
void children(std::string &sql_statement)
Definition: DQMStoreStats.h:249
DQMStoreStats::calcstats
int calcstats(int)
Definition: DQMStoreStats.cc:159
Folder
Definition: DQMStoreStats.h:134
DQMStoreStats::verbose_
int verbose_
Definition: DQMStoreStats.h:348
DQMStoreStats::considerAllME
Definition: DQMStoreStats.h:304
Folder::level
unsigned int level()
Definition: DQMStoreStats.h:167
DQMStoreStats::beginRun
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
Definition: DQMStoreStats.cc:679
Iterator::CurrentItem
virtual Item CurrentItem() const =0
DQMStoreStats::runonendrun_
bool runonendrun_
Definition: DQMStoreStats.h:355
value
Definition: value.py:1
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
DQMStoreStatsSubfolder::AddBinsS
void AddBinsS(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:60
Folder::getHistos
unsigned int getHistos()
Definition: DQMStoreStats.h:176
DQMStoreStats::maxbinssubsys_
int maxbinssubsys_
Definition: DQMStoreStats.h:342
edm::EventSetup
Definition: EventSetup.h:58
DQMStoreStats::statsdepth_
int statsdepth_
Definition: DQMStoreStats.h:346
DQMStoreStats::procFileName_
std::stringstream procFileName_
Definition: DQMStoreStats.h:353
DQMStoreStatsTopLevel::DQMStoreStatsTopLevel
DQMStoreStatsTopLevel()=default
DQMStoreStats::nbinsglobal_
int nbinsglobal_
Definition: DQMStoreStats.h:337
VIterator::getIndex
virtual int getIndex()
Definition: DQMStoreStats.h:114
VIterator::size
virtual int size()
Definition: DQMStoreStats.h:113
alignCSCRings.r
r
Definition: alignCSCRings.py:93
DQMStoreStatsSubfolder::AddBinsD
void AddBinsD(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:66
DQMStoreStats::subfolder_
std::string subfolder_
Definition: DQMStoreStats.h:336
Folder::symbols
void symbols(std::string &sql_statement)
Definition: DQMStoreStats.h:228
DQMStoreStats::nmesubsys_
int nmesubsys_
Definition: DQMStoreStats.h:340
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
VIterator::Next
void Next() override
Definition: DQMStoreStats.h:112
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
mps_setup.memory
memory
Definition: mps_setup.py:156
Folder::id_
unsigned int id_
Definition: DQMStoreStats.h:289
relativeConstraints.value
value
Definition: relativeConstraints.py:53
DQMStoreStats::calcIgProfDump
void calcIgProfDump(Folder &)
Definition: DQMStoreStats.cc:77
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
phase2tkutil::DQMStore
dqm::reco::DQMStore DQMStore
Definition: TrackerPhase2DQMUtil.h:16
DQMStoreStatsSubsystem::subsystemName_
std::string subsystemName_
Definition: DQMStoreStats.h:81
util.rrClient.indent
indent
Definition: rrClient.py:41
Folder::add
void add(Folder *f)
Definition: DQMStoreStats.h:169
VIterator::index
unsigned int index
Definition: DQMStoreStats.h:126
DQMStoreStatsSubfolder::totalBins_
unsigned int totalBins_
Definition: DQMStoreStats.h:51
Folder::mainrows_cumulative
void mainrows_cumulative(std::string &sql_statement)
Definition: DQMStoreStats.h:262
VIterator::VIterator
VIterator(const std::vector< Item > *aVector)
Definition: DQMStoreStats.h:109
VIterator::CurrentItem
Item CurrentItem() const override
Definition: DQMStoreStats.h:122
MonitorElement
dqm::legacy::MonitorElement MonitorElement
Definition: SiPixelSCurveCalibrationAnalysis.h:55
Folder::CreateIterator
VIterator< Folder * > CreateIterator()
Definition: DQMStoreStats.h:214
DQMStoreStats::nbinssubsys_
int nbinssubsys_
Definition: DQMStoreStats.h:338
mps_fire.result
result
Definition: mps_fire.py:311
Folder::subfolders_
std::vector< Folder * > subfolders_
Definition: DQMStoreStats.h:293
trigObjTnPSource_cfi.bins
bins
Definition: trigObjTnPSource_cfi.py:20
VIterator::~VIterator
~VIterator() override=default
ParameterSet.h
getId
static unsigned int getId()
Definition: DQMStoreStats.h:129
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
edm::Event
Definition: Event.h:73
DQMStoreStatsSubfolder::totalEmptyBins_
unsigned int totalEmptyBins_
Definition: DQMStoreStats.h:52
DQMStoreStats::parameters_
edm::ParameterSet parameters_
Definition: DQMStoreStats.h:333
Folder::setLevel
void setLevel(unsigned int value)
Definition: DQMStoreStats.h:166
DQMStoreStats::dumpMemoryProfile
void dumpMemoryProfile()
Definition: DQMStoreStats.cc:559
Folder::update
void update(unsigned int bins, unsigned int empty, unsigned int memory)
Definition: DQMStoreStats.h:200
DQMStoreStats::runonendlumi_
bool runonendlumi_
Definition: DQMStoreStats.h:357
Folder::getFather
Folder * getFather()
Definition: DQMStoreStats.h:152
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37