Classes | Namespaces | Macros | Typedefs | Functions
Event_t.cc File Reference
#include "boost/test/unit_test.hpp"
#include "art/Framework/Principal/Event.h"
#include "art/Framework/Principal/EventPrincipal.h"
#include "art/Framework/Principal/Handle.h"
#include "art/Framework/Principal/RunPrincipal.h"
#include "art/Framework/Principal/Selector.h"
#include "art/Framework/Principal/SubRunPrincipal.h"
#include "art/Persistency/Provenance/ModuleContext.h"
#include "art/Persistency/Provenance/ModuleDescription.h"
#include "art/Persistency/Provenance/ModuleType.h"
#include "art/Persistency/Provenance/ProcessHistoryRegistry.h"
#include "art/Version/GetReleaseVersion.h"
#include "art/test/TestObjects/ToyProducts.h"
#include "canvas/Persistency/Common/WrappedTypeID.h"
#include "canvas/Persistency/Provenance/BranchDescription.h"
#include "canvas/Persistency/Provenance/EventAuxiliary.h"
#include "canvas/Persistency/Provenance/EventID.h"
#include "canvas/Persistency/Provenance/History.h"
#include "canvas/Persistency/Provenance/ProcessHistory.h"
#include "canvas/Persistency/Provenance/ProductTables.h"
#include "canvas/Persistency/Provenance/RunAuxiliary.h"
#include "canvas/Persistency/Provenance/SubRunAuxiliary.h"
#include "canvas/Persistency/Provenance/Timestamp.h"
#include "canvas/Persistency/Provenance/TypeLabel.h"
#include "canvas/Utilities/InputTag.h"
#include "cetlib/container_algorithms.h"
#include "fhiclcpp/ParameterSet.h"
#include <algorithm>
#include <fstream>
#include <iterator>
#include <map>
#include <memory>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

Go to the source code of this file.

Classes

class  art::EDProducer
 
class  ProductTablesFixture
 
struct  EventTestFixture
 

Namespaces

 art
 

Macros

#define BOOST_TEST_MODULE   (Event_t)
 

Typedefs

using product_t = arttest::IntProduct
 

Functions

std::ostream & art::boost_test_print_type (std::ostream &os, Timestamp const timestamp)
 
 BOOST_AUTO_TEST_CASE (badProductID)
 
 BOOST_AUTO_TEST_CASE (emptyEvent)
 
 BOOST_AUTO_TEST_CASE (getBySelectorFromEmpty)
 
 BOOST_AUTO_TEST_CASE (dereferenceDfltHandle)
 
 BOOST_AUTO_TEST_CASE (putAnIntProduct)
 
 BOOST_AUTO_TEST_CASE (putAndGetAnIntProduct)
 
 BOOST_AUTO_TEST_CASE (getByProductID)
 
 BOOST_AUTO_TEST_CASE (transaction)
 
 BOOST_AUTO_TEST_CASE (getProductTokens)
 
 BOOST_AUTO_TEST_CASE (getByInstanceName)
 
 BOOST_AUTO_TEST_CASE (getBySelector)
 
 BOOST_AUTO_TEST_CASE (getByLabel)
 
 BOOST_AUTO_TEST_CASE (getByLabelSpecialProcessNames)
 
 BOOST_AUTO_TEST_CASE (getManyByType)
 
 BOOST_AUTO_TEST_CASE (printHistory)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (Event_t)

Definition at line 2 of file Event_t.cc.

Typedef Documentation

Definition at line 61 of file Event_t.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( badProductID  )

Definition at line 341 of file Event_t.cc.

342 {
343  auto const pid = ProductID::invalid();
344  InputTag tag{};
345  if (auto pd = currentEvent_->getProductDescription(pid)) {
346  tag = pd->inputTag();
347  }
348  BOOST_TEST(tag.empty());
349 }
BOOST_AUTO_TEST_CASE ( emptyEvent  )

Definition at line 351 of file Event_t.cc.

352 {
353  BOOST_TEST_REQUIRE(currentEvent_.get());
354  BOOST_TEST(currentEvent_->id() == make_id());
355  BOOST_TEST(currentEvent_->time() == make_timestamp());
356 }
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
BOOST_AUTO_TEST_CASE ( getBySelectorFromEmpty  )

Definition at line 358 of file Event_t.cc.

359 {
360  ModuleLabelSelector const byModuleLabel{"mod1"};
361  Handle<int> nonesuch;
362  BOOST_TEST(not nonesuch);
363  BOOST_TEST(!nonesuch.isValid());
364  BOOST_TEST(!currentEvent_->get(byModuleLabel, nonesuch));
365  BOOST_TEST(!nonesuch.isValid());
366  BOOST_TEST(nonesuch.failedToGet());
367  BOOST_CHECK_THROW(*nonesuch, cet::exception);
368 }
bool isValid() const noexcept
Definition: Handle.h:191
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool failedToGet() const
Definition: Handle.h:198
BOOST_AUTO_TEST_CASE ( dereferenceDfltHandle  )

Definition at line 370 of file Event_t.cc.

371 {
372  Handle<int> nonesuch;
373  BOOST_CHECK_THROW(*nonesuch, cet::exception);
374  BOOST_CHECK_THROW(nonesuch.product(), cet::exception);
375 }
T const * product() const
Definition: Handle.h:163
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
BOOST_AUTO_TEST_CASE ( putAnIntProduct  )

Definition at line 377 of file Event_t.cc.

378 {
379  currentEvent_->put(product_with_value(3), "int1");
380  EDProducer::commitEvent(*principal_, *currentEvent_);
381 }
BOOST_AUTO_TEST_CASE ( putAndGetAnIntProduct  )

Definition at line 383 of file Event_t.cc.

384 {
385  currentEvent_->put(product_with_value(4), "int1");
386  EDProducer::commitEvent(*principal_, *currentEvent_);
387 
388  ProcessNameSelector const should_match{"CURRENT"};
389  ProcessNameSelector const should_not_match{"NONESUCH"};
390  // The ProcessNameSelector does not understand the "current_process"
391  // string. See notes in the Selector header file.
392  ProcessNameSelector const should_also_not_match{"current_process"};
394  BOOST_TEST_REQUIRE(currentEvent_->get(should_match, h));
395  BOOST_TEST(h);
396  BOOST_TEST(h.isValid());
397  h.clear();
398  BOOST_CHECK_THROW(*h, cet::exception);
399  BOOST_TEST_REQUIRE(!currentEvent_->get(should_not_match, h));
400  BOOST_TEST(!h.isValid());
401  BOOST_CHECK_THROW(*h, cet::exception);
402  BOOST_TEST_REQUIRE(!currentEvent_->get(should_also_not_match, h));
403  BOOST_TEST(!h.isValid());
404  BOOST_CHECK_THROW(*h, cet::exception);
405 }
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
bool isValid() const noexcept
Definition: Handle.h:191
void clear()
Definition: Handle.h:236
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
BOOST_AUTO_TEST_CASE ( getByProductID  )

Definition at line 407 of file Event_t.cc.

408 {
409  using handle_t = Handle<product_t>;
410 
411  ProductID wanted;
412  {
413  auto const id1 =
414  addSourceProduct(product_with_value(1), "int1_tag", "int1");
415  BOOST_TEST(id1 != ProductID{});
416  wanted = id1;
417 
418  auto const id2 =
419  addSourceProduct(product_with_value(2), "int2_tag", "int2");
420  BOOST_TEST(id2 != ProductID{});
421  BOOST_TEST(id2 != id1);
422  }
424  currentEvent_->get(wanted, h);
425  BOOST_TEST(h.isValid());
426  BOOST_TEST(h.id() == wanted);
427  BOOST_TEST(h->value == 1);
428 
429  ProductID const notpresent{};
430  BOOST_TEST_REQUIRE(!currentEvent_->get(notpresent, h));
431  BOOST_TEST(!h.isValid());
432  BOOST_TEST(h.failedToGet());
433  BOOST_CHECK_THROW(*h, cet::exception);
434 }
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
bool isValid() const noexcept
Definition: Handle.h:191
ProductID id() const
Definition: Handle.h:212
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool failedToGet() const
Definition: Handle.h:198
BOOST_AUTO_TEST_CASE ( transaction  )

Definition at line 436 of file Event_t.cc.

437 {
438  // Put a product into an Event, and make sure that if we don't
439  // movePutProductsToPrincipal, there is no product in the EventPrincipal
440  // afterwards.
441  BOOST_TEST(principal_->size() == 6u);
442  currentEvent_->put(product_with_value(3), "int1");
443  BOOST_TEST(principal_->size() == 6u);
444 }
BOOST_AUTO_TEST_CASE ( getProductTokens  )

Definition at line 446 of file Event_t.cc.

447 {
448  addSourceProduct(product_with_value(1), "int1_tag", "int1");
449  addSourceProduct(product_with_value(2), "int2_tag", "int2");
450  addSourceProduct(product_with_value(3), "int3_tag");
451  addSourceProduct(product_with_value(4), "nolabel_tag");
452 
453  auto const tags = currentEvent_->getInputTags<product_t>();
454  auto const tokens = currentEvent_->getProductTokens<product_t>();
455  BOOST_TEST(size(tags) == size(tokens));
456 
457  // Verify that the same products are retrieved whether tags or
458  // tokens are used.
459  for (std::size_t i{}; i < tags.size(); ++i) {
460  auto h1 = currentEvent_->getHandle<product_t>(tags[i]);
461  auto h2 = currentEvent_->getHandle(tokens[i]);
462  BOOST_TEST(static_cast<bool>(h1) == static_cast<bool>(h2));
463  }
464 }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
BOOST_AUTO_TEST_CASE ( getByInstanceName  )

Definition at line 466 of file Event_t.cc.

467 {
468  using handle_t = Handle<product_t>;
469  using handle_vec = std::vector<handle_t>;
470 
471  addSourceProduct(product_with_value(1), "int1_tag", "int1");
472  addSourceProduct(product_with_value(2), "int2_tag", "int2");
473  addSourceProduct(product_with_value(3), "int3_tag");
474  addSourceProduct(product_with_value(4), "nolabel_tag");
475 
476  Selector const sel{ProductInstanceNameSelector{"int2"} &&
477  ModuleLabelSelector{"modMulti"}};
478  auto h = currentEvent_->getHandle<product_t>(sel);
480  BOOST_TEST(h->value == 2);
481 
482  Selector const sel2{ProductInstanceNameSelector{"int2"} ||
484  auto handles = currentEvent_->getMany<product_t>(sel2);
485  BOOST_TEST(handles.size() == std::size_t{2});
486 
487  std::string const instance;
488  Selector sel1{ProductInstanceNameSelector{instance}};
489  sel1 = Selector{sel1 && ModuleLabelSelector{"modMulti"}};
490 
491  BOOST_TEST_REQUIRE(currentEvent_->get(sel1, h));
492  BOOST_TEST(h->value == 3);
493  handles.clear();
494 
495  // There should be five registered products with the 'modMulti'
496  // module label.
497  auto tags = currentEvent_->getInputTags<product_t>(modMultiSelector);
498  BOOST_TEST(tags.size() == 5u);
499  // Now remove the unavailable products
500  auto new_end =
501  std::remove_if(begin(tags), end(tags), [this](auto const& tag) {
502  return !currentEvent_->getHandle<product_t>(tag);
503  });
504  tags.erase(new_end, end(tags));
505 
506  // Only three of the registered products are available.
507  handles = currentEvent_->getMany<product_t>(modMultiSelector);
508  BOOST_TEST(handles.size() == 3u);
509 
510  // Make sure the resolved products agree with those specified in the
511  // 'tags' variable above. The products are resolved in the same
512  // order as the input-tag list.
513  for (std::size_t i{}; i < 3u; ++i) {
514  BOOST_TEST(handles[i].provenance()->inputTag() == tags[i]);
515  }
516 
517  handles = currentEvent_->getMany<product_t>(ModuleLabelSelector{"nomatch"});
518  BOOST_TEST_REQUIRE(handles.empty());
519 
520  auto const nomatches = currentEvent_->getMany<int>(modMultiSelector);
521  BOOST_TEST_REQUIRE(nomatches.empty());
522 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::string string
Definition: nybbler.cc:12
const std::string instance
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
BOOST_AUTO_TEST_CASE ( getBySelector  )

Definition at line 524 of file Event_t.cc.

525 {
526  using handle_t = Handle<product_t>;
527  using handle_vec = std::vector<handle_t>;
528 
529  addSourceProduct(product_with_value(1), "int1_tag", "int1");
530  addSourceProduct(product_with_value(2), "int2_tag", "int2");
531  addSourceProduct(product_with_value(3), "int3_tag");
532  addSourceProduct(product_with_value(4), "nolabel_tag");
533  addSourceProduct(product_with_value(100), "int1_tag_late", "int1");
534 
535  currentEvent_->put(product_with_value(200), "int1");
536  EDProducer::commitEvent(*principal_, *currentEvent_);
537 
538  Selector const sel{ProductInstanceNameSelector{"int2"} && modMultiSelector &&
539  ProcessNameSelector{"EARLY"}};
540  handle_t h;
541  BOOST_TEST_REQUIRE(currentEvent_->get(sel, h));
542  BOOST_TEST(h->value == 2);
543 
544  Selector const sel1{ProductInstanceNameSelector{"nomatch"} &&
545  modMultiSelector && ProcessNameSelector{"EARLY"}};
546  BOOST_TEST_REQUIRE(!currentEvent_->get(sel1, h));
547  BOOST_TEST_REQUIRE(!h.isValid());
548  BOOST_REQUIRE_THROW(*h, cet::exception);
549 
550  Selector const sel2{ProductInstanceNameSelector{"int2"} &&
551  ModuleLabelSelector{"nomatch"} &&
552  ProcessNameSelector{"EARLY"}};
553  BOOST_TEST_REQUIRE(!currentEvent_->get(sel2, h));
554  BOOST_TEST_REQUIRE(!h.isValid());
555  BOOST_REQUIRE_THROW(*h, cet::exception);
556 
557  Selector const sel3{ProductInstanceNameSelector{"int2"} && modMultiSelector &&
558  ProcessNameSelector{"nomatch"}};
559  BOOST_TEST_REQUIRE(!currentEvent_->get(sel3, h));
560  BOOST_TEST_REQUIRE(!h.isValid());
561  BOOST_REQUIRE_THROW(*h, cet::exception);
562 
563  Selector const sel4{modMultiSelector && ProcessNameSelector{"EARLY"}};
564  // multiple selections throw
565  BOOST_REQUIRE_THROW(currentEvent_->get(sel4, h), cet::exception);
566 
567  Selector const sel5{modMultiSelector && ProcessNameSelector{"LATE"}};
568  BOOST_TEST_REQUIRE(currentEvent_->get(sel5, h));
569  BOOST_TEST(h->value == 100);
570 
571  Selector const sel6{modMultiSelector && ProcessNameSelector{"CURRENT"}};
572  BOOST_TEST_REQUIRE(currentEvent_->get(sel6, h));
573  BOOST_TEST(h->value == 200);
574 
575  Selector const sel7{modMultiSelector};
576  BOOST_TEST_REQUIRE(currentEvent_->get(sel7, h));
577  BOOST_TEST(h->value == 200);
578 
579  auto handles = currentEvent_->getMany<product_t>(modMultiSelector);
580  BOOST_TEST(size(handles) == 5u);
581  int sum = 0;
582  for (int k = 0; k < 5; ++k) {
583  sum += handles[k]->value;
584  }
585  BOOST_TEST(sum == 306);
586 }
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
BOOST_AUTO_TEST_CASE ( getByLabel  )

Definition at line 588 of file Event_t.cc.

589 {
590  using handle_t = Handle<product_t>;
591  using handle_vec = std::vector<handle_t>;
592 
593  addSourceProduct(product_with_value(1), "int1_tag", "int1");
594  addSourceProduct(product_with_value(2), "int2_tag", "int2");
595  addSourceProduct(product_with_value(3), "int3_tag");
596  addSourceProduct(product_with_value(4), "nolabel_tag");
597  addSourceProduct(product_with_value(100), "int1_tag_late", "int1");
598 
599  currentEvent_->put(product_with_value(200), "int1");
600 
601  EDProducer::commitEvent(*principal_, *currentEvent_);
602 
603  handle_t h;
604  BOOST_TEST_REQUIRE(currentEvent_->getByLabel("modMulti", h));
605  BOOST_TEST(h->value == 3);
606  BOOST_TEST_REQUIRE(currentEvent_->getByLabel("modMulti", "int1", h));
607  BOOST_TEST(h->value == 200);
609  currentEvent_->getByLabel("modMulti", "int1", "CURRENT", h));
610  BOOST_TEST(h->value == 200);
612  currentEvent_->getByLabel("modMulti", "int1", "current_process", h));
613  BOOST_TEST(h->value == 200);
614  BOOST_TEST(!currentEvent_->getByLabel("modMulti", "nomatch", h));
615  BOOST_TEST(!h.isValid());
616  BOOST_CHECK_THROW(*h, cet::exception);
617 
618  InputTag const inputTag{"modMulti", "int1"};
619  BOOST_TEST_REQUIRE(currentEvent_->getByLabel(inputTag, h));
620  BOOST_TEST(h->value == 200);
621 
622  GroupQueryResult bh{principal_->getByLabel(currentModuleContext_,
623  WrappedTypeID::make<product_t>(),
624  "modMulti",
625  "int1",
626  ProcessTag{"LATE", "CURRENT"})};
627  h = handle_t{bh};
628  BOOST_TEST(h->value == 100);
629 
630  GroupQueryResult bh2{
631  principal_->getByLabel(currentModuleContext_,
632  WrappedTypeID::make<product_t>(),
633  "modMulti",
634  "int1",
635  ProcessTag{"nomatch", "CURRENT"})};
636  BOOST_TEST(!bh2.succeeded());
637 }
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
BOOST_AUTO_TEST_CASE ( getByLabelSpecialProcessNames  )

Definition at line 639 of file Event_t.cc.

640 {
641  addSourceProduct(product_with_value(2), "int2_tag", "int2");
642  currentEvent_->put(product_with_value(200), "int1");
643 
644  // Try to retrieve something that does not exist in the current process.
645  InputTag const badEarlyTag{"modMulti", "int2", "current_process"};
646  BOOST_REQUIRE_THROW(currentEvent_->getValidHandle<product_t>(badEarlyTag),
648 
649  // Verify that it can be read using the 'input_source' process name
651  InputTag const goodEarlyTag{"modMulti", "int2", "input_source"};
652  BOOST_TEST_REQUIRE(currentEvent_->getByLabel(goodEarlyTag, h));
653  BOOST_TEST(h->value == 2);
654 
655  // Verify that "int1" cannot be looked up using the "input_source"
656  // process name.
657  InputTag const badCurrentTag{"modMulti", "int1", "input_source"};
658  BOOST_CHECK_THROW(currentEvent_->getValidHandle<product_t>(badCurrentTag),
660 }
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
BOOST_AUTO_TEST_CASE ( getManyByType  )

Definition at line 662 of file Event_t.cc.

663 {
664  addSourceProduct(product_with_value(1), "int1_tag", "int1");
665  addSourceProduct(product_with_value(2), "int2_tag", "int2");
666  addSourceProduct(product_with_value(3), "int3_tag");
667  addSourceProduct(product_with_value(4), "nolabel_tag");
668 
669  addSourceProduct(product_with_value(100), "int1_tag_late", "int1");
670 
671  currentEvent_->put(product_with_value(200), "int1");
672  EDProducer::commitEvent(*principal_, *currentEvent_);
673 
674  // Verify that the returned tags match thos provided through the
675  // handles below.
676  auto const tags = currentEvent_->getInputTags<product_t>();
677  BOOST_TEST(tags.size() == 6u);
678 
679  auto const handles = currentEvent_->getMany<product_t>();
680  BOOST_TEST(handles.size() == 6u);
681  int sum = 0;
682  for (int k = 0; k < 6; ++k) {
683  auto const& h = handles[k];
684  BOOST_TEST(tags[k] == h.provenance()->productDescription().inputTag());
685  sum += h->value;
686  }
687  BOOST_TEST(sum == 310);
688 }
BOOST_AUTO_TEST_CASE ( printHistory  )

Definition at line 690 of file Event_t.cc.

691 {
692  auto const& history = currentEvent_->processHistory();
693  std::ofstream out{"history.log"};
694 
696  history,
697  std::ostream_iterator<ProcessHistory::const_iterator::value_type>(out,
698  "\n"));
699 }
auto copy_all(FwdCont &, FwdIter)