From 7cc113d07b155dd57a310070ccdc6c1e89bf67a2 Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Mon, 6 Jan 2025 21:31:49 +0100 Subject: [PATCH] Add simple test for reusing collection names It is possible that users want to "ignore" a certain collection when reading files. It should then still be possible to add a new collection with the same name to the event that has been created without breaking anything. --- tests/read_frame.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/read_frame.h b/tests/read_frame.h index 06a9f34cb..af3b27051 100644 --- a/tests/read_frame.h +++ b/tests/read_frame.h @@ -1,6 +1,7 @@ #ifndef PODIO_TESTS_READ_FRAME_H // NOLINT(llvm-header-guard): folder structure not suitable #define PODIO_TESTS_READ_FRAME_H // NOLINT(llvm-header-guard): folder structure not suitable +#include "datamodel/ExampleHitCollection.h" #include "datamodel/ExampleWithInterfaceRelationCollection.h" #include "datamodel/ExampleWithVectorMemberCollection.h" #include "read_test.h" @@ -279,7 +280,7 @@ template int test_read_frame_limited(ReaderT& reader) { const std::vector collsToRead = {"mcparticles", "clusters"}; - const auto event = [&]() { + auto event = [&]() { if constexpr (std::is_same_v) { return podio::Frame(reader.readFrame("events", 1, collsToRead)); } else { @@ -325,6 +326,17 @@ int test_read_frame_limited(ReaderT& reader) { return 1; } + const auto& newHits = [&]() -> auto const& { + auto mutHits = ExampleHitCollection(); + mutHits.create(); + return event.put(std::move(mutHits), "hits"); + }(); + + if (newHits.size() != 1) { + std::cerr << "Adding new collection with same name as available from data (but not read) doesn't work" << std::endl; + return 1; + } + // Check that nothing breaks if we pass in an unavailable collection name const auto emptyEvent = [&]() { if constexpr (std::is_same_v) {