CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTPerformanceInfo.h
Go to the documentation of this file.
1 // -*-c++-*-
2 #ifndef HLTPERFORMANCEINFO_H
3 #define HLTPERFORMANCEINFO_H
4 
5 #include <string>
6 #include <vector>
7 
10 
12 public:
13  class Path;
14  class Module;
15  typedef std::vector<Path> PathList;
16  typedef std::vector<Module> Modules;
17  typedef std::vector<cms_uint32_t> ModulesInPath;
19  //
20  class Module {
21  private:
22  std::string name_; // module instance name
23  double dt_; // Wall-clock time
24  double dtCPU_ ; // CPU time
25  // I am using this even for modules....
27  public:
28  Module()
29  : name_("unknown")
30  {}
31  // new constructor adding cpu time
32  Module(const char *n, const double dt, const double dtCPU,
34  : name_(n), dt_(dt), dtCPU_(dtCPU), status_(stat)
35  { }
36  std::string name() const {
37  return name_;
38  }
39  double time() const { return dt_; }
40  double cputime() const { return dtCPU_; }
41  edm::HLTPathStatus status() const { return status_; }
42  bool operator==(const char *tname ) {
43  return std::string(tname) == name();
44  }
45  void clear() {
46  dt_ = 0 ;
47  dtCPU_ = 0 ;
48  status_.reset();// = edm::hlt::Ready;
49  }
50  void setTime(double t) { dt_=t;}
51  void setCPUTime(double t) { dtCPU_=t;}
53  // pw - can't a module be on different paths?
54  //void setStatusByPath(Path *path) ;
55  //int indexInPath(Path path) const ;
56 
57  };
58  // end Module class definition
59 
60  // in this version the module can no longer iterate over the paths
61  // by itself, since it has no access to the actual module list.
62  class Path {
63  private:
65  ModulesInPath moduleView_; // indices into the module vector
67 
68  public:
69  Path(const std::string n = "unknown") :
70  name_(n),
71  moduleView_(),
72  status_()
73  {}
74  std::string name() const {
75  return name_;
76  }
78  status_ = result;
79  }
80 
82  return status_;
83  }
84  void clear() {
85  status_.reset();
86  // time is dynamic, nothing to reset
87  }
88  bool operator==( const char* tname) {
89  return (std::string(tname) == name());
90  }
91 
92  const size_t operator[](size_t m) const {
93  return moduleView_.at(m);
94  }
95 
96  void addModuleRef( size_t m) {
97  moduleView_.push_back(m);
98  }
99 
100  ModulesInPath::const_iterator begin() {
101  return moduleView_.begin();
102  }
103  ModulesInPath::const_iterator end() {
104  return moduleView_.end();
105  }
106  size_t getModuleIndex(size_t j) const {
107  return moduleView_.at(j);
108  }
109 
110  size_t numberOfModules() const { return moduleView_.size(); };
111 
112  };
113  // end Path class definition
114 private:
117 
118 public:
119  void addPath(const Path & p) {
120  paths_.push_back(p);
121  }
122  void addModule(const Module & m ) {
123  modules_.push_back(m);
124  }
125  // by name
126  void addModuleToPath(const char *mod, const char *path) {
127  // first make sure module exists
128  Modules::iterator m = findModule(mod);
129  if ( m == endModules() ) {
130  // new module - create it and stick it on the end
131  Module newMod(mod, 0, 0); // time (wall and cpu) = 0 since it wasn't run
132  modules_.push_back(newMod);
133  }
134 
135  for ( size_t i = 0; i < paths_.size(); ++i ) {
136  if ( !( paths_[i] == path ) ) continue;
137  // we found the path, add module to the end
138  for ( size_t j = 0; j < modules_.size(); ++j ) {
139  if ( !(modules_[j] == mod) ) continue;
140  paths_[i].addModuleRef(j);
141  break;
142  }
143  break;
144  }
145  }
146  // by index
147  void addModuleToPath(const size_t mod, const size_t path) {
148  assert(( path <paths_.size()) && (mod < modules_.size()) );
149  paths_[path].addModuleRef(mod);
150  }
151 
152  void clear() {
153  modules_.clear(); paths_.clear();
154  }
155  void clearModules() {
156  for ( size_t i = 0; i < modules_.size(); ++i ) {
157  modules_[i].clear();
158  }
159  }
160 
161  // non-const?
162  const Module & getModuleOnPath(size_t m, size_t p) const ;
163  const Module & getModule(size_t m) const { return modules_.at(m); }
164  const Path & getPath(size_t p) const { return paths_.at(p); }
165 
166 
167  // find a module, given its name.
168  // returns endModules() on failure
169  Modules::iterator findModule(const char* moduleInstanceName) ;
170  PathList::iterator findPath(const char* pathName) ;
171 
172  int moduleIndexInPath(const char *mod, const char *path);
173 
174  size_t numberOfPaths() const {
175  return paths_.size();
176  }
177  size_t numberOfModules() const {
178  return modules_.size();
179  }
180 
181  PathList::iterator beginPaths() {
182  return paths_.begin();
183  }
184  PathList::iterator endPaths() {
185  return paths_.end();
186  }
187 
188  Modules::const_iterator beginModules() const {
189  return modules_.begin();
190  }
191 
192  Modules::const_iterator endModules() const {
193  return modules_.end();
194  }
195 
196  double totalTime() const;
197  double totalCPUTime() const;
198  double longestModuleTime() const;
199  double longestModuleCPUTime() const;
200  const char* longestModuleTimeName() const;
201  const char* longestModuleCPUTimeName() const;
202 
203  double totalPathTime(const size_t path);
204  double totalPathCPUTime(const size_t path);
205 
206 
207  void setStatusOfModulesFromPath(const char* pathName);
208 
209 // double lastModuleOnPathTime(const size_t pathnumber);
210 // double lastModuleOnPathCPUTime(const size_t pathnumber);
211 
212  // is this module only on one path?
213  bool uniqueModule(const char *mod) const ;
214 };
215 
216 
217 typedef std::vector<HLTPerformanceInfo> HLTPerformanceInfoCollection;
218 
219 #endif // HLTPERFORMANCEINFO_H
PathList::iterator findPath(const char *pathName)
float dt
Definition: AMPTWrapper.h:126
std::vector< HLTPerformanceInfo > HLTPerformanceInfoCollection
const Module & getModule(size_t m) const
size_t numberOfModules() const
bool operator==(const char *tname)
int i
Definition: DBlmapReader.cc:9
std::string name() const
not [yet] run
Definition: HLTenums.h:18
void reset()
reset this path
Definition: HLTPathStatus.h:57
double longestModuleCPUTime() const
const Module & getModuleOnPath(size_t m, size_t p) const
static char const * tname
Definition: GTSchema.h:13
assert(m_qm.get())
void addModuleToPath(const size_t mod, const size_t path)
void addPath(const Path &p)
double totalPathTime(const size_t path)
Modules::const_iterator endModules() const
#define Module(md)
Definition: vmac.h:201
double longestModuleTime() const
edm::HLTPathStatus status_
size_t numberOfPaths() const
tuple result
Definition: mps_fire.py:84
PathList::iterator beginPaths()
edm::HLTPathStatus status() const
void setStatus(const edm::HLTPathStatus &result)
bool uniqueModule(const char *mod) const
void setStatusOfModulesFromPath(const char *pathName)
PathList::iterator endPaths()
edm::HLTPathStatus status() const
size_t getModuleIndex(size_t j) const
int j
Definition: DBlmapReader.cc:9
Path(const std::string n="unknown")
Modules::const_iterator beginModules() const
double totalTime() const
bool operator==(const char *tname)
const size_t operator[](size_t m) const
std::vector< cms_uint32_t > ModulesInPath
double totalPathCPUTime(const size_t path)
ModulesInPath::const_iterator end()
Module(const char *n, const double dt, const double dtCPU, edm::HLTPathStatus stat=edm::hlt::Ready)
ModulesInPath::const_iterator begin()
const char * longestModuleTimeName() const
const Path & getPath(size_t p) const
Modules::iterator findModule(const char *moduleInstanceName)
void addModuleToPath(const char *mod, const char *path)
const char * longestModuleCPUTimeName() const
std::vector< Module > Modules
void setStatus(edm::HLTPathStatus status)
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
std::vector< Path > PathList
void addModule(const Module &m)
int moduleIndexInPath(const char *mod, const char *path)
double totalCPUTime() const
std::string name() const