CMS 3D CMS Logo

WorkerInPath.h

Go to the documentation of this file.
00001 #ifndef FWCore_Framework_WorkerInPath_h
00002 #define FWCore_Framework_WorkerInPath_h
00003 
00004 /*
00005 
00006         Author: Jim Kowalkowski 28-01-06
00007 
00008         $Id: WorkerInPath.h,v 1.12 2008/10/16 23:06:28 wmtan Exp $
00009 
00010         A wrapper around a Worker, so that statistics can be managed
00011         per path.  A Path holds Workers as these things.
00012 
00013 */
00014 
00015 #include "FWCore/Framework/src/Worker.h"
00016 #include "FWCore/Framework/src/RunStopwatch.h"
00017 #include "FWCore/Framework/interface/Frameworkfwd.h"
00018 
00019 namespace edm {
00020 
00021   class WorkerInPath {
00022   public:
00023     enum FilterAction { Normal=0, Ignore, Veto };
00024 
00025     explicit WorkerInPath(Worker*);
00026     WorkerInPath(Worker*, FilterAction theAction);
00027 
00028     template <typename T>
00029     bool runWorker(typename T::MyPrincipal&, EventSetup const&,
00030                    CurrentProcessingContext const* cpc);
00031 
00032     std::pair<double,double> timeCpuReal() const {
00033       return std::pair<double,double>(stopwatch_->cpuTime(),stopwatch_->realTime());
00034     }
00035 
00036     void clearCounters() {
00037       timesVisited_ = timesPassed_ = timesFailed_ = timesExcept_ = 0;
00038     }
00039 
00040     int timesVisited() const { return timesVisited_; }
00041     int timesPassed() const { return timesPassed_; }
00042     int timesFailed() const { return timesFailed_; }
00043     int timesExcept() const { return timesExcept_; }
00044 
00045     FilterAction filterAction() const { return filterAction_; }
00046     Worker* getWorker() const { return worker_; }
00047 
00048   private:
00049     RunStopwatch::StopwatchPointer stopwatch_;
00050 
00051     int timesVisited_;
00052     int timesPassed_;
00053     int timesFailed_;
00054     int timesExcept_;
00055     
00056     FilterAction filterAction_;
00057     Worker* worker_;
00058   };
00059 
00060   template <typename T>
00061   bool WorkerInPath::runWorker(typename T::MyPrincipal & ep, EventSetup const & es,
00062                                CurrentProcessingContext const* cpc) {
00063 
00064     // A RunStopwatch, but only if we are processing an event.
00065     std::auto_ptr<RunStopwatch> stopwatch(T::isEvent_ ? new RunStopwatch(stopwatch_) : 0);
00066 
00067     if (T::isEvent_) {
00068       ++timesVisited_;
00069     }
00070     bool rc = true;
00071 
00072     try {
00073         // may want to change the return value from the worker to be 
00074         // the Worker::FilterAction so conditions in the path will be easier to 
00075         // identify
00076         rc = worker_->doWork<T>(ep, es, cpc);
00077 
00078         // Ignore return code for non-event (e.g. run, lumi) calls
00079         if (!T::isEvent_) rc = true;
00080         else if (filterAction_ == Veto) rc = !rc;
00081         else if (filterAction_ == Ignore) rc = true;
00082 
00083         if (T::isEvent_) {
00084           if(rc) ++timesPassed_; else ++timesFailed_;
00085         }
00086     }
00087     catch(...) {
00088         if (T::isEvent_) ++timesExcept_;
00089         throw;
00090     }
00091 
00092     return rc;
00093   }
00094 
00095 }
00096 
00097 #endif
00098 

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