CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DataFormats/HLTReco/src/HLTPerformanceInfo.cc

Go to the documentation of this file.
00001 // $Id: HLTPerformanceInfo.cc,v 1.17 2009/01/30 23:32:35 elmer Exp $
00002 
00003 #include "DataFormats/Common/interface/HLTenums.h"
00004 #include "DataFormats/HLTReco/interface/HLTPerformanceInfo.h"
00005 #include <algorithm>
00006 
00007 HLTPerformanceInfo::HLTPerformanceInfo() {
00008   paths_.clear(); modules_.clear();
00009 }
00010 
00011 HLTPerformanceInfo::PathList::iterator 
00012 HLTPerformanceInfo::findPath(const char* pathName) {
00013   PathList::iterator l = std::find(paths_.begin(), paths_.end(),
00014                                          pathName);
00015   return l; 
00016 }
00017 
00018 HLTPerformanceInfo::Modules::iterator 
00019 HLTPerformanceInfo::findModule(const char* moduleInstanceName) {
00020   return std::find(modules_.begin(), modules_.end(),
00021                    moduleInstanceName);
00022 }
00023 
00024 
00025 
00026 double HLTPerformanceInfo::totalTime() const {
00027   double t = 0;
00028   for ( size_t i = 0; i < modules_.size(); ++i ) {
00029     t += modules_[i].time();
00030   }
00031   return t;
00032 }
00033 
00034 double HLTPerformanceInfo::totalCPUTime() const {
00035   double t = 0;
00036   for ( size_t i = 0; i < modules_.size(); ++i ) {
00037     t += modules_[i].cputime();
00038   }
00039   return t;
00040 }
00041 
00042 double HLTPerformanceInfo::totalPathTime(const size_t pathnumber)
00043 {
00044   double t = 0;
00045   unsigned int cnt = 0;
00046   ModulesInPath::const_iterator i = paths_[pathnumber].begin();
00047   for ( ; i != paths_[pathnumber].end(); ++i ) {
00048     if ( cnt > paths_[pathnumber].status().index()) break;
00049     ++cnt;
00050     t += modules_[*i].time();
00051   }
00052   return t;
00053 }
00054 
00055 double HLTPerformanceInfo::totalPathCPUTime(const size_t pathnumber)
00056 {
00057   double t = 0;
00058   unsigned int cnt = 0;
00059   ModulesInPath::const_iterator i = paths_[pathnumber].begin();
00060   for ( ; i != paths_[pathnumber].end(); ++i ) {
00061     if ( cnt > paths_[pathnumber].status().index()) break;
00062     ++cnt;
00063     t += modules_[*i].cputime();
00064   }
00065   return t;
00066 }
00067 
00068 
00069 
00070 double HLTPerformanceInfo::longestModuleTime() const {
00071   double t = -1;
00072   for ( Modules::const_iterator i = modules_.begin();
00073         i != modules_.end(); ++i ) {
00074     t = std::max(i->time(),t);
00075   }
00076   return t;
00077 }
00078 
00079 double HLTPerformanceInfo::longestModuleCPUTime() const {
00080   double t = -1;
00081   for ( Modules::const_iterator i = modules_.begin();
00082         i != modules_.end(); ++i ) {
00083     t = std::max(i->cputime(),t);
00084   }
00085   return t;
00086 }
00087 
00088 const char* HLTPerformanceInfo::longestModuleTimeName() const 
00089 {
00090   double t = -1;
00091   std::string slowpoke("unknown");
00092   for ( Modules::const_iterator i = modules_.begin();
00093         i != modules_.end(); ++i ) {
00094     if ( i->time() > t ) {
00095       slowpoke = i->name();
00096       t = i->time();
00097     }
00098   }
00099   return slowpoke.c_str();
00100 }
00101     
00102 const char* HLTPerformanceInfo::longestModuleCPUTimeName() const 
00103 {
00104   double t = -1;
00105   std::string slowpoke("unknown");
00106   for ( Modules::const_iterator i = modules_.begin();
00107         i != modules_.end(); ++i ) {
00108     if ( i->cputime() > t ) {
00109       slowpoke = i->name();
00110       t = i->cputime();
00111     }
00112   }
00113   return slowpoke.c_str();
00114 }
00115     
00116 
00117 // I think we can no longer do this as it requires going from path -> modules
00118 // int HLTPerformanceInfo::Module::indexInPath(Path path) const 
00119 // {
00120 //   int ctr = 0 ; 
00121 //   ModulesInPath::const_iterator iter = path.begin();
00122 //   for ( ; iter != path.end(); ++iter ) {
00123 //     if (modules_[*iter].name() == this->name()) return ctr ; 
00124 //     ctr++ ; 
00125 //   }
00126 //   //--- Module not found in path ---
00127 //   return -1 ; 
00128 // }
00129 
00130 const HLTPerformanceInfo::Module & HLTPerformanceInfo::getModuleOnPath(size_t m, 
00131                                                                        size_t p) const 
00132 {
00133   // well if this doesn't get your attention....
00134   assert(p<paths_.size()&& m<paths_[p].numberOfModules());
00135   size_t j = paths_[p].getModuleIndex(m);
00136   return modules_.at(j);
00137 }
00138 
00139 
00140 bool HLTPerformanceInfo::uniqueModule(const char *mod) const {
00141   int mCtr = 0 ;
00142   for ( size_t p = 0; p < paths_.size(); ++p ) {
00143     for ( size_t m = 0; m < paths_[p].numberOfModules(); ++m ) {
00144       size_t modIndex = paths_[p].getModuleIndex(m);
00145       if ( modules_[modIndex].name() == std::string(mod) ) 
00146         ++mCtr;
00147       if ( mCtr > 1 ) 
00148         return false;
00149     }
00150   }
00151 
00152   if (mCtr == 0) return false ;
00153   return true ;
00154 }
00155 
00156 int HLTPerformanceInfo::moduleIndexInPath(const char *mod, const char *path)
00157 {
00158   PathList::iterator p = findPath(path);
00159   if ( p == endPaths() ) return -1; // Path doesn't exist
00160   int ctr = 0 ; 
00161   for ( ModulesInPath::const_iterator j = p->begin(); j != p->end(); ++j ) {
00162       if ( modules_.at(*j) == mod ) return ctr ; 
00163       ctr++ ; 
00164   }
00165   return -2; // module not found on path
00166 }
00167 
00168 
00169 // Set the status of the module based on the path's status
00170 // make sure not to wipe out ones that come after the last 
00171 // module run on the particular path
00172 void HLTPerformanceInfo::setStatusOfModulesFromPath(const char *pathName)
00173 {
00174   PathList::iterator p = findPath(pathName);
00175   if ( p == endPaths() ) {
00176     return; // do nothing
00177   }
00178   unsigned int ctr = 0;
00179   for ( ModulesInPath::const_iterator j = p->begin(); j != p->end(); ++j ) {
00180     edm::hlt::HLTState modState = edm::hlt::Ready ; 
00181     unsigned int modIndex = 0 ; 
00182 
00183     // get module in the master list
00184     Module & mod = modules_.at(*j);
00185     
00186     if ( ! mod.status().wasrun() ) {
00187         if (p->status().accept()) {
00188             modState = edm::hlt::Pass ;
00189         } else {
00190             if ( p->status().index() > ctr ) {
00191                 modState = edm::hlt::Pass ; 
00192             } else if ( p->status().index() == ctr ) {
00193                 modState = p->status().state() ; 
00194             }
00195         }
00196         mod.setStatus(edm::HLTPathStatus(modState,modIndex)) ;
00197     }
00198     ctr++ ; 
00199   }
00200   
00201 }