LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
WorkerInPath.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_WorkerInPath_h
2 #define art_Framework_Core_WorkerInPath_h
3 
4 // ======================================================================
5 //
6 // WorkerInPath: A wrapper around a Worker, so that statistics can be
7 // managed per path. A Path holds Workers as these things.
8 //
9 // ======================================================================
10 
14 #include "cetlib/exempt_ptr.h"
15 
16 #include <memory>
17 #include <utility>
18 
19 // ----------------------------------------------------------------------
20 
21 namespace art {
22 
23  class WorkerInPath {
24  public:
25  enum FilterAction { Normal = 0, Ignore, Veto };
26 
27  explicit WorkerInPath(cet::exempt_ptr<Worker>);
28  WorkerInPath(cet::exempt_ptr<Worker> worker, FilterAction theAction);
29 
30  template <typename T>
31  bool runWorker(typename T::MyPrincipal&,
32  CurrentProcessingContext const* cpc);
33 
34  void
36  {
37  counts_ = Counts_t{};
38  }
39 
40  std::size_t
41  timesVisited() const
42  {
43  return counts_.times<stats::Visited>();
44  }
45  std::size_t
46  timesPassed() const
47  {
48  return counts_.times<stats::Passed>();
49  }
50  std::size_t
51  timesFailed() const
52  {
53  return counts_.times<stats::Failed>();
54  }
55  std::size_t
56  timesExcept() const
57  {
59  }
60 
62  filterAction() const
63  {
64  return filterAction_;
65  }
66  cet::exempt_ptr<Worker>
67  getWorker() const
68  {
69  return worker_;
70  }
71 
72  std::string const&
73  label() const
74  {
75  return worker_->label();
76  }
77  bool
78  modifiesEvent() const
79  {
80  return worker_->modifiesEvent();
81  }
82 
83  private:
89 
91  cet::exempt_ptr<Worker> worker_;
92  }; // WorkerInPath
93 
94  template <typename T>
95  bool
96  WorkerInPath::runWorker(typename T::MyPrincipal& ep,
97  CurrentProcessingContext const* cpc)
98  {
100  counts.template increment<stats::Visited>();
101 
102  bool rc{true};
103  try {
104  // may want to change the return value from the worker to be the
105  // Worker::FilterAction so conditions in the path will be easier
106  // to identify
107  rc = worker_->doWork<T>(ep, cpc);
108  }
109  catch (...) {
110  counts.template increment<stats::ExceptionThrown>();
111  throw;
112  }
113 
114  // Ignore return code for non-event (e.g. run, subRun) calls
115  if (T::level == Level::Event && filterAction_ == Veto)
116  rc = !rc;
117  else if (T::level != Level::Event || filterAction_ == Ignore)
118  rc = true;
119 
120  counts.update(rc);
121  return rc;
122  } // runWorker<>()
123 
124 } // art
125 
126  // ======================================================================
127 
128 #endif /* art_Framework_Core_WorkerInPath_h */
129 
130 // Local Variables:
131 // mode: c++
132 // End:
std::size_t times() const
std::string const & label() const
Definition: WorkerInPath.h:73
std::size_t timesExcept() const
Definition: WorkerInPath.h:56
std::size_t timesPassed() const
Definition: WorkerInPath.h:46
cet::exempt_ptr< Worker > getWorker() const
Definition: WorkerInPath.h:67
std::size_t timesFailed() const
Definition: WorkerInPath.h:51
WorkerInPath(cet::exempt_ptr< Worker >)
Definition: WorkerInPath.cc:17
bool modifiesEvent() const
Definition: WorkerInPath.h:78
bool runWorker(typename T::MyPrincipal &, CurrentProcessingContext const *cpc)
Definition: WorkerInPath.h:96
std::size_t timesVisited() const
Definition: WorkerInPath.h:41
FilterAction filterAction_
Definition: WorkerInPath.h:90
FilterAction filterAction() const
Definition: WorkerInPath.h:62
HLT enums.
cet::exempt_ptr< Worker > worker_
Definition: WorkerInPath.h:91