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 };
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),
143  folderName_(std::move(name)),
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
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_
std::string subsystemName_
Definition: DQMStoreStats.h:81
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)