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 
9  A wrapper around a Worker, so that statistics can be managed
10  per path. A Path holds Workers as these things.
11 
12 */
13 
18 
19 namespace edm {
20 
21  class PathContext;
22  class StreamID;
23 
24  class WorkerInPath {
25  public:
27 
28  WorkerInPath(Worker*, FilterAction theAction, unsigned int placeInPath);
29 
30  template <typename T>
31  bool runWorker(typename T::MyPrincipal&, EventSetup const&,
32  StreamID streamID,
33  typename T::Context const* context);
34 
35  std::pair<double,double> timeCpuReal() const {
36  if(stopwatch_) {
37  return std::pair<double,double>(stopwatch_->cpuTime(),stopwatch_->realTime());
38  }
39  return std::pair<double,double>(0.,0.);
40  }
41 
42  void clearCounters() {
44  }
45  void useStopwatch();
46 
47  int timesVisited() const { return timesVisited_; }
48  int timesPassed() const { return timesPassed_; }
49  int timesFailed() const { return timesFailed_; }
50  int timesExcept() const { return timesExcept_; }
51 
53  Worker* getWorker() const { return worker_; }
54 
56 
57  private:
59 
64 
67 
69  };
70 
71  template <typename T>
72  bool WorkerInPath::runWorker(typename T::MyPrincipal & ep, EventSetup const & es,
73  StreamID streamID,
74  typename T::Context const* context) {
75 
76  if (T::isEvent_) {
77  ++timesVisited_;
78  }
79  bool rc = true;
80 
81  try {
82  // may want to change the return value from the worker to be
83  // the Worker::FilterAction so conditions in the path will be easier to
84  // identify
85  if(T::isEvent_) {
86  ParentContext parentContext(&placeInPathContext_);
87  rc = worker_->doWork<T>(ep, es, stopwatch_.get(),streamID, parentContext, context);
88  } else {
89  ParentContext parentContext(context);
90  rc = worker_->doWork<T>(ep, es, stopwatch_.get(),streamID, parentContext, context);
91  }
92  // Ignore return code for non-event (e.g. run, lumi) calls
93  if (!T::isEvent_) rc = true;
94  else if (filterAction_ == Veto) rc = !rc;
95  else if (filterAction_ == Ignore) rc = true;
96 
97  if (T::isEvent_) {
98  if(rc) ++timesPassed_; else ++timesFailed_;
99  }
100  }
101  catch(...) {
102  if (T::isEvent_) ++timesExcept_;
103  throw;
104  }
105 
106  return rc;
107  }
108 
109 }
110 
111 #endif
112 
int timesVisited() const
Definition: WorkerInPath.h:47
void setPathContext(PathContext const *v)
bool runWorker(typename T::MyPrincipal &, EventSetup const &, StreamID streamID, typename T::Context const *context)
Definition: WorkerInPath.h:72
int timesExcept() const
Definition: WorkerInPath.h:50
bool doWork(typename T::MyPrincipal &, EventSetup const &c, CPUTimer *const timer, StreamID stream, ParentContext const &parentContext, typename T::Context const *context)
Definition: Worker.h:351
FilterAction filterAction() const
Definition: WorkerInPath.h:52
void setPathContext(PathContext const *v)
Definition: WorkerInPath.h:55
boost::shared_ptr< CPUTimer > StopwatchPointer
Definition: RunStopwatch.h:22
Worker * getWorker() const
Definition: WorkerInPath.h:53
FilterAction filterAction_
Definition: WorkerInPath.h:65
PlaceInPathContext placeInPathContext_
Definition: WorkerInPath.h:68
std::pair< double, double > timeCpuReal() const
Definition: WorkerInPath.h:35
RunStopwatch::StopwatchPointer stopwatch_
Definition: WorkerInPath.h:58
int timesFailed() const
Definition: WorkerInPath.h:49
WorkerInPath(Worker *, FilterAction theAction, unsigned int placeInPath)
Definition: WorkerInPath.cc:6
int timesPassed() const
Definition: WorkerInPath.h:48
long double T