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 ////////////////////////////////////////////////////////////////////////
4 // 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 //
14 ////////////////////////////////////////////////////////////////////////
19 #include "cetlib/metaprogramming.h"
20 #include "fhiclcpp/ParameterSet.h"
21 
22 namespace art {
23  namespace 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 =
59  if (!resolved_product) {
60  continue;
61  }
62  }
63  bool wantCallFunc = true;
64  Provenance const prov{cet::make_exempt_ptr(&g)};
65  if (wantResolvedOnly_) {
66  wantCallFunc = (g.anyProduct() != nullptr);
67  } else if (wantPresentOnly_) {
68  // Unfortunately, there are files in which the product
69  // provenance has not been appropriately stored for dropped
70  // products. The first check below on the product
71  // provenance pointer is a precondition to calling
72  // prov.isPresent(), getting around this incorrect
73  // persistency behavior.
74  wantCallFunc =
75  (g.productProvenancePtr() != nullptr) && prov.isPresent();
76  }
77 
78  if (wantCallFunc) {
79  (detail_.*func)(prov);
80  }
81  }
82  }
83 
84  ////////////////////////////////////////////////////////////////////////
85  // Metaprogramming to provide default function if optional
86  // functions do not exist.
87 
88  template <typename T>
90 
91  template <typename R, typename... ARGS>
92  struct default_invocation<R(ARGS...)> {
93  static R
94  invoke(ARGS...)
95  {}
96  };
97 
98  ////////////////////////////////////////////////////////////////////////
99  // Metaprogramming to deal with optional pre/post and begin/end
100  // job functions.
102 
103  // void DETAIL::beginJob();
104  template <typename DETAIL, typename Enable = void>
105  struct maybe_beginJob : default_invocation<void(DETAIL&)> {};
106 
107  template <typename DETAIL>
109  DETAIL,
111  static void
112  invoke(DETAIL& detail)
113  {
114  detail.beginJob();
115  }
116  };
117 
118  // void DETAIL::preProcessEvent();
119  template <typename DETAIL, typename Enable = void>
120  struct maybe_preProcessEvent : default_invocation<void(DETAIL&)> {};
121 
122  template <typename DETAIL>
124  DETAIL,
125  enable_if_function_exists_t<void (DETAIL::*)(),
126  &DETAIL::preProcessEvent>> {
127  static void
128  invoke(DETAIL& detail)
129  {
130  detail.preProcessEvent();
131  }
132  };
133 
134  // void DETAIL::postProcessEvent();
135  template <typename DETAIL, typename Enable = void>
136  struct maybe_postProcessEvent : default_invocation<void(DETAIL&)> {};
137 
138  template <typename DETAIL>
140  DETAIL,
141  enable_if_function_exists_t<void (DETAIL::*)(),
142  &DETAIL::postProcessEvent>> {
143  static void
144  invoke(DETAIL& detail)
145  {
146  detail.postProcessEvent();
147  }
148  };
149 
150  // void DETAIL::preProcessSubRun();
151  template <typename DETAIL, typename Enable = void>
152  struct maybe_preProcessSubRun : default_invocation<void(DETAIL&)> {};
153 
154  template <typename DETAIL>
156  DETAIL,
157  enable_if_function_exists_t<void (DETAIL::*)(),
158  &DETAIL::preProcessSubRun>> {
159  static void
160  invoke(DETAIL& detail)
161  {
162  detail.preProcessSubRun();
163  }
164  };
165 
166  // void DETAIL::postProcessSubRun();
167  template <typename DETAIL, typename Enable = void>
168  struct maybe_postProcessSubRun : default_invocation<void(DETAIL&)> {};
169 
170  template <typename DETAIL>
172  DETAIL,
173  enable_if_function_exists_t<void (DETAIL::*)(),
174  &DETAIL::postProcessSubRun>> {
175  static void
176  invoke(DETAIL& detail)
177  {
178  detail.postProcessSubRun();
179  }
180  };
181 
182  // void DETAIL::preProcessRun();
183  template <typename DETAIL, typename Enable = void>
184  struct maybe_preProcessRun : default_invocation<void(DETAIL&)> {};
185 
186  template <typename DETAIL>
188  DETAIL,
189  enable_if_function_exists_t<void (DETAIL::*)(), &DETAIL::preProcessRun>> {
190  static void
191  invoke(DETAIL& detail)
192  {
193  detail.preProcessRun();
194  }
195  };
196 
197  // void DETAIL::postProcessRun();
198  template <typename DETAIL, typename Enable = void>
199  struct maybe_postProcessRun : default_invocation<void(DETAIL&)> {};
200 
201  template <typename DETAIL>
203  DETAIL,
204  enable_if_function_exists_t<void (DETAIL::*)(),
205  &DETAIL::postProcessRun>> {
206  static void
207  invoke(DETAIL& detail)
208  {
209  detail.postProcessRun();
210  }
211  };
212 
213  // void DETAIL::endJob();
214  template <typename DETAIL, typename Enable = void>
215  struct maybe_endJob : default_invocation<void(DETAIL&)> {};
216 
217  template <typename DETAIL>
218  struct maybe_endJob<
219  DETAIL,
220  enable_if_function_exists_t<void (DETAIL::*)(), &DETAIL::endJob>> {
221  static void
222  invoke(DETAIL& detail)
223  {
224  detail.endJob();
225  }
226  };
227  ////////////////////////////////////////////////////////////////////////
228 
229  ////////////////////////////////////////////////////////////////////////
230  // Metaprogramming to deal with optional per-provenance functions.
231 
232  // void DETAIL::processSubRunProvenance(art:Provenance const &);
233  template <typename DETAIL, typename Enable = void>
235  : default_invocation<void(PrincipalProcessor<DETAIL> const&,
236  EventPrincipal const&)> {};
237 
238  template <typename DETAIL>
240  DETAIL,
241  enable_if_function_exists_t<void (DETAIL::*)(Provenance const&),
242  &DETAIL::processEventProvenance>> {
243  static void
245  {
246  pp(p, &DETAIL::processEventProvenance);
247  }
248  };
249 
250  // void DETAIL::processSubRunProvenance(art:Provenance const &);
251  template <typename DETAIL, typename Enable = void>
253  : default_invocation<void(PrincipalProcessor<DETAIL> const&,
254  SubRunPrincipal const&)> {};
255 
256  template <typename DETAIL>
258  DETAIL,
259  enable_if_function_exists_t<void (DETAIL::*)(Provenance const&),
260  &DETAIL::processSubRunProvenance>> {
261  static void
263  {
264  pp(p, &DETAIL::processSubRunProvenance);
265  }
266  };
267 
268  // void DETAIL::processRunProvenance(art:Provenance const &);
269  template <typename DETAIL, typename Enable = void>
271  : default_invocation<void(PrincipalProcessor<DETAIL> const&,
272  RunPrincipal const&)> {};
273 
274  template <typename DETAIL>
276  DETAIL,
277  enable_if_function_exists_t<void (DETAIL::*)(Provenance const&),
278  &DETAIL::processRunProvenance>> {
279  static void
281  {
282  pp(p, &DETAIL::processRunProvenance);
283  }
284  };
285 
286  ////////////////////////////////////////////////////////////////////////
287 
288  template <typename DETAIL>
290 
291  DETAIL& detail_;
293 
294  public:
296  : detail_{detail}, pp_{pp}
297  {}
298 
299  void
301  {
303  }
304 
305  void
307  {
311  }
312 
313  void
315  {
319  }
320 
321  void
323  {
327  }
328 
329  void
331  {
333  }
334  };
335 
336  } // detail
337 } // art
338 
339 #endif /* art_Framework_Modules_detail_ProvenanceDumperImpl_h */
340 
341 // Local Variables:
342 // mode: c++
343 // End:
void operator()(art::Principal const &p, void(DETAIL::*func)(art::Provenance const &)) const
const char * p
Definition: xmltok.h:285
enable_if_same_t< FT, decltype(f), R > enable_if_function_exists_t
void beginJob()
TypeID const & producedWrapperType() const
Definition: Group.h:162
void writeSubRun(SubRunPrincipal &sr)
exempt_ptr< E > make_exempt_ptr(E *) noexcept
bool resolveProductIfAvailable(TypeID const &) const override
#define R(x)
caf::StandardRecord * sr
double func(double x, double y)
TRandom3 r(0)
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
PrincipalProcessor(DETAIL &detail, bool const wantPresentOnly, bool const resolveProducts, bool const wantResolvedOnly)
Float_t e
Definition: plot.C:35
EDProduct const * anyProduct() const override
Definition: Group.h:97
cet::exempt_ptr< ProductProvenance const > productProvenancePtr() const
ProvenanceDumperImpl(DETAIL &detail, PrincipalProcessor< DETAIL > &pp)
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData
PrincipalProcessor< DETAIL > & pp_