CMS 3D CMS Logo

Path.h

Go to the documentation of this file.
00001 #ifndef FWCore_Framework_Path_h
00002 #define FWCore_Framework_Path_h
00003 
00004 /*
00005 
00006   Author: Jim Kowalkowski 28-01-06
00007 
00008   $Id: Path.h,v 1.17 2008/10/16 23:06:28 wmtan Exp $
00009 
00010   An object of this type represents one path in a job configuration.
00011   It holds the assigned bit position and the list of workers that are
00012   an event must pass through when this parh is processed.  The workers
00013   are held in WorkerInPath wrappers so that per path execution statistics
00014   can be kept for each worker.
00015 
00016 */
00017 
00018 #include "FWCore/Framework/interface/CurrentProcessingContext.h"
00019 #include "FWCore/Framework/interface/OccurrenceTraits.h"
00020 #include "FWCore/Framework/src/WorkerInPath.h"
00021 #include "FWCore/Framework/src/Worker.h"
00022 #include "DataFormats/Common/interface/HLTenums.h"
00023 #include "DataFormats/Common/interface/TriggerResults.h"
00024 
00025 #include "boost/shared_ptr.hpp"
00026 
00027 #include <string>
00028 #include <vector>
00029 
00030 #include "FWCore/Framework/src/RunStopwatch.h"
00031 
00032 namespace edm {
00033   class ParameterSet;
00034 
00035   class Path {
00036   public:
00037     typedef hlt::HLTState State;
00038 
00039     typedef std::vector<WorkerInPath> WorkersInPath;
00040     typedef WorkersInPath::size_type        size_type;
00041     typedef boost::shared_ptr<HLTGlobalStatus> TrigResPtr;
00042 
00043     Path(int bitpos, std::string const& path_name,
00044          WorkersInPath const& workers,
00045          TrigResPtr trptr,
00046          ParameterSet const& proc_pset,
00047          ActionTable& actions,
00048          boost::shared_ptr<ActivityRegistry> reg,
00049          bool isEndPath);
00050 
00051     template <typename T>
00052     void processOneOccurrence(typename T::MyPrincipal&, EventSetup const&);
00053 
00054     int bitPosition() const { return bitpos_; }
00055     std::string const& name() const { return name_; }
00056 
00057     std::pair<double,double> timeCpuReal() const {
00058       return std::pair<double,double>(stopwatch_->cpuTime(),stopwatch_->realTime());
00059     }
00060 
00061     std::pair<double,double> timeCpuReal(unsigned int const i) const {
00062       return workers_.at(i).timeCpuReal();
00063     }
00064 
00065     void clearCounters();
00066 
00067     int timesRun() const { return timesRun_; }
00068     int timesPassed() const { return timesPassed_; }
00069     int timesFailed() const { return timesFailed_; }
00070     int timesExcept() const { return timesExcept_; }
00071     //int abortWorker() const { return abortWorker_; }
00072     State state() const { return state_; }
00073 
00074     size_type size() const { return workers_.size(); }
00075     int timesVisited(size_type i) const { return workers_.at(i).timesVisited(); }
00076     int timesPassed (size_type i) const { return workers_.at(i).timesPassed() ; }
00077     int timesFailed (size_type i) const { return workers_.at(i).timesFailed() ; }
00078     int timesExcept (size_type i) const { return workers_.at(i).timesExcept() ; }
00079     Worker const* getWorker(size_type i) const { return workers_.at(i).getWorker(); }
00080 
00081   private:
00082     RunStopwatch::StopwatchPointer stopwatch_;
00083     int timesRun_;
00084     int timesPassed_;
00085     int timesFailed_;
00086     int timesExcept_;
00087     //int abortWorker_;
00088     State state_;
00089 
00090     int bitpos_;
00091     std::string name_;
00092     TrigResPtr trptr_;
00093     boost::shared_ptr<ActivityRegistry> actReg_;
00094     ActionTable* act_table_;
00095 
00096     WorkersInPath workers_;
00097 
00098     bool isEndPath_;
00099 
00100     // Helper functions
00101     // nwrwue = numWorkersRunWithoutUnhandledException (really!)
00102     bool handleWorkerFailure(cms::Exception const& e, int nwrwue, bool isEvent);
00103     void recordUnknownException(int nwrwue, bool isEvent);
00104     void recordStatus(int nwrwue, bool isEvent);
00105     void updateCounters(bool succeed, bool isEvent);
00106   };
00107 
00108   namespace {
00109     template <typename T>
00110     class PathSignalSentry {
00111     public:
00112       PathSignalSentry(ActivityRegistry *a,
00113                        std::string const& name,
00114                        int const& nwrwue,
00115                        hlt::HLTState const& state) :
00116       a_(a), name_(name), nwrwue_(nwrwue), state_(state) {
00117         if (a_) T::prePathSignal(a_, name_);
00118       }
00119       ~PathSignalSentry() {
00120         HLTPathStatus status(state_, nwrwue_);
00121         if(a_) T::postPathSignal(a_, name_, status);
00122       }
00123     private:
00124       ActivityRegistry* a_;
00125       std::string const& name_;
00126       int const& nwrwue_;
00127       hlt::HLTState const& state_;
00128     };
00129   }
00130 
00131   template <typename T>
00132   void Path::processOneOccurrence(typename T::MyPrincipal& ep,
00133              EventSetup const& es) {
00134 
00135     //Create the PathSignalSentry before the RunStopwatch so that
00136     // we only record the time spent in the path not from the signal
00137     int nwrwue = -1;
00138     std::auto_ptr<PathSignalSentry<T> > signaler(new PathSignalSentry<T>(actReg_.get(), name_, nwrwue, state_));
00139                                                                            
00140     // A RunStopwatch, but only if we are processing an event.
00141     std::auto_ptr<RunStopwatch> stopwatch(T::isEvent_ ? new RunStopwatch(stopwatch_) : 0);
00142 
00143     if (T::isEvent_) {
00144       ++timesRun_;
00145     }
00146     state_ = hlt::Ready;
00147 
00148     // nwrue =  numWorkersRunWithoutUnhandledException
00149     bool should_continue = true;
00150     CurrentProcessingContext cpc(&name_, bitPosition(), isEndPath_);
00151 
00152     WorkersInPath::size_type idx = 0;
00153     // It seems likely that 'nwrwue' and 'idx' can never differ ---
00154     // if so, we should remove one of them!.
00155     for (WorkersInPath::iterator i = workers_.begin(), end = workers_.end();
00156           i != end && should_continue;
00157           ++i, ++idx) {
00158       ++nwrwue;
00159       assert (static_cast<int>(idx) == nwrwue);
00160       try {
00161         cpc.activate(idx, i->getWorker()->descPtr());
00162         should_continue = i->runWorker<T>(ep, es, &cpc);
00163       }
00164       catch(cms::Exception& e) {
00165         // handleWorkerFailure may throw a new exception.
00166         should_continue = handleWorkerFailure(e, nwrwue, T::isEvent_);
00167       }
00168       catch(...) {
00169         recordUnknownException(nwrwue, T::isEvent_);
00170         throw;
00171       }
00172     }
00173     updateCounters(should_continue, T::isEvent_);
00174     recordStatus(nwrwue, T::isEvent_);
00175   }
00176 
00177 }
00178 
00179 #endif

Generated on Tue Jun 9 17:36:11 2009 for CMSSW by  doxygen 1.5.4