test
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 
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 void First() = 0;
76  virtual void Next() = 0;
77  virtual bool IsDone() const = 0;
78  virtual Item CurrentItem() const = 0;
79  protected:
80  Iterator(){;}
81 };
82 
83 template <class Item>
84 class VIterator : public Iterator<Item>
85 {
86  public:
87  VIterator(const std::vector<Item>* aVector):vector_(aVector),index(0) {;}
88 
89  virtual void First() {index=0;}
90  virtual void Next() { ++index;}
91  virtual int size() { return vector_->size();}
92  virtual int getIndex() { return (int)index;}
93 
94  virtual bool IsDone() const
95  {
96  if(index < (unsigned int)vector_->size()) return false ;
97  return true ;
98  }
99 
100  virtual Item CurrentItem() const
101  {
102  return vector_->operator[](index) ;
103  }
104 
105  private:
106  const std::vector<Item> * vector_ ;
107  unsigned int index ;
108 };
109 
110 static unsigned int getId(void)
111 {
112  static unsigned int id=10;
113  return ++id;
114 }
115 
116 
117 class Folder {
118 public:
121  id_(10),level_(0),folderName_(name),
122  father_(0){;}
123 
124  ~Folder(void) {
125  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i)
126  delete (*i);
127  }
128 
129  void setFather(Folder* e) {father_ = e;}
130  Folder * getFather() {return father_;}
131  const std::string & name(void) {return folderName_;}
132 
133  Folder * cd(const std::string &name) {
134  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i)
135  if ( (*i)->name()==name )
136  return (*i);
137  Folder * tmp = new Folder(name);
138  this->add(tmp);
139  return tmp;
140  }
141 
142  void setId(unsigned int id) {id_ = id;}
143  unsigned int id(void) {return id_;}
144  void setLevel(unsigned int value) {level_=value;}
145  unsigned int level(void) {return level_;}
146 
147 
148  void add(Folder * f) {
149  f->setFather(this);
150  subfolders_.push_back(f);
151  f->setLevel(level_+1);
152  f->setId(getId());
153  }
154 
155  unsigned int getHistos(void) {
156  unsigned int result=totalHistos_;
157  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i)
158  result += (*i)->getHistos();
159  return result;
160  }
161  unsigned int getBins(void) {
162  unsigned int result=totalBins_;
163  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i)
164  result += (*i)->getBins();
165  return result;
166  }
167  unsigned int getEmptyBins(void) {
168  unsigned int result=totalEmptyBins_;
169  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i)
170  result += (*i)->getEmptyBins();
171  return result;
172  }
173  unsigned int getMemory(void) {
174  unsigned int result=totalMemory_;
175  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i)
176  result += (*i)->getMemory();
177  return result;
178  }
179  void update(unsigned int bins,
180  unsigned int empty,
181  unsigned int memory) {
182  totalHistos_ += 1;
183  totalBins_ += bins;
185  totalMemory_ += memory;
186  }
188  {
189  indent.append(" ");
190  std::cout << indent << "I'm a " << name() << " whose father is " << getFather()
191  << " with ID: " << id_
192  << " Histo: " << getHistos() << " Bins: " << getBins()
193  << " EmptyBins: " << getEmptyBins() << " Memory: " << getMemory()
194  << " and my children are: " << std::endl;
195  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i )
196  (*i)->dump(indent) ;
197  }
199  {
201  }
202 
203  void mainrows(std::string & sql_statement)
204  {
205  std::stringstream s("");
206  s << "INSERT INTO mainrows(id, symbol_id, self_count, cumulative_count, kids, self_calls, total_calls, self_paths, total_paths, pct)"
207  " VALUES(" << id_ << ", " << id_ << ", "
208  << getMemory() << ", " << getMemory() << ", " << subfolders_.size() << ", "
209  << getBins() - getEmptyBins() << ", " << getBins() << ", "
210  << getHistos() << ", " << getHistos() << ", 0.0);\n";
211  sql_statement.append(s.str());
212  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i )
213  (*i)->mainrows(sql_statement) ;
214  }
215 
216  void symbols(std::string & sql_statement)
217  {
218  unsigned int parentid = this->getFather() ? this->getFather()->id() : id_;
219  std::stringstream s("");
220  s << "INSERT INTO symbols(id, name, filename_id) VALUES (" << id_ << ",\"" << folderName_ << "\", "
221  << parentid << ");\n" ;
222  sql_statement.append(s.str());
223  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i )
224  (*i)->symbols(sql_statement) ;
225  }
226 
227  void parents(std::string & sql_statement)
228  {
229  unsigned int parentid = this->getFather() ? this->getFather()->id() : id_;
230  std::stringstream s("");
231  s << "INSERT INTO parents(self_id, child_id, to_child_count, to_child_calls, to_child_paths, pct) VALUES("
232  << parentid << "," << id_ << "," << totalMemory_ << ","
233  << totalBins_ << "," << totalHistos_ << ",0" << ");\n";
234  sql_statement.append(s.str());
235  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i )
236  (*i)->parents(sql_statement) ;
237  }
238 
239  void children(std::string & sql_statement)
240  {
241  unsigned int parentid = this->getFather() ? this->getFather()->id() : id_;
242  std::stringstream s("");
243  s << "INSERT INTO children(self_id, parent_id, from_parent_count, from_parent_calls, from_parent_paths, pct) VALUES("
244  << id_ << "," << parentid << ","
245  << getMemory() << "," << getBins() - getEmptyBins()
246  << "," << totalHistos_ << ",0" << ");\n";
247  sql_statement.append(s.str());
248  for(std::vector<Folder*>::iterator i = subfolders_.begin(), e = subfolders_.end() ; i != e ; ++i )
249  (*i)->children(sql_statement) ;
250  }
251 
252  void mainrows_cumulative(std::string & sql_statement)
253  {
254  std::stringstream s("");
255  s << "INSERT INTO mainrows(id, symbol_id, self_count, cumulative_count, kids, self_calls, total_calls, self_paths, total_paths, pct)"
256  << " VALUES(" << id_ << "," << id_ << "," << 0 << "," << getMemory() << ", 0,"
257  << getBins()-getEmptyBins() << "," << getBins()
258  << ", 0, " << getHistos() << ", 0);\n";
259  sql_statement.append(s.str());
260  }
261 
262  void summary(std::string & sql_statement)
263  {
264  std::stringstream s("");
265  s << "INSERT INTO summary(counter, total_count, total_freq, tick_period) VALUES (\"BINS_LIVE\","
266  << getMemory() << "," << getBins() << ", 1);\n";
267  sql_statement.append(s.str());
268  }
269 
270  void files(std::string & sql_statement)
271  {
272  std::stringstream s("");
273  s << "INSERT INTO files(id, name) VALUES(" << id_ << ",\"" << folderName_ << "\");\n" ;
274  sql_statement.append(s.str());
275  }
276 
277 private:
278  unsigned int totalHistos_;
279  unsigned int totalBins_;
280  unsigned int totalEmptyBins_;
281  unsigned int totalMemory_;
282  unsigned int id_;
283  unsigned int level_;
286  std::vector<Folder*> subfolders_;
287 };
288 
293 public:
295  ~DQMStoreStats();
296 
298 
299 protected:
300 
301  // BeginJob
302  void beginJob();
303 
304  // BeginRun
305  void beginRun(const edm::Run& r, const edm::EventSetup& c);
306 
307  // Fake Analyze
308  void analyze(const edm::Event& e, const edm::EventSetup& c);
309 
310  void beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
311  const edm::EventSetup& context);
312 
313  // DQM Client Diagnostic
314  void endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
315  const edm::EventSetup& c);
316 
317  // EndRun
318  void endRun(const edm::Run& r, const edm::EventSetup& c);
319 
320  // Endjob
321  void endJob();
322 
323 private:
324 
325  int calcstats( int );
326  void calcIgProfDump(Folder &);
327  void dumpMemoryProfile( void );
328  std::pair<unsigned int, unsigned int> readMemoryEntry( void ) const;
329  void print();
330 
333 
344 
347  int verbose_ ;
348 
349  std::vector<std::pair<time_t, unsigned int> > memoryHistoryVector_;
352  std::stringstream procFileName_;
353 
360 
361  // ---------- member data ----------
362 
363 };
364 
365 #endif
366 
std::string subfolderName_
Definition: DQMStoreStats.h:42
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:48
virtual void First()
Definition: DQMStoreStats.h:89
void update(unsigned int bins, unsigned int empty, unsigned int memory)
virtual Item CurrentItem() const =0
Definition: vlib.h:186
void beginRun(const edm::Run &r, const edm::EventSetup &c)
void AddBinsD(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:49
virtual bool IsDone() const
Definition: DQMStoreStats.h:94
static unsigned int getId(void)
virtual void First()=0
VIterator(const std::vector< Item > *aVector)
Definition: DQMStoreStats.h:87
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
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:92
unsigned int totalMemory_
void summary(std::string &sql_statement)
const std::string & name(void)
tuple result
Definition: mps_fire.py:84
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:45
Folder * getFather()
std::pair< unsigned int, unsigned int > readMemoryEntry(void) const
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:90
unsigned int index
Folder * father_
virtual int size()
Definition: DQMStoreStats.h:91
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:46
unsigned int getEmptyBins(void)
void AddBinsF(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:47
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:43
tuple cout
Definition: gather_cfg.py:145
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:42
void setId(unsigned int id)