IntVectorAnalyzer_module.cc
Go to the documentation of this file.
1 // vim: set sw=2 expandtab :
2 
7 #include "cetlib_except/exception.h"
8 #include "fhiclcpp/types/Atom.h"
9 
10 #include <cassert>
11 #include <cstddef>
12 #include <iostream>
13 #include <string>
14 #include <vector>
15 
16 using namespace std;
17 using namespace art;
18 using namespace fhicl;
19 
20 namespace arttest {
21 
23  public:
24  struct Config {
25  Atom<string> input_label{Name("input_label")};
26  Atom<size_t> nvalues{Name("nvalues")};
27  };
29  explicit IntVectorAnalyzer(Parameters const& p, ProcessingFrame const&);
30 
31  private:
32  void analyze(Event const&, ProcessingFrame const&) override;
33 
34  string const moduleLabel_;
35  size_t const nvalues_;
37  };
38 
39  IntVectorAnalyzer::IntVectorAnalyzer(Parameters const& p,
40  ProcessingFrame const&)
41  : SharedAnalyzer{p}
42  , moduleLabel_{p().input_label()}
43  , nvalues_{p().nvalues()}
44  , viewToken_{consumesView<int>(moduleLabel_)}
45  {
46  async<InEvent>();
47  }
48 
49  void
51  {
52  {
53  vector<int const*> ptrs;
54  size_t sz = e.getView(moduleLabel_, ptrs);
55  if (sz != nvalues_) {
56  cerr << "SizeMismatch expected a view of size " << nvalues_
57  << " but the obtained size is " << sz << '\n';
58  throw cet::exception("SizeMismatch")
59  << "Expected a view of size " << nvalues_
60  << " but the obtained size is " << sz << '\n';
61  }
62  for (size_t k = 0; k != sz; ++k) {
63  if (*ptrs[k] != (int)(e.id().event() + k)) {
64  cerr << "ValueMismatch at position " << k << " expected value "
65  << e.id().event() + k << " but obtained " << *ptrs[k] << '\n';
66  throw cet::exception("ValueMismatch")
67  << "At position " << k << " expected value " << e.id().event() + k
68  << " but obtained " << *ptrs[k] << '\n';
69  }
70  }
71  }
72  {
73  View<int> vw;
74  e.getView(viewToken_, vw);
75  assert(vw.isValid());
76  // Test that the range-for loop compiles.
77  for (auto it : vw) {
78  assert(*it >= 0);
79  }
80  }
81  }
82 
83 } // namespace arttest
84 
def analyze(root, level, gtrees, gbranches, doprint)
Definition: rootstat.py:67
STL namespace.
void analyze(Event const &, ProcessingFrame const &) override
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
parameter set interface
Definition: fwd.h:43
p
Definition: test.py:228
auto isValid() const
Definition: View.h:60
EventNumber_t event() const
Definition: EventID.h:117
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
Definition: DataViewImpl.h:525
EventID id() const
Definition: Event.cc:37
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
AdcRoiViewer::Name Name