CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  void AddBinsI(unsigned int nBins, unsigned int nEmptyBins) {
73  ++totalHistos_;
74  totalBins_ += nBins;
75  totalEmptyBins_ += nEmptyBins;
76  totalMemory_ += (nBins *= sizeof(int));
77  }
78 };
79 
84 class DQMStoreStatsSubsystem : public std::vector<DQMStoreStatsSubfolder> {
85 public:
86  DQMStoreStatsSubsystem() = default;
88 };
89 
94 class DQMStoreStatsTopLevel : public std::vector<DQMStoreStatsSubsystem> {
95 public:
96  DQMStoreStatsTopLevel() = default;
97 };
98 
99 template <class Item>
100 class Iterator {
101 public:
102  virtual ~Iterator() = default;
103  virtual void First() = 0;
104  virtual void Next() = 0;
105  virtual bool IsDone() const = 0;
106  virtual Item CurrentItem() const = 0;
107 
108 protected:
109  Iterator() = default;
110 };
111 
112 template <class Item>
113 class VIterator : public Iterator<Item> {
114 public:
115  VIterator(const std::vector<Item>* aVector) : vector_(aVector), index(0) {}
116  ~VIterator() override = default;
117  void First() override { index = 0; }
118  void Next() override { ++index; }
119  virtual int size() { return vector_->size(); }
120  virtual int getIndex() { return (int)index; }
121 
122  bool IsDone() const override {
123  if (index < (unsigned int)vector_->size())
124  return false;
125  return true;
126  }
127 
128  Item CurrentItem() const override { return vector_->operator[](index); }
129 
130 private:
131  const std::vector<Item>* vector_;
132  unsigned int index;
133 };
134 
135 static unsigned int getId() {
136  static unsigned int id = 10;
137  return ++id;
138 }
139 
140 class Folder {
141 public:
143  : totalHistos_(0),
144  totalBins_(0),
145  totalEmptyBins_(0),
146  totalMemory_(0),
147  id_(10),
148  level_(0),
149  folderName_(std::move(name)),
150  father_(nullptr) {}
151 
153  for (auto& subfolder : subfolders_)
154  delete subfolder;
155  }
156 
157  void setFather(Folder* e) { father_ = e; }
158  Folder* getFather() { return father_; }
159  const std::string& name() { return folderName_; }
160 
162  for (auto& subfolder : subfolders_)
163  if (subfolder->name() == name)
164  return subfolder;
165  auto* tmp = new Folder(name);
166  this->add(tmp);
167  return tmp;
168  }
169 
170  void setId(unsigned int id) { id_ = id; }
171  unsigned int id() { return id_; }
172  void setLevel(unsigned int value) { level_ = value; }
173  unsigned int level() { return level_; }
174 
175  void add(Folder* f) {
176  f->setFather(this);
177  subfolders_.push_back(f);
178  f->setLevel(level_ + 1);
179  f->setId(getId());
180  }
181 
182  unsigned int getHistos() {
183  unsigned int result = totalHistos_;
184  for (auto& subfolder : subfolders_)
185  result += subfolder->getHistos();
186  return result;
187  }
188  unsigned int getBins() {
189  unsigned int result = totalBins_;
190  for (auto& subfolder : subfolders_)
191  result += subfolder->getBins();
192  return result;
193  }
194  unsigned int getEmptyBins() {
195  unsigned int result = totalEmptyBins_;
196  for (auto& subfolder : subfolders_)
197  result += subfolder->getEmptyBins();
198  return result;
199  }
200  unsigned int getMemory() {
201  unsigned int result = totalMemory_;
202  for (auto& subfolder : subfolders_)
203  result += subfolder->getMemory();
204  return result;
205  }
206  void update(unsigned int bins, unsigned int empty, unsigned int memory) {
207  totalHistos_ += 1;
208  totalBins_ += bins;
210  totalMemory_ += memory;
211  }
213  indent.append(" ");
214  std::cout << indent << "I'm a " << name() << " whose father is " << getFather() << " with ID: " << id_
215  << " Histo: " << getHistos() << " Bins: " << getBins() << " EmptyBins: " << getEmptyBins()
216  << " Memory: " << getMemory() << " and my children are: " << std::endl;
217  for (auto& subfolder : subfolders_)
218  subfolder->dump(indent);
219  }
221 
222  void mainrows(std::string& sql_statement) {
223  std::stringstream s("");
224  s << "INSERT INTO mainrows(id, symbol_id, self_count, cumulative_count, kids, self_calls, total_calls, self_paths, "
225  "total_paths, pct)"
226  " VALUES("
227  << id_ << ", " << id_ << ", " << getMemory() << ", " << getMemory() << ", " << subfolders_.size() << ", "
228  << getBins() - getEmptyBins() << ", " << getBins() << ", " << getHistos() << ", " << getHistos() << ", 0.0);\n";
229  sql_statement.append(s.str());
230  for (auto& subfolder : subfolders_)
231  subfolder->mainrows(sql_statement);
232  }
233 
234  void symbols(std::string& sql_statement) {
235  unsigned int parentid = this->getFather() ? this->getFather()->id() : id_;
236  std::stringstream s("");
237  s << "INSERT INTO symbols(id, name, filename_id) VALUES (" << id_ << ",\"" << folderName_ << "\", " << parentid
238  << ");\n";
239  sql_statement.append(s.str());
240  for (auto& subfolder : subfolders_)
241  subfolder->symbols(sql_statement);
242  }
243 
244  void parents(std::string& sql_statement) {
245  unsigned int parentid = this->getFather() ? this->getFather()->id() : id_;
246  std::stringstream s("");
247  s << "INSERT INTO parents(self_id, child_id, to_child_count, to_child_calls, to_child_paths, pct) VALUES("
248  << parentid << "," << id_ << "," << totalMemory_ << "," << totalBins_ << "," << totalHistos_ << ",0"
249  << ");\n";
250  sql_statement.append(s.str());
251  for (auto& subfolder : subfolders_)
252  subfolder->parents(sql_statement);
253  }
254 
255  void children(std::string& sql_statement) {
256  unsigned int parentid = this->getFather() ? this->getFather()->id() : id_;
257  std::stringstream s("");
258  s << "INSERT INTO children(self_id, parent_id, from_parent_count, from_parent_calls, from_parent_paths, pct) "
259  "VALUES("
260  << id_ << "," << parentid << "," << getMemory() << "," << getBins() - getEmptyBins() << "," << totalHistos_
261  << ",0"
262  << ");\n";
263  sql_statement.append(s.str());
264  for (auto& subfolder : subfolders_)
265  subfolder->children(sql_statement);
266  }
267 
268  void mainrows_cumulative(std::string& sql_statement) {
269  std::stringstream s("");
270  s << "INSERT INTO mainrows(id, symbol_id, self_count, cumulative_count, kids, self_calls, total_calls, self_paths, "
271  "total_paths, pct)"
272  << " VALUES(" << id_ << "," << id_ << "," << 0 << "," << getMemory() << ", 0," << getBins() - getEmptyBins()
273  << "," << getBins() << ", 0, " << getHistos() << ", 0);\n";
274  sql_statement.append(s.str());
275  }
276 
277  void summary(std::string& sql_statement) {
278  std::stringstream s("");
279  s << "INSERT INTO summary(counter, total_count, total_freq, tick_period) VALUES (\"BINS_LIVE\"," << getMemory()
280  << "," << getBins() << ", 1);\n";
281  sql_statement.append(s.str());
282  }
283 
284  void files(std::string& sql_statement) {
285  std::stringstream s("");
286  s << "INSERT INTO files(id, name) VALUES(" << id_ << ",\"" << folderName_ << "\");\n";
287  sql_statement.append(s.str());
288  }
289 
290 private:
291  unsigned int totalHistos_;
292  unsigned int totalBins_;
293  unsigned int totalEmptyBins_;
294  unsigned int totalMemory_;
295  unsigned int id_;
296  unsigned int level_;
299  std::vector<Folder*> subfolders_;
300 };
301 
306 public:
308  ~DQMStoreStats() override;
309 
311 
312 protected:
313  // BeginJob
314  void beginJob() override;
315 
316  // BeginRun
317  void beginRun(const edm::Run& r, const edm::EventSetup& c) override;
318 
319  // Fake Analyze
320  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
321 
322  // DQM Client Diagnostic
323  void endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& c) override;
324 
325  // EndRun
326  void endRun(const edm::Run& r, const edm::EventSetup& c) override;
327 
328  // Endjob
329  void endJob() override;
330 
331 private:
332  int calcstats(int);
333  void calcIgProfDump(Folder&);
334  void dumpMemoryProfile();
335  std::pair<unsigned int, unsigned int> readMemoryEntry() const;
336  void print();
337 
340 
351 
354  int verbose_;
355 
356  std::vector<std::pair<time_t, unsigned int> > memoryHistoryVector_;
359  std::stringstream procFileName_;
360 
367 
368  // ---------- member data ----------
369 };
370 
371 #endif
std::string subfolderName_
Definition: DQMStoreStats.h:49
static unsigned int getId()
virtual void Next()=0
virtual bool IsDone() const =0
DQMStore * dbe_
const edm::EventSetup & c
unsigned int getHistos()
void AddBinsS(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:60
void endJob() override
~VIterator() override=default
DQMStoreStatsSubsystem()=default
void update(unsigned int bins, unsigned int empty, unsigned int memory)
uint16_t *__restrict__ id
virtual Item CurrentItem() const =0
virtual ~Iterator()=default
unsigned int level()
void AddBinsD(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:66
virtual void First()=0
VIterator(const std::vector< Item > *aVector)
std::vector< std::pair< time_t, unsigned int > > memoryHistoryVector_
void AddBinsI(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:72
std::string subsystemName_
Definition: DQMStoreStats.h:87
void add(Folder *f)
Folder(std::string name)
void beginJob() override
unsigned int totalBins_
void mainrows_cumulative(std::string &sql_statement)
unsigned int getEmptyBins()
VIterator< Folder * > CreateIterator()
unsigned int totalBins_
Definition: DQMStoreStats.h:51
time_t startingTime_
virtual int getIndex()
unsigned int totalMemory_
void summary(std::string &sql_statement)
tuple result
Definition: mps_fire.py:311
dqm::reco::DQMStore DQMStore
std::string subsystem_
std::string maxbinsmeglobal_
void endRun(const edm::Run &r, const edm::EventSetup &c) override
void mainrows(std::string &sql_statement)
DQMStoreStatsTopLevel()=default
std::vector< Folder * > subfolders_
int calcstats(int)
const std::string & name()
unsigned int getBins()
bool isOpenProcFileSuccessful_
unsigned int totalEmptyBins_
void setLevel(unsigned int value)
unsigned int totalEmptyBins_
Definition: DQMStoreStats.h:52
Folder * getFather()
def move
Definition: eostools.py:511
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
Item CurrentItem() const override
std::string pathnamematch_
std::string maxbinsmesubsys_
DQMStoreStats(const edm::ParameterSet &)
void files(std::string &sql_statement)
unsigned int id()
void Next() override
void setFather(Folder *e)
void dump(std::string indent)
unsigned int index
Folder * father_
virtual int size()
unsigned int totalHistos_
void analyze(const edm::Event &e, const edm::EventSetup &c) override
unsigned int level_
void parents(std::string &sql_statement)
bool IsDone() const override
dqm::legacy::MonitorElement MonitorElement
void First() override
std::string subfolder_
Folder * cd(const std::string &name)
edm::ParameterSet parameters_
unsigned int totalMemory_
Definition: DQMStoreStats.h:53
void AddBinsF(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:54
void children(std::string &sql_statement)
void calcIgProfDump(Folder &)
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
std::pair< unsigned int, unsigned int > readMemoryEntry() const
unsigned int totalHistos_
Definition: DQMStoreStats.h:50
tuple cout
Definition: gather_cfg.py:144
const std::vector< Item > * vector_
unsigned int getMemory()
std::stringstream procFileName_
~DQMStoreStats() override
tmp
align.sh
Definition: createJobs.py:716
void dumpMemoryProfile()
void symbols(std::string &sql_statement)
unsigned int id_
Iterator()=default
std::string folderName_
Definition: Run.h:45
void setId(unsigned int id)