GenericOneSimpleProductAnalyzer.h
Go to the documentation of this file.
1 #ifndef art_test_Integration_GenericOneSimpleProductAnalyzer_h
2 #define art_test_Integration_GenericOneSimpleProductAnalyzer_h
3 
10 #include "cetlib/metaprogramming.h"
11 #include "cetlib_except/exception.h"
12 #include "fhiclcpp/ParameterSet.h"
13 #include "fhiclcpp/types/Atom.h"
14 
15 #include <string>
16 #include <type_traits>
17 
18 namespace arttest {
19  template <typename V, typename P>
21  namespace detail {
22 
23  // All this detail is to decide whether our product P has a "value"
24  // member or is (effectively) convertible-to-V.
25 
26  template <typename V, typename P, V P::*>
27  struct value_member;
28  template <typename V, typename P>
30  template <typename V, typename P>
32 
33  template <typename V, typename P>
35  static bool constexpr value{sizeof(has_value_helper<V, P>(nullptr)) ==
36  sizeof(cet::yes_tag)};
37  };
38 
39  template <typename V, typename P>
40  struct GetValue {
41  V const&
43  {
44  return h->value;
45  }
46  };
47 
48  template <typename V, typename P>
50  V const&
52  {
53  return *h;
54  }
55  };
56 
57  } // namespace detail
58 } // namespace arttest
59 
60 template <typename V, typename P>
62 public:
63  struct Config {
64 
66  : input_label{fhicl::Name{"input_label"}}
67  , branch_type{fhicl::Name{"branch_type"}, art::InEvent}
68  , require_presence{fhicl::Name{"require_presence"},
70  "If 'require_presence' is true, then the product\n"
71  "must be successfully retrievable. If false, then\n"
72  "the product must NOT be successfully "
73  "retrievable--i.e.\n"
74  "a call to 'getByLabel' must return false."},
75  true}
76  , expected_value{
77  fhicl::Name{"expected_value"},
78  fhicl::Comment{"The value of the following parameter is retrieved\n"
79  "only if require_presence is 'true'."},
80  [this] { return require_presence(); }}
81  {}
82 
87  };
88 
89  using Parameters = EDAnalyzer::Table<Config>;
91  : EDAnalyzer{ps}
92  , input_label_{ps().input_label()}
93  , branch_type_{art::BranchType(ps().branch_type())}
94  , require_presence_{ps().require_presence()}
95  {
96  switch (branch_type_) {
97  case art::InEvent:
98  consumes<P>(input_label_);
99  break;
100  case art::InSubRun:
101  consumes<P, art::InSubRun>(input_label_);
102  break;
103  case art::InRun:
104  consumes<P, art::InRun>(input_label_);
105  break;
106  default:
107  throw cet::exception("BranchTypeMismatch")
108  << "Branch type: " << branch_type_
109  << "not supported for this module.";
110  }
111  if (require_presence_) {
112  value_ = ps().expected_value();
113  }
114  }
115 
116  void
118  {
122  get_value;
123  if (get_value(h) != value_) {
124  throw cet::exception("ValueMismatch")
125  << "The value for \"" << input_label_ << "\", branchType \"" << bt
126  << "\" is " << get_value(h) << " but was supposed to be " << value_
127  << '\n';
128  }
129  }
130 
131  void
132  analyze(art::Event const& e) override
133  {
134  if (branch_type_ != art::InEvent)
135  return;
136  art::Handle<P> handle;
137  e.getByLabel(input_label_, handle);
138  assert(handle.isValid() == require_presence_);
139  if (require_presence_) {
140  verify_value(art::InEvent, handle);
141  }
142  }
143 
144  void
145  endSubRun(art::SubRun const& sr) override
146  {
147  if (branch_type_ != art::InSubRun)
148  return;
149  art::Handle<P> handle;
150  sr.getByLabel(input_label_, handle);
151  assert(handle.isValid() == require_presence_);
152  if (require_presence_) {
153  verify_value(art::InSubRun, handle);
154  }
155  }
156 
157  void
158  endRun(art::Run const& r) override
159  {
160  if (branch_type_ != art::InRun)
161  return;
162  art::Handle<P> handle;
163  r.getByLabel(input_label_, handle);
164  assert(handle.isValid() == require_presence_);
165  if (require_presence_) {
166  verify_value(art::InRun, handle);
167  }
168  }
169 
170 private:
171  V value_{};
175 };
176 
177 #endif /* art_test_Integration_GenericOneSimpleProductAnalyzer_h */
178 
179 // Local Variables:
180 // mode: c++
181 // End:
V const & operator()(art::Handle< P > const &h)
char(&)[2] yes_tag
static const double ps
Definition: Units.h:103
std::string string
Definition: nybbler.cc:12
Definition: Run.h:21
void verify_value(art::BranchType const bt, art::Handle< P > const &h) const
bool isValid() const
Definition: Handle.h:190
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:435
const double e
char(&)[1] no_tag
BranchType
Definition: BranchType.h:18
V const & operator()(art::Handle< P > const &h)
cet::no_tag has_value_helper(...)
static const double sr
Definition: Units.h:167
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
h
training ###############################
Definition: train_cnn.py:186