Skip to content

Commit

Permalink
Rename store to event
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Oct 12, 2023
1 parent f54850d commit c390452
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions tests/read_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ bool check_fixed_width_value(FixedWidthT actual, FixedWidthT expected, const std
return true;
}

void processEvent(const podio::Frame& store, int eventNum, podio::version::Version fileVersion) {
const float evtWeight = store.getParameter<float>("UserEventWeight");
void processEvent(const podio::Frame& event, int eventNum, podio::version::Version fileVersion) {
const float evtWeight = event.getParameter<float>("UserEventWeight");
if (evtWeight != (float)100. * eventNum) {
std::cout << " read UserEventWeight: " << evtWeight << " - expected : " << (float)100. * eventNum << std::endl;
throw std::runtime_error("Couldn't read event meta data parameters 'UserEventWeight'");
}

std::stringstream ss;
ss << " event_number_" << eventNum;
const auto& evtName = store.getParameter<std::string>("UserEventName");
const auto& evtName = event.getParameter<std::string>("UserEventName");

if (evtName != ss.str()) {
std::cout << " read UserEventName: " << evtName << " - expected : " << ss.str() << std::endl;
throw std::runtime_error("Couldn't read event meta data parameters 'UserEventName'");
}

if (fileVersion > podio::version::Version{0, 14, 1}) {
const auto& someVectorData = store.getParameter<std::vector<int>>("SomeVectorData");
const auto& someVectorData = event.getParameter<std::vector<int>>("SomeVectorData");
if (someVectorData.size() != 4) {
throw std::runtime_error("Couldn't read event meta data parameters: 'SomeVectorData'");
}
Expand All @@ -67,7 +67,7 @@ void processEvent(const podio::Frame& store, int eventNum, podio::version::Versi
}

if (fileVersion > podio::version::Version{0, 16, 2}) {
const auto& doubleParams = store.getParameter<std::vector<double>>("SomeVectorData");
const auto& doubleParams = event.getParameter<std::vector<double>>("SomeVectorData");
if (doubleParams.size() != 2 || doubleParams[0] != eventNum * 1.1 || doubleParams[1] != eventNum * 2.2) {
throw std::runtime_error("Could not read event parameter: 'SomeDoubleValues' correctly");
}
Expand All @@ -76,18 +76,18 @@ void processEvent(const podio::Frame& store, int eventNum, podio::version::Versi
try {
// not assigning to a variable, because it will remain unused, we just want
// the exception here
store.get<ExampleClusterCollection>("notthere");
event.get<ExampleClusterCollection>("notthere");
} catch (const std::runtime_error& err) {
if (std::string(err.what()) != "No collection \'notthere\' is present in the EventStore") {
throw std::runtime_error("Trying to get non present collection \'notthere' should throw an exception");
}
}

// read collection meta data
auto& hits = store.get<ExampleHitCollection>("hits");
auto& hits = event.get<ExampleHitCollection>("hits");

if (fileVersion > podio::version::Version{0, 14, 0}) {
auto& hitRefs = store.get<ExampleHitCollection>("hitRefs");
auto& hitRefs = event.get<ExampleHitCollection>("hitRefs");
if (hitRefs.size() != hits.size()) {
throw std::runtime_error("hit and subset hit collection do not have the same size");
}
Expand All @@ -96,7 +96,7 @@ void processEvent(const podio::Frame& store, int eventNum, podio::version::Versi
}
}

auto& clusters = store.get<ExampleClusterCollection>("clusters");
auto& clusters = event.get<ExampleClusterCollection>("clusters");
if (clusters.isValid()) {
auto cluster = clusters[0];
for (auto i = cluster.Hits_begin(), end = cluster.Hits_end(); i != end; ++i) {
Expand All @@ -110,7 +110,7 @@ void processEvent(const podio::Frame& store, int eventNum, podio::version::Versi
// 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.get<ExampleMCCollection>("mcParticleRefs");
auto& mcpRefs = event.get<ExampleMCCollection>("mcParticleRefs");
if (!mcpRefs.isValid()) {
throw std::runtime_error("Collection 'mcParticleRefs' should be present");
}
Expand All @@ -132,7 +132,7 @@ void processEvent(const podio::Frame& store, int eventNum, podio::version::Versi
}
}

auto& mcps = store.get<ExampleMCCollection>("mcparticles");
auto& mcps = event.get<ExampleMCCollection>("mcparticles");
if (!mcps.isValid()) {
throw std::runtime_error("Collection 'mcparticles' should be present");
}
Expand Down Expand Up @@ -200,7 +200,7 @@ void processEvent(const podio::Frame& store, int eventNum, podio::version::Versi

// Load the subset collection first to ensure that it pulls in objects taht
// have not been read yet
auto& mcpRefs = store.get<ExampleMCCollection>("mcParticleRefs");
auto& mcpRefs = event.get<ExampleMCCollection>("mcParticleRefs");
if (!mcpRefs.isValid()) {
throw std::runtime_error("Collection 'mcParticleRefs' should be present");
}
Expand All @@ -212,7 +212,7 @@ void processEvent(const podio::Frame& store, int eventNum, podio::version::Versi
}
}

auto& moreMCs = store.get<ExampleMCCollection>("moreMCs");
auto& moreMCs = event.get<ExampleMCCollection>("moreMCs");

// First check that the two mc collections that we store are the same
if (mcps.size() != moreMCs.size()) {
Expand Down Expand Up @@ -245,7 +245,7 @@ void processEvent(const podio::Frame& store, int eventNum, podio::version::Versi
}

// std::cout << "Fetching collection 'refs'" << std::endl;
auto& refs = store.get<ExampleReferencingTypeCollection>("refs");
auto& refs = event.get<ExampleReferencingTypeCollection>("refs");
if (refs.isValid()) {
auto ref = refs[0];
for (auto cluster : ref.Clusters()) {
Expand All @@ -257,15 +257,15 @@ void processEvent(const podio::Frame& store, int eventNum, podio::version::Versi
throw std::runtime_error("Collection 'refs' should be present");
}
// std::cout << "Fetching collection 'OneRelation'" << std::endl;
auto& rels = store.get<ExampleWithOneRelationCollection>("OneRelation");
auto& rels = event.get<ExampleWithOneRelationCollection>("OneRelation");
if (rels.isValid()) {
// std::cout << "Referenced object has an energy of " << (*rels)[0].cluster().energy() << std::endl;
} else {
throw std::runtime_error("Collection 'OneRelation' should be present");
}

// std::cout << "Fetching collection 'WithVectorMember'" << std::endl;
auto& vecs = store.get<ExampleWithVectorMemberCollection>("WithVectorMember");
auto& vecs = event.get<ExampleWithVectorMemberCollection>("WithVectorMember");
if (vecs.isValid()) {
if (vecs.size() != 2) {
throw std::runtime_error("Collection 'WithVectorMember' should have two elements'");
Expand All @@ -292,13 +292,13 @@ void processEvent(const podio::Frame& store, int eventNum, podio::version::Versi
throw std::runtime_error("Collection 'WithVectorMember' should be present");
}

auto& comps = store.get<ExampleWithComponentCollection>("Component");
auto& comps = event.get<ExampleWithComponentCollection>("Component");
if (comps.isValid()) {
auto comp = comps[0];
int a [[maybe_unused]] = comp.component().data.x + comp.component().data.z;
}

auto& arrays = store.get<ExampleWithArrayCollection>("arrays");
auto& arrays = event.get<ExampleWithArrayCollection>("arrays");
if (arrays.isValid() && arrays.size() != 0) {
auto array = arrays[0];
if (array.myArray(1) != eventNum) {
Expand All @@ -314,8 +314,8 @@ void processEvent(const podio::Frame& store, int eventNum, podio::version::Versi
throw std::runtime_error("Collection 'arrays' should be present");
}

auto& nmspaces = store.get<ex42::ExampleWithARelationCollection>("WithNamespaceRelation");
auto& copies = store.get<ex42::ExampleWithARelationCollection>("WithNamespaceRelationCopy");
auto& nmspaces = event.get<ex42::ExampleWithARelationCollection>("WithNamespaceRelation");
auto& copies = event.get<ex42::ExampleWithARelationCollection>("WithNamespaceRelationCopy");

auto cpytest = ex42::ExampleWithARelationCollection{};
if (nmspaces.isValid() && copies.isValid()) {
Expand Down Expand Up @@ -354,7 +354,7 @@ void processEvent(const podio::Frame& store, int eventNum, podio::version::Versi
}

if (fileVersion >= podio::version::Version{0, 13, 1}) {
const auto& fixedWidthInts = store.get<ExampleWithFixedWidthIntegersCollection>("fixedWidthInts");
const auto& fixedWidthInts = event.get<ExampleWithFixedWidthIntegersCollection>("fixedWidthInts");
if (not fixedWidthInts.isValid() or fixedWidthInts.size() != 3) {
throw std::runtime_error("Collection \'fixedWidthInts\' should be present and have 3 elements");
}
Expand Down Expand Up @@ -388,7 +388,7 @@ void processEvent(const podio::Frame& store, int eventNum, podio::version::Versi
}

if (fileVersion >= podio::version::Version{0, 13, 2}) {
auto& usrInts = store.get<podio::UserDataCollection<uint64_t>>("userInts");
auto& usrInts = event.get<podio::UserDataCollection<uint64_t>>("userInts");

if (usrInts.size() != (unsigned)eventNum + 1) {
throw std::runtime_error("Could not read all userInts properly (expected: " + std::to_string(eventNum + 1) +
Expand All @@ -410,7 +410,7 @@ void processEvent(const podio::Frame& store, int eventNum, podio::version::Versi
}
}

auto& usrDbl = store.get<podio::UserDataCollection<double>>("userDoubles");
auto& usrDbl = event.get<podio::UserDataCollection<double>>("userDoubles");
if (usrDbl.size() != 100) {
throw std::runtime_error(
"Could not read all userDoubles properly (expected: 100, actual: " + std::to_string(usrDbl.size()) + ")");
Expand Down

0 comments on commit c390452

Please sign in to comment.