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