MockClusterListAnalyzer_module.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // MockClusterListAnalyzer
4 //
5 // ======================================================================
6 
12 #include "cetlib_except/exception.h"
13 #include "fhiclcpp/ParameterSet.h"
14 
15 #include <cassert>
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 namespace arttest {
22 }
23 
25 
26 //--------------------------------------------------------------------
27 //
28 // Produces a SimpleProduct product instance.
29 //
31 public:
32  typedef std::vector<arttest::SimpleDerived> SimpleDerivedProduct;
33 
35  : art::EDAnalyzer(p)
36  , inputLabel_(p.get<std::string>("input_label"))
37  , nvalues_(p.get<int>("nvalues"))
38  {}
39 
40  void analyze(art::Event const& e) override;
41 
42 private:
44  unsigned nvalues_;
45 
46 }; // MockClusterListAnalyzer
47 
48 void
50 {
51  int event_num = e.id().event();
54  e.getByLabel(inputLabel_, h);
55 
56  assert(h.isValid());
57  unsigned psz = h->size();
58  assert(psz == 2);
59  for (product_t::const_iterator pb = h->begin(), pi = pb, pe = h->end();
60  pi != pe;
61  ++pi) {
62  int pk = pi - pb;
63  size_t csz = pi->cells.size();
64  if (pk == 0) {
65  assert(csz == nvalues_ / 2);
66  } else {
67  assert(csz == nvalues_ - (nvalues_ / 2)); // Remainder
68  }
69  assert(pi->skew == pk + 1);
70  // Try to access the first one directly.
71  art::Ptr<SimpleDerived> sd0 = pi->cells[0];
72  assert(sd0.get() != nullptr);
73 
74  // Now use the iterator to loop over the PtrVector.
75  size_t cell_count = 0;
76  for (product_t::value_type::CellList::const_iterator cb = pi->cells.begin(),
77  ci = cb,
78  ce = pi->cells.end();
79  ci != ce;
80  ++ci, ++cell_count) {
81  int ck = ci - cb;
82  art::Ptr<SimpleDerived> ptsd = *ci;
83  assert((unsigned)ptsd->key == 2 * csz - (ck + pk * csz) + event_num);
84  assert(ptsd->value == 1.5 * (ck + pk * csz) + 100.0);
85  assert(ptsd->dummy() == 16.25);
86  }
87  assert(cell_count == csz);
88  assert(pi->eNum == (unsigned)(event_num + pk));
89  }
90 } // test_PtrVector()
91 
92 // ----------------------------------------------------------------------
93 
95 
96 // ======================================================================
std::string string
Definition: nybbler.cc:12
MockClusterListAnalyzer(fhicl::ParameterSet const &p)
STL namespace.
std::vector< arttest::MockCluster > MockClusterList
Definition: MockCluster.h:26
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
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
static const double pb
Definition: Units.h:90
const double e
intermediate_table::const_iterator const_iterator
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
key_type key() const
Definition: Ptr.h:240
void analyze(art::Event const &e) override
p
Definition: test.py:228
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
EventNumber_t event() const
Definition: EventID.h:117
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
T const * get() const
Definition: Ptr.h:153
std::vector< arttest::SimpleDerived > SimpleDerivedProduct
arttest::IntProduct product_t
Definition: Event_t.cc:63
Definition: fwd.h:26
EventID id() const
Definition: Event.cc:37
h
training ###############################
Definition: train_cnn.py:186