AssnsReaderTest_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: AssnsReaderTest
3 // Module Type: analyzer
4 // File: AssnsReaderTest_module.cc
5 //
6 // Generated at Wed Jul 13 14:36:05 2011 by Chris Green using artmod
7 // from art v0_07_12.
8 ////////////////////////////////////////////////////////////////////////
9 
16 #include "canvas/Persistency/Common/FindMany.h"
17 #include "canvas/Persistency/Common/FindManyP.h"
18 #include "canvas/Persistency/Common/FindOne.h"
19 #include "canvas/Persistency/Common/FindOneP.h"
23 #include "cetlib/maybe_ref.h"
25 
26 #include "boost/type_traits.hpp"
27 
28 #include <iostream>
29 #include <type_traits>
30 
31 namespace arttest {
32  class AssnsReaderTest;
33 }
34 
35 #include <initializer_list>
36 
38 public:
39  explicit AssnsReaderTest(fhicl::ParameterSet const& p);
40 
41  void analyze(art::Event const& e) override;
42 
43 private:
46  std::string const wantVoid_; // "ALL," "NONE," or "SOME."
47  bool const wantMV_; // Expect mapvector and derived Assns.
48  bool const wantMany_; // Expect many-to-many associations.
49  bool const wantAmbiguous_; // Expect an extra ABD, causing ambiguity.
50 };
51 
52 namespace {
53  typedef size_t A_t;
54  typedef std::string B_t;
61 } // namespace
62 
63 using namespace std::string_literals;
64 
66  : art::EDAnalyzer(ps)
67  , inputLabel_(ps.get<std::string>("inputLabel"))
68  , process_(ps.get<std::string>("process", {}))
69  , wantVoid_(ps.get<std::string>("wantVoid", "ALL"))
70  , wantMV_(ps.get<bool>("wantMV", true))
71  , wantMany_(ps.get<bool>("wantMany", true))
72  , wantAmbiguous_(ps.get<bool>("wantAmbiguous", false))
73 {
74  // consumes<AssnsABV_t>(inputLabel_);
75  // consumes<AssnsBAV_t>(inputLabel_);
76  // consumes<AssnsABV_t>({inputLabel_, "many"s});
77  // consumes<AssnsBAV_t>({inputLabel_, "many"s});
78  // consumes<AssnsABV_t>({inputLabel_, "mapvec"s});
79  // consumes<AssnsBAV_t>({inputLabel_, "mapvec"s});
80  // consumes<AssnsABV_t>({inputLabel_, "manymapvec"s});
81  // consumes<AssnsBAV_t>({inputLabel_, "manymapvec"s});
82 
83  // consumes<AssnsABX_t>(inputLabel_);
84  // consumes<AssnsBAX_t>(inputLabel_);
85  // consumes<AssnsABX_t>({inputLabel_, "many"s});
86  // consumes<AssnsBAX_t>({inputLabel_, "many"s});
87  // consumes<AssnsABX_t>({inputLabel_, "mapvec"s});
88  // consumes<AssnsBAX_t>({inputLabel_, "mapvec"s});
89  // consumes<AssnsABX_t>({inputLabel_, "manymapvec"s});
90  // consumes<AssnsBAX_t>({inputLabel_, "manymapvec"s});
91 
92  // consumesMany<AssnsABV_t>();
93  // consumesMany<AssnsBAV_t>();
94  // consumesMany<AssnsABX_t>();
95  // consumesMany<AssnsBAX_t>();
96 }
97 
98 namespace {
99  template <typename A, typename B, typename D>
100  std::size_t
101  expectedSize(std::string const& wantVoid,
102  bool wantMV,
103  bool wantMany,
104  bool wantAmbiguous,
105  std::string const& process)
106  {
107  using namespace std::string_literals;
108  static constexpr bool isVoid[[gnu::unused]] = std::is_same<D, void>::value;
109  std::size_t wanted = 0ull;
110  wanted += 1ull;
111  if (isVoid && wantVoid != "ALL"s && wantAmbiguous) {
112  // Have an Assns<A, B, Y> to deal with too.
113  wanted += 1ull;
114  }
115  if (wantMany) {
116  wanted += 1ull;
117  }
118  if (wantMV) {
119  wanted += 1ull;
120  if (wantMany) {
121  wanted += 1ull;
122  }
123  }
124  wanted *= 2ull; // Two writer modules.
125  if (process == "ASSNSW2") {
126  // FIXME: Should pull out the config for this process and
127  // recursively call ourselves with the right options.
128  wanted *= 2ull;
129  }
130  return wanted;
131  }
132 
133  template <typename A, typename B, typename D>
134  void
135  checkExpectedSize(std::vector<art::Handle<art::Assns<A, B, D>>> const& v,
136  std::string const& wantVoid,
137  bool wantMV,
138  bool wantMany,
139  bool wantAmbiguous,
140  std::string const& process)
141  {
142  BOOST_CHECK_EQUAL(v.size(),
143  (expectedSize<A, B, D>(
144  wantVoid, wantMV, wantMany, wantAmbiguous, process)));
145  }
146 } // namespace
147 
148 void
150 {
151  std::size_t const vSize = (wantVoid_ == "ALL"s) ? 4ull : 3ull;
152  std::size_t const mvVSize = (wantVoid_ != "NONE"s) ? 4ull : 3ull;
153 
154  auto const vSizeM = vSize + ((wantVoid_ == "ALL"s) ? 2ull : 1ull);
155  auto const mvVSizeM = mvVSize + ((wantVoid_ != "NONE"s) ? 2ull : 1ull);
156 
157  // Check <A, B> and <B, A>.
159  try {
160  e.getByLabel(inputLabel_, hABV);
161  BOOST_CHECK_EQUAL(hABV->size(), vSize);
162  if (!process_.empty()) {
163  BOOST_CHECK_EQUAL(hABV.provenance()->processName(), process_);
164  }
165  }
166  catch (art::Exception const& e) {
167  if (!wantAmbiguous_ || wantVoid_ == "ALL") {
168  throw; // Shouldn't have gotten here.
169  } else { // Expected exception.
170  BOOST_REQUIRE(e.categoryCode() == art::errors::ProductNotFound);
171  BOOST_CHECK_EQUAL(
172  std::string(e.what()).substr(29, 69),
173  "getByLabel: Found 2 products rather than one which match all criteria"s);
174  }
175  }
176 
178  try {
179  e.getByLabel(inputLabel_, hBAV);
180  BOOST_CHECK_EQUAL(hBAV->size(), vSize);
181  if (!process_.empty()) {
182  BOOST_CHECK_EQUAL(hBAV.provenance()->processName(), process_);
183  }
184  }
185  catch (art::Exception const& e) {
186  if (!wantAmbiguous_ || wantVoid_ == "ALL") {
187  throw; // Shouldn't have gotten here.
188  } else { // Expected exception.
189  BOOST_REQUIRE(e.categoryCode() == art::errors::ProductNotFound);
190  BOOST_CHECK_EQUAL(
191  std::string(e.what()).substr(29, 69),
192  "getByLabel: Found 2 products rather than one which match all criteria"s);
193  }
194  }
195 
196  if (wantMany_) {
197  auto const hABVM = e.getValidHandle<AssnsABV_t>({inputLabel_, "many"s});
198  BOOST_CHECK_EQUAL(hABVM->size(), vSizeM);
199  auto const hBAVM = e.getValidHandle<AssnsBAV_t>({inputLabel_, "many"s});
200  BOOST_CHECK_EQUAL(hBAVM->size(), vSizeM);
201  if (!process_.empty()) {
202  BOOST_CHECK_EQUAL(hABVM.provenance()->processName(), process_);
203  BOOST_CHECK_EQUAL(hBAVM.provenance()->processName(), process_);
204  }
205  }
206  if (wantMV_) {
207  auto const hmvABV = e.getValidHandle<AssnsABV_t>({inputLabel_, "mapvec"s});
208  BOOST_CHECK_EQUAL(hmvABV->size(), mvVSize);
209  auto const hmvBAV = e.getValidHandle<AssnsBAV_t>({inputLabel_, "mapvec"s});
210  BOOST_CHECK_EQUAL(hmvBAV->size(), mvVSize);
211  if (!process_.empty()) {
212  BOOST_CHECK_EQUAL(hmvABV.provenance()->processName(), process_);
213  BOOST_CHECK_EQUAL(hmvBAV.provenance()->processName(), process_);
214  }
215  if (wantMany_) {
216  auto const hmvABVM =
217  e.getValidHandle<AssnsABV_t>({inputLabel_, "manymapvec"s});
218  BOOST_CHECK_EQUAL(hmvABVM->size(), mvVSizeM);
219  auto const hmvBAVM =
220  e.getValidHandle<AssnsBAV_t>({inputLabel_, "manymapvec"s});
221  BOOST_CHECK_EQUAL(hmvBAVM->size(), mvVSizeM);
222  if (!process_.empty()) {
223  BOOST_CHECK_EQUAL(hmvABVM.provenance()->processName(), process_);
224  BOOST_CHECK_EQUAL(hmvBAVM.provenance()->processName(), process_);
225  }
226  }
227  }
228 
229  // Check all <A, B, V> and <B, A, V>.
230  BOOST_CHECK_EQUAL(e.getValidHandle<AssnsABX_t>(inputLabel_)->size(), 3ull);
231  BOOST_CHECK_EQUAL(e.getValidHandle<AssnsBAX_t>(inputLabel_)->size(), 3ull);
232  if (wantMany_) {
233  BOOST_CHECK_EQUAL(
234  e.getValidHandle<AssnsABX_t>({inputLabel_, "many"s})->size(), 4ull);
235  BOOST_CHECK_EQUAL(
236  e.getValidHandle<AssnsBAX_t>({inputLabel_, "many"s})->size(), 4ull);
237  }
238  if (wantMV_) {
239  BOOST_CHECK_EQUAL(
240  e.getValidHandle<AssnsABX_t>({inputLabel_, "mapvec"s})->size(), 3ull);
241  BOOST_CHECK_EQUAL(
242  e.getValidHandle<AssnsBAX_t>({inputLabel_, "mapvec"s})->size(), 3ull);
243  if (wantMany_) {
244  BOOST_CHECK_EQUAL(
245  e.getValidHandle<AssnsABX_t>({inputLabel_, "manymapvec"s})->size(),
246  4ull);
247  BOOST_CHECK_EQUAL(
248  e.getValidHandle<AssnsBAX_t>({inputLabel_, "manymapvec"s})->size(),
249  4ull);
250  }
251  }
252 
253  // Check expected behavior of getManyByType().
254  std::vector<art::Handle<AssnsABV_t>> hSet1;
255  e.getManyByType(hSet1);
256  checkExpectedSize(
257  hSet1, wantVoid_, wantMV_, wantMany_, wantAmbiguous_, process_);
258  std::vector<art::Handle<AssnsBAV_t>> hSet2;
259  e.getManyByType(hSet2);
260  checkExpectedSize(
261  hSet2, wantVoid_, wantMV_, wantMany_, wantAmbiguous_, process_);
262  std::vector<art::Handle<AssnsABX_t>> hSet3;
263  e.getManyByType(hSet3);
264  checkExpectedSize(
265  hSet3, wantVoid_, wantMV_, wantMany_, wantAmbiguous_, process_);
266  std::vector<art::Handle<AssnsBAX_t>> hSet4;
267  e.getManyByType(hSet4);
268  checkExpectedSize(
269  hSet4, wantVoid_, wantMV_, wantMany_, wantAmbiguous_, process_);
270 }
271 
size_type size() const
Definition: Assns.h:447
static const double ps
Definition: Units.h:103
std::string string
Definition: nybbler.cc:12
art::Assns< A_t, B_t > AssnsABV_t
AssnsReaderTest(fhicl::ParameterSet const &p)
STL namespace.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
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
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
size_t A_t
Provenance const * provenance() const
Definition: Handle.h:204
void analyze(art::Event const &e) override
BOOST_REQUIRE(inFile)
p
Definition: test.py:228
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::string B_t
static const double s
Definition: Units.h:99
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
art::Assns< B_t, size_t > AssnsBAV_t