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 <set>
90 #include <string>
91 
92 namespace art {
93 
94  class EventPrincipal;
95  class ResultsPrincipal;
96  class RunPrincipal;
97  class SubRunPrincipal;
98 
99  class Event;
100  class Results;
101  class Run;
102  class SubRun;
103 
104  class ResultsProducer : public ModuleBase,
105  private detail::SharedModule,
106  private ProductRegistryHelper {
107  public:
108  virtual ~ResultsProducer() noexcept = default;
109 
110  ResultsProducer() noexcept(false);
111 
112  template <typename UserConfig, typename KeysToIgnore = void>
114 
115  void doBeginJob();
116  void doEndJob();
117 
118  void doBeginRun(RunPrincipal const&);
119  void doEndRun(RunPrincipal const&);
120 
121  void doBeginSubRun(SubRunPrincipal const&);
122  void doEndSubRun(SubRunPrincipal const&);
123 
124  void doEvent(EventPrincipal const&);
125 
126  void doReadResults(ResultsPrincipal const&);
128  void doClear();
129 
130  void registerProducts(ProductDescriptions& producedProducts,
131  ModuleDescription const& md);
132 
133  protected:
134  template <class P>
135  void produces(std::string const& instanceName = {});
136 
137  private:
138  virtual void readResults(Results const&);
139  virtual void writeResults(Results&) = 0;
140 
141  virtual void clear() = 0;
142 
143  virtual void beginJob();
144  virtual void endJob();
145 
146  virtual void beginRun(Run const&);
147  virtual void endRun(Run const&);
148 
149  virtual void beginSubRun(SubRun const&);
150  virtual void endSubRun(SubRun const&);
151 
152  virtual void event(Event const&);
153  };
154 
155 } // namespace art
156 
157 template <class P>
158 inline void
160 {
161  ProductRegistryHelper::produces<P, InResults>(instanceName);
162 }
163 
164 namespace cet {
165  template <>
167  static std::string const value;
168  };
169 } // namespace cet
170 
171 #define DEFINE_ART_RESULTS_PLUGIN(klass) \
172  EXTERN_C_FUNC_DECLARE_START \
173  CET_PROVIDE_FILE_PATH() \
174  FHICL_PROVIDE_ALLOWED_CONFIGURATION(klass) \
175  DEFINE_BASIC_PLUGINTYPE_FUNC(art::ResultsProducer) \
176  std::unique_ptr<art::RPWorker> makeRP(art::RPParams const& rpParams, \
177  fhicl::ParameterSet const& ps) \
178  { \
179  return std::make_unique<art::RPWorkerT<klass>>(rpParams, ps); \
180  } \
181  EXTERN_C_FUNC_DECLARE_END
182 
183 #endif /* art_Framework_Core_ResultsProducer_h */
184 
185 // Local Variables:
186 // mode: c++
187 // End:
virtual void endJob()
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
virtual void beginSubRun(SubRun const &)
void doEndRun(RunPrincipal const &)
virtual void writeResults(Results &)=0
virtual void beginRun(Run const &)
Definition: Run.h:21
void doBeginRun(RunPrincipal const &)
virtual void clear()=0
void doEndSubRun(SubRunPrincipal const &)
virtual void endRun(Run const &)
virtual ~ResultsProducer() noexcept=default
virtual void readResults(Results const &)
void produces(std::string const &instanceName={})
virtual void endSubRun(SubRun const &)
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
virtual void beginJob()
virtual void event(Event const &)
enum BeamMode string