Go to the documentation of this file.00001 #ifndef FWCore_Framework_WorkerInPath_h
00002 #define FWCore_Framework_WorkerInPath_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "FWCore/Framework/src/Worker.h"
00016 #include "FWCore/Framework/src/RunStopwatch.h"
00017
00018 namespace edm {
00019
00020 class WorkerInPath {
00021 public:
00022 enum FilterAction { Normal=0, Ignore, Veto };
00023
00024 explicit WorkerInPath(Worker*);
00025 WorkerInPath(Worker*, FilterAction theAction);
00026
00027 template <typename T>
00028 bool runWorker(typename T::MyPrincipal&, EventSetup const&,
00029 CurrentProcessingContext const* cpc);
00030
00031 std::pair<double,double> timeCpuReal() const {
00032 if(stopwatch_) {
00033 return std::pair<double,double>(stopwatch_->cpuTime(),stopwatch_->realTime());
00034 }
00035 return std::pair<double,double>(0.,0.);
00036 }
00037
00038 void clearCounters() {
00039 timesVisited_ = timesPassed_ = timesFailed_ = timesExcept_ = 0;
00040 }
00041 void useStopwatch();
00042
00043 int timesVisited() const { return timesVisited_; }
00044 int timesPassed() const { return timesPassed_; }
00045 int timesFailed() const { return timesFailed_; }
00046 int timesExcept() const { return timesExcept_; }
00047
00048 FilterAction filterAction() const { return filterAction_; }
00049 Worker* getWorker() const { return worker_; }
00050
00051 private:
00052 RunStopwatch::StopwatchPointer stopwatch_;
00053
00054 int timesVisited_;
00055 int timesPassed_;
00056 int timesFailed_;
00057 int timesExcept_;
00058
00059 FilterAction filterAction_;
00060 Worker* worker_;
00061 };
00062
00063 template <typename T>
00064 bool WorkerInPath::runWorker(typename T::MyPrincipal & ep, EventSetup const & es,
00065 CurrentProcessingContext const* cpc) {
00066
00067 if (T::isEvent_) {
00068 ++timesVisited_;
00069 }
00070 bool rc = true;
00071
00072 try {
00073
00074
00075
00076 rc = worker_->doWork<T>(ep, es, cpc,stopwatch_.get());
00077
00078
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