PtrListAnalyzer_module.cc
Go to the documentation of this file.
9 
10 #include <list>
11 #include <vector>
12 
13 namespace art {
14  namespace test {
15 
17  public:
18  explicit PtrListAnalyzer(fhicl::ParameterSet const& pset);
19 
20  private:
21  void analyze(art::Event const& ev) override;
22  // input_t is the type of the product we expect to obtain from the
23  // Event
24  using input_t = std::vector<int>;
25 
26  void test_fill_list(art::Event const&);
27  void test_fill_vector(art::Event const&);
28 
30  unsigned num_expected_;
31  };
32 
34  : art::EDAnalyzer{pset}
35  , input_label_{pset.get<std::string>("input_label")}
36  , num_expected_{pset.get<unsigned>("nvalues")}
37  {
38  // consumes<input_t>(input_label_);
39  }
40 
41  void
43  {
45  ev.getByLabel(input_label_, h);
46  assert(h.isValid());
47  assert(h->size() == num_expected_);
48 
49  test_fill_list(ev);
50  test_fill_vector(ev);
51  }
52 
53  void
55  {
56  // This is how to fill a list of Ptr<T> from a Handle<T>.
58  ev.getByLabel(input_label_, h);
59  assert(h.isValid());
60 
61  std::list<art::Ptr<int>> ptrs;
62  art::fill_ptr_list(ptrs, h);
63  assert(ptrs.size() == num_expected_);
64 
65  int expected_value = ev.id().event();
66  for (std::list<art::Ptr<int>>::const_iterator i = ptrs.begin(),
67  e = ptrs.end();
68  i != e;
69  ++i) {
70  assert(**i == expected_value);
71  ++expected_value;
72  }
73 
74  // Basic test of ensurePointer for Ptrs.
75  art::ensurePointer<int const*>(ptrs.begin());
76  std::list<art::Ptr<int>> const& ptrscref(ptrs);
77  art::ensurePointer<int const*>(ptrscref.begin());
78  }
79 
80  void
82  {
83  // This is how to fill a vector of Ptr<T> from a Handle<T>.
85  ev.getByLabel(input_label_, h);
86  assert(h.isValid());
87 
88  std::vector<art::Ptr<int>> ptrs;
89  art::fill_ptr_vector(ptrs, h);
90  assert(ptrs.size() == num_expected_);
91 
92  int expected_value = ev.id().event();
93  for (std::vector<art::Ptr<int>>::const_iterator i = ptrs.begin(),
94  e = ptrs.end();
95  i != e;
96  ++i) {
97  assert(**i == expected_value);
98  ++expected_value;
99  }
100  }
101 
102  } // namespace test
103 } // namespace art
104 
void test_fill_list(art::Event const &)
std::string string
Definition: nybbler.cc:12
Definition: test.py:1
void analyze(art::Event const &ev) override
void test_fill_vector(art::Event const &)
PtrListAnalyzer(fhicl::ParameterSet const &pset)
bool isValid() const
Definition: Handle.h:190
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:435
const double e
intermediate_table::const_iterator const_iterator
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
void fill_ptr_list(std::list< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:305
EventNumber_t event() const
Definition: EventID.h:117
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:295
Definition: fwd.h:26
EventID id() const
Definition: Event.cc:37
h
training ###############################
Definition: train_cnn.py:186