LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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 "cetlib/exempt_ptr.h"
12 
13 #include <memory>
14 #include <type_traits>
15 
16 namespace art {
17  class Modifier;
18  template <typename T>
19  class WorkerT : public Worker {
20  public:
21  WorkerT(T*, WorkerParams const&);
22 
23  private:
24  hep::concurrency::SerialTaskQueueChain* doSerialTaskQueueChain()
25  const override;
26  void doBeginJob(detail::SharedResources const&) override;
27  void doEndJob() override;
28  void doRespondToOpenInputFile(FileBlock const&) override;
29  void doRespondToCloseInputFile(FileBlock const&) override;
30  void doRespondToOpenOutputFiles(FileBlock const&) override;
31  void doRespondToCloseOutputFiles(FileBlock const&) override;
32  void doBegin(RunPrincipal&, ModuleContext const&) override;
33  void doEnd(RunPrincipal&, ModuleContext const&) override;
34  void doBegin(SubRunPrincipal&, ModuleContext const&) override;
35  void doEnd(SubRunPrincipal&, ModuleContext const&) override;
36  bool doProcess(EventPrincipal&, ModuleContext const&) override;
37 
38  // A module is co-owned by one worker per schedule. Only
39  // replicated modules have a one-to-one correspondence with their
40  // worker.
41  cet::exempt_ptr<T> module_;
42  };
43 
44  namespace detail {
45  class SharedModule;
46  }
47 
48  // This is called directly by the make_worker function created by
49  // the DEFINE_ART_MODULE macro.
50  template <typename T>
52  : Worker{module->moduleDescription(), wp}, module_{module}
53  {
54  if constexpr (std::is_base_of_v<Modifier, T>) {
55  if (wp.scheduleID_ == ScheduleID::first()) {
56  // We only want to register the products, not once for every
57  // schedule...
58  module_->registerProducts(wp.producedProducts_);
59  } else {
60  // ...but we need to fill product descriptions for each module
61  // copy.
62  module_->fillProductDescriptions();
63  }
64  }
65 
66  // Register shared resources only once
67  if constexpr (std::is_base_of_v<detail::SharedModule, T>) {
68  if (wp.scheduleID_ == ScheduleID::first()) {
69  wp.resources_.registerSharedResources(module_->sharedResources());
70  }
71  }
72  }
73 
74  template <typename T>
75  hep::concurrency::SerialTaskQueueChain*
77  {
78  if constexpr (std::is_base_of_v<detail::SharedModule, T>) {
79  return module_->serialTaskQueueChain();
80  } else {
81  return nullptr;
82  }
83  }
84 
85  template <typename T>
86  void
88  {
89  module_->doBeginJob(resources);
90  }
91 
92  template <typename T>
93  void
95  {
96  module_->doEndJob();
97  }
98 
99  template <typename T>
100  void
102  {
103  module_->doRespondToOpenInputFile(fb);
104  }
105 
106  template <typename T>
107  void
109  {
110  module_->doRespondToCloseInputFile(fb);
111  }
112 
113  template <typename T>
114  void
116  {
117  module_->doRespondToOpenOutputFiles(fb);
118  }
119 
120  template <typename T>
121  void
123  {
124  module_->doRespondToCloseOutputFiles(fb);
125  }
126 
127  template <typename T>
128  void
130  {
131  module_->doBeginRun(rp, mc);
132  }
133 
134  template <typename T>
135  void
137  {
138  module_->doEndRun(rp, mc);
139  }
140 
141  template <typename T>
142  void
144  {
145  module_->doBeginSubRun(srp, mc);
146  }
147 
148  template <typename T>
149  void
151  {
152  module_->doEndSubRun(srp, mc);
153  }
154 
155  template <typename T>
156  bool
158  {
159  // Note, only filters ever return false, and when they do it means
160  // they have rejected.
161  return module_->doEvent(
163  }
164 
165 } // namespace art
166 
167 #endif /* art_Framework_Core_WorkerT_h */
168 
169 // Local Variables:
170 // mode: c++
171 // End:
hep::concurrency::SerialTaskQueueChain * doSerialTaskQueueChain() const override
Definition: WorkerT.h:76
void doEndJob() override
Definition: WorkerT.h:94
void doBegin(RunPrincipal &, ModuleContext const &) override
Definition: WorkerT.h:129
static constexpr ScheduleID first()
Definition: ScheduleID.h:50
void doRespondToOpenInputFile(FileBlock const &) override
Definition: WorkerT.h:101
void doBeginJob(detail::SharedResources const &) override
Definition: WorkerT.h:87
bool doProcess(EventPrincipal &, ModuleContext const &) override
Definition: WorkerT.h:157
WorkerT(T *, WorkerParams const &)
Definition: WorkerT.h:51
TFile fb("Li6.root")
std::atomic< std::size_t > counts_run_
Definition: Worker.h:99
void doEnd(RunPrincipal &, ModuleContext const &) override
Definition: WorkerT.h:136
void doRespondToOpenOutputFiles(FileBlock const &) override
Definition: WorkerT.h:115
cet::exempt_ptr< T > module_
Definition: WorkerT.h:41
std::atomic< std::size_t > counts_passed_
Definition: Worker.h:100
void doRespondToCloseOutputFiles(FileBlock const &) override
Definition: WorkerT.h:122
std::atomic< std::size_t > counts_failed_
Definition: Worker.h:101
Definition: MVAAlg.h:12
void doRespondToCloseInputFile(FileBlock const &) override
Definition: WorkerT.h:108