IntsVerifier_module.cc
Go to the documentation of this file.
6 
7 #include <algorithm>
8 #include <cassert>
9 #include <vector>
10 
11 using namespace fhicl;
12 
13 namespace {
14  class IntsVerifier : public art::SharedProducer {
15  public:
16  struct Config {
17  Sequence<int> expectedValues{
18  Name{"expectedValues"},
19  Comment{
20  "The 'expectedValues' parameter lists the values that\n"
21  "are intended to be present whenever a getManyByType call is made."}};
22  };
23  using Parameters = Table<Config>;
24  explicit IntsVerifier(Parameters const&, art::ProcessingFrame const&);
25 
26  private:
27  void produce(art::Event&, art::ProcessingFrame const&) override;
28  std::vector<int> expectedValues_;
29  };
30 
31  IntsVerifier::IntsVerifier(Parameters const& p, art::ProcessingFrame const&)
32  : art::SharedProducer{p}, expectedValues_{p().expectedValues()}
33  {
34  std::sort(begin(expectedValues_), end(expectedValues_));
35  async<art::InEvent>();
36  consumesMany<arttest::IntProduct>();
37  }
38 
39  void
40  IntsVerifier::produce(art::Event& e, art::ProcessingFrame const&)
41  {
42  std::vector<art::Handle<arttest::IntProduct>> products;
43  e.getManyByType(products);
44  std::set<int> presentValues;
45  for (auto const& h : products) {
46  presentValues.insert(h->value);
47  }
48  assert(presentValues.size() == expectedValues_.size());
49  auto const sameValues = std::equal(
50  cbegin(presentValues), cend(presentValues), cbegin(expectedValues_));
51  assert(sameValues);
52  }
53 }
54 
55 DEFINE_ART_MODULE(IntsVerifier)
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
parameter set interface
auto begin(Data< Value > const &data)
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:518
p
Definition: test.py:228
end
Definition: test.py:8
h
training ###############################
Definition: train_cnn.py:186