ResultsProducer.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_ResultsProducer_h
2 #define art_Framework_Core_ResultsProducer_h
3 ////////////////////////////////////////////////////////////////////////
4 // ResultsProducer
5 //
6 // Base class for all ResultsProducer plugins.
7 //
8 // Subclasses shuld not have a separate header, as, in common with other
9 // art modules such as EDProducers and EDAnalyzers, communiation between
10 // modules is only allowed via defined data products and not via calls
11 // to the class' interface.
12 //
13 // Notes for subclass implementors:
14 //
15 // * Subclass implementations *must* invoke:
16 //
17 // DEFINE_ART_RESULTS_PLUGIN(class)
18 //
19 // * Subclasses *must* define:
20 //
21 // Constructor(fhicl::ParameterSet const&);
22 //
23 // Declare data products to be put into the Results (via
24 // art::Results::put() in writeResults() below) using produces<>(),
25 // in a similar fashion to producers and filters.
26 //
27 // void writeResults(art::Results&);
28 //
29 // Called immediately prior to output file closure. Users should
30 // put() their declared products into the Results object. Using
31 // getLabel() here will access only those results products that were
32 // put() by plugins executed earlier for the same output module. In
33 // order to access results products from input files, use
34 // readResults(), below. Note that for the purposes of product
35 // retrieval, the "module label" of a results product is
36 // <output-module-label>#<results-producer-label> eg for results
37 // producer label rp1 defined for output module o1, any product
38 // produced by rp1 will have the label, o1#rp1.
39 //
40 // void clear();
41 //
42 // In this function (called after writeResults()), the user should
43 // reset any accumulated information in preparation for (possibly)
44 // accumulating data for the next output file.
45 //
46 // * Subclasses *may* define:
47 //
48 // void beginJob();
49 //
50 // void endJob();
51 //
52 // void beginSubRun(SubRun const&);
53 //
54 // void endSubRun(SubRun const&);
55 //
56 // void beginRun(Run const&);
57 //
58 // void endRun(Run const&);
59 //
60 // void event(Event const&);
61 //
62 // void readResults(art::Results const&);
63 //
64 // Access any results-level products in input files here. The user
65 // is entirely responsible for combining information from possibly
66 // multiple input files into a possible output product, and for
67 // dealing with the fact that reading a product from an input (here)
68 // is distinctly different from reading a product placed into the
69 // outgoing results object by a ResultsProducer running in the same
70 // job (which must be done in writeResults(), above).
71 //
72 ////////////////////////////////////////////////////////////////////////
73 
85 #include "cetlib/compiler_macros.h"
86 #include "fhiclcpp/ParameterSet.h"
89 
90 namespace art {
91  class ResultsPrincipal;
92  class ResultsProducer;
93 }
94 
95 #include <memory>
96 #include <string>
97 
98 namespace cet {
99  template <>
100  struct PluginTypeDeducer<art::ResultsProducer> {
101  static std::string const value;
102  };
103 }
104 
106 protected:
107  template <class P>
108  void produces(std::string const& instanceName = {});
109 
110 public:
111  virtual ~ResultsProducer() = default;
112 
113  template <typename UserConfig, typename KeysToIgnore = void>
115 
116  void doBeginJob();
117  void doEndJob();
118  void doBeginSubRun(SubRunPrincipal const&);
119  void doEndSubRun(SubRunPrincipal const&);
120  void doBeginRun(RunPrincipal const&);
121  void doEndRun(RunPrincipal const&);
122  void doEvent(EventPrincipal const&);
123  void doReadResults(ResultsPrincipal const&);
124  void doWriteResults(ResultsPrincipal&);
125  void doClear();
126 
127  void
129  ProductDescriptions& producedProducts,
130  ModuleDescription const& md)
131  {
132  ProductRegistryHelper::registerProducts(mpr, producedProducts, md);
133  moduleDescription_ = &md;
134  }
135 
136 private:
137  cet::exempt_ptr<ModuleDescription const> moduleDescription_{nullptr};
138 
139  // Functions for implementation by subclasses.
140  virtual void beginJob();
141  virtual void endJob();
142 
143  virtual void beginSubRun(SubRun const&);
144  virtual void endSubRun(SubRun const&);
145 
146  virtual void beginRun(Run const&);
147  virtual void endRun(Run const&);
148 
149  virtual void event(Event const&);
150 
151  virtual void readResults(Results const&);
152  virtual void writeResults(Results&) = 0;
153 
154  virtual void clear() = 0;
155 };
156 
157 template <class P>
158 inline void
160 {
161  ProductRegistryHelper::produces<P, InResults>(instanceName);
162 }
163 
164 inline void
166 {
167  assert(moduleDescription_);
168  // Preparing the consumer for the job must be done after the
169  // constructer has been called.
170  auto const& mainID = moduleDescription_->mainParameterSetID();
171  auto const& scheduler_pset =
173  "services.scheduler");
174  Consumer::setModuleDescription(*moduleDescription_);
175  prepareForJob(scheduler_pset);
176  beginJob();
177 }
178 
179 inline void
181 {
182  endJob();
183  showMissingConsumes();
184 }
185 
186 inline void
188 {
189  SubRun const sr{srp, *moduleDescription_, this};
190  beginSubRun(sr);
191 }
192 
193 inline void
195 {
196  SubRun const sr{srp, *moduleDescription_, this};
197  endSubRun(sr);
198 }
199 
200 inline void
202 {
203  Run const r{rp, *moduleDescription_, this};
204  beginRun(r);
205 }
206 
207 inline void
209 {
210  Run const r{rp, *moduleDescription_, this};
211  endRun(r);
212 }
213 
214 inline void
216 {
217  Event const e{ep, *moduleDescription_, this};
218  event(e);
219 }
220 
221 inline void
223 {
224  Results const res{resp, *moduleDescription_, this};
225  readResults(res);
226 }
227 
228 inline void
230 {
231  clear();
232 }
233 
234 #define DEFINE_ART_RESULTS_PLUGIN(klass) \
235  EXTERN_C_FUNC_DECLARE_START \
236  CET_PROVIDE_FILE_PATH() \
237  FHICL_PROVIDE_ALLOWED_CONFIGURATION(klass) \
238  DEFINE_BASIC_PLUGINTYPE_FUNC(art::ResultsProducer) \
239  std::unique_ptr<art::RPWorker> makeRP(art::RPParams const& rpParams, \
240  fhicl::ParameterSet const& ps) \
241  { \
242  return std::make_unique<art::RPWorkerT<klass>>(rpParams, ps); \
243  } \
244  EXTERN_C_FUNC_DECLARE_END
245 
246 #endif /* art_Framework_Core_ResultsProducer_h */
247 
248 // Local Variables:
249 // mode: c++
250 // End:
void registerProducts(MasterProductRegistry &mpr, ProductDescriptions &productsToRegister, ModuleDescription const &md)
void doEvent(EventPrincipal const &)
void doBeginSubRun(SubRunPrincipal const &)
vector< vector< double > > clear
static collection_type const & get() noexcept
void registerProducts(MasterProductRegistry &mpr, ProductDescriptions &producedProducts, ModuleDescription const &md)
void doReadResults(ResultsPrincipal const &)
std::vector< BranchDescription > ProductDescriptions
void doEndRun(RunPrincipal const &)
Definition: Run.h:31
void doBeginRun(RunPrincipal const &)
void beginJob()
void doEndSubRun(SubRunPrincipal const &)
void setModuleDescription(ModuleDescription const &md)
caf::StandardRecord * sr
void produces(std::string const &instanceName={})
assert(nhit_max >=nhit_nbins)
TRandom3 r(0)
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
Float_t e
Definition: plot.C:35
enum BeamMode string