CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DataFormats/HLTReco/interface/HLTPerformanceInfo.h

Go to the documentation of this file.
00001 // -*-c++-*-
00002 // $Id: HLTPerformanceInfo.h,v 1.14 2008/08/04 14:52:28 bdahmes Exp $
00003 #ifndef HLTPERFORMANCEINFO_H
00004 #define HLTPERFORMANCEINFO_H
00005 
00006 #include <string>
00007 #include <vector>
00008 
00009 #include "DataFormats/Common/interface/HLTPathStatus.h"
00010 
00011 class HLTPerformanceInfo {
00012 public:
00013   class Path;
00014   class Module;
00015   typedef std::vector<Path> PathList;
00016   typedef std::vector<Module> Modules;
00017   typedef std::vector<size_t> ModulesInPath;
00018   HLTPerformanceInfo();
00019   //
00020   class Module {
00021   private:
00022     std::string name_; // module instance name
00023     double dt_; // Wall-clock time
00024     double dtCPU_ ; // CPU time
00025     // I am using this even for modules....
00026     edm::HLTPathStatus status_;
00027   public:
00028     Module() 
00029       : name_("unknown")
00030     {}
00031     // new constructor adding cpu time
00032     Module(const char *n, const double dt, const double dtCPU, 
00033            edm::HLTPathStatus stat = edm::hlt::Ready)
00034       : name_(n), dt_(dt), dtCPU_(dtCPU), status_(stat)
00035     { }
00036     std::string name() const {
00037       return name_;
00038     }
00039     double time() const { return dt_; }
00040     double cputime() const { return dtCPU_; }
00041     edm::HLTPathStatus status() const { return status_; }
00042     bool operator==(const char *tname ) {
00043       return std::string(tname) == name();
00044     }
00045     void clear() {
00046       dt_ = 0 ;
00047       dtCPU_ = 0 ; 
00048       status_.reset();// = edm::hlt::Ready;
00049     }
00050     void setTime(double t) { dt_=t;}
00051     void setCPUTime(double t) { dtCPU_=t;}
00052     void setStatus(edm::HLTPathStatus status) { status_=status;} 
00053     // pw - can't a module be on different paths?
00054     //void setStatusByPath(Path *path) ; 
00055     //int indexInPath(Path path) const ; 
00056         
00057   };
00058   // end Module class definition
00059 
00060   // in this version the module can no longer iterate over the paths
00061   // by itself, since it has no access to the actual module list.
00062   class Path {
00063   private:
00064     std::string name_;
00065     ModulesInPath moduleView_; // indices into the module vector
00066     edm::HLTPathStatus status_;
00067         
00068   public:
00069     Path(const std::string n = "unknown") : 
00070       name_(n),
00071       moduleView_(),
00072       status_()
00073     {}
00074     std::string name() const {
00075       return name_;
00076     }
00077     void setStatus( const edm::HLTPathStatus & result ) {
00078       status_ = result;
00079     }
00080     
00081     edm::HLTPathStatus status() const {
00082       return status_;
00083     }
00084     void clear() {
00085       status_.reset();
00086       // time is dynamic, nothing to reset
00087     }
00088     bool operator==( const char* tname) {
00089       return (std::string(tname) == name());
00090     }
00091     
00092     const size_t operator[](size_t m) const {
00093       return moduleView_.at(m);
00094     }
00095     
00096     void addModuleRef( size_t m) {
00097       moduleView_.push_back(m);
00098     }
00099     
00100     ModulesInPath::const_iterator begin() {
00101       return moduleView_.begin();
00102     }
00103     ModulesInPath::const_iterator end() {
00104       return moduleView_.end();
00105     }
00106     size_t getModuleIndex(size_t j) const {
00107       return moduleView_.at(j);
00108     }
00109     
00110     size_t numberOfModules() const { return moduleView_.size(); };
00111     
00112   };
00113   // end Path class definition
00114 private:
00115   PathList paths_;
00116   Modules modules_;
00117 
00118 public:
00119   void addPath(const Path & p) {
00120     paths_.push_back(p);
00121   }
00122   void addModule(const Module & m ) {
00123     modules_.push_back(m);
00124   } 
00125   // by name
00126    void addModuleToPath(const char *mod, const char *path) {
00127      // first make sure module exists
00128      Modules::iterator m = findModule(mod);
00129      if ( m == endModules() ) {
00130        // new module - create it and stick it on the end
00131        Module newMod(mod, 0, 0); // time (wall and cpu) = 0 since it wasn't run  
00132        modules_.push_back(newMod);
00133      }
00134 
00135      for ( size_t i = 0; i < paths_.size(); ++i ) {
00136        if ( !( paths_[i] == path ) ) continue;
00137        // we found the path, add module to the end
00138        for ( size_t j = 0; j < modules_.size(); ++j ) {
00139          if ( !(modules_[j] == mod) ) continue;
00140          paths_[i].addModuleRef(j);
00141          break;
00142        }
00143        break;
00144      }
00145    }
00146   // by index
00147   void addModuleToPath(const size_t mod, const size_t path) {
00148     assert(( path <paths_.size()) && (mod < modules_.size()) );
00149     paths_[path].addModuleRef(mod);
00150   }
00151 
00152   void clear() {
00153     modules_.clear(); paths_.clear();
00154   }
00155   void clearModules() {
00156     for ( size_t i = 0; i < modules_.size(); ++i ) {
00157       modules_[i].clear();
00158     }
00159   }
00160 
00161   // non-const?
00162   const Module & getModuleOnPath(size_t m, size_t p) const ;
00163   const Module & getModule(size_t m) const { return modules_.at(m); }
00164   const Path & getPath(size_t p) const { return paths_.at(p); }
00165 
00166 
00167   // find a module, given its name.
00168   // returns endModules() on failure
00169   Modules::iterator findModule(const char* moduleInstanceName) ;
00170   PathList::iterator findPath(const char* pathName) ;
00171 
00172   int moduleIndexInPath(const char *mod, const char *path);
00173 
00174   size_t numberOfPaths() const {
00175     return paths_.size();
00176   }
00177   size_t numberOfModules() const {
00178     return modules_.size();
00179   }
00180 
00181   PathList::iterator beginPaths()  {
00182        return paths_.begin();
00183   }
00184   PathList::iterator endPaths()  {
00185     return paths_.end();
00186   }
00187     
00188   Modules::const_iterator beginModules() const {
00189     return modules_.begin();
00190   }
00191   
00192   Modules::const_iterator endModules() const {
00193     return modules_.end();
00194   }
00195     
00196   double totalTime() const;
00197   double totalCPUTime() const;
00198   double longestModuleTime() const;
00199   double longestModuleCPUTime() const;
00200   const char* longestModuleTimeName() const;
00201   const char* longestModuleCPUTimeName() const;
00202 
00203   double totalPathTime(const size_t path);
00204   double totalPathCPUTime(const size_t path);
00205 
00206   
00207   void setStatusOfModulesFromPath(const char* pathName);
00208     
00209 //   double lastModuleOnPathTime(const size_t pathnumber);
00210 //   double lastModuleOnPathCPUTime(const size_t pathnumber);
00211   
00212   // is this module only on one path?
00213   bool uniqueModule(const char *mod) const ;
00214 };
00215 
00216 
00217 typedef std::vector<HLTPerformanceInfo> HLTPerformanceInfoCollection;
00218 
00219 #endif // HLTPERFORMANCEINFO_H