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 
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  virtual void readResults(Results const&);
128  virtual void writeResults(Results&) = 0;
129 
130  virtual void clear() = 0;
131 
132  virtual void beginJob();
133  virtual void endJob();
134 
135  virtual void beginRun(Run const&);
136  virtual void endRun(Run const&);
137 
138  virtual void beginSubRun(SubRun const&);
139  virtual void endSubRun(SubRun const&);
140 
141  virtual void event(Event const&);
142  };
143 
144 } // namespace art
145 
146 template <class P>
147 inline void
149 {
150  ProductRegistryHelper::produces<P, InResults>(instanceName);
151 }
152 
153 namespace cet {
154  template <>
156  static std::string const value;
157  };
158 } // namespace cet
159 
160 #define DEFINE_ART_RESULTS_PLUGIN(klass) \
161  EXTERN_C_FUNC_DECLARE_START \
162  CET_PROVIDE_FILE_PATH() \
163  FHICL_PROVIDE_ALLOWED_CONFIGURATION(klass) \
164  DEFINE_BASIC_PLUGINTYPE_FUNC(art::ResultsProducer) \
165  std::unique_ptr<art::RPWorker> makeRP(art::RPParams const& rpParams, \
166  fhicl::ParameterSet const& ps) \
167  { \
168  return std::make_unique<art::RPWorkerT<klass>>(rpParams, ps); \
169  } \
170  EXTERN_C_FUNC_DECLARE_END
171 
172 #endif /* art_Framework_Core_ResultsProducer_h */
173 
174 // Local Variables:
175 // mode: c++
176 // End:
virtual void beginSubRun(SubRun const &)
void registerProducts(ProductDescriptions &producedProducts, ModuleDescription const &md)
void doEvent(EventPrincipal const &)
std::string string
Definition: nybbler.cc:12
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:17
virtual void endSubRun(SubRun const &)
void doBeginRun(RunPrincipal const &)
virtual void event(Event const &)
virtual void clear()=0
void doEndSubRun(SubRunPrincipal const &)
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 &)