Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:42

0001 
0002 #include "DataFormats/Common/interface/HLTenums.h"
0003 #include "DataFormats/HLTReco/interface/HLTPerformanceInfo.h"
0004 #include <algorithm>
0005 
0006 HLTPerformanceInfo::HLTPerformanceInfo() {
0007   paths_.clear();
0008   modules_.clear();
0009 }
0010 
0011 HLTPerformanceInfo::PathList::iterator HLTPerformanceInfo::findPath(const char* pathName) {
0012   PathList::iterator l = std::find(paths_.begin(), paths_.end(), pathName);
0013   return l;
0014 }
0015 
0016 HLTPerformanceInfo::Modules::iterator HLTPerformanceInfo::findModule(const char* moduleInstanceName) {
0017   return std::find(modules_.begin(), modules_.end(), moduleInstanceName);
0018 }
0019 
0020 double HLTPerformanceInfo::totalTime() const {
0021   double t = 0;
0022   for (size_t i = 0; i < modules_.size(); ++i) {
0023     t += modules_[i].time();
0024   }
0025   return t;
0026 }
0027 
0028 double HLTPerformanceInfo::totalCPUTime() const {
0029   double t = 0;
0030   for (size_t i = 0; i < modules_.size(); ++i) {
0031     t += modules_[i].cputime();
0032   }
0033   return t;
0034 }
0035 
0036 double HLTPerformanceInfo::totalPathTime(const size_t pathnumber) {
0037   double t = 0;
0038   unsigned int cnt = 0;
0039   ModulesInPath::const_iterator i = paths_[pathnumber].begin();
0040   for (; i != paths_[pathnumber].end(); ++i) {
0041     if (cnt > paths_[pathnumber].status().index())
0042       break;
0043     ++cnt;
0044     t += modules_[*i].time();
0045   }
0046   return t;
0047 }
0048 
0049 double HLTPerformanceInfo::totalPathCPUTime(const size_t pathnumber) {
0050   double t = 0;
0051   unsigned int cnt = 0;
0052   ModulesInPath::const_iterator i = paths_[pathnumber].begin();
0053   for (; i != paths_[pathnumber].end(); ++i) {
0054     if (cnt > paths_[pathnumber].status().index())
0055       break;
0056     ++cnt;
0057     t += modules_[*i].cputime();
0058   }
0059   return t;
0060 }
0061 
0062 double HLTPerformanceInfo::longestModuleTime() const {
0063   double t = -1;
0064   for (Modules::const_iterator i = modules_.begin(); i != modules_.end(); ++i) {
0065     t = std::max(i->time(), t);
0066   }
0067   return t;
0068 }
0069 
0070 double HLTPerformanceInfo::longestModuleCPUTime() const {
0071   double t = -1;
0072   for (Modules::const_iterator i = modules_.begin(); i != modules_.end(); ++i) {
0073     t = std::max(i->cputime(), t);
0074   }
0075   return t;
0076 }
0077 
0078 std::string HLTPerformanceInfo::longestModuleTimeName() const {
0079   double t = -1;
0080   std::string slowpoke("unknown");
0081   for (Modules::const_iterator i = modules_.begin(); i != modules_.end(); ++i) {
0082     if (i->time() > t) {
0083       slowpoke = i->name();
0084       t = i->time();
0085     }
0086   }
0087   return slowpoke;
0088 }
0089 
0090 std::string HLTPerformanceInfo::longestModuleCPUTimeName() const {
0091   double t = -1;
0092   std::string slowpoke("unknown");
0093   for (Modules::const_iterator i = modules_.begin(); i != modules_.end(); ++i) {
0094     if (i->cputime() > t) {
0095       slowpoke = i->name();
0096       t = i->cputime();
0097     }
0098   }
0099   return slowpoke;
0100 }
0101 
0102 // I think we can no longer do this as it requires going from path -> modules
0103 // int HLTPerformanceInfo::Module::indexInPath(Path path) const
0104 // {
0105 //   int ctr = 0 ;
0106 //   ModulesInPath::const_iterator iter = path.begin();
0107 //   for ( ; iter != path.end(); ++iter ) {
0108 //     if (modules_[*iter].name() == this->name()) return ctr ;
0109 //     ctr++ ;
0110 //   }
0111 //   //--- Module not found in path ---
0112 //   return -1 ;
0113 // }
0114 
0115 const HLTPerformanceInfo::Module& HLTPerformanceInfo::getModuleOnPath(size_t m, size_t p) const {
0116   // well if this doesn't get your attention....
0117   assert(p < paths_.size() && m < paths_[p].numberOfModules());
0118   size_t j = paths_[p].getModuleIndex(m);
0119   return modules_.at(j);
0120 }
0121 
0122 bool HLTPerformanceInfo::uniqueModule(const char* mod) const {
0123   int mCtr = 0;
0124   for (size_t p = 0; p < paths_.size(); ++p) {
0125     for (size_t m = 0; m < paths_[p].numberOfModules(); ++m) {
0126       size_t modIndex = paths_[p].getModuleIndex(m);
0127       if (modules_[modIndex].name() == std::string(mod))
0128         ++mCtr;
0129       if (mCtr > 1)
0130         return false;
0131     }
0132   }
0133 
0134   if (mCtr == 0)
0135     return false;
0136   return true;
0137 }
0138 
0139 int HLTPerformanceInfo::moduleIndexInPath(const char* mod, const char* path) {
0140   PathList::iterator p = findPath(path);
0141   if (p == endPaths())
0142     return -1;  // Path doesn't exist
0143   int ctr = 0;
0144   for (ModulesInPath::const_iterator j = p->begin(); j != p->end(); ++j) {
0145     if (modules_.at(*j) == mod)
0146       return ctr;
0147     ctr++;
0148   }
0149   return -2;  // module not found on path
0150 }
0151 
0152 // Set the status of the module based on the path's status
0153 // make sure not to wipe out ones that come after the last
0154 // module run on the particular path
0155 void HLTPerformanceInfo::setStatusOfModulesFromPath(const char* pathName) {
0156   PathList::iterator p = findPath(pathName);
0157   if (p == endPaths()) {
0158     return;  // do nothing
0159   }
0160   unsigned int ctr = 0;
0161   for (ModulesInPath::const_iterator j = p->begin(); j != p->end(); ++j) {
0162     edm::hlt::HLTState modState = edm::hlt::Ready;
0163     unsigned int modIndex = 0;
0164 
0165     // get module in the master list
0166     Module& mod = modules_.at(*j);
0167 
0168     if (!mod.status().wasrun()) {
0169       if (p->status().accept()) {
0170         modState = edm::hlt::Pass;
0171       } else {
0172         if (p->status().index() > ctr) {
0173           modState = edm::hlt::Pass;
0174         } else if (p->status().index() == ctr) {
0175           modState = p->status().state();
0176         }
0177       }
0178       mod.setStatus(edm::HLTPathStatus(modState, modIndex));
0179     }
0180     ctr++;
0181   }
0182 }