MixAnalyzer_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: MixAnalyzer
3 // Module Type: analyzer
4 // File: MixAnalyzer_module.cc
5 //
6 // Generated at Mon May 16 10:45:57 2011 by Chris Green using artmod
7 // from art v0_06_02.
8 ////////////////////////////////////////////////////////////////////////
9 
11 
19 
20 #include <cassert>
21 #include <iomanip>
22 #include <iostream>
23 #include <sstream>
24 #include <string>
25 
26 namespace arttest {
27  class MixAnalyzer;
28 }
29 
31 public:
32  explicit MixAnalyzer(fhicl::ParameterSet const& p);
33 
34 private:
35  void analyze(art::Event const& e) override;
36 
40 
41  size_t eventCounter_{};
42  size_t nSecondaries_;
44 };
45 
47  : art::EDAnalyzer{p}
48  , nSecondaries_{p.get<size_t>("numSecondaries", 1)}
49  , mixFilterLabel_{p.get<std::string>("mixFilterLabel", "mixFilter")}
50 {}
51 
52 void
54 {
55  ++eventCounter_;
56 
57  // Double
59  e.getByLabel(mixFilterLabel_, "doubleLabel", dH);
60  double dExpected =
61  ((2 * eventCounter_ - 1) * nSecondaries_ + 1) * nSecondaries_ / 2;
62  assert(*dH == dExpected);
63 
64  // IntProduct
66  BOOST_REQUIRE(e.getByLabel(mixFilterLabel_, "IntProductLabel", ipH));
67  BOOST_REQUIRE_EQUAL(ipH->value, dExpected + 1000000 * nSecondaries_);
68 
69  // String
71  BOOST_REQUIRE(e.getByLabel(mixFilterLabel_, "stringLabel", sH));
72  std::ostringstream sExp;
73  for (size_t i = 1; i <= nSecondaries_; ++i) {
74  sExp << "string value: " << std::setfill('0') << std::setw(7)
75  << (eventCounter_ - 1) * nSecondaries_ + i << "\n";
76  }
77  BOOST_REQUIRE_EQUAL(*sH, sExp.str());
78 
79  // 1. std::vector<double>
81  BOOST_REQUIRE(e.getByLabel(mixFilterLabel_, "doubleCollectionLabel", vdH));
82  BOOST_REQUIRE_EQUAL(vdH->size(), 10 * nSecondaries_);
83  for (size_t i = 0; i < nSecondaries_; ++i) {
84  for (size_t j = 1; j < 11; ++j) {
85  BOOST_REQUIRE_EQUAL((*vdH)[i * 10 + j - 1],
86  j + 10 * (i + (eventCounter_ - 1) * nSecondaries_));
87  }
88  }
89 
90  // 2. std::vector<art::Ptr<double> >
91  // 3. art::PtrVector<double>
92  // 4. ProductWithPtrs
95  e.getByLabel(mixFilterLabel_, "doubleVectorPtrLabel", vpdH)); // 2.
96 #ifndef ART_NO_MIX_PTRVECTOR
99  e.getByLabel(mixFilterLabel_, "doublePtrVectorLabel", pvdH)); // 3.
100 #endif
103  e.getByLabel(mixFilterLabel_, "ProductWithPtrsLabel", pwpH)); // 4.
104 
105  for (size_t i = 0; i < nSecondaries_; ++i) {
106  BOOST_REQUIRE_EQUAL(*(*vpdH)[i * 3 + 0], (*vdH)[(i * 10) + 0]); // 2.
107  BOOST_REQUIRE_EQUAL(*(*vpdH)[i * 3 + 1], (*vdH)[(i * 10) + 4]); // 2.
108  BOOST_REQUIRE_EQUAL(*(*vpdH)[i * 3 + 2], (*vdH)[(i * 10) + 8]); // 2.
109 #ifndef ART_NO_MIX_PTRVECTOR
110  BOOST_REQUIRE_EQUAL(*(*pvdH)[i * 3 + 0], (*vdH)[(i * 10) + 1]); // 3.
111  BOOST_REQUIRE_EQUAL(*(*pvdH)[i * 3 + 1], (*vdH)[(i * 10) + 5]); // 3.
112  BOOST_REQUIRE_EQUAL(*(*pvdH)[i * 3 + 2], (*vdH)[(i * 10) + 9]); // 3.
113 #endif
114  BOOST_REQUIRE_EQUAL(*(pwpH->vectorPtrDouble())[i * 3 + 0],
115  *(*vpdH)[i * 3 + 0]); // 4.
116  BOOST_REQUIRE_EQUAL(*(pwpH->vectorPtrDouble())[i * 3 + 1],
117  *(*vpdH)[i * 3 + 1]); // 4.
118  BOOST_REQUIRE_EQUAL(*(pwpH->vectorPtrDouble())[i * 3 + 2],
119  *(*vpdH)[i * 3 + 2]); // 4.
120 #ifndef ART_NO_MIX_PTRVECTOR
121  BOOST_REQUIRE_EQUAL(*(pwpH->ptrVectorDouble())[i * 3 + 0],
122  *(*pvdH)[i * 3 + 0]); // 4.
123  BOOST_REQUIRE_EQUAL(*(pwpH->ptrVectorDouble())[i * 3 + 1],
124  *(*pvdH)[i * 3 + 1]); // 4.
125  BOOST_REQUIRE_EQUAL(*(pwpH->ptrVectorDouble())[i * 3 + 2],
126  *(*pvdH)[i * 3 + 2]); // 4.
127 #endif
128  }
129 
130  // map_vector<unsigned int>
132  BOOST_REQUIRE(e.getByLabel(mixFilterLabel_, "mapVectorLabel", mv));
133  BOOST_REQUIRE_EQUAL(mv->size(), 5 * nSecondaries_);
134  {
135  auto it = mv->begin();
136  size_t delta = 0;
137  size_t index = 0;
138  for (size_t i = 0; i < nSecondaries_; ++i, delta = index + 1) {
139  for (size_t j = 0; j < 5; ++j, ++it) {
140  index =
141  1 + j * 2 + delta + 10 * (i + nSecondaries_ * (eventCounter_ - 1));
142  BOOST_REQUIRE_EQUAL(it->first, static_cast<cet::map_vector_key>(index));
143  size_t answer = j + 1 + 5 * i + (eventCounter_ - 1) * 5 * nSecondaries_;
144  BOOST_REQUIRE_EQUAL(it->second, answer);
145  BOOST_REQUIRE_EQUAL(*mv->getOrNull(cet::map_vector_key(index)), answer);
146  }
147  }
148  std::cerr << "\n";
149  }
150 
151  // Ptrs into map_vector
153  BOOST_REQUIRE(e.getByLabel(mixFilterLabel_, "intVectorPtrLabel", mvvp));
154  BOOST_REQUIRE_EQUAL(mvvp->size(), 5 * nSecondaries_);
155  {
156  auto it = mvvp->begin();
157  size_t delta = 0;
158  size_t index_base = 0;
159  for (size_t i = 0; i < nSecondaries_; ++i, delta = index_base + 9, ++it) {
160  std::cerr << "delta = " << delta << "\n";
161  index_base = delta + 1 + 10 * (i + nSecondaries_ * (eventCounter_ - 1));
162  size_t answer_base = (eventCounter_ - 1) * 5 * nSecondaries_ + i * 5 + 1;
163  BOOST_REQUIRE_EQUAL((*it)->first,
164  static_cast<cet::map_vector_key>(index_base + 6));
165  BOOST_REQUIRE_EQUAL((*it)->second, answer_base + 3);
166  ++it;
167  BOOST_REQUIRE_EQUAL((*it)->first,
168  static_cast<cet::map_vector_key>(index_base + 0));
169  BOOST_REQUIRE_EQUAL((*it)->second, answer_base + 0);
170  ++it;
171  BOOST_REQUIRE_EQUAL((*it)->first,
172  static_cast<cet::map_vector_key>(index_base + 2));
173  BOOST_REQUIRE_EQUAL((*it)->second, answer_base + 1);
174  ++it;
175  BOOST_REQUIRE_EQUAL((*it)->first,
176  static_cast<cet::map_vector_key>(index_base + 8));
177  BOOST_REQUIRE_EQUAL((*it)->second, answer_base + 4);
178  ++it;
179  BOOST_REQUIRE_EQUAL((*it)->first,
180  static_cast<cet::map_vector_key>(index_base + 4));
181  BOOST_REQUIRE_EQUAL((*it)->second, answer_base + 2);
182  }
183  }
184 
185  // Bookkeeping.
188  BOOST_REQUIRE_EQUAL((*bsH), "BlahBlahBlah");
189 
192  for (size_t i = 0; i < nSecondaries_; ++i) {
193  BOOST_REQUIRE_EQUAL((*eidsH)[i].event() + ((*eidsH)[i].subRun() * 100) +
194  (((*eidsH)[i].run() - 1) * 500),
195  (eventCounter_ - 1) * nSecondaries_ + i + 1);
196  }
197 }
198 
mv_t::value_type mvv_t
std::string string
Definition: nybbler.cc:12
std::pair< key_type, mapped_type > value_type
Definition: map_vector.h:89
MixAnalyzer(fhicl::ParameterSet const &p)
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
Value mapped_type
Definition: map_vector.h:88
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
BOOST_REQUIRE(inFile)
p
Definition: test.py:228
mv_t::mapped_type mvm_t
void analyze(art::Event const &e) override
unsigned int run