WorkerT.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_WorkerT_h
2 #define art_Framework_Core_WorkerT_h
3 // vim: set sw=2 expandtab :
4 
11 #include "fhiclcpp/ParameterSet.h"
12 
13 #include <cstddef>
14 #include <iosfwd>
15 #include <memory>
16 #include <type_traits>
17 
18 namespace art {
19  template <typename T>
20  class WorkerT : public Worker {
21  // Let PathManager use module() to delete the trigger results inserter.
22  friend class PathManager;
23 
24  public: // TYPES
25  using ModuleType = T;
26 
27  // This is called directly by the make_worker function created by
28  // the DEFINE_ART_MODULE macro.
29  WorkerT(std::shared_ptr<T>, ModuleDescription const&, WorkerParams const&);
30 
31  protected: // MEMBER FUNCTIONS -- API for implementation classes
32  T&
34  {
35  return *module_;
36  }
37  T const&
38  module() const
39  {
40  return *module_;
41  }
42 
43  private:
44  std::string workerType() const override;
45  hep::concurrency::SerialTaskQueueChain* implSerialTaskQueueChain()
46  const override;
47  void implBeginJob(detail::SharedResources const&) override;
48  void implEndJob() override;
49  void implRespondToOpenInputFile(FileBlock const&) override;
50  void implRespondToCloseInputFile(FileBlock const&) override;
51  void implRespondToOpenOutputFiles(FileBlock const&) override;
52  void implRespondToCloseOutputFiles(FileBlock const&) override;
53  bool implDoBegin(RunPrincipal&, ModuleContext const&) override;
54  bool implDoEnd(RunPrincipal&, ModuleContext const&) override;
55  bool implDoBegin(SubRunPrincipal&, ModuleContext const&) override;
56  bool implDoEnd(SubRunPrincipal&, ModuleContext const&) override;
57  bool implDoProcess(EventPrincipal&, ModuleContext const&) override;
58 
59  // A module is co-owned by one worker per schedule. Only
60  // replicated modules have a one-to-one correspondence with their
61  // worker.
62  std::shared_ptr<T> module_;
63  };
64 
65  namespace detail {
66  class SharedModule;
67  }
68 
69  // This is called directly by the make_worker function created by
70  // the DEFINE_ART_MODULE macro.
71  template <typename T>
72  WorkerT<T>::WorkerT(std::shared_ptr<T> module,
73  ModuleDescription const& md,
74  WorkerParams const& wp)
75  : Worker{md, wp}, module_{module}
76  {
77  if (wp.scheduleID_ == ScheduleID::first()) {
78  // We only want to register the products (and any shared
79  // resources) once, not once for every schedule...
80  module_->registerProducts(wp.producedProducts_, md);
81  if constexpr (std::is_base_of_v<detail::SharedModule, T>) {
82  wp.resources_.registerSharedResources(module_->sharedResources());
83  }
84  } else {
85  // ...but we need to fill product descriptions for each module
86  // copy.
87  module_->fillDescriptions(md);
88  }
89  }
90 
91  template <typename T>
94  {
95  return module_->workerType();
96  }
97 
98  template <typename T>
99  hep::concurrency::SerialTaskQueueChain*
101  {
102  if constexpr (std::is_base_of_v<detail::SharedModule, T>) {
103  return module_->serialTaskQueueChain();
104  }
105  return nullptr;
106  }
107 
108  template <typename T>
109  void
111  {
112  module_->doBeginJob(resources);
113  }
114 
115  template <typename T>
116  void
118  {
119  module_->doEndJob();
120  }
121 
122  template <typename T>
123  void
125  {
126  module_->doRespondToOpenInputFile(fb);
127  }
128 
129  template <typename T>
130  void
132  {
133  module_->doRespondToCloseInputFile(fb);
134  }
135 
136  template <typename T>
137  void
139  {
140  module_->doRespondToOpenOutputFiles(fb);
141  }
142 
143  template <typename T>
144  void
146  {
147  module_->doRespondToCloseOutputFiles(fb);
148  }
149 
150  template <typename T>
151  bool
153  {
154  return module_->doBeginRun(rp, mc);
155  }
156 
157  template <typename T>
158  bool
160  {
161  return module_->doEndRun(rp, mc);
162  }
163 
164  template <typename T>
165  bool
167  {
168  return module_->doBeginSubRun(srp, mc);
169  }
170 
171  template <typename T>
172  bool
174  {
175  return module_->doEndSubRun(srp, mc);
176  }
177 
178  template <typename T>
179  bool
181  {
182  // Note, only filters ever return false, and when they do it means
183  // they have rejected.
184  return module_->doEvent(
186  }
187 
188 } // namespace art
189 
190 #endif /* art_Framework_Core_WorkerT_h */
191 
192 // Local Variables:
193 // mode: c++
194 // End:
void implRespondToCloseOutputFiles(FileBlock const &) override
Definition: WorkerT.h:145
std::shared_ptr< T > module_
Definition: WorkerT.h:62
std::string string
Definition: nybbler.cc:12
static constexpr ScheduleID first()
Definition: ScheduleID.h:50
std::string workerType() const override
Definition: WorkerT.h:93
void implRespondToOpenOutputFiles(FileBlock const &) override
Definition: WorkerT.h:138
T const & module() const
Definition: WorkerT.h:38
hep::concurrency::SerialTaskQueueChain * implSerialTaskQueueChain() const override
Definition: WorkerT.h:100
void implRespondToOpenInputFile(FileBlock const &) override
Definition: WorkerT.h:124
void implBeginJob(detail::SharedResources const &) override
Definition: WorkerT.h:110
WorkerT(std::shared_ptr< T >, ModuleDescription const &, WorkerParams const &)
Definition: WorkerT.h:72
std::atomic< std::size_t > counts_run_
Definition: Worker.h:147
T & module()
Definition: WorkerT.h:33
std::atomic< std::size_t > counts_passed_
Definition: Worker.h:148
void implEndJob() override
Definition: WorkerT.h:117
std::atomic< std::size_t > counts_failed_
Definition: Worker.h:149
bool implDoProcess(EventPrincipal &, ModuleContext const &) override
Definition: WorkerT.h:180
bool implDoBegin(RunPrincipal &, ModuleContext const &) override
Definition: WorkerT.h:152
void implRespondToCloseInputFile(FileBlock const &) override
Definition: WorkerT.h:131
bool implDoEnd(RunPrincipal &, ModuleContext const &) override
Definition: WorkerT.h:159