diff --git a/python/podio/test_Frame.py b/python/podio/test_Frame.py index aa798a8ae..2d7675215 100644 --- a/python/podio/test_Frame.py +++ b/python/podio/test_Frame.py @@ -41,6 +41,7 @@ "extension_ExternalComponent", "extension_ExternalRelation", "VectorMemberSubsetColl", + "interface_examples", } # The expected parameter names in each frame diff --git a/tests/read_frame.h b/tests/read_frame.h index 3a9ec2929..0103afea1 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/ExampleWithInterfaceRelationCollection.h" #include "datamodel/ExampleWithVectorMemberCollection.h" #include "read_test.h" @@ -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("interface_examples"); + ASSERT(interfaceColl.size() == 2, "interface_examples should have two elements"); + + const auto& hits = event.get("hits"); + const auto& particles = event.get("mcparticles"); + const auto& clusters = event.get("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 int read_frames(const std::string& filename, bool assertBuildVersion = true) { auto reader = ReaderT(); @@ -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)) { diff --git a/tests/write_frame.h b/tests/write_frame.h index 8a7b71619..1e1c9f966 100644 --- a/tests/write_frame.h +++ b/tests/write_frame.h @@ -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" @@ -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{}; @@ -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; }