Skip to content

Commit

Permalink
Add namespace read/write tests to Frame I/O
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed May 30, 2022
1 parent 45ccc2f commit 038a3ad
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 39 deletions.
68 changes: 33 additions & 35 deletions tests/read_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,45 +329,43 @@ void processEvent(StoreT& store, int eventNum, podio::version::Version fileVersi
throw std::runtime_error("Collection 'arrays' should be present");
}

if constexpr (isEventStore<StoreT>) {
auto& nmspaces = store.template get<ex42::ExampleWithARelationCollection>("WithNamespaceRelation");
auto& copies = store.template get<ex42::ExampleWithARelationCollection>("WithNamespaceRelationCopy");

auto& cpytest = store.template create<ex42::ExampleWithARelationCollection>("TestConstCopy");
if (nmspaces.isValid() && copies.isValid()) {
for (size_t j = 0; j < nmspaces.size(); j++) {
auto nmsp = nmspaces[j];
auto cpy = copies[j];
cpytest.push_back(nmsp.clone());
if (nmsp.ref().isAvailable()) {
if (nmsp.ref().component().x != cpy.ref().component().x ||
nmsp.ref().component().y != cpy.ref().component().y) {
throw std::runtime_error("Copied item has differing component in OneToOne referenced item.");
}
// check direct accessors of POD sub members
if (nmsp.ref().x() != cpy.ref().x()) {
throw std::runtime_error("Getting wrong values when using direct accessors for sub members.");
}
if (nmsp.number() != cpy.number()) {
throw std::runtime_error("Copied item has differing member.");
}
if (!(nmsp.ref().getObjectID() == cpy.ref().getObjectID())) {
throw std::runtime_error("Copied item has wrong OneToOne references.");
}
auto& nmspaces = store.template get<ex42::ExampleWithARelationCollection>("WithNamespaceRelation");
auto& copies = store.template get<ex42::ExampleWithARelationCollection>("WithNamespaceRelationCopy");

auto cpytest = ex42::ExampleWithARelationCollection{};
if (nmspaces.isValid() && copies.isValid()) {
for (size_t j = 0; j < nmspaces.size(); j++) {
auto nmsp = nmspaces[j];
auto cpy = copies[j];
cpytest.push_back(nmsp.clone());
if (nmsp.ref().isAvailable()) {
if (nmsp.ref().component().x != cpy.ref().component().x ||
nmsp.ref().component().y != cpy.ref().component().y) {
throw std::runtime_error("Copied item has differing component in OneToOne referenced item.");
}
// check direct accessors of POD sub members
if (nmsp.ref().x() != cpy.ref().x()) {
throw std::runtime_error("Getting wrong values when using direct accessors for sub members.");
}
auto cpy_it = cpy.refs_begin();
for (auto it = nmsp.refs_begin(); it != nmsp.refs_end(); ++it, ++cpy_it) {
if (it->component().x != cpy_it->component().x || it->component().y != cpy_it->component().y) {
throw std::runtime_error("Copied item has differing component in OneToMany referenced item.");
}
if (!(it->getObjectID() == cpy_it->getObjectID())) {
throw std::runtime_error("Copied item has wrong OneToMany references.");
}
if (nmsp.number() != cpy.number()) {
throw std::runtime_error("Copied item has differing member.");
}
if (!(nmsp.ref().getObjectID() == cpy.ref().getObjectID())) {
throw std::runtime_error("Copied item has wrong OneToOne references.");
}
}
auto cpy_it = cpy.refs_begin();
for (auto it = nmsp.refs_begin(); it != nmsp.refs_end(); ++it, ++cpy_it) {
if (it->component().x != cpy_it->component().x || it->component().y != cpy_it->component().y) {
throw std::runtime_error("Copied item has differing component in OneToMany referenced item.");
}
if (!(it->getObjectID() == cpy_it->getObjectID())) {
throw std::runtime_error("Copied item has wrong OneToMany references.");
}
}
} else {
throw std::runtime_error("Collection 'WithNamespaceRelation' and 'WithNamespaceRelationCopy' should be present");
}
} else {
throw std::runtime_error("Collection 'WithNamespaceRelation' and 'WithNamespaceRelationCopy' should be present");
}

if (fileVersion >= podio::version::Version{0, 13, 1}) {
Expand Down
38 changes: 38 additions & 0 deletions tests/write_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#include "datamodel/ExampleHitCollection.h"
#include "datamodel/ExampleMCCollection.h"
#include "datamodel/ExampleReferencingTypeCollection.h"
#include "datamodel/ExampleWithARelationCollection.h"
#include "datamodel/ExampleWithArrayCollection.h"
#include "datamodel/ExampleWithFixedWidthIntegersCollection.h"
#include "datamodel/ExampleWithNamespaceCollection.h"
#include "datamodel/ExampleWithOneRelationCollection.h"
#include "datamodel/ExampleWithStringCollection.h"
#include "datamodel/ExampleWithVectorMemberCollection.h"
Expand Down Expand Up @@ -278,6 +280,37 @@ auto createUserDataCollections(int i) {
return retType;
}

auto createNamespaceRelationCollection(int i) {
auto retVal = std::tuple<ex42::ExampleWithNamespaceCollection, ex42::ExampleWithARelationCollection,
ex42::ExampleWithARelationCollection>{};
auto& [namesps, namesprels, cpytest] = retVal;

for (int j = 0; j < 5; j++) {
auto rel = ex42::MutableExampleWithARelation();
rel.number(0.5 * j);
auto exWithNamesp = ex42::MutableExampleWithNamespace();
exWithNamesp.component().x = i;
exWithNamesp.component().y = 1000 * i;
namesps.push_back(exWithNamesp);
if (j != 3) { // also check for empty relations
rel.ref(exWithNamesp);
for (int k = 0; k < 5; k++) {
auto namesp = ex42::MutableExampleWithNamespace();
namesp.x(3 * k);
namesp.component().y = k;
namesps.push_back(namesp);
rel.addrefs(namesp);
}
}
namesprels.push_back(rel);
}
for (auto&& namesprel : namesprels) {
cpytest.push_back(namesprel.clone());
}

return retVal;
}

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

Expand Down Expand Up @@ -311,6 +344,11 @@ podio::Frame makeFrame(int iFrame) {
frame.put(std::move(usrInts), "userInts");
frame.put(std::move(usrDoubles), "userDoubles");

auto [namesps, namespsrels, cpytest] = createNamespaceRelationCollection(iFrame);
frame.put(std::move(namesps), "WithNamespaceMember");
frame.put(std::move(namespsrels), "WithNamespaceRelation");
frame.put(std::move(cpytest), "WithNamespaceRelationCopy");

// Parameters
frame.putParameter("anInt", 42 + iFrame);
frame.putParameter("UserEventWeight", 100.f * iFrame);
Expand Down
23 changes: 19 additions & 4 deletions tests/write_frame_root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,25 @@
#include <string>
#include <vector>

static const std::vector<std::string> collsToWrite = {
"mcparticles", "moreMCs", "arrays", "mcParticleRefs", "strings", "hits",
"hitRefs", "refs", "refs2", "clusters", "OneRelation", "info",
"WithVectorMember", "fixedWidthInts", "userInts", "userDoubles"};
static const std::vector<std::string> collsToWrite = {"mcparticles",
"moreMCs",
"arrays",
"mcParticleRefs",
"strings",
"hits",
"hitRefs",
"refs",
"refs2",
"clusters",
"OneRelation",
"info",
"WithVectorMember",
"fixedWidthInts",
"userInts",
"userDoubles",
"WithNamespaceMember",
"WithNamespaceRelation",
"WithNamespaceRelationCopy"};

int main(int, char**) {
auto writer = podio::ROOTFrameWriter("example_frame.root");
Expand Down

0 comments on commit 038a3ad

Please sign in to comment.