CMS 3D CMS Logo

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  rc = false;
86  break;
87  }
88  case Worker::Pass:
89  break;
90  case Worker::Exception:
91  {
92  ++timesExcept_;
93  return true;
94  }
95 
96  default:
97  assert(false);
98  }
99 
100  if(Ignore == filterAction()) {
101  rc = true;
102  } else if(Veto == filterAction()) {
103  rc = !rc;
104  }
105 
106  if(rc) {
107  ++timesPassed_;
108  } else {
109  ++timesFailed_;
110  }
111  return rc;
112 
113  }
114 
115  template <typename T>
117  typename T::MyPrincipal const& ep, EventSetup const & es,
118  StreamID streamID,
119  typename T::Context const* context) {
120  if (T::isEvent_) {
121  ++timesVisited_;
122  }
123 
124  if(T::isEvent_) {
125  ParentContext parentContext(&placeInPathContext_);
126  worker_->doWorkAsync<T>(iTask,ep, es,streamID, parentContext, context);
127  } else {
128  ParentContext parentContext(context);
129  worker_->doWorkNoPrefetchingAsync<T>(iTask,ep, es,streamID, parentContext, context);
130  }
131  }
132 
133  template <typename T>
134  bool WorkerInPath::runWorker(typename T::MyPrincipal const& ep, EventSetup const & es,
135  StreamID streamID,
136  typename T::Context const* context) {
137 
138  if (T::isEvent_) {
139  ++timesVisited_;
140  }
141  bool rc = true;
142 
143  try {
144  // may want to change the return value from the worker to be
145  // the Worker::FilterAction so conditions in the path will be easier to
146  // identify
147  if(T::isEvent_) {
148  ParentContext parentContext(&placeInPathContext_);
149  rc = worker_->doWork<T>(ep, es,streamID, parentContext, context);
150  } else {
151  ParentContext parentContext(context);
152  rc = worker_->doWork<T>(ep, es,streamID, parentContext, context);
153  }
154  // Ignore return code for non-event (e.g. run, lumi) calls
155  if (!T::isEvent_) rc = true;
156  else if (filterAction_ == Veto) rc = !rc;
157  else if (filterAction_ == Ignore) rc = true;
158 
159  if (T::isEvent_) {
160  if(rc) ++timesPassed_; else ++timesFailed_;
161  }
162  }
163  catch(...) {
164  if (T::isEvent_) ++timesExcept_;
165  throw;
166  }
167 
168  return rc;
169  }
170 
171 }
172 
173 #endif
174 
int timesVisited() const
Definition: WorkerInPath.h:54
void skipOnPath()
Definition: Worker.cc:325
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:134
bool doWork(typename T::MyPrincipal const &, EventSetup const &c, StreamID stream, ParentContext const &parentContext, typename T::Context const *context)
Definition: Worker.h:718
State state() const
Definition: Worker.h:179
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
void doWorkNoPrefetchingAsync(WaitingTask *task, typename T::MyPrincipal const &, EventSetup const &c, StreamID stream, ParentContext const &parentContext, typename T::Context const *context)
Definition: Worker.h:680
FilterAction filterAction_
Definition: WorkerInPath.h:70
void skipWorker(LuminosityBlockPrincipal const &)
Definition: WorkerInPath.h:48
PlaceInPathContext placeInPathContext_
Definition: WorkerInPath.h:73
HLT enums.
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:620
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:116
int timesPassed() const
Definition: WorkerInPath.h:55
long double T