Skip to content

Commit

Permalink
Add simple test for reusing collection names
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tmadlener committed Jan 8, 2025
1 parent 3a0abf8 commit 1123457
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/read_frame.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -279,7 +280,7 @@ template <typename ReaderT>
int test_read_frame_limited(ReaderT& reader) {
const std::vector<std::string> collsToRead = {"mcparticles", "clusters"};

const auto event = [&]() {
auto event = [&]() {
if constexpr (std::is_same_v<ReaderT, podio::Reader>) {
return podio::Frame(reader.readFrame("events", 1, collsToRead));
} else {
Expand Down Expand Up @@ -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<ReaderT, podio::Reader>) {
Expand Down

0 comments on commit 1123457

Please sign in to comment.