CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DataFormats/HLTReco/interface/HLTPerformanceInfo.h

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