Skip to content

Commit

Permalink
Add I/O tests for a type with an interface relation (AIDASoft#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener authored Jun 10, 2024
1 parent 9cd68c0 commit 99caa5e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/podio/test_Frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"extension_ExternalComponent",
"extension_ExternalRelation",
"VectorMemberSubsetColl",
"interface_examples",
}

# The expected parameter names in each frame
Expand Down
34 changes: 34 additions & 0 deletions 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/ExampleWithInterfaceRelationCollection.h"
#include "datamodel/ExampleWithVectorMemberCollection.h"
#include "read_test.h"

Expand Down Expand Up @@ -69,6 +70,35 @@ void checkVecMemSubsetColl(const podio::Frame& event) {
ASSERT(subsetColl[0] == origColl[0], "subset coll does not have the right contents");
}

void checkInterfaceCollection(const podio::Frame& event) {
const auto& interfaceColl = event.get<ExampleWithInterfaceRelationCollection>("interface_examples");
ASSERT(interfaceColl.size() == 2, "interface_examples should have two elements");

const auto& hits = event.get<ExampleHitCollection>("hits");
const auto& particles = event.get<ExampleMCCollection>("mcparticles");
const auto& clusters = event.get<ExampleClusterCollection>("clusters");

const auto iface0 = interfaceColl[0];
const auto iface1 = interfaceColl[1];

ASSERT(iface0.aSingleEnergyType() == hits[0], "OneToOneRelation aSingleEnergy not persisted as expected");
ASSERT(iface1.aSingleEnergyType() == clusters[0], "OneToOneRelation aSingleEnergy not persisted as expected");

const auto iface0Rels = iface0.manyEnergies();
ASSERT(iface0Rels.size() == 3,
"OneToManyRelation to interface does not have the expected number of related elements");
ASSERT(iface0Rels[0] == hits[0], "OneToManyRelations to interface not persisted correctly");
ASSERT(iface0Rels[1] == clusters[0], "OneToManyRelations to interface not persisted correctly");
ASSERT(iface0Rels[2] == particles[0], "OneToManyRelations to interface not persisted correctly");

const auto iface1Rels = iface1.manyEnergies();
ASSERT(iface1Rels.size() == 3,
"OneToManyRelation to interface does not have the expected number of related elements");
ASSERT(iface1Rels[0] == particles[0], "OneToManyRelations to interface not persisted correctly");
ASSERT(iface1Rels[1] == hits[0], "OneToManyRelations to interface not persisted correctly");
ASSERT(iface1Rels[2] == clusters[0], "OneToManyRelations to interface not persisted correctly");
}

template <typename ReaderT>
int read_frames(const std::string& filename, bool assertBuildVersion = true) {
auto reader = ReaderT();
Expand Down Expand Up @@ -125,6 +155,10 @@ int read_frames(const std::string& filename, bool assertBuildVersion = true) {
if (reader.currentFileVersion() >= podio::version::Version{0, 16, 99}) {
checkVecMemSubsetColl(otherFrame);
}
// Interface tests once they are present
if (reader.currentFileVersion() >= podio::version::Version{0, 99, 99}) {
checkInterfaceCollection(otherFrame);
}
}

if (reader.readNextEntry(podio::Category::Event)) {
Expand Down
21 changes: 21 additions & 0 deletions tests/write_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "datamodel/ExampleWithARelationCollection.h"
#include "datamodel/ExampleWithArrayCollection.h"
#include "datamodel/ExampleWithFixedWidthIntegersCollection.h"
#include "datamodel/ExampleWithInterfaceRelationCollection.h"
#include "datamodel/ExampleWithNamespaceCollection.h"
#include "datamodel/ExampleWithOneRelationCollection.h"
#include "datamodel/ExampleWithVectorMemberCollection.h"
Expand Down Expand Up @@ -361,6 +362,24 @@ auto createExtensionExternalRelationCollection(int i, const ExampleHitCollection
return coll;
}

auto createExampleWithInterfaceCollection(const ExampleHitCollection& hits, const ExampleClusterCollection& clusters,
const ExampleMCCollection& particles) {
auto coll = ExampleWithInterfaceRelationCollection{};
auto elem = coll.create();
elem.aSingleEnergyType(hits[0]);
elem.addmanyEnergies(hits[0]);
elem.addmanyEnergies(clusters[0]);
elem.addmanyEnergies(particles[0]);

elem = coll.create();
elem.aSingleEnergyType(clusters[0]);
elem.addmanyEnergies(particles[0]);
elem.addmanyEnergies(hits[0]);
elem.addmanyEnergies(clusters[0]);

return coll;
}

podio::Frame makeFrame(int iFrame) {
podio::Frame frame{};

Expand Down Expand Up @@ -420,6 +439,8 @@ podio::Frame makeFrame(int iFrame) {
frame.put(createExtensionExternalComponentCollection(iFrame), "extension_ExternalComponent");
frame.put(createExtensionExternalRelationCollection(iFrame, hits, clusters), "extension_ExternalRelation");

frame.put(createExampleWithInterfaceCollection(hits, clusters, mcps), "interface_examples");

return frame;
}

Expand Down

0 comments on commit 99caa5e

Please sign in to comment.