Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
arttest::AssnsAnalyzer Class Reference
Inheritance diagram for arttest::AssnsAnalyzer:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Classes

struct  Config
 

Public Types

using Parameters = Table< Config >
 
- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 

Public Member Functions

 AssnsAnalyzer (Parameters const &p)
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob ()
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
std::string const & processName () const
 
bool wantAllEvents () const
 
bool wantEvent (Event const &e)
 
fhicl::ParameterSetID selectorConfig () const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void analyze (art::Event const &e) override
 
template<template< typename, typename > class FO>
void testOne (art::Event const &e) const
 
template<template< typename, typename > class FM>
void testMany (art::Event const &e) const
 

Private Attributes

std::string inputLabel_
 
bool testAB_
 
bool testBA_
 
bool bCollMissing_
 
art::ProductToken< AssnsAB_tmapVecToken1_
 
art::ProductToken< AssnsBA_tmapVecToken2_
 

Additional Inherited Members

- Protected Member Functions inherited from art::Observer
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &paths, fhicl::ParameterSet const &config)
 
detail::ProcessAndEventSelectorsprocessAndEventSelectors ()
 

Detailed Description

Definition at line 43 of file AssnsAnalyzer_module.cc.

Member Typedef Documentation

Definition at line 51 of file AssnsAnalyzer_module.cc.

Constructor & Destructor Documentation

arttest::AssnsAnalyzer::AssnsAnalyzer ( Parameters const &  p)
explicit

Definition at line 165 of file AssnsAnalyzer_module.cc.

166  : art::EDAnalyzer{p}
167  , inputLabel_{p().input_label()}
168  , testAB_{p().test_AB()}
169  , testBA_{p().test_BA()}
170  , bCollMissing_{p().bCollMissing()}
171  , mapVecToken1_{consumes<AssnsAB_t>({inputLabel_, "mapvec"})}
172  , mapVecToken2_{consumes<AssnsBA_t>({inputLabel_, "mapvec"})}
173 {
174  consumes<AssnsAB_t>(inputLabel_);
175  consumes<AssnsABV_t>(inputLabel_);
176  consumes<AssnsBA_t>(inputLabel_);
177  consumes<AssnsBAV_t>(inputLabel_);
178  consumes<std::vector<A_t>>(inputLabel_);
179  consumes<std::vector<B_t>>(inputLabel_);
180  consumes<AssnsAB_t>({inputLabel_, "many"});
181  consumes<AssnsAB_t>("noModule");
182  consumes<AssnsABV_t>({inputLabel_, "many"});
183  consumes<AssnsABV_t>({inputLabel_, "manymapvec"});
184 }
art::ProductToken< AssnsBA_t > mapVecToken2_
p
Definition: test.py:228
art::ProductToken< AssnsAB_t > mapVecToken1_

Member Function Documentation

void arttest::AssnsAnalyzer::analyze ( art::Event const &  e)
overrideprivatevirtual

Implements art::EDAnalyzer.

Definition at line 187 of file AssnsAnalyzer_module.cc.

188 {
189  testOne<art::FindOne>(e);
190  testOne<art::FindOneP>(e);
191 
192  testMany<art::FindMany>(e);
193  testMany<art::FindManyP>(e);
194 }
const double e
template<template< typename, typename=void > class FM>
void arttest::AssnsAnalyzer::testMany ( art::Event const &  e) const
private

Definition at line 390 of file AssnsAnalyzer_module.cc.

391 {
392  static constexpr bool isFMP[[gnu::unused]] =
393  std::is_same<typename FM<B_t>::value_type,
396  BOOST_REQUIRE(e.getByLabel(inputLabel_, hAcoll));
397 
398  // First, check we can make an FM on a non-existent label without
399  // barfing immediately.
400  FM<B_t, arttest::AssnTestData> fmDead(hAcoll, e, "noModule");
401  BOOST_REQUIRE(!fmDead.isValid());
402  BOOST_REQUIRE_EXCEPTION(
403  fmDead.size(), art::Exception, [](art::Exception const& e) {
404  return e.categoryCode() == art::errors::LogicError &&
405  e.history().back() == "ProductNotFound";
406  });
407  BOOST_REQUIRE_EXCEPTION(
408  fmDead.data(0), art::Exception, [](art::Exception const& e) {
409  return e.categoryCode() == art::errors::LogicError &&
410  e.history().back() == "ProductNotFound";
411  });
412 
413  // Now do our normal checks.
414  // Check FindMany.
415  FM<B_t, arttest::AssnTestData> fmB(
416  hAcoll, e, art::InputTag(inputLabel_, "many"));
417  art::Ptr<A_t> larry(hAcoll, 0), curly(hAcoll, 1), mo(hAcoll, 2);
418  FM<B_t, arttest::AssnTestData> fmB2(
419  {larry, curly, mo}, e, art::InputTag(inputLabel_, "many"));
420  for (auto const& f : {fmB, fmB2}) {
421  BOOST_REQUIRE_EQUAL(f.size(), 3ul);
422  BOOST_CHECK_EQUAL(f.at(0).size(), 1ul);
423  BOOST_CHECK_EQUAL(f.at(1).size(), 2ul);
424  BOOST_CHECK_EQUAL(f.at(2).size(), 1ul);
425  BOOST_CHECK_EQUAL(f.data(0).size(), 1ul);
426  BOOST_CHECK_EQUAL(f.data(1).size(), 2ul);
427  BOOST_CHECK_EQUAL(f.data(2).size(), 1ul);
428  }
429  FM<B_t> fmBV(hAcoll, e, art::InputTag(inputLabel_, "many"));
430  BOOST_CHECK_EQUAL(fmBV.at(0).size(), 1ul);
431  BOOST_CHECK_EQUAL(fmBV.at(1).size(), 2ul);
432  BOOST_CHECK_EQUAL(fmBV.at(2).size(), 1ul);
433  BOOST_CHECK_NO_THROW(check_get(fmB, fmBV));
434  // Check FindMany on View.
435  art::View<A_t> va;
436  BOOST_REQUIRE(e.getView(inputLabel_, va));
437  FM<B_t> fmBv(va, e, art::InputTag(inputLabel_, "many"));
438  BOOST_REQUIRE(fmBV == fmBv);
439  // Check FindMany on shuffled reference collection.
440  auto va2 = va.vals(); // Copy.
441  {
442  using std::swap;
443  swap(*va2.begin(), *(va2.begin() + 1));
444  swap(*va2.begin(), *(va2.begin() + 2));
445  }
446  BOOST_REQUIRE(va.vals() != va2);
447  FM<B_t> fmBv2(va2, e, art::InputTag(inputLabel_, "many"));
448  for (size_t i = 0, e = fmBv2.size(); i != e; ++i) {
449  using std::find;
450  auto it = find(va.begin(), va.end(), va2[i]);
451  BOOST_REQUIRE(it != va.end());
452  BOOST_REQUIRE(fmBv.at(std::distance(va.begin(), it)) == fmBv2.at(i));
453  }
454 
455  // Check FindMany on map_vector
456  FM<B_t> fmvBV(hAcoll, e, art::InputTag(inputLabel_, "manymapvec"));
457  if (!bCollMissing_) {
458  BOOST_CHECK_EQUAL(fmvBV.at(0).size(), 1ul);
459  BOOST_CHECK_EQUAL(fmvBV.at(1).size(), 2ul);
460  BOOST_CHECK_EQUAL(fmvBV.at(2).size(), 1ul);
461  BOOST_CHECK_NO_THROW(check_get(fmB, fmBV));
462  }
463 }
auto end()
Definition: View.h:98
auto begin()
Definition: View.h:92
const double e
void swap(Handle< T > &a, Handle< T > &b)
Definition: fwd.h:43
auto vals() -> auto &
Definition: View.h:76
BOOST_REQUIRE(inFile)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Definition: fwd.h:26
template<template< typename, typename=void > class FO>
void arttest::AssnsAnalyzer::testOne ( art::Event const &  e) const
private

Definition at line 198 of file AssnsAnalyzer_module.cc.

199 {
200  // Behavior on missing bColl is different for FindOne vs FindOneP.
201  static constexpr bool isFOP =
202  std::is_same<typename FO<B_t>::value_type,
204  bool const extendedTestsOK = isFOP || (!bCollMissing_);
209  if (testAB_) {
210  BOOST_REQUIRE(e.getByLabel(inputLabel_, hAB));
211  BOOST_REQUIRE_EQUAL(hAB->size(), 3ul);
212  BOOST_REQUIRE(e.getByLabel(inputLabel_, hABV));
213  BOOST_REQUIRE_EQUAL(hABV->size(), 3ul);
214  // Check alternative accessors and range checking for Assns.
215  BOOST_CHECK_THROW((*hAB).at(3), std::out_of_range);
216  BOOST_CHECK_EQUAL(&(*hAB).data(0), &(*hAB).data((*hAB).begin()));
217  BOOST_CHECK_THROW((*hAB).data(3), std::out_of_range);
218  }
219  if (testBA_) {
220  BOOST_REQUIRE(e.getByLabel(inputLabel_, hBA));
221  BOOST_REQUIRE_EQUAL(hBA->size(), 3ul);
222  BOOST_REQUIRE(e.getByLabel(inputLabel_, hBAV));
223  BOOST_REQUIRE_EQUAL(hBAV->size(), 3ul);
224  // Check alternative accessors and range checking for Assns.
225  BOOST_CHECK_THROW((*hBA).at(3), std::out_of_range);
226  BOOST_CHECK_EQUAL(&(*hBA).data(0), &(*hBA).data((*hBA).begin()));
227  BOOST_CHECK_THROW((*hBA).data(3), std::out_of_range);
228  }
229  // Construct a FO using a handle to a collection.
231  BOOST_REQUIRE(e.getByLabel(inputLabel_, hAcoll));
232  auto vhAcoll = e.getValidHandle<std::vector<A_t>>(inputLabel_);
233  // First, check we can make an FO on a non-existent label without
234  // barfing immediately.
235  FO<B_t, arttest::AssnTestData> foDead(hAcoll, e, "noModule");
236  BOOST_REQUIRE(!foDead.isValid());
237  BOOST_REQUIRE_EXCEPTION(
238  foDead.size(), art::Exception, [](art::Exception const& e) {
239  return e.categoryCode() == art::errors::LogicError &&
240  e.history().back() == "ProductNotFound";
241  });
242  BOOST_REQUIRE_EXCEPTION(
243  foDead.data(0), art::Exception, [](art::Exception const& e) {
244  return e.categoryCode() == art::errors::LogicError &&
245  e.history().back() == "ProductNotFound";
246  });
247 
248  // Now do our normal checks.
250  BOOST_REQUIRE_EQUAL(e.getByLabel(inputLabel_, hBcoll), !bCollMissing_);
251  std::unique_ptr<FO<A_t, arttest::AssnTestData>> foA;
252  std::unique_ptr<FO<A_t>> foAV;
253  if (!bCollMissing_) {
254  foA.reset(new FO<A_t, arttest::AssnTestData>{hBcoll, e, inputLabel_});
255  foAV.reset(new FO<A_t>{hBcoll, e, inputLabel_});
256  }
257  if (extendedTestsOK) {
258  FO<B_t, arttest::AssnTestData> foB(hAcoll, e, inputLabel_);
259  FO<B_t, arttest::AssnTestData> foB2(vhAcoll, e, inputLabel_);
260  FO<B_t> foBV(hAcoll, e, inputLabel_);
261  std::vector<art::Ptr<A_t>> vp;
262  vp.reserve(3);
263  for (size_t i = 0; i < 3; ++i) {
264  vp.emplace_back(hAcoll, i);
265  if (testAB_) {
266  BOOST_CHECK_EQUAL(*(*hAB)[i].first, i);
267  if (!bCollMissing_) {
268  BOOST_CHECK_EQUAL(*(*hAB)[i].second, std::string(X[i]));
269  }
270  BOOST_CHECK_EQUAL((*hAB).data(i).d1, (*hAB)[i].first.key());
271  BOOST_CHECK_EQUAL((*hAB).data(i).d2, (*hAB)[i].second.key());
272  BOOST_CHECK_EQUAL((*hAB).data(i).label, std::string(A[i]));
273  BOOST_CHECK_EQUAL(*(*hABV)[i].first, i);
274  if (!bCollMissing_) {
275  BOOST_CHECK_EQUAL(*(*hABV)[i].second, std::string(X[i]));
276  }
277  }
278  if (testBA_) {
279  if (!bCollMissing_) {
280  BOOST_CHECK_EQUAL(*(*hBA)[i].first, std::string(X[i]));
281  }
282  BOOST_CHECK_EQUAL(*(*hBA)[i].second, i);
283  BOOST_CHECK_EQUAL((*hBA).data(i).d2, (*hBA)[i].first.key());
284  BOOST_CHECK_EQUAL((*hBA).data(i).d1, (*hBA)[i].second.key());
285  BOOST_CHECK_EQUAL((*hBA).data(i).label, std::string(A[i]));
286  if (!bCollMissing_) {
287  BOOST_CHECK_EQUAL(*(*hBAV)[i].first, std::string(X[i]));
288  }
289  BOOST_CHECK_EQUAL(*(*hBAV)[i].second, i);
290  }
291  if (bCollMissing_) {
292  BOOST_CHECK(!foBV.at(i));
293  } else {
294  BOOST_CHECK_EQUAL(dereference(foBV.at(i)), std::string(X[AI[i]]));
295  BOOST_CHECK_EQUAL(dereference(foA->at(i)), BI[i]);
296  BOOST_CHECK_EQUAL(dereference(foA->data(i)).d1, AI[i]);
297  BOOST_CHECK_EQUAL(dereference(foA->data(i)).d2, i);
298  BOOST_CHECK_EQUAL(dereference(foAV->at(i)), BI[i]);
299  BOOST_CHECK_NO_THROW(check_get(*foA, *foAV));
300  }
301  for (auto const& f : {foB, foB2}) {
302  if (!bCollMissing_) {
303  BOOST_CHECK_EQUAL(dereference(f.at(i)), std::string(X[AI[i]]));
304  }
305  BOOST_CHECK_EQUAL(dereference(f.data(i)).d1, i);
306  BOOST_CHECK_EQUAL(dereference(f.data(i)).d2, BI[i]);
307  }
308  }
309  // Check FindOne on View.
310  art::View<A_t> va;
311  BOOST_REQUIRE(e.getView(inputLabel_, va));
312  FO<B_t, arttest::AssnTestData> foBv(va, e, inputLabel_);
313  BOOST_REQUIRE(foB == foBv);
314  art::View<B_t> vb;
315  std::unique_ptr<FO<A_t, arttest::AssnTestData>> foAv;
316  if (!bCollMissing_) {
317  BOOST_REQUIRE(e.getView(inputLabel_, vb));
318  foAv.reset(new FO<A_t, arttest::AssnTestData>{vb, e, inputLabel_});
319  BOOST_REQUIRE(*foA == *foAv);
320  }
321  // Check FindOne on shuffled reference collection.
322  auto va2 = va.vals(); // Copy.
323  {
324  using std::swap;
325  swap(*va2.begin(), *(va2.begin() + 1));
326  swap(*va2.begin(), *(va2.begin() + 2));
327  }
328  BOOST_REQUIRE(va.vals() != va2);
329  FO<B_t, arttest::AssnTestData> foBv2(va2, e, inputLabel_);
330  for (size_t i = 0, e = foBv2.size(); i != e; ++i) {
331  using std::find;
332  auto it = find(va.begin(), va.end(), va2[i]);
333  BOOST_REQUIRE(it != va.end());
334  BOOST_REQUIRE(foBv.at(std::distance(va.begin(), it)) == foBv2.at(i));
335  }
336  // Check FindOne on PtrVector.
337  va.vals()[1] = 0;
339  va.fill(pva);
340  FO<B_t, arttest::AssnTestData> foBpv(pva, e, inputLabel_);
341  BOOST_CHECK_EQUAL(foBpv.at(0), foB.at(0));
342  BOOST_CHECK_EQUAL(foBpv.data(0), foB.data(0));
343  BOOST_CHECK_EQUAL(foBpv.at(1), foB.at(2)); // Knocked out the middle.
344  BOOST_CHECK_EQUAL(foBpv.data(1), foB.data(2));
346  if (!bCollMissing_) {
347  vb.vals()[1] = 0;
348  vb.fill(pvb);
349  }
350  FO<A_t, arttest::AssnTestData> foApv(pvb, e, inputLabel_);
351  // Check for range errors.
352  BOOST_CHECK_THROW(foApv.at(3), std::out_of_range);
353  BOOST_CHECK_THROW(foApv.data(3), std::out_of_range);
354 
355  if (!bCollMissing_) {
356  BOOST_CHECK_EQUAL(foApv.at(0), foA->at(0));
357  BOOST_CHECK_EQUAL(foApv.data(0), foA->data(0));
358  BOOST_CHECK_EQUAL(foApv.at(1), foA->at(2)); // Knocked out the middle.
359  BOOST_CHECK_EQUAL(foApv.data(1), foA->data(2));
360  }
361 
362  // Check FindOne looking into a map_vector.
363  BOOST_REQUIRE(hAcoll.isValid());
364  FO<B_t, arttest::AssnTestData> foBmv(hAcoll, e, mapVecToken1_);
365  if (!bCollMissing_) {
366  BOOST_CHECK_EQUAL(dereference(foBmv.at(0)), dereference(foB.at(0)));
367  BOOST_CHECK_EQUAL(dereference(foBmv.data(0)).label,
368  dereference(foB.data(0)).label);
369  BOOST_CHECK_EQUAL(dereference(foBmv.at(1)), dereference(foB.at(1)));
370  BOOST_CHECK_EQUAL(dereference(foBmv.data(1)).label,
371  dereference(foB.data(1)).label);
372  BOOST_CHECK_EQUAL(dereference(foBmv.at(2)), dereference(foB.at(2)));
373  BOOST_CHECK_EQUAL(dereference(foBmv.data(2)).label,
374  dereference(foB.data(2)).label);
375  }
376  // ... and a View into a map_vector.
377  art::View<B_t> vmvb;
378  if (!bCollMissing_) {
379  BOOST_REQUIRE(e.getView(inputLabel_, "mv", vmvb));
380  FO<A_t, arttest::AssnTestData> foAmvv(vmvb, e, mapVecToken2_);
381  for (std::size_t i = 0ul, sz = foAmvv.size(); i != sz; ++i) {
382  BOOST_REQUIRE_EQUAL(dereference(foAmvv.at(i)), i);
383  }
384  }
385  }
386 }
size_type size() const
Definition: Assns.h:447
static const double second
Definition: Units.h:35
std::string string
Definition: nybbler.cc:12
auto end()
Definition: View.h:98
void fill(PtrVector< T > &pv) const
Definition: View.h:158
details::dereference_class< T, details::has_dereference_class< T >::value >::reference_type dereference(T &v)
Returns the value pointed by the argument, or the argument itself.
Definition: Dereference.h:254
auto begin()
Definition: View.h:92
const double e
void swap(Handle< T > &a, Handle< T > &b)
Definition: fwd.h:43
art::ProductToken< AssnsBA_t > mapVecToken2_
auto vals() -> auto &
Definition: View.h:76
BOOST_REQUIRE(inFile)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
art::ProductToken< AssnsAB_t > mapVecToken1_
Definition: fwd.h:26

Member Data Documentation

bool arttest::AssnsAnalyzer::bCollMissing_
private

Definition at line 66 of file AssnsAnalyzer_module.cc.

std::string arttest::AssnsAnalyzer::inputLabel_
private

Definition at line 63 of file AssnsAnalyzer_module.cc.

art::ProductToken<AssnsAB_t> arttest::AssnsAnalyzer::mapVecToken1_
private

Definition at line 67 of file AssnsAnalyzer_module.cc.

art::ProductToken<AssnsBA_t> arttest::AssnsAnalyzer::mapVecToken2_
private

Definition at line 68 of file AssnsAnalyzer_module.cc.

bool arttest::AssnsAnalyzer::testAB_
private

Definition at line 64 of file AssnsAnalyzer_module.cc.

bool arttest::AssnsAnalyzer::testBA_
private

Definition at line 65 of file AssnsAnalyzer_module.cc.


The documentation for this class was generated from the following file: