LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ResultsProducer.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_ResultsProducer_h
2 #define art_Framework_Core_ResultsProducer_h
3 // vim: set sw=2 expandtab :
4 
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 // getByLabel() 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 //
37 // <output-module-label>#<results-producer-label>
38 //
39 // For example for results producer label rp1 defined for output
40 // module o1, any product produced by rp1 will have the label, o1#rp1.
41 //
42 // void clear();
43 //
44 // In this function (called after writeResults()), the user should
45 // reset any accumulated information in preparation for (possibly)
46 // accumulating data for the next output file.
47 //
48 // * Subclasses *may* define:
49 //
50 // void beginJob();
51 //
52 // void endJob();
53 //
54 // void beginSubRun(SubRun const&);
55 //
56 // void endSubRun(SubRun const&);
57 //
58 // void beginRun(Run const&);
59 //
60 // void endRun(Run const&);
61 //
62 // void event(Event const&);
63 //
64 // void readResults(art::Results const&);
65 //
66 // Access any results-level products in input files here. The user
67 // is entirely responsible for combining information from possibly
68 // multiple input files into a possible output product, and for
69 // dealing with the fact that reading a product from an input here
70 // is distinctly different from reading a product placed into the
71 // outgoing results object by a ResultsProducer running in the same
72 // job (which must be done in writeResults(), above).
73 //
74 
82 #include "cetlib/PluginTypeDeducer.h"
83 #include "cetlib/ProvideFilePathMacro.h"
84 #include "cetlib/compiler_macros.h"
85 #include "fhiclcpp/ParameterSet.h"
87 
88 #include <memory>
89 #include <string>
90 
91 namespace art {
92 
93  class ResultsProducer : public ModuleBase,
94  private detail::SharedModule,
95  private ProductRegistryHelper {
96  public:
97  virtual ~ResultsProducer() noexcept = default;
98 
99  ResultsProducer() noexcept(false);
100 
101  template <typename UserConfig, typename KeysToIgnore = void>
103 
104  void doBeginJob();
105  void doEndJob();
106 
107  void doBeginRun(RunPrincipal const&);
108  void doEndRun(RunPrincipal const&);
109 
110  void doBeginSubRun(SubRunPrincipal const&);
111  void doEndSubRun(SubRunPrincipal const&);
112 
113  void doEvent(EventPrincipal const&);
114 
115  void doReadResults(ResultsPrincipal const&);
117  void doClear();
118 
119  void registerProducts(ProductDescriptions& producedProducts,
120  ModuleDescription const& md);
121 
122  protected:
123  template <class P>
124  void produces(std::string const& instanceName = {});
125 
126  private:
127  [[noreturn]] std::unique_ptr<Worker> doMakeWorker(
128  WorkerParams const& wp) final;
129  virtual void readResults(Results const&);
130  virtual void writeResults(Results&) = 0;
131 
132  virtual void clear() = 0;
133 
134  virtual void beginJob();
135  virtual void endJob();
136 
137  virtual void beginRun(Run const&);
138  virtual void endRun(Run const&);
139 
140  virtual void beginSubRun(SubRun const&);
141  virtual void endSubRun(SubRun const&);
142 
143  virtual void event(Event const&);
144  };
145 
146 } // namespace art
147 
148 template <class P>
149 inline void
150 art::ResultsProducer::produces(std::string const& instanceName)
151 {
152  ProductRegistryHelper::produces<P, InResults>(instanceName);
153 }
154 
155 namespace cet {
156  template <>
157  struct PluginTypeDeducer<art::ResultsProducer> {
158  static std::string const value;
159  };
160 } // namespace cet
161 
162 #define DEFINE_ART_RESULTS_PLUGIN(klass) \
163  EXTERN_C_FUNC_DECLARE_START \
164  CET_PROVIDE_FILE_PATH() \
165  FHICL_PROVIDE_ALLOWED_CONFIGURATION(klass) \
166  DEFINE_BASIC_PLUGINTYPE_FUNC(art::ResultsProducer) \
167  std::unique_ptr<art::RPWorker> makeRP(art::RPParams const& rpParams, \
168  fhicl::ParameterSet const& ps) \
169  { \
170  return std::make_unique<art::RPWorkerT<klass>>(rpParams, ps); \
171  } \
172  EXTERN_C_FUNC_DECLARE_END
173 
174 #endif /* art_Framework_Core_ResultsProducer_h */
175 
176 // Local Variables:
177 // mode: c++
178 // End:
virtual void beginSubRun(SubRun const &)
void registerProducts(ProductDescriptions &producedProducts, ModuleDescription const &md)
void doEvent(EventPrincipal const &)
void doBeginSubRun(SubRunPrincipal const &)
void doWriteResults(ResultsPrincipal &)
void doReadResults(ResultsPrincipal const &)
ResultsProducer() noexcept(false)
std::vector< BranchDescription > ProductDescriptions
void doEndRun(RunPrincipal const &)
virtual void writeResults(Results &)=0
Definition: Run.h:37
virtual void endSubRun(SubRun const &)
void doBeginRun(RunPrincipal const &)
virtual void event(Event const &)
virtual void clear()=0
void doEndSubRun(SubRunPrincipal const &)
std::unique_ptr< Worker > doMakeWorker(WorkerParams const &wp) final
virtual ~ResultsProducer() noexcept=default
virtual void readResults(Results const &)
virtual void beginJob()
void produces(std::string const &instanceName={})
virtual void beginRun(Run const &)
virtual void endRun(Run const &)
Definition: MVAAlg.h:12