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 ////////////////////////////////////////////////////////////////////////
20 #include "cetlib/metaprogramming.h"
21 #include "fhiclcpp/ParameterSet.h"
22 
23 namespace art {
24  namespace detail {
25 
26  template <typename DETAIL>
28  public:
30  bool const wantPresentOnly,
31  bool const resolveProducts,
32  bool const wantResolvedOnly)
33  : detail_(detail)
34  , wantPresentOnly_(wantPresentOnly)
35  , resolveProducts_(resolveProducts)
36  , wantResolvedOnly_(wantResolvedOnly)
37  {}
38 
39  void operator()(art::Principal const& p,
40  void (DETAIL::*func)(art::Provenance const&)) const;
41 
42  private:
43  DETAIL& detail_;
44  bool const wantPresentOnly_;
45  bool const resolveProducts_;
46  bool const wantResolvedOnly_;
47  };
48 
49  template <typename DETAIL>
50  void
52  art::Principal const& p,
53  void (DETAIL::*func)(art::Provenance const&)) const
54  {
55  for (auto const& pr : p) {
56  Group const& g = *pr.second;
57  if (resolveProducts_) {
58  bool const resolved_product = g.resolveProductIfAvailable();
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 = (g.productProvenance() != nullptr) && prov.isPresent();
75  }
76 
77  if (wantCallFunc) {
78  (detail_.*func)(prov);
79  }
80  }
81  }
82 
83  ////////////////////////////////////////////////////////////////////////
84  // Metaprogramming to provide default function if optional
85  // functions do not exist.
86 
87  template <typename T>
89 
90  template <typename R, typename... ARGS>
91  struct default_invocation<R(ARGS...)> {
92  static R
93  invoke(ARGS...)
94  {}
95  };
96 
97  ////////////////////////////////////////////////////////////////////////
98  // Metaprogramming to deal with optional pre/post and begin/end
99  // job functions.
101 
102  // void DETAIL::beginJob();
103  template <typename DETAIL, typename Enable = void>
104  struct maybe_beginJob : default_invocation<void(DETAIL&)> {};
105 
106  template <typename DETAIL>
108  DETAIL,
109  enable_if_function_exists_t<void (DETAIL::*)(), &DETAIL::beginJob>> {
110  static void
111  invoke(DETAIL& detail)
112  {
113  detail.beginJob();
114  }
115  };
116 
117  // void DETAIL::preProcessEvent();
118  template <typename DETAIL, typename Enable = void>
119  struct maybe_preProcessEvent : default_invocation<void(DETAIL&)> {};
120 
121  template <typename DETAIL>
123  DETAIL,
124  enable_if_function_exists_t<void (DETAIL::*)(),
125  &DETAIL::preProcessEvent>> {
126  static void
127  invoke(DETAIL& detail)
128  {
129  detail.preProcessEvent();
130  }
131  };
132 
133  // void DETAIL::postProcessEvent();
134  template <typename DETAIL, typename Enable = void>
135  struct maybe_postProcessEvent : default_invocation<void(DETAIL&)> {};
136 
137  template <typename DETAIL>
139  DETAIL,
140  enable_if_function_exists_t<void (DETAIL::*)(),
141  &DETAIL::postProcessEvent>> {
142  static void
143  invoke(DETAIL& detail)
144  {
145  detail.postProcessEvent();
146  }
147  };
148 
149  // void DETAIL::preProcessSubRun();
150  template <typename DETAIL, typename Enable = void>
151  struct maybe_preProcessSubRun : default_invocation<void(DETAIL&)> {};
152 
153  template <typename DETAIL>
155  DETAIL,
156  enable_if_function_exists_t<void (DETAIL::*)(),
157  &DETAIL::preProcessSubRun>> {
158  static void
159  invoke(DETAIL& detail)
160  {
161  detail.preProcessSubRun();
162  }
163  };
164 
165  // void DETAIL::postProcessSubRun();
166  template <typename DETAIL, typename Enable = void>
167  struct maybe_postProcessSubRun : default_invocation<void(DETAIL&)> {};
168 
169  template <typename DETAIL>
171  DETAIL,
172  enable_if_function_exists_t<void (DETAIL::*)(),
173  &DETAIL::postProcessSubRun>> {
174  static void
175  invoke(DETAIL& detail)
176  {
177  detail.postProcessSubRun();
178  }
179  };
180 
181  // void DETAIL::preProcessRun();
182  template <typename DETAIL, typename Enable = void>
183  struct maybe_preProcessRun : default_invocation<void(DETAIL&)> {};
184 
185  template <typename DETAIL>
187  DETAIL,
188  enable_if_function_exists_t<void (DETAIL::*)(), &DETAIL::preProcessRun>> {
189  static void
190  invoke(DETAIL& detail)
191  {
192  detail.preProcessRun();
193  }
194  };
195 
196  // void DETAIL::postProcessRun();
197  template <typename DETAIL, typename Enable = void>
198  struct maybe_postProcessRun : default_invocation<void(DETAIL&)> {};
199 
200  template <typename DETAIL>
202  DETAIL,
203  enable_if_function_exists_t<void (DETAIL::*)(),
204  &DETAIL::postProcessRun>> {
205  static void
206  invoke(DETAIL& detail)
207  {
208  detail.postProcessRun();
209  }
210  };
211 
212  // void DETAIL::endJob();
213  template <typename DETAIL, typename Enable = void>
214  struct maybe_endJob : default_invocation<void(DETAIL&)> {};
215 
216  template <typename DETAIL>
217  struct maybe_endJob<
218  DETAIL,
219  enable_if_function_exists_t<void (DETAIL::*)(), &DETAIL::endJob>> {
220  static void
221  invoke(DETAIL& detail)
222  {
223  detail.endJob();
224  }
225  };
226  ////////////////////////////////////////////////////////////////////////
227 
228  ////////////////////////////////////////////////////////////////////////
229  // Metaprogramming to deal with optional per-provenance functions.
230 
231  // void DETAIL::processSubRunProvenance(art:Provenance const &);
232  template <typename DETAIL, typename Enable = void>
234  : default_invocation<void(PrincipalProcessor<DETAIL> const&,
235  EventPrincipal const&)> {};
236 
237  template <typename DETAIL>
239  DETAIL,
240  enable_if_function_exists_t<void (DETAIL::*)(Provenance const&),
241  &DETAIL::processEventProvenance>> {
242  static void
244  {
245  pp(p, &DETAIL::processEventProvenance);
246  }
247  };
248 
249  // void DETAIL::processSubRunProvenance(art:Provenance const &);
250  template <typename DETAIL, typename Enable = void>
252  : default_invocation<void(PrincipalProcessor<DETAIL> const&,
253  SubRunPrincipal const&)> {};
254 
255  template <typename DETAIL>
257  DETAIL,
258  enable_if_function_exists_t<void (DETAIL::*)(Provenance const&),
259  &DETAIL::processSubRunProvenance>> {
260  static void
262  {
263  pp(p, &DETAIL::processSubRunProvenance);
264  }
265  };
266 
267  // void DETAIL::processRunProvenance(art:Provenance const &);
268  template <typename DETAIL, typename Enable = void>
270  : default_invocation<void(PrincipalProcessor<DETAIL> const&,
271  RunPrincipal const&)> {};
272 
273  template <typename DETAIL>
275  DETAIL,
276  enable_if_function_exists_t<void (DETAIL::*)(Provenance const&),
277  &DETAIL::processRunProvenance>> {
278  static void
280  {
281  pp(p, &DETAIL::processRunProvenance);
282  }
283  };
284 
285  ////////////////////////////////////////////////////////////////////////
286 
287  template <typename DETAIL>
289 
290  DETAIL& detail_;
292 
293  public:
295  : detail_{detail}, pp_{pp}
296  {}
297 
298  void
300  {
302  }
303 
304  void
306  {
310  }
311 
312  void
314  {
318  }
319 
320  void
322  {
326  }
327 
328  void
330  {
332  }
333  };
334 
335  } // namespace detail
336 } // namespace art
337 
338 #endif /* art_Framework_Modules_detail_ProvenanceDumperImpl_h */
339 
340 // Local Variables:
341 // mode: c++
342 // End:
void operator()(art::Principal const &p, void(DETAIL::*func)(art::Provenance const &)) const
static constexpr double g
Definition: Units.h:144
enable_if_same_t< FT, decltype(f), R > enable_if_function_exists_t
cet::exempt_ptr< ProductProvenance const > productProvenance() const
Definition: Group.cc:145
const double e
void beginJob()
Definition: Breakpoints.cc:14
void writeSubRun(SubRunPrincipal &sr)
constexpr exempt_ptr< E > make_exempt_ptr(E *) noexcept
p
Definition: test.py:223
EDProduct const * anyProduct() const
Definition: Group.cc:54
def func()
Definition: docstring.py:7
bool resolveProductIfAvailable(TypeID wanted_wrapper=TypeID{}) const
Definition: Group.cc:286
PrincipalProcessor(DETAIL &detail, bool const wantPresentOnly, bool const resolveProducts, bool const wantResolvedOnly)
static constexpr double sr
Definition: Units.h:166
ProvenanceDumperImpl(DETAIL &detail, PrincipalProcessor< DETAIL > &pp)
PrincipalProcessor< DETAIL > & pp_