PtrVectorAnalyzer_module.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // PtrVectorAnalyzer
4 //
5 // ======================================================================
6 
12 #include "cetlib_except/exception.h"
13 #include "fhiclcpp/ParameterSet.h"
14 
15 #include <string>
16 #include <vector>
17 
18 namespace arttest {
19  class PtrVectorAnalyzer;
20 }
21 
22 // ----------------------------------------------------------------------
23 
25 public:
27 
29  : art::EDAnalyzer(p)
30  , input_label_(p.get<std::string>("input_label"))
31  , nvalues_(p.get<unsigned>("nvalues"))
32  {}
33 
34  void
35  analyze(art::Event const& e) override
36  {
39 
40  size_t sz = h->size();
41  if (sz != nvalues_) {
42  throw cet::exception("SizeMismatch")
43  << "Expected a PtrVector of size " << nvalues_
44  << " but the obtained size is " << sz << '\n';
45  }
46 
47  int value = e.id().event();
48  size_t count = 0;
49  for (const auto ptr : *h) {
50  if (*ptr != value) {
51  throw cet::exception("ValueMismatch")
52  << "At position " << count << " expected value " << value
53  << " but obtained " << *ptr << '\n';
54  }
55  ++value;
56  ++count;
57  }
58  if (count != sz) {
59  throw cet::exception("CountMismatch")
60  << "Expected to iterate over " << sz << " values, but found " << count
61  << '\n';
62  }
63 
64  // Make a copy of the PtrVector, so we can call sort on it.
65  product_t local(*h);
66  // Make sure we're not sorted yet...
67  sz = local.size();
68  assert(sz > 1);
69 
70  local.sort();
71  assert(sz == local.size());
72  for (size_t i = 1; i != sz; ++i)
73  assert(*local[i - 1] < *local[i]);
74 
75  std::greater<int> gt;
76  local.sort(gt);
77  assert(sz == local.size());
78  for (size_t i = 1; i != sz; ++i)
79  assert(*local[i - 1] > *local[i]);
80 
81  // Make a new PtrVector so we can range-insert into it.
82  product_t insert_test;
83  auto half_size = h->size() / 2;
84  insert_test.insert(
85  insert_test.begin(), h->cbegin(), h->cbegin() + half_size);
86  auto it =
87  insert_test.insert(insert_test.end(), h->cbegin() + half_size, h->cend());
88  assert(it == insert_test.begin() + half_size);
89  assert(insert_test.size() == h->size());
90  it = insert_test.insert(it, h->cbegin(), h->end());
91  assert(it == insert_test.begin() + half_size);
92  assert(insert_test.size() == h->size() * 2);
93  } // analyze()
94 
95 private:
97  unsigned nvalues_;
98 
99 }; // PtrVectorAnalyzer
100 
101 // ----------------------------------------------------------------------
102 
104 
105 // ======================================================================
void analyze(art::Event const &e) override
std::string string
Definition: nybbler.cc:12
iterator begin()
Definition: PtrVector.h:223
STL namespace.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:435
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
iterator end()
Definition: PtrVector.h:237
size_type size() const
Definition: PtrVector.h:308
PtrVectorAnalyzer(fhicl::ParameterSet const &p)
p
Definition: test.py:228
iterator insert(iterator position, Ptr< U > const &p)
EventNumber_t event() const
Definition: EventID.h:117
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
EventID id() const
Definition: Event.cc:37
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
h
training ###############################
Definition: train_cnn.py:186