CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
WorkerInPath.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_WorkerInPath_h
2 #define FWCore_Framework_WorkerInPath_h
3 
4 /*
5 
6  Author: Jim Kowalkowski 28-01-06
7 
8  $Id: WorkerInPath.h,v 1.14 2010/10/30 01:34:01 chrjones Exp $
9 
10  A wrapper around a Worker, so that statistics can be managed
11  per path. A Path holds Workers as these things.
12 
13 */
14 
17 
18 namespace edm {
19 
20  class WorkerInPath {
21  public:
23 
24  explicit WorkerInPath(Worker*);
25  WorkerInPath(Worker*, FilterAction theAction);
26 
27  template <typename T>
28  bool runWorker(typename T::MyPrincipal&, EventSetup const&,
29  CurrentProcessingContext const* cpc);
30 
31  std::pair<double,double> timeCpuReal() const {
32  if(stopwatch_) {
33  return std::pair<double,double>(stopwatch_->cpuTime(),stopwatch_->realTime());
34  }
35  return std::pair<double,double>(0.,0.);
36  }
37 
38  void clearCounters() {
40  }
41  void useStopwatch();
42 
43  int timesVisited() const { return timesVisited_; }
44  int timesPassed() const { return timesPassed_; }
45  int timesFailed() const { return timesFailed_; }
46  int timesExcept() const { return timesExcept_; }
47 
49  Worker* getWorker() const { return worker_; }
50 
51  private:
53 
58 
61  };
62 
63  template <typename T>
64  bool WorkerInPath::runWorker(typename T::MyPrincipal & ep, EventSetup const & es,
65  CurrentProcessingContext const* cpc) {
66 
67  if (T::isEvent_) {
68  ++timesVisited_;
69  }
70  bool rc = true;
71 
72  try {
73  // may want to change the return value from the worker to be
74  // the Worker::FilterAction so conditions in the path will be easier to
75  // identify
76  rc = worker_->doWork<T>(ep, es, cpc,stopwatch_.get());
77 
78  // Ignore return code for non-event (e.g. run, lumi) calls
79  if (!T::isEvent_) rc = true;
80  else if (filterAction_ == Veto) rc = !rc;
81  else if (filterAction_ == Ignore) rc = true;
82 
83  if (T::isEvent_) {
84  if(rc) ++timesPassed_; else ++timesFailed_;
85  }
86  }
87  catch(...) {
88  if (T::isEvent_) ++timesExcept_;
89  throw;
90  }
91 
92  return rc;
93  }
94 
95 }
96 
97 #endif
98 
int timesVisited() const
Definition: WorkerInPath.h:43
int timesExcept() const
Definition: WorkerInPath.h:46
FilterAction filterAction() const
Definition: WorkerInPath.h:48
bool runWorker(typename T::MyPrincipal &, EventSetup const &, CurrentProcessingContext const *cpc)
Definition: WorkerInPath.h:64
boost::shared_ptr< CPUTimer > StopwatchPointer
Definition: RunStopwatch.h:23
Worker * getWorker() const
Definition: WorkerInPath.h:49
FilterAction filterAction_
Definition: WorkerInPath.h:59
WorkerInPath(Worker *)
Definition: WorkerInPath.cc:17
std::pair< double, double > timeCpuReal() const
Definition: WorkerInPath.h:31
RunStopwatch::StopwatchPointer stopwatch_
Definition: WorkerInPath.h:52
int timesFailed() const
Definition: WorkerInPath.h:45
bool doWork(typename T::MyPrincipal &, EventSetup const &c, CurrentProcessingContext const *cpc, CPUTimer *const timer)
Definition: Worker.h:204
int timesPassed() const
Definition: WorkerInPath.h:44
long double T