1#ifndef PODIO_TESTS_READ_FRAME_H
2#define PODIO_TESTS_READ_FRAME_H
6#include "extension_model/ContainedTypeCollection.h"
7#include "extension_model/ExternalComponentTypeCollection.h"
8#include "extension_model/ExternalRelationTypeCollection.h"
14#define ASSERT(condition, msg) \
16 throw std::runtime_error(msg); \
20 const auto& extColl =
event.get<extension::ContainedTypeCollection>(
"extension_Contained");
21 ASSERT(extColl.isValid(),
"extension_Contained collection should be present");
22 ASSERT(extColl.size() == 1,
"extension_Contained collection should have one element");
23 auto extElem = extColl[0];
24 const auto& polVec = extElem.getAVector();
25 ASSERT(polVec.r == iEvent * 123.f,
"polVec.r value not as expected");
26 ASSERT(polVec.phi == 0.15f,
"polVec.phi value not as epxected");
27 ASSERT(polVec.rho == 3.14f,
"polVec.phi value not as epxected");
29 const auto& extCompColl =
event.get<extension::ExternalComponentTypeCollection>(
"extension_ExternalComponent");
30 ASSERT(extCompColl.isValid(),
"extension_ExternalComponent collection should be present");
31 ASSERT(extCompColl.size() == 1,
"extension_ExternalComponent should have one element");
32 auto extCompElem = extCompColl[0];
33 ASSERT((extCompElem.getAStruct().p == std::array{iEvent, iEvent - 2, iEvent + 4, iEvent * 8}),
34 "aStruct.p value not as expected");
35 ASSERT(extCompElem.getAComponent().aStruct.data.x == 42 * iEvent,
"aComponent.aStruct.x value not as expected");
36 ASSERT(extCompElem.getAComponent().nspStruct.x == iEvent,
"aComponent.nspStruct.x value not as expected");
37 ASSERT(extCompElem.getAComponent().nspStruct.y == iEvent * 2,
"aComponent.nspStruct.y value not as expected");
39 const auto& extRelColl =
event.get<extension::ExternalRelationTypeCollection>(
"extension_ExternalRelation");
40 ASSERT(extRelColl.isValid(),
"extension_ExternalRelation collection should be present");
41 ASSERT(extRelColl.size() == 3,
"extension_ExternalRelation collection should contain 3 elements");
43 const auto& hits =
event.get<ExampleHitCollection>(
"hits");
44 auto elem0 = extRelColl[0];
45 ASSERT(elem0.getWeight() == iEvent * 100.f,
"weight of first element not as expected");
46 ASSERT(elem0.getSingleHit() == hits[0],
"single hit relation not as expected");
48 const auto& clusters =
event.get<ExampleClusterCollection>(
"clusters");
49 auto elem1 = extRelColl[1];
50 const auto relClusters = elem1.getClusters();
51 ASSERT(relClusters.size() == 2,
"element should have two related clusters");
52 ASSERT(relClusters[0] == clusters[1],
"first related cluster not as expected");
53 ASSERT(relClusters[1] == clusters[0],
"first related cluster not as expected");
55 auto elem2 = extRelColl[2];
56 const auto& structs = elem2.getSomeStructs();
57 ASSERT(structs.size() == 3,
"element should have 3 struct vector members");
58 ASSERT(structs[0].y == 0,
"struct value not as expected");
59 ASSERT(structs[1].y == iEvent,
"struct value not as expected");
60 ASSERT(structs[2].y == 2 * iEvent,
"struct value not as expected");
63template <
typename ReaderT>
65 auto reader = ReaderT();
67 reader.openFile(filename);
68 }
catch (
const std::runtime_error& e) {
69 std::cout <<
"File could not be opened, aborting." << std::endl;
73 if (reader.currentFileVersion() != podio::version::build_version) {
74 std::cerr <<
"The podio build version could not be read back correctly. "
75 <<
"(expected:" << podio::version::build_version <<
", actual: " << reader.currentFileVersion() <<
")"
80 if (reader.getEntries(
"events") != 10) {
81 std::cerr <<
"Could not read back the number of events correctly. "
82 <<
"(expected:" << 10 <<
", actual: " << reader.getEntries(
"events") <<
")" << std::endl;
86 if (reader.getEntries(
"events") != reader.getEntries(
"other_events")) {
87 std::cerr <<
"Could not read back the number of events correctly. "
88 <<
"(expected:" << 10 <<
", actual: " << reader.getEntries(
"other_events") <<
")" << std::endl;
94 for (
size_t i = 0; i < reader.getEntries(
"events"); ++i) {
95 auto frame =
podio::Frame(reader.readNextEntry(
"events"));
96 if (frame.get(
"emptySubsetColl") ==
nullptr) {
97 std::cerr <<
"Could not retrieve an empty subset collection" << std::endl;
100 if (frame.get(
"emptyCollection") ==
nullptr) {
101 std::cerr <<
"Could not retrieve an empty collection" << std::endl;
107 auto otherFrame =
podio::Frame(reader.readNextEntry(
"other_events"));
108 processEvent(otherFrame, i + 100, reader.currentFileVersion());
113 if (reader.readNextEntry(
"events")) {
114 std::cerr <<
"Trying to read more frame data than is present should return a nullptr" << std::endl;
118 std::cout <<
"========================================================\n" << std::endl;
119 if (reader.readNextEntry(
"not_present")) {
120 std::cerr <<
"Trying to read non-existant frame data should return a nullptr" << std::endl;
126 auto frame =
podio::Frame(reader.readEntry(
"events", 4));
129 auto nextFrame =
podio::Frame(reader.readNextEntry(
"events"));
130 processEvent(nextFrame, 5, reader.currentFileVersion());
132 auto otherFrame =
podio::Frame(reader.readEntry(
"other_events", 4));
133 processEvent(otherFrame, 4 + 100, reader.currentFileVersion());
137 auto previousFrame =
podio::Frame(reader.readEntry(
"other_events", 2));
138 processEvent(previousFrame, 2 + 100, reader.currentFileVersion());
142 if (reader.readEntry(
"events", 10)) {
143 std::cerr <<
"Trying to read a specific entry that does not exist should return a nullptr" << std::endl;
void processExtensions(const podio::Frame &event, int iEvent, podio::version::Version)
int read_frames(const std::string &filename)
#define ASSERT(condition, msg)
void processEvent(StoreT &store, int eventNum, podio::version::Version fileVersion)