ProvenanceDumper.h
Go to the documentation of this file.
1 #ifndef art_Framework_Modules_ProvenanceDumper_h
2 #define art_Framework_Modules_ProvenanceDumper_h
3 ////////////////////////////////////////////////////////////////////////
4 // ProvenanceDumper
5 //
6 // This class template is used to create output modules capable of
7 // iterating over all Provenances in an event, subrun or run.
8 //
9 // Note that it is always possible to obtain the provenance for a
10 // *particular* product through its handle: this class template is only
11 // for cases where one wishes to iterate over many Provenances without
12 // necesarily loading each product.
13 //
14 // There are two parameters that control the behavior of this module
15 // template:
16 //
17 // 1. wantPresentOnly (bool, default true).
18 //
19 // If true, produce provenances and invoke relevant callbacks only
20 // if the product is actually present in the event (but see
21 // wantResolvedOnly below, which supercedes).
22 //
23 // 2. resolveProducts (bool, default true).
24 //
25 // If true, attempt to resolve the product if it is present.
26 //
27 // 3. wantResolvedOnly (bool, default false).
28 // If true, produce provenances and invoke relevant callbacks only
29 // if the product has already been resolved successfully (either
30 // due to resolveProducts or by other means).
31 //
32 // The ProvenanceDumper class template requires the use of a type DETAIL
33 // as its template paramenter; this type DETAIL must supply the
34 // following non-static member functions:
35 //
36 // DETAIL(art::OutputModule::Table<Config> const &p);
37 //
38 // // Construct an object of type DETAIL. The 'Config' struct
39 // // will be that provided corresponding to the module constructing the
40 // // DETAIL. It is recommended (but not enforced) that detail
41 // // parameters be placed in their own (eg "detail") ParameterSet to
42 // // reduce the potential for clashes with parameters used by the
43 // // template.
44 //
45 // In addition, T may optionally provide any or all of the following
46 // member functions; each will be callled at the appropriate time iff it
47 // is declared. Note that *none* of the functions here should be
48 // declared const.
49 //
50 // void beginJob();
51 //
52 // // Called at the beginning of the job, from the template module's
53 // // beginJob() member function.
54 //
55 // void preProcessEvent();
56 //
57 // // Called prior to looping over any Provenances to be found in the
58 // // event (always called if present).
59 //
60 // void processEventProvenance(art::Provenance const &); // OR
61 //
62 // // Called for each Provenance in the event (not called if there
63 // // are none).
64 //
65 // void postProcessEvent();
66 //
67 // // Called after looping over any Provenances to be found in the
68 // // event (always called if present).
69 //
70 // void preProcessSubRun();
71 //
72 // // Called prior to looping over any Provenances to be found in the
73 // // subrun (always called if present).
74 //
75 // void processSubRunProvenance(art::Provenance const &); // OR
76 //
77 // // Called for each Provenance in the subrun (not called if there
78 // // are none).
79 //
80 // void postProcessSubRun();
81 //
82 // // Called after looping over any Provenances to be found in the
83 // // subrun (always called if present).
84 //
85 // void preProcessRun();
86 //
87 // // Called prior to looping over any Provenances to be found in the
88 // // run (always called if present).
89 //
90 // void processRunProvenance(art::Provenance const &); // OR
91 //
92 // // Called for each Provenance in the run (not called if there
93 // // are none).
94 //
95 // void postProcessRun();
96 //
97 // // Called after looping over any Provenances to be found in the
98 // // run (always called if present).
99 //
100 // void endJob();
101 //
102 // // Called at the end of the job, from the template module's
103 // // endJob() member function.
104 //
105 ////////////////////////////////////
106 // For advanced notes, see detail/ProvenanceDumperImpl.h.
107 //
108 //
109 ////////////////////////////////////////////////////////////////////////
118 #include "cetlib/exempt_ptr.h"
119 #include "cetlib/metaprogramming.h"
120 #include "fhiclcpp/ParameterSet.h"
121 #include "fhiclcpp/types/Atom.h"
123 #include "fhiclcpp/types/Sequence.h"
124 
125 #include <algorithm>
126 
127 namespace art {
128  template <typename DETAIL, typename Enable = void>
130 
131  template <typename DETAIL, typename Enable = void>
134  fhicl::Atom<bool> wantPresentOnly{fhicl::Name("wantPresentOnly"), true};
135  fhicl::Atom<bool> resolveProducts{fhicl::Name("resolveProducts"), true};
136  fhicl::Atom<bool> wantResolvedOnly{fhicl::Name("wantResolvedOnly"), true};
137  };
138 
139  template <typename DETAIL>
140  struct ProvenanceDumperConfig<DETAIL, std::void_t<typename DETAIL::Config>> {
142  fhicl::Atom<bool> wantPresentOnly{fhicl::Name("wantPresentOnly"), true};
143  fhicl::Atom<bool> resolveProducts{fhicl::Name("resolveProducts"), true};
144  fhicl::Atom<bool> wantResolvedOnly{fhicl::Name("wantResolvedOnly"), true};
146  };
147 
148  namespace detail {
149  template <typename DETAIL>
150  class PrincipalProcessor;
151  }
152 } // namespace art
153 
154 template <typename DETAIL, typename Enable>
155 class art::ProvenanceDumper : public OutputModule {
156 public:
158  : OutputModule{ps}
159  , detail_{ps}
160  , pp_{detail_,
161  ps.get<bool>("wantPresentOnly", true),
162  ps.get<bool>("resolveProducts", true),
163  ps.get<bool>("wantResolvedOnly", false)}
164  , impl_{detail_, pp_}
165  {}
166 
167 private:
168  void
169  beginJob() override
170  {
171  impl_.beginJob();
172  }
173  void
174  endJob() override
175  {
176  impl_.endJob();
177  }
178 
179  void
180  write(EventPrincipal& e) override
181  {
182  impl_.write(e);
183  }
184  void
186  {
187  impl_.writeSubRun(sr);
188  }
189  void
191  {
192  impl_.writeRun(r);
193  }
194 
195  DETAIL detail_;
198 };
199 
200 namespace art {
201 
202  template <typename DETAIL>
203  class ProvenanceDumper<DETAIL, std::void_t<typename DETAIL::Config>>
204  : public OutputModule {
205  public:
206  using Parameters =
209 
210  explicit ProvenanceDumper(Parameters const& ps)
211  : OutputModule{ps().omConfig, ps.get_PSet()}
212  , detail_{ps().user}
213  , pp_{detail_,
214  ps().wantPresentOnly(),
215  ps().resolveProducts(),
216  ps().wantResolvedOnly()}
217  , impl_{detail_, pp_}
218  {}
219 
220  private:
221  void
222  beginJob() override
223  {
224  impl_.beginJob();
225  }
226  void
227  endJob() override
228  {
229  impl_.endJob();
230  }
231 
232  void
233  write(EventPrincipal& e) override
234  {
235  impl_.write(e);
236  }
237  void
239  {
240  impl_.writeSubRun(sr);
241  }
242  void
244  {
245  impl_.writeRun(r);
246  }
247 
248  DETAIL detail_;
251  };
252 } // namespace art
253 
254 #endif /* art_Framework_Modules_ProvenanceDumper_h */
255 
256 // Local Variables:
257 // mode: c++
258 // End:
void endJob() override
fhicl::Atom< bool > resolveProducts
auto const & get_PSet() const
void beginJob() override
ChannelGroupService::Name Name
detail::ProvenanceDumperImpl< DETAIL > impl_
STL namespace.
fhicl::Atom< bool > wantPresentOnly
void writeRun(RunPrincipal &r) override
fhicl::Atom< bool > wantResolvedOnly
const double e
fhicl::TableFragment< art::OutputModule::Config > omConfig
void writeSubRun(SubRunPrincipal &sr) override
ProvenanceDumper(fhicl::ParameterSet const &ps)
static constexpr double ps
Definition: Units.h:99
void write(EventPrincipal &e) override
detail::PrincipalProcessor< DETAIL > pp_
static constexpr double sr
Definition: Units.h:166