LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
ProvenanceDumper.h
Go to the documentation of this file.
1 #ifndef art_Framework_Modules_ProvenanceDumper_h
2 #define art_Framework_Modules_ProvenanceDumper_h
3 // 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 //
106 // For advanced notes, see detail/ProvenanceDumperImpl.h.
107 //
108 //
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>
141  DETAIL,
142  cet::enable_if_type_exists_t<typename DETAIL::Config>> {
144  fhicl::Atom<bool> wantPresentOnly{fhicl::Name("wantPresentOnly"), true};
145  fhicl::Atom<bool> resolveProducts{fhicl::Name("resolveProducts"), true};
146  fhicl::Atom<bool> wantResolvedOnly{fhicl::Name("wantResolvedOnly"), true};
148  };
149 
150  namespace detail {
151  template <typename DETAIL>
152  class PrincipalProcessor;
153  }
154 }
155 
156 template <typename DETAIL, typename Enable>
157 class art::ProvenanceDumper : public OutputModule {
158 public:
160  : OutputModule{ps}
161  , detail_{ps}
162  , pp_{detail_,
163  ps.get<bool>("wantPresentOnly", true),
164  ps.get<bool>("resolveProducts", true),
165  ps.get<bool>("wantResolvedOnly", false)}
166  , impl_{detail_, pp_}
167  {}
168 
169 private:
170  void
171  beginJob() override
172  {
173  impl_.beginJob();
174  }
175  void
176  endJob() override
177  {
178  impl_.endJob();
179  }
180 
181  void
182  write(EventPrincipal& e) override
183  {
184  impl_.write(e);
185  }
186  void
188  {
189  impl_.writeSubRun(sr);
190  }
191  void
192  writeRun(RunPrincipal& r) override
193  {
194  impl_.writeRun(r);
195  }
196 
197  DETAIL detail_;
200 };
201 
202 namespace art {
203 
204  template <typename DETAIL>
205  class ProvenanceDumper<DETAIL,
206  cet::enable_if_type_exists_t<typename DETAIL::Config>>
207  : public OutputModule {
208  public:
209  using Parameters =
212 
213  explicit ProvenanceDumper(Parameters const& ps)
214  : OutputModule{ps().omConfig, ps.get_PSet()}
215  , detail_{ps().user}
216  , pp_{detail_,
217  ps().wantPresentOnly(),
218  ps().resolveProducts(),
219  ps().wantResolvedOnly()}
220  , impl_{detail_, pp_}
221  {}
222 
223  private:
224  void
225  beginJob() override
226  {
227  impl_.beginJob();
228  }
229  void
230  endJob() override
231  {
232  impl_.endJob();
233  }
234 
235  void
236  write(EventPrincipal& e) override
237  {
238  impl_.write(e);
239  }
240  void
242  {
243  impl_.writeSubRun(sr);
244  }
245  void
246  writeRun(RunPrincipal& r) override
247  {
248  impl_.writeRun(r);
249  }
250 
251  DETAIL detail_;
254  };
255 }
256 
257 #endif /* art_Framework_Modules_ProvenanceDumper_h */
258 
259 // Local Variables:
260 // mode: c++
261 // End:
void endJob() override
fhicl::Atom< bool > resolveProducts
auto const & get_PSet() const
void beginJob() override
detail::ProvenanceDumperImpl< DETAIL > impl_
fhicl::Atom< bool > wantPresentOnly
void writeRun(RunPrincipal &r) override
fhicl::Atom< bool > wantResolvedOnly
fhicl::TableFragment< art::OutputModule::Config > omConfig
typename enable_if_type_exists< T, R >::type enable_if_type_exists_t
T get(std::string const &key) const
Definition: ParameterSet.h:231
void writeSubRun(SubRunPrincipal &sr) override
ProvenanceDumper(fhicl::ParameterSet const &ps)
void write(EventPrincipal &e) override
HLT enums.
detail::PrincipalProcessor< DETAIL > pp_
Float_t e
Definition: plot.C:34