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 
17 
18 namespace edm {
19 
20  class PathContext;
21  class StreamID;
22 
23  class WorkerInPath {
24  public:
26 
27  WorkerInPath(Worker*, FilterAction theAction, unsigned int placeInPath);
28 
29  template <typename T>
30  bool runWorker(typename T::MyPrincipal&, EventSetup const&,
31  StreamID streamID,
32  typename T::Context const* context);
33 
34  void clearCounters() {
36  }
37 
38  int timesVisited() const { return timesVisited_; }
39  int timesPassed() const { return timesPassed_; }
40  int timesFailed() const { return timesFailed_; }
41  int timesExcept() const { return timesExcept_; }
42 
44  Worker* getWorker() const { return worker_; }
45 
47 
48  private:
53 
56 
58  };
59 
60  template <typename T>
61  bool WorkerInPath::runWorker(typename T::MyPrincipal & ep, EventSetup const & es,
62  StreamID streamID,
63  typename T::Context const* context) {
64 
65  if (T::isEvent_) {
66  ++timesVisited_;
67  }
68  bool rc = true;
69 
70  try {
71  // may want to change the return value from the worker to be
72  // the Worker::FilterAction so conditions in the path will be easier to
73  // identify
74  if(T::isEvent_) {
75  ParentContext parentContext(&placeInPathContext_);
76  rc = worker_->doWork<T>(ep, es,streamID, parentContext, context);
77  } else {
78  ParentContext parentContext(context);
79  rc = worker_->doWork<T>(ep, es,streamID, parentContext, context);
80  }
81  // Ignore return code for non-event (e.g. run, lumi) calls
82  if (!T::isEvent_) rc = true;
83  else if (filterAction_ == Veto) rc = !rc;
84  else if (filterAction_ == Ignore) rc = true;
85 
86  if (T::isEvent_) {
87  if(rc) ++timesPassed_; else ++timesFailed_;
88  }
89  }
90  catch(...) {
91  if (T::isEvent_) ++timesExcept_;
92  throw;
93  }
94 
95  return rc;
96  }
97 
98 }
99 
100 #endif
101 
bool doWork(typename T::MyPrincipal &, EventSetup const &c, StreamID stream, ParentContext const &parentContext, typename T::Context const *context)
Definition: Worker.h:399
int timesVisited() const
Definition: WorkerInPath.h:38
void setPathContext(PathContext const *v)
bool runWorker(typename T::MyPrincipal &, EventSetup const &, StreamID streamID, typename T::Context const *context)
Definition: WorkerInPath.h:61
int timesExcept() const
Definition: WorkerInPath.h:41
FilterAction filterAction() const
Definition: WorkerInPath.h:43
void setPathContext(PathContext const *v)
Definition: WorkerInPath.h:46
Worker * getWorker() const
Definition: WorkerInPath.h:44
FilterAction filterAction_
Definition: WorkerInPath.h:54
PlaceInPathContext placeInPathContext_
Definition: WorkerInPath.h:57
int timesFailed() const
Definition: WorkerInPath.h:40
WorkerInPath(Worker *, FilterAction theAction, unsigned int placeInPath)
Definition: WorkerInPath.cc:6
int timesPassed() const
Definition: WorkerInPath.h:39
long double T