2 #define BOOST_TEST_MODULE (Event_t) 17 #include "boost/test/unit_test.hpp" 58 using namespace string_literals;
84 product_with_value(
int const v)
86 return std::make_unique<arttest::IntProduct>(v);
98 return os << timestamp.
value();
120 std::map<std::string, std::map<std::string, ParameterSet>>
121 moduleConfigurations_{};
122 std::map<std::string, ModuleDescription> moduleDescriptions_{};
129 std::map<std::string, TypeLabelLookup_t> earlyLookup_{};
136 template <
typename T,
bool Present>
146 constexpr
bool presentFromSource{
true};
147 constexpr
bool produced{
false};
150 registerProduct<product_t, presentFromSource>(
151 "nolabel_tag",
"modOne",
"EARLY");
152 registerProduct<product_t, presentFromSource>(
153 "int1_tag",
"modMulti",
"EARLY",
"int1");
154 registerProduct<product_t, presentFromSource>(
155 "int2_tag",
"modMulti",
"EARLY",
"int2");
156 registerProduct<product_t, presentFromSource>(
157 "int3_tag",
"modMulti",
"EARLY");
160 registerProduct<product_t, presentFromSource>(
161 "int1_tag_late",
"modMulti",
"LATE",
"int1");
166 descriptions_.clear();
170 currentModuleDescription_ = registerProduct<product_t, produced>(
171 "current_tag",
"modMulti",
"CURRENT",
"int1");
176 descriptions_.clear();
180 template <
class T,
bool Present>
188 moduleParams.
put(
"module_type", module_class_name());
189 moduleParams.
put(
"module_label", moduleLabel);
191 moduleConfigurations_[processName][moduleLabel] = moduleParams;
194 processParams.
put(
"process_name", processName);
195 processParams.
put(moduleLabel, moduleParams);
207 TypeID const product_type{
typeid(
T)};
209 moduleDescriptions_[tag] = localModuleDescription;
219 earlyLookup_[tag].emplace(typeLabel, pd);
221 currentLookup_.emplace(typeLabel, pd);
223 descriptions_.push_back(pd);
224 return moduleDescriptions_[tag];
232 ProductID addSourceProduct(std::unique_ptr<T>&& product,
237 std::unique_ptr<RunPrincipal> runPrincipal_{};
238 std::unique_ptr<SubRunPrincipal> subRunPrincipal_{};
239 std::unique_ptr<EventPrincipal> principal_{
nullptr};
241 std::unique_ptr<Event> currentEvent_{
nullptr};
250 for (
auto const&
process : ptf().moduleConfigurations_) {
251 auto const& process_name =
process.first;
253 if (process_name ==
"CURRENT") {
258 auto const& module_configurations =
process.second;
260 processParameterSet.
put(
"process_name", process_name);
261 for (
auto const& modConfig : module_configurations) {
262 processParameterSet.
put(modConfig.first, modConfig.second);
267 processHistory.
push_back(processConfiguration);
270 auto const processHistoryID = processHistory.
id();
281 constexpr
auto time = make_timestamp();
284 ptf().currentModuleDescription_.processConfiguration();
287 runPrincipal_ = std::make_unique<RunPrincipal>(runAux,
pc,
nullptr);
290 subRunPrincipal_ = std::make_unique<SubRunPrincipal>(subRunAux,
pc,
nullptr);
291 subRunPrincipal_->setRunPrincipal(runPrincipal_.get());
294 auto history = std::make_unique<History>();
295 const_cast<ProcessHistoryID&
>(history->processHistoryID()) = processHistoryID;
296 principal_ = std::make_unique<EventPrincipal>(
297 eventAux,
pc, &ptf().presentProducts_,
std::move(history));
298 principal_->setSubRunPrincipal(subRunPrincipal_.get());
299 principal_->createGroupsForProducedProducts(ptf().producedProducts_);
300 principal_->enableLookupOfProducedProducts(ptf().producedProducts_);
302 currentModuleContext_ =
ModuleContext{ptf().currentModuleDescription_};
303 currentEvent_ = std::make_unique<Event>(*principal_, currentModuleContext_);
314 auto description = ptf().moduleDescriptions_.find(tag);
315 if (
description == ptf().moduleDescriptions_.end())
317 <<
"Failed to find a module description for tag: " << tag <<
'\n';
319 auto lookup = ptf().earlyLookup_.find(tag);
320 if (lookup == ptf().earlyLookup_.end())
322 <<
"Failed to find a product lookup for tag: " << tag <<
'\n';
325 Event temporaryEvent{*principal_, tempMC};
345 if (
auto pd = currentEvent_->getProductDescription(
pid)) {
346 tag = pd->inputTag();
348 BOOST_TEST(
tag.empty());
354 BOOST_TEST(currentEvent_->id() == make_id());
355 BOOST_TEST(currentEvent_->time() == make_timestamp());
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());
379 currentEvent_->put(product_with_value(3),
"int1");
385 currentEvent_->put(product_with_value(4),
"int1");
414 addSourceProduct(product_with_value(1),
"int1_tag",
"int1");
419 addSourceProduct(product_with_value(2),
"int2_tag",
"int2");
421 BOOST_TEST(id2 != id1);
424 currentEvent_->get(wanted, h);
426 BOOST_TEST(h.
id() == wanted);
427 BOOST_TEST(h->
value == 1);
441 BOOST_TEST(principal_->size() == 6u);
442 currentEvent_->put(product_with_value(3),
"int1");
443 BOOST_TEST(principal_->size() == 6u);
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");
453 auto const tags = currentEvent_->getInputTags<
product_t>();
454 auto const tokens = currentEvent_->getProductTokens<
product_t>();
455 BOOST_TEST(
size(tags) ==
size(tokens));
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));
469 using handle_vec = std::vector<handle_t>;
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");
478 auto h = currentEvent_->getHandle<
product_t>(sel);
480 BOOST_TEST(
h->value == 2);
484 auto handles = currentEvent_->getMany<
product_t>(sel2);
485 BOOST_TEST(handles.size() == std::size_t{2});
492 BOOST_TEST(
h->value == 3);
497 auto tags = currentEvent_->getInputTags<
product_t>(modMultiSelector);
498 BOOST_TEST(tags.size() == 5u);
501 std::remove_if(
begin(tags),
end(tags), [
this](
auto const&
tag) {
504 tags.erase(new_end,
end(tags));
507 handles = currentEvent_->getMany<
product_t>(modMultiSelector);
508 BOOST_TEST(handles.size() == 3u);
513 for (std::size_t i{}; i < 3u; ++i) {
514 BOOST_TEST(handles[i].provenance()->inputTag() == tags[i]);
520 auto const nomatches = currentEvent_->getMany<
int>(modMultiSelector);
527 using handle_vec = std::vector<handle_t>;
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");
535 currentEvent_->put(product_with_value(200),
"int1");
542 BOOST_TEST(h->value == 2);
569 BOOST_TEST(h->value == 100);
573 BOOST_TEST(h->value == 200);
575 Selector const sel7{modMultiSelector};
577 BOOST_TEST(h->value == 200);
579 auto handles = currentEvent_->getMany<
product_t>(modMultiSelector);
580 BOOST_TEST(
size(handles) == 5u);
582 for (
int k = 0;
k < 5; ++
k) {
583 sum += handles[
k]->value;
585 BOOST_TEST(sum == 306);
591 using handle_vec = std::vector<handle_t>;
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");
599 currentEvent_->put(product_with_value(200),
"int1");
605 BOOST_TEST(h->value == 3);
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());
618 InputTag const inputTag{
"modMulti",
"int1"};
620 BOOST_TEST(h->value == 200);
623 WrappedTypeID::make<product_t>(),
628 BOOST_TEST(h->value == 100);
631 principal_->getByLabel(currentModuleContext_,
632 WrappedTypeID::make<product_t>(),
636 BOOST_TEST(!bh2.succeeded());
641 addSourceProduct(product_with_value(2),
"int2_tag",
"int2");
642 currentEvent_->put(product_with_value(200),
"int1");
645 InputTag const badEarlyTag{
"modMulti",
"int2",
"current_process"};
646 BOOST_REQUIRE_THROW(currentEvent_->getValidHandle<
product_t>(badEarlyTag),
651 InputTag const goodEarlyTag{
"modMulti",
"int2",
"input_source"};
653 BOOST_TEST(h->
value == 2);
657 InputTag const badCurrentTag{
"modMulti",
"int1",
"input_source"};
658 BOOST_CHECK_THROW(currentEvent_->getValidHandle<
product_t>(badCurrentTag),
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");
669 addSourceProduct(product_with_value(100),
"int1_tag_late",
"int1");
671 currentEvent_->put(product_with_value(200),
"int1");
676 auto const tags = currentEvent_->getInputTags<
product_t>();
677 BOOST_TEST(tags.size() == 6u);
679 auto const handles = currentEvent_->getMany<
product_t>();
680 BOOST_TEST(handles.size() == 6u);
682 for (
int k = 0;
k < 6; ++
k) {
683 auto const&
h = handles[
k];
684 BOOST_TEST(tags[
k] ==
h.provenance()->productDescription().inputTag());
687 BOOST_TEST(sum == 310);
692 auto const& history = currentEvent_->processHistory();
693 std::ofstream out{
"history.log"};
697 std::ostream_iterator<ProcessHistory::const_iterator::value_type>(out,
701 BOOST_AUTO_TEST_SUITE_END()
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
ProductTablesFixture & ptf()
BOOST_AUTO_TEST_CASE(badProductID)
ModuleDescription const & registerProduct(std::string const &tag, std::string const &moduleLabel, std::string const &processName, std::string const &productInstanceName={})
const std::string instance
auto & get(BranchType const bt)
std::vector< BranchDescription > ProductDescriptions
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
constexpr TimeValue_t value() const
ProcessHistoryID id() const
void movePutProductsToPrincipal(Principal &principal)
bool isValid() const noexcept
std::map< TypeLabel, BranchDescription > TypeLabelLookup_t
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
T const * product() const
std::string const & getReleaseVersion()
std::ostream & boost_test_print_type(std::ostream &os, Timestamp const timestamp)
RunNumber_t run() const noexcept
ParameterSetID id() const
static ProductTables invalid()
RunNumber_t run() const noexcept
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
auto copy_all(FwdCont &, FwdIter)
static void commitEvent(EventPrincipal &ep, Event &e)
static constexpr ProductID invalid() noexcept
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
void push_back(const_reference t)
static auto emplace(value_type const &value)
ProductID addSourceProduct(std::unique_ptr< T > &&product, std::string const &tag, std::string const &instanceName={})
static ModuleContext invalid()
void put(std::string const &key)
cet::coded_exception< error, detail::translate > exception