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