CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DQMStoreStats.h
Go to the documentation of this file.
1 #ifndef DQMStoreStats_H
2 #define DQMStoreStats_H
3 
15 #include <string>
16 #include <sstream>
17 #include <vector>
18 #include <iostream>
19 #include <iomanip>
20 #include <utility>
21 #include <fstream>
22 #include <sstream>
23 
24 #include "TFile.h"
25 #include "TTree.h"
26 
31 
32 //
33 // class declarations
34 //
35 
36 
42  public:
44  std::string subfolderName_;
45  unsigned int totalHistos_;
46  unsigned int totalBins_;
47  unsigned int totalEmptyBins_;
48  unsigned int totalMemory_;
49  void AddBinsF( unsigned int nBins, unsigned int nEmptyBins ) { ++totalHistos_; totalBins_ += nBins; totalEmptyBins_ += nEmptyBins; totalMemory_ += ( nBins *= sizeof( float ) ); }
50  void AddBinsS( unsigned int nBins, unsigned int nEmptyBins ) { ++totalHistos_; totalBins_ += nBins; totalEmptyBins_ += nEmptyBins; totalMemory_ += ( nBins *= sizeof( short ) ); }
51  void AddBinsD( unsigned int nBins, unsigned int nEmptyBins ) { ++totalHistos_; totalBins_ += nBins; totalEmptyBins_ += nEmptyBins; totalMemory_ += ( nBins *= sizeof( double ) ); }
52 };
53 
58 class DQMStoreStatsSubsystem : public std::vector<DQMStoreStatsSubfolder> {
59  public:
61  std::string subsystemName_;
62 };
63 
64 
69 class DQMStoreStatsTopLevel : public std::vector<DQMStoreStatsSubsystem> {
70  public:
72 };
73 
74 template <class Item>
75 class Iterator {
76  public:
77  virtual void First() = 0;
78  virtual void Next() = 0;
79  virtual bool IsDone() const = 0;
80  virtual Item CurrentItem() const = 0;
81  protected:
82  Iterator(){;}
83 };
84 
85 template <class Item>
86 class VIterator : public Iterator<Item>
87 {
88  public:
89  VIterator(const std::vector<Item>* aVector):vector_(aVector),index(0) {;}
90 
91  virtual void First() {index=0;}
92  virtual void Next() { ++index;}
93  virtual int size() { return vector_->size();}
94  virtual int getIndex() { return (int)index;}
95 
96  virtual bool IsDone() const
97  {
98  if(index < (unsigned int)vector_->size()) return false ;
99  return true ;
100  }
101 
102  virtual Item CurrentItem() const
103  {
104  return vector_->operator[](index) ;
105  }
106 
107  private:
108  const std::vector<Item> * vector_ ;
109  unsigned int index ;
110 };
111 
112 static unsigned int getId(void)
113 {
114  static unsigned int id=10;
115  return ++id;
116 }
117 
118 
119 class Folder {
120 public:
121  Folder(const std::string name):totalHistos_(0),totalBins_(0),
123  id_(10),level_(0),folderName_(name),
124  father_(0){;}
125 
126  ~Folder(void) {
127  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i)
128  delete (*i);
129  }
130 
131  void setFather(Folder* e) {father_ = e;}
132  Folder * getFather() {return father_;}
133  const std::string & name(void) {return folderName_;}
134 
135  Folder * cd(const std::string &name) {
136  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i)
137  if ( (*i)->name()==name )
138  return (*i);
139  Folder * tmp = new Folder(name);
140  this->add(tmp);
141  return tmp;
142  }
143 
144  void setId(unsigned int id) {id_ = id;}
145  unsigned int id(void) {return id_;}
146  void setLevel(unsigned int value) {level_=value;}
147  unsigned int level(void) {return level_;}
148 
149 
150  void add(Folder * f) {
151  f->setFather(this);
152  subfolders_.push_back(f);
153  f->setLevel(level_+1);
154  f->setId(getId());
155  }
156 
157  unsigned int getHistos(void) {
158  unsigned int result=totalHistos_;
159  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i)
160  result += (*i)->getHistos();
161  return result;
162  }
163  unsigned int getBins(void) {
164  unsigned int result=totalBins_;
165  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i)
166  result += (*i)->getBins();
167  return result;
168  }
169  unsigned int getEmptyBins(void) {
170  unsigned int result=totalEmptyBins_;
171  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i)
172  result += (*i)->getEmptyBins();
173  return result;
174  }
175  unsigned int getMemory(void) {
176  unsigned int result=totalMemory_;
177  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i)
178  result += (*i)->getMemory();
179  return result;
180  }
181  void update(unsigned int bins,
182  unsigned int empty,
183  unsigned int memory) {
184  totalHistos_ += 1;
185  totalBins_ += bins;
187  totalMemory_ += memory;
188  }
189  void dump(std::string indent)
190  {
191  indent.append(" ");
192  std::cout << indent << "I'm a " << name() << " whose father is " << getFather()
193  << " with ID: " << id_
194  << " Histo: " << getHistos() << " Bins: " << getBins()
195  << " EmptyBins: " << getEmptyBins() << " Memory: " << getMemory()
196  << " and my children are: " << std::endl;
197  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i )
198  (*i)->dump(indent) ;
199  }
201  {
203  }
204 
205  void mainrows(std::string & sql_statement)
206  {
207  std::stringstream s("");
208  s << "INSERT INTO mainrows(id, symbol_id, self_count, cumulative_count, kids, self_calls, total_calls, self_paths, total_paths, pct)"
209  " VALUES(" << id_ << ", " << id_ << ", "
210  << getMemory() << ", " << getMemory() << ", " << subfolders_.size() << ", "
211  << getBins() - getEmptyBins() << ", " << getBins() << ", "
212  << getHistos() << ", " << getHistos() << ", 0.0);\n";
213  sql_statement.append(s.str());
214  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i )
215  (*i)->mainrows(sql_statement) ;
216  }
217 
218  void symbols(std::string & sql_statement)
219  {
220  unsigned int parentid = this->getFather() ? this->getFather()->id() : id_;
221  std::stringstream s("");
222  s << "INSERT INTO symbols(id, name, filename_id) VALUES (" << id_ << ",\"" << folderName_ << "\", "
223  << parentid << ");\n" ;
224  sql_statement.append(s.str());
225  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i )
226  (*i)->symbols(sql_statement) ;
227  }
228 
229  void parents(std::string & sql_statement)
230  {
231  unsigned int parentid = this->getFather() ? this->getFather()->id() : id_;
232  std::stringstream s("");
233  s << "INSERT INTO parents(self_id, child_id, to_child_count, to_child_calls, to_child_paths, pct) VALUES("
234  << parentid << "," << id_ << "," << totalMemory_ << ","
235  << totalBins_ << "," << totalHistos_ << ",0" << ");\n";
236  sql_statement.append(s.str());
237  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i )
238  (*i)->parents(sql_statement) ;
239  }
240 
241  void children(std::string & sql_statement)
242  {
243  unsigned int parentid = this->getFather() ? this->getFather()->id() : id_;
244  std::stringstream s("");
245  s << "INSERT INTO children(self_id, parent_id, from_parent_count, from_parent_calls, from_parent_paths, pct) VALUES("
246  << id_ << "," << parentid << ","
247  << getMemory() << "," << getBins() - getEmptyBins()
248  << "," << totalHistos_ << ",0" << ");\n";
249  sql_statement.append(s.str());
250  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i )
251  (*i)->children(sql_statement) ;
252  }
253 
254  void mainrows_cumulative(std::string & sql_statement)
255  {
256  std::stringstream s("");
257  s << "INSERT INTO mainrows(id, symbol_id, self_count, cumulative_count, kids, self_calls, total_calls, self_paths, total_paths, pct)"
258  << " VALUES(" << id_ << "," << id_ << "," << 0 << "," << getMemory() << ", 0,"
259  << getBins()-getEmptyBins() << "," << getBins()
260  << ", 0, " << getHistos() << ", 0);\n";
261  sql_statement.append(s.str());
262  }
263 
264  void summary(std::string & sql_statement)
265  {
266  std::stringstream s("");
267  s << "INSERT INTO summary(counter, total_count, total_freq, tick_period) VALUES (\"BINS_LIVE\","
268  << getMemory() << "," << getBins() << ", 1);\n";
269  sql_statement.append(s.str());
270  }
271 
272  void files(std::string & sql_statement)
273  {
274  std::stringstream s("");
275  s << "INSERT INTO files(id, name) VALUES(" << id_ << ",\"" << folderName_ << "\");\n" ;
276  sql_statement.append(s.str());
277  }
278 
279 private:
280  unsigned int totalHistos_;
281  unsigned int totalBins_;
282  unsigned int totalEmptyBins_;
283  unsigned int totalMemory_;
284  unsigned int id_;
285  unsigned int level_;
286  std::string folderName_;
288  std::vector<Folder*> subfolders_;
289 };
290 
295 public:
297  ~DQMStoreStats();
298 
300 
301 protected:
302 
303  // BeginJob
304  void beginJob();
305 
306  // BeginRun
307  void beginRun(const edm::Run& r, const edm::EventSetup& c);
308 
309  // Fake Analyze
310  void analyze(const edm::Event& e, const edm::EventSetup& c);
311 
312  void beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
313  const edm::EventSetup& context);
314 
315  // DQM Client Diagnostic
316  void endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
317  const edm::EventSetup& c);
318 
319  // EndRun
320  void endRun(const edm::Run& r, const edm::EventSetup& c);
321 
322  // Endjob
323  void endJob();
324 
325 private:
326 
327  int calcstats( int );
328  void calcIgProfDump(Folder &);
329  void dumpMemoryProfile( void );
330  std::pair<unsigned int, unsigned int> readMemoryEntry( void ) const;
331  void print();
332 
335 
336  std::string subsystem_;
337  std::string subfolder_;
344  std::string maxbinsmeglobal_;
345  std::string maxbinsmesubsys_;
346 
348  std::string pathnamematch_ ;
349  int verbose_ ;
350 
351  std::vector<std::pair<time_t, unsigned int> > memoryHistoryVector_;
354  std::stringstream procFileName_;
355 
362 
363  // ---------- member data ----------
364 
365 };
366 
367 #endif
368 
std::string subfolderName_
Definition: DQMStoreStats.h:44
int i
Definition: DBlmapReader.cc:9
virtual void Next()=0
virtual bool IsDone() const =0
DQMStore * dbe_
void AddBinsS(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:50
virtual void First()
Definition: DQMStoreStats.h:91
void update(unsigned int bins, unsigned int empty, unsigned int memory)
virtual Item CurrentItem() const =0
Definition: vlib.h:187
void beginRun(const edm::Run &r, const edm::EventSetup &c)
void AddBinsD(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:51
virtual bool IsDone() const
Definition: DQMStoreStats.h:96
static unsigned int getId(void)
virtual void First()=0
VIterator(const std::vector< Item > *aVector)
Definition: DQMStoreStats.h:89
std::vector< std::pair< time_t, unsigned int > > memoryHistoryVector_
std::string subsystemName_
Definition: DQMStoreStats.h:61
void add(Folder *f)
unsigned int getBins(void)
unsigned int totalBins_
void mainrows_cumulative(std::string &sql_statement)
VIterator< Folder * > CreateIterator()
unsigned int totalBins_
Definition: DQMStoreStats.h:46
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
time_t startingTime_
void endRun(const edm::Run &r, const edm::EventSetup &c)
virtual int getIndex()
Definition: DQMStoreStats.h:94
unsigned int totalMemory_
void summary(std::string &sql_statement)
const std::string & name(void)
std::string subsystem_
std::string maxbinsmeglobal_
void mainrows(std::string &sql_statement)
std::vector< Folder * > subfolders_
int calcstats(int)
unsigned int level(void)
bool isOpenProcFileSuccessful_
unsigned int totalEmptyBins_
void setLevel(unsigned int value)
unsigned int totalEmptyBins_
Definition: DQMStoreStats.h:47
Folder * getFather()
std::pair< unsigned int, unsigned int > readMemoryEntry(void) const
tuple result
Definition: query.py:137
std::string pathnamematch_
std::string maxbinsmesubsys_
double f[11][100]
DQMStoreStats(const edm::ParameterSet &)
unsigned int getHistos(void)
void files(std::string &sql_statement)
void setFather(Folder *e)
void dump(std::string indent)
virtual void Next()
Definition: DQMStoreStats.h:92
unsigned int index
Folder * father_
virtual int size()
Definition: DQMStoreStats.h:93
virtual Item CurrentItem() const
unsigned int totalHistos_
unsigned int level_
void parents(std::string &sql_statement)
std::string subfolder_
Folder(const std::string name)
Folder * cd(const std::string &name)
edm::ParameterSet parameters_
void dumpMemoryProfile(void)
unsigned int totalMemory_
Definition: DQMStoreStats.h:48
unsigned int getEmptyBins(void)
void AddBinsF(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:49
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
void children(std::string &sql_statement)
void calcIgProfDump(Folder &)
unsigned int id(void)
~Folder(void)
unsigned int totalHistos_
Definition: DQMStoreStats.h:45
tuple cout
Definition: gather_cfg.py:121
const std::vector< Item > * vector_
std::stringstream procFileName_
void analyze(const edm::Event &e, const edm::EventSetup &c)
void symbols(std::string &sql_statement)
unsigned int getMemory(void)
unsigned int id_
std::string folderName_
Definition: Run.h:33
void setId(unsigned int id)