Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing setting of relations in nested get calls #349

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/podio/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ bool Frame::FrameModel<FrameDataT>::get(int collectionID, CollectionBase*& colle
const auto& name = m_idTable.name(collectionID);
const auto& [_, inserted] = m_retrievedIDs.insert(collectionID);

if (!inserted) {
if (inserted) {
auto coll = doGet(name);
if (coll) {
collection = coll;
Expand Down
26 changes: 26 additions & 0 deletions tests/read_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,32 @@ void processEvent(StoreT& store, int eventNum, podio::version::Version fileVersi
throw std::runtime_error("Collection 'clusters' should be present");
}

if (fileVersion >= podio::version::Version{0, 13, 2}) {
// Read the mcParticleRefs before reading any of the other collections that
// are referenced to make sure that all the necessary relations are handled
// correctly
auto& mcpRefs = store.template get<ExampleMCCollection>("mcParticleRefs");
if (!mcpRefs.isValid()) {
throw std::runtime_error("Collection 'mcParticleRefs' should be present");
}

// Only doing a very basic check here, that mainly just ensures that the
// RelationRange is valid and does not segfault.
for (auto ref : mcpRefs) {
const auto daughters = ref.daughters();
if (!daughters.empty()) {
// This will segfault in case things are not working
auto d [[maybe_unused]] = daughters[0];
}

const auto parents = ref.parents();
if (!parents.empty()) {
// This will segfault in case things are not working
auto d [[maybe_unused]] = parents[0];
}
}
}

auto& mcps = store.template get<ExampleMCCollection>("mcparticles");
if (!mcps.isValid()) {
throw std::runtime_error("Collection 'mcparticles' should be present");
Expand Down