WorkerInPath.cc
Go to the documentation of this file.
2 // vim: set sw=2 expandtab :
3 
9 #include "hep_concurrency/WaitingTask.h"
10 
11 using namespace art::detail;
12 using namespace hep::concurrency;
13 using namespace std;
14 
15 namespace art {
16 
18  FilterAction const fa,
19  ModuleContext const& mc,
20  GlobalTaskGroup& taskGroup)
21  : worker_{w}, filterAction_{fa}, moduleContext_{mc}, taskGroup_{&taskGroup}
22  {}
23 
24  Worker*
26  {
27  return worker_.get();
28  }
29 
32  {
33  return filterAction_;
34  }
35 
36  // Used only by Path
37  bool
39  {
40  return returnCode_;
41  }
42 
43  string const&
45  {
46  return worker_->label();
47  }
48 
49  // Used by writeSummary
50  size_t
52  {
53  return counts_visited_;
54  }
55 
56  // Used by writeSummary
57  size_t
59  {
60  return counts_passed_;
61  }
62 
63  // Used by writeSummary
64  size_t
66  {
67  return counts_failed_;
68  }
69 
70  // Used by writeSummary
71  size_t
73  {
74  return counts_thrown_;
75  }
76 
77  bool
78  WorkerInPath::run(Transition const trans, Principal& principal)
79  {
80  // Note: We ignore the return code because we do not process events here.
81  worker_->doWork(trans, principal, moduleContext_);
82  return true;
83  }
84 
86  public:
88  ScheduleID const scheduleID,
89  WaitingTaskPtr workerDoneTask,
90  GlobalTaskGroup* taskGroup)
91  : wip_{wip}
92  , sid_{scheduleID}
93  , workerDoneTask_{std::move(workerDoneTask)}
94  , taskGroup_{taskGroup}
95  {}
96 
97  void
98  operator()(exception_ptr const ex) const
99  {
100  TDEBUG_BEGIN_TASK_SI(4, sid_);
101  if (ex) {
102  ++wip_->counts_thrown_;
103  taskGroup_->may_run(workerDoneTask_, ex);
104  TDEBUG_END_TASK_SI(4, sid_) << "because of EXCEPTION";
105  return;
106  }
107 
108  wip_->returnCode_ = wip_->worker_->returnCode();
109  TDEBUG_TASK_SI(5, sid_) << "raw returnCode_: " << wip_->returnCode_;
110  if (wip_->filterAction_ == FilterAction::Veto) {
111  wip_->returnCode_ = !wip_->returnCode_;
112  } else if (wip_->filterAction_ == FilterAction::Ignore) {
113  wip_->returnCode_ = true;
114  }
115  TDEBUG_TASK_SI(5, sid_) << "final returnCode_: " << wip_->returnCode_;
116  if (wip_->returnCode_) {
117  ++wip_->counts_passed_;
118  } else {
119  ++wip_->counts_failed_;
120  }
121  TDEBUG_END_TASK_SI(4, sid_) << "returnCode_: " << wip_->returnCode_;
122  taskGroup_->may_run(workerDoneTask_);
123  }
124 
125  private:
128  WaitingTaskPtr workerDoneTask_;
130  };
131 
132  void
133  WorkerInPath::run(WaitingTaskPtr workerDoneTask, EventPrincipal& ep)
134  {
135  auto const scheduleID = moduleContext_.scheduleID();
136  TDEBUG_BEGIN_FUNC_SI(4, scheduleID);
137  ++counts_visited_;
138  try {
139  auto workerInPathDoneTask = make_waiting_task<WorkerInPathDoneTask>(
140  this, scheduleID, workerDoneTask, taskGroup_);
141  worker_->doWork_event(workerInPathDoneTask, ep, moduleContext_);
142  }
143  catch (...) {
144  ++counts_thrown_;
145  taskGroup_->may_run(workerDoneTask, current_exception());
146  TDEBUG_END_FUNC_SI(4, scheduleID) << "because of EXCEPTION";
147  return;
148  }
149  TDEBUG_END_FUNC_SI(4, scheduleID);
150  }
151 
152 } // namespace art
#define TDEBUG_BEGIN_TASK_SI(LEVEL, SI)
detail::FilterAction filterAction() const
Definition: WorkerInPath.cc:31
std::size_t timesPassed() const
Definition: WorkerInPath.cc:58
Worker * getWorker() const
Definition: WorkerInPath.cc:25
std::size_t timesFailed() const
Definition: WorkerInPath.cc:65
#define TDEBUG_END_TASK_SI(LEVEL, SI)
auto scheduleID() const
Definition: ModuleContext.h:28
STL namespace.
ModuleContext moduleContext_
Definition: WorkerInPath.h:71
bool returnCode() const
Definition: WorkerInPath.cc:38
#define TDEBUG_TASK_SI(LEVEL, SI)
GlobalTaskGroup * taskGroup_
Definition: WorkerInPath.h:72
Transition
Definition: Transition.h:7
WorkerInPath(cet::exempt_ptr< Worker >, detail::FilterAction, ModuleContext const &, GlobalTaskGroup &group)
Definition: WorkerInPath.cc:17
def move(depos, offset)
Definition: depos.py:107
void operator()(exception_ptr const ex) const
Definition: WorkerInPath.cc:98
std::size_t counts_thrown_
Definition: WorkerInPath.h:81
std::size_t timesVisited() const
Definition: WorkerInPath.cc:51
#define TDEBUG_END_FUNC_SI(LEVEL, SI)
detail::FilterAction filterAction_
Definition: WorkerInPath.h:70
bool run(Transition, Principal &)
Definition: WorkerInPath.cc:78
WorkerInPathDoneTask(WorkerInPath *wip, ScheduleID const scheduleID, WaitingTaskPtr workerDoneTask, GlobalTaskGroup *taskGroup)
Definition: WorkerInPath.cc:87
std::size_t timesExcept() const
Definition: WorkerInPath.cc:72
void may_run(hep::concurrency::WaitingTaskPtr task, std::exception_ptr ex_ptr={})
std::size_t counts_visited_
Definition: WorkerInPath.h:78
#define TDEBUG_BEGIN_FUNC_SI(LEVEL, SI)
std::size_t counts_failed_
Definition: WorkerInPath.h:80
cet::exempt_ptr< Worker > worker_
Definition: WorkerInPath.h:67
std::string const & label() const
Definition: WorkerInPath.cc:44
std::size_t counts_passed_
Definition: WorkerInPath.h:79