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 <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 
30 
31 //
32 // class declarations
33 //
34 
35 
41  public:
44  unsigned int totalHistos_;
45  unsigned int totalBins_;
46  unsigned int totalEmptyBins_;
47  unsigned int totalMemory_;
48  void AddBinsF( unsigned int nBins, unsigned int nEmptyBins ) { ++totalHistos_; totalBins_ += nBins; totalEmptyBins_ += nEmptyBins; totalMemory_ += ( nBins *= sizeof( float ) ); }
49  void AddBinsS( unsigned int nBins, unsigned int nEmptyBins ) { ++totalHistos_; totalBins_ += nBins; totalEmptyBins_ += nEmptyBins; totalMemory_ += ( nBins *= sizeof( short ) ); }
50  void AddBinsD( unsigned int nBins, unsigned int nEmptyBins ) { ++totalHistos_; totalBins_ += nBins; totalEmptyBins_ += nEmptyBins; totalMemory_ += ( nBins *= sizeof( double ) ); }
51 };
52 
57 class DQMStoreStatsSubsystem : public std::vector<DQMStoreStatsSubfolder> {
58  public:
59  DQMStoreStatsSubsystem() = default;
61 };
62 
63 
68 class DQMStoreStatsTopLevel : public std::vector<DQMStoreStatsSubsystem> {
69  public:
70  DQMStoreStatsTopLevel() = default;
71 };
72 
73 template <class Item>
74 class Iterator {
75  public:
76  virtual ~Iterator() = default;
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() = default;
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  ~VIterator() override = default;
91  void First() override {index=0;}
92  void Next() override { ++index;}
93  virtual int size() { return vector_->size();}
94  virtual int getIndex() { return (int)index;}
95 
96  bool IsDone() const override
97  {
98  if(index < (unsigned int)vector_->size()) return false ;
99  return true ;
100  }
101 
102  Item CurrentItem() const override
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()
113 {
114  static unsigned int id=10;
115  return ++id;
116 }
117 
118 
119 class Folder {
120 public:
123  id_(10),level_(0),folderName_(std::move(name)),
124  father_(nullptr) {}
125 
127  for(auto & subfolder : subfolders_)
128  delete subfolder;
129  }
130 
131  void setFather(Folder* e) {father_ = e;}
132  Folder * getFather() {return father_;}
133  const std::string & name() {return folderName_;}
134 
135  Folder * cd(const std::string &name) {
136  for(auto & subfolder : subfolders_)
137  if ( subfolder->name()==name )
138  return subfolder;
139  auto * 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() {return id_;}
146  void setLevel(unsigned int value) {level_=value;}
147  unsigned int level() {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() {
158  unsigned int result=totalHistos_;
159  for(auto & subfolder : subfolders_)
160  result += subfolder->getHistos();
161  return result;
162  }
163  unsigned int getBins() {
164  unsigned int result=totalBins_;
165  for(auto & subfolder : subfolders_)
166  result += subfolder->getBins();
167  return result;
168  }
169  unsigned int getEmptyBins() {
170  unsigned int result=totalEmptyBins_;
171  for(auto & subfolder : subfolders_)
172  result += subfolder->getEmptyBins();
173  return result;
174  }
175  unsigned int getMemory() {
176  unsigned int result=totalMemory_;
177  for(auto & subfolder : subfolders_)
178  result += subfolder->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  }
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(auto & subfolder : subfolders_)
198  subfolder->dump(indent) ;
199  }
201  {
202  return VIterator<Folder *>(&subfolders_) ;
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(auto & subfolder : subfolders_)
215  subfolder->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(auto & subfolder : subfolders_)
226  subfolder->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(auto & subfolder : subfolders_)
238  subfolder->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(auto & subfolder : subfolders_)
251  subfolder->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_;
288  std::vector<Folder*> subfolders_;
289 };
290 
295 public:
297  ~DQMStoreStats() override;
298 
299  enum statsMode { considerAllME = 0, considerOnlyLumiProductME = 1 };
300 
301 protected:
302 
303  // BeginJob
304  void beginJob() override;
305 
306  // BeginRun
307  void beginRun(const edm::Run& r, const edm::EventSetup& c) override;
308 
309  // Fake Analyze
310  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
311 
312 
313  // DQM Client Diagnostic
314  void endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
315  const edm::EventSetup& c) override;
316 
317  // EndRun
318  void endRun(const edm::Run& r, const edm::EventSetup& c) override;
319 
320  // Endjob
321  void endJob() override;
322 
323 private:
324 
325  int calcstats( int );
326  void calcIgProfDump(Folder &);
327  void dumpMemoryProfile( );
328  std::pair<unsigned int, unsigned int> readMemoryEntry( ) 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:43
static unsigned int getId()
DQMStore * dbe_
unsigned int getHistos()
void AddBinsS(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:49
void update(unsigned int bins, unsigned int empty, unsigned int memory)
unsigned int level()
Definition: vlib.h:186
void AddBinsD(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:50
VIterator(const std::vector< Item > *aVector)
Definition: DQMStoreStats.h:89
#define nullptr
std::vector< std::pair< time_t, unsigned int > > memoryHistoryVector_
std::string subsystemName_
Definition: DQMStoreStats.h:60
void add(Folder *f)
Folder(std::string name)
unsigned int totalBins_
void mainrows_cumulative(std::string &sql_statement)
unsigned int getEmptyBins()
VIterator< Folder * > CreateIterator()
unsigned int totalBins_
Definition: DQMStoreStats.h:45
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
time_t startingTime_
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
Item CurrentItem() const override
TGeoIterator Iterator
virtual int getIndex()
Definition: DQMStoreStats.h:94
unsigned int totalMemory_
void beginJob()
Definition: Breakpoints.cc:14
void summary(std::string &sql_statement)
std::string subsystem_
std::string maxbinsmeglobal_
void mainrows(std::string &sql_statement)
std::vector< Folder * > subfolders_
const std::string & name()
unsigned int getBins()
bool isOpenProcFileSuccessful_
unsigned int totalEmptyBins_
void setLevel(unsigned int value)
unsigned int totalEmptyBins_
Definition: DQMStoreStats.h:46
Folder * getFather()
std::string pathnamematch_
std::string maxbinsmesubsys_
double f[11][100]
void files(std::string &sql_statement)
unsigned int id()
Definition: value.py:1
void Next() override
Definition: DQMStoreStats.h:92
void setFather(Folder *e)
void dump(std::string indent)
bool IsDone() const override
Definition: DQMStoreStats.h:96
unsigned int index
Folder * father_
virtual int size()
Definition: DQMStoreStats.h:93
unsigned int totalHistos_
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
unsigned int level_
void parents(std::string &sql_statement)
void First() override
Definition: DQMStoreStats.h:91
std::string subfolder_
Folder * cd(const std::string &name)
edm::ParameterSet parameters_
unsigned int totalMemory_
Definition: DQMStoreStats.h:47
void AddBinsF(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:48
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
void children(std::string &sql_statement)
unsigned int totalHistos_
Definition: DQMStoreStats.h:44
const std::vector< Item > * vector_
unsigned int getMemory()
std::stringstream procFileName_
void symbols(std::string &sql_statement)
unsigned int id_
def move(src, dest)
Definition: eostools.py:511
std::string folderName_
Definition: Run.h:45
void setId(unsigned int id)