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  class WaitingTask;
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 const&, EventSetup const&,
32  StreamID streamID,
33  typename T::Context const* context);
34 
35  template <typename T>
36  void runWorkerAsync(WaitingTask* iTask,
37  typename T::MyPrincipal const&, EventSetup const&,
38  StreamID streamID,
39  typename T::Context const* context);
40 
41 
42  bool checkResultsOfRunWorker(bool wasEvent);
43 
44  void skipWorker(EventPrincipal const& iPrincipal) {
46  }
47  void skipWorker(RunPrincipal const&) {}
49 
50  void clearCounters() {
52  }
53 
54  int timesVisited() const { return timesVisited_; }
55  int timesPassed() const { return timesPassed_; }
56  int timesFailed() const { return timesFailed_; }
57  int timesExcept() const { return timesExcept_; }
58 
60  Worker* getWorker() const { return worker_; }
61 
63 
64  private:
69 
72 
74  };
75 
76  inline bool WorkerInPath::checkResultsOfRunWorker(bool wasEvent) {
77  if(not wasEvent) {
78  return true;
79  }
80  auto state = worker_->state();
81  bool rc = true;
82  switch (state) {
83  case Worker::Fail:
84  {
85  ++timesFailed_;
86  rc = false;
87  break;
88  }
89  case Worker::Pass:
90  break;
91  case Worker::Exception:
92  {
93  ++timesExcept_;
94  return true;
95  }
96 
97  default:
98  assert(false);
99  }
100 
101  if(Ignore == filterAction()) {
102  rc = true;
103  } else if(Veto == filterAction()) {
104  rc = !rc;
105  }
106 
107  if(rc) {
108  ++timesPassed_;
109  } else {
110  ++timesFailed_;
111  }
112  return rc;
113 
114  }
115 
116  template <typename T>
118  typename T::MyPrincipal const& ep, EventSetup const & es,
119  StreamID streamID,
120  typename T::Context const* context) {
121  if (T::isEvent_) {
122  ++timesVisited_;
123  }
124 
125  if(T::isEvent_) {
126  ParentContext parentContext(&placeInPathContext_);
127  worker_->doWorkAsync<T>(iTask,ep, es,streamID, parentContext, context);
128  } else {
129  ParentContext parentContext(context);
130  worker_->doWorkAsync<T>(iTask,ep, es,streamID, parentContext, context);
131  }
132  }
133 
134  template <typename T>
135  bool WorkerInPath::runWorker(typename T::MyPrincipal const& ep, EventSetup const & es,
136  StreamID streamID,
137  typename T::Context const* context) {
138 
139  if (T::isEvent_) {
140  ++timesVisited_;
141  }
142  bool rc = true;
143 
144  try {
145  // may want to change the return value from the worker to be
146  // the Worker::FilterAction so conditions in the path will be easier to
147  // identify
148  if(T::isEvent_) {
149  ParentContext parentContext(&placeInPathContext_);
150  rc = worker_->doWork<T>(ep, es,streamID, parentContext, context);
151  } else {
152  ParentContext parentContext(context);
153  rc = worker_->doWork<T>(ep, es,streamID, parentContext, context);
154  }
155  // Ignore return code for non-event (e.g. run, lumi) calls
156  if (!T::isEvent_) rc = true;
157  else if (filterAction_ == Veto) rc = !rc;
158  else if (filterAction_ == Ignore) rc = true;
159 
160  if (T::isEvent_) {
161  if(rc) ++timesPassed_; else ++timesFailed_;
162  }
163  }
164  catch(...) {
165  if (T::isEvent_) ++timesExcept_;
166  throw;
167  }
168 
169  return rc;
170  }
171 
172 }
173 
174 #endif
175 
int timesVisited() const
Definition: WorkerInPath.h:54
void skipOnPath()
Definition: Worker.cc:311
void setPathContext(PathContext const *v)
bool checkResultsOfRunWorker(bool wasEvent)
Definition: WorkerInPath.h:76
int timesExcept() const
Definition: WorkerInPath.h:57
bool runWorker(typename T::MyPrincipal const &, EventSetup const &, StreamID streamID, typename T::Context const *context)
Definition: WorkerInPath.h:135
assert(m_qm.get())
bool doWork(typename T::MyPrincipal const &, EventSetup const &c, StreamID stream, ParentContext const &parentContext, typename T::Context const *context)
Definition: Worker.h:671
State state() const
Definition: Worker.h:162
void skipWorker(EventPrincipal const &iPrincipal)
Definition: WorkerInPath.h:44
FilterAction filterAction() const
Definition: WorkerInPath.h:59
void setPathContext(PathContext const *v)
Definition: WorkerInPath.h:62
void skipWorker(RunPrincipal const &)
Definition: WorkerInPath.h:47
Worker * getWorker() const
Definition: WorkerInPath.h:60
FilterAction filterAction_
Definition: WorkerInPath.h:70
void skipWorker(LuminosityBlockPrincipal const &)
Definition: WorkerInPath.h:48
PlaceInPathContext placeInPathContext_
Definition: WorkerInPath.h:73
int timesFailed() const
Definition: WorkerInPath.h:56
void doWorkAsync(WaitingTask *task, typename T::MyPrincipal const &, EventSetup const &c, StreamID stream, ParentContext const &parentContext, typename T::Context const *context)
Definition: Worker.h:602
WorkerInPath(Worker *, FilterAction theAction, unsigned int placeInPath)
Definition: WorkerInPath.cc:6
void runWorkerAsync(WaitingTask *iTask, typename T::MyPrincipal const &, EventSetup const &, StreamID streamID, typename T::Context const *context)
Definition: WorkerInPath.h:117
int timesPassed() const
Definition: WorkerInPath.h:55
long double T