LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ProvenanceDumperImpl.h
Go to the documentation of this file.
1 #ifndef art_Framework_Modules_detail_ProvenanceDumperImpl_h
2 #define art_Framework_Modules_detail_ProvenanceDumperImpl_h
3 // ProvenanceDumperImpl
5 //
6 // Provides main implementation for ProvenanceDumper
7 //
8 // Uses A LOT of metaprogramming.
9 //
10 // The process_() function will loop over the Groups in a particular
11 // Principal, attempt to resolve the product if possible and then
12 // construct a Provenance to pass to the correct callback function func.
13 //
20 #include "cetlib/metaprogramming.h"
21 #include "fhiclcpp/ParameterSet.h"
22 
23 namespace art::detail {
24 
25  template <typename DETAIL>
27  public:
28  PrincipalProcessor(DETAIL& detail,
29  bool const wantPresentOnly,
30  bool const resolveProducts,
31  bool const wantResolvedOnly)
32  : detail_(detail)
33  , wantPresentOnly_(wantPresentOnly)
34  , resolveProducts_(resolveProducts)
35  , wantResolvedOnly_(wantResolvedOnly)
36  {}
37 
38  void operator()(art::Principal const& p,
39  void (DETAIL::*func)(art::Provenance const&)) const;
40 
41  private:
42  DETAIL& detail_;
43  bool const wantPresentOnly_;
44  bool const resolveProducts_;
45  bool const wantResolvedOnly_;
46  };
47 
48  template <typename DETAIL>
49  void
51  art::Principal const& p,
52  void (DETAIL::*func)(art::Provenance const&)) const
53  {
54  for (auto const& pr : p) {
55  Group const& g = *pr.second;
56  if (resolveProducts_) {
57  bool const resolved_product = g.resolveProductIfAvailable();
58  if (!resolved_product) {
59  continue;
60  }
61  }
62  bool wantCallFunc = true;
63  Provenance const prov{cet::make_exempt_ptr(&g)};
64  if (wantResolvedOnly_) {
65  wantCallFunc = (g.anyProduct() != nullptr);
66  } else if (wantPresentOnly_) {
67  // Unfortunately, there are files in which the product
68  // provenance has not been appropriately stored for dropped
69  // products. The first check below on the product
70  // provenance pointer is a precondition to calling
71  // prov.isPresent(), getting around this incorrect
72  // persistency behavior.
73  wantCallFunc = (g.productProvenance() != nullptr) && prov.isPresent();
74  }
75 
76  if (wantCallFunc) {
77  (detail_.*func)(prov);
78  }
79  }
80  }
81 
83  // Metaprogramming to provide default function if optional
84  // functions do not exist.
85 
86  template <typename T>
88 
89  template <typename R, typename... ARGS>
90  struct default_invocation<R(ARGS...)> {
91  static R
92  invoke(ARGS...)
93  {}
94  };
95 
97  // Metaprogramming to deal with optional pre/post and begin/end
98  // job functions.
99  using cet::enable_if_function_exists_t;
100 
101  // void DETAIL::beginJob();
102  template <typename DETAIL, typename Enable = void>
103  struct maybe_beginJob : default_invocation<void(DETAIL&)> {};
104 
105  template <typename DETAIL>
107  DETAIL,
108  enable_if_function_exists_t<void (DETAIL::*)(), &DETAIL::beginJob>> {
109  static void
110  invoke(DETAIL& detail)
111  {
112  detail.beginJob();
113  }
114  };
115 
116  // void DETAIL::preProcessEvent();
117  template <typename DETAIL, typename Enable = void>
118  struct maybe_preProcessEvent : default_invocation<void(DETAIL&)> {};
119 
120  template <typename DETAIL>
122  DETAIL,
123  enable_if_function_exists_t<void (DETAIL::*)(), &DETAIL::preProcessEvent>> {
124  static void
125  invoke(DETAIL& detail)
126  {
127  detail.preProcessEvent();
128  }
129  };
130 
131  // void DETAIL::postProcessEvent();
132  template <typename DETAIL, typename Enable = void>
133  struct maybe_postProcessEvent : default_invocation<void(DETAIL&)> {};
134 
135  template <typename DETAIL>
137  DETAIL,
138  enable_if_function_exists_t<void (DETAIL::*)(),
139  &DETAIL::postProcessEvent>> {
140  static void
141  invoke(DETAIL& detail)
142  {
143  detail.postProcessEvent();
144  }
145  };
146 
147  // void DETAIL::preProcessSubRun();
148  template <typename DETAIL, typename Enable = void>
149  struct maybe_preProcessSubRun : default_invocation<void(DETAIL&)> {};
150 
151  template <typename DETAIL>
153  DETAIL,
154  enable_if_function_exists_t<void (DETAIL::*)(),
155  &DETAIL::preProcessSubRun>> {
156  static void
157  invoke(DETAIL& detail)
158  {
159  detail.preProcessSubRun();
160  }
161  };
162 
163  // void DETAIL::postProcessSubRun();
164  template <typename DETAIL, typename Enable = void>
165  struct maybe_postProcessSubRun : default_invocation<void(DETAIL&)> {};
166 
167  template <typename DETAIL>
169  DETAIL,
170  enable_if_function_exists_t<void (DETAIL::*)(),
171  &DETAIL::postProcessSubRun>> {
172  static void
173  invoke(DETAIL& detail)
174  {
175  detail.postProcessSubRun();
176  }
177  };
178 
179  // void DETAIL::preProcessRun();
180  template <typename DETAIL, typename Enable = void>
181  struct maybe_preProcessRun : default_invocation<void(DETAIL&)> {};
182 
183  template <typename DETAIL>
185  DETAIL,
186  enable_if_function_exists_t<void (DETAIL::*)(), &DETAIL::preProcessRun>> {
187  static void
188  invoke(DETAIL& detail)
189  {
190  detail.preProcessRun();
191  }
192  };
193 
194  // void DETAIL::postProcessRun();
195  template <typename DETAIL, typename Enable = void>
196  struct maybe_postProcessRun : default_invocation<void(DETAIL&)> {};
197 
198  template <typename DETAIL>
200  DETAIL,
201  enable_if_function_exists_t<void (DETAIL::*)(), &DETAIL::postProcessRun>> {
202  static void
203  invoke(DETAIL& detail)
204  {
205  detail.postProcessRun();
206  }
207  };
208 
209  // void DETAIL::endJob();
210  template <typename DETAIL, typename Enable = void>
211  struct maybe_endJob : default_invocation<void(DETAIL&)> {};
212 
213  template <typename DETAIL>
214  struct maybe_endJob<
215  DETAIL,
216  enable_if_function_exists_t<void (DETAIL::*)(), &DETAIL::endJob>> {
217  static void
218  invoke(DETAIL& detail)
219  {
220  detail.endJob();
221  }
222  };
224 
226  // Metaprogramming to deal with optional per-provenance functions.
227 
228  // void DETAIL::processSubRunProvenance(art:Provenance const &);
229  template <typename DETAIL, typename Enable = void>
231  : default_invocation<void(PrincipalProcessor<DETAIL> const&,
232  EventPrincipal const&)> {};
233 
234  template <typename DETAIL>
236  DETAIL,
237  enable_if_function_exists_t<void (DETAIL::*)(Provenance const&),
238  &DETAIL::processEventProvenance>> {
239  static void
241  {
242  pp(p, &DETAIL::processEventProvenance);
243  }
244  };
245 
246  // void DETAIL::processSubRunProvenance(art:Provenance const &);
247  template <typename DETAIL, typename Enable = void>
249  : default_invocation<void(PrincipalProcessor<DETAIL> const&,
250  SubRunPrincipal const&)> {};
251 
252  template <typename DETAIL>
254  DETAIL,
255  enable_if_function_exists_t<void (DETAIL::*)(Provenance const&),
256  &DETAIL::processSubRunProvenance>> {
257  static void
259  {
260  pp(p, &DETAIL::processSubRunProvenance);
261  }
262  };
263 
264  // void DETAIL::processRunProvenance(art:Provenance const &);
265  template <typename DETAIL, typename Enable = void>
267  : default_invocation<void(PrincipalProcessor<DETAIL> const&,
268  RunPrincipal const&)> {};
269 
270  template <typename DETAIL>
272  DETAIL,
273  enable_if_function_exists_t<void (DETAIL::*)(Provenance const&),
274  &DETAIL::processRunProvenance>> {
275  static void
277  {
278  pp(p, &DETAIL::processRunProvenance);
279  }
280  };
281 
283 
284  template <typename DETAIL>
286 
287  DETAIL& detail_;
289 
290  public:
292  : detail_{detail}, pp_{pp}
293  {}
294 
295  void
297  {
299  }
300 
301  void
303  {
307  }
308 
309  void
311  {
315  }
316 
317  void
319  {
323  }
324 
325  void
327  {
329  }
330  };
331 
332 } // namespace art::detail
333 
334 #endif /* art_Framework_Modules_detail_ProvenanceDumperImpl_h */
335 
336 // Local Variables:
337 // mode: c++
338 // End:
TRandom r
Definition: spectrum.C:23
void operator()(art::Principal const &p, void(DETAIL::*func)(art::Provenance const &)) const
cet::exempt_ptr< ProductProvenance const > productProvenance() const
Definition: Group.cc:145
void beginJob()
Definition: Breakpoints.cc:14
void writeSubRun(SubRunPrincipal &sr)
EDProduct const * anyProduct() const
Definition: Group.cc:54
bool resolveProductIfAvailable(TypeID wanted_wrapper=TypeID{}) const
Definition: Group.cc:286
PrincipalProcessor(DETAIL &detail, bool const wantPresentOnly, bool const resolveProducts, bool const wantResolvedOnly)
bool isPresent() const
Definition: Provenance.cc:115
Float_t e
Definition: plot.C:35
ProvenanceDumperImpl(DETAIL &detail, PrincipalProcessor< DETAIL > &pp)
PrincipalProcessor< DETAIL > & pp_