Skip to content

Commit

Permalink
Switch test case from EventStore to Frame based I/O
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Sep 15, 2023
1 parent b00fd75 commit 05f6041
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions tests/root_io/read_and_write_associated.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "podio/EventStore.h"
#include "podio/ROOTReader.h"
#include "podio/ROOTWriter.h"
#include "podio/Frame.h"
#include "podio/ROOTFrameReader.h"
#include "podio/ROOTFrameWriter.h"

#include "datamodel/EventInfoCollection.h"
#include "datamodel/ExampleClusterCollection.h"
Expand All @@ -10,41 +10,33 @@
#include <string>

void writeCollection() {

auto store = podio::EventStore();
podio::ROOTWriter writer("associations.root", &store);
podio::ROOTFrameWriter writer("associations.root");

std::cout << "start writting collections...\n";
auto& info = store.create<EventInfoCollection>("info");
auto& hits = store.create<ExampleHitCollection>("hits");
auto& clusters = store.create<ExampleClusterCollection>("clusters");
auto& hits_subset = store.create<ExampleHitCollection>("hits_subset");
hits_subset.setSubsetCollection(true);

writer.registerForWrite("clusters");
// writer.registerForWrite("hits");
writer.registerForWrite("hits_subset");

unsigned nevents = 2;

for (unsigned i = 0; i < nevents; ++i) {
auto event = podio::Frame{};

auto info = EventInfoCollection{};
auto item1 = MutableEventInfo();
item1.Number(i);
info.push_back(item1);

auto& evtMD = store.getEventMetaData();
evtMD.setValue("UserEventWeight", (float)100. * i);
event.putParameter("UserEventWeight", (float)100. * i);
std::cout << " event number: " << i << std::endl;
evtMD.setValue("UserEventName", std::to_string(i));
event.putParameter("UserEventName", std::to_string(i));

auto hits = ExampleHitCollection{};
auto hit1 = ExampleHit(0xbad, 0., 0., 0., 23. + i);
auto hit2 = ExampleHit(0xcaffee, 1., 0., 0., 12. + i);

hits.push_back(hit1);
hits.push_back(hit2);

// Clusters
auto clusters = ExampleClusterCollection{};
auto cluster = MutableExampleCluster();
auto clu0 = MutableExampleCluster();
auto clu1 = MutableExampleCluster();
Expand All @@ -60,6 +52,8 @@ void writeCollection() {
cluster.addClusters(clu1);

// Add tracked hits to subset hits collection
auto hits_subset = ExampleHitCollection{};
hits_subset.setSubsetCollection();
hits_subset.push_back(hit1);
hits_subset.push_back(hit2);

Expand All @@ -68,24 +62,24 @@ void writeCollection() {
clusters.push_back(clu1);
clusters.push_back(cluster);

writer.writeEvent();
store.clearCollections();
// event.put(std::move(hits), "hits");
event.put(std::move(info), "info");
event.put(std::move(hits_subset), "hits_subset");
event.put(std::move(clusters), "clusters");

writer.writeFrame(event, podio::Category::Event);
}
writer.finish();
}

void readCollection() {

// Start reading the input
auto reader = podio::ROOTReader();
auto reader = podio::ROOTFrameReader();
reader.openFile("associations.root");

auto store = podio::EventStore();
store.setReader(&reader);

const auto nEvents = reader.getEntries();
const auto nEvents = reader.getEntries(podio::Category::Event);

for (unsigned i = 0; i < nEvents; ++i) {
auto store = podio::Frame(reader.readNextEntry(podio::Category::Event));

auto& clusters = store.get<ExampleClusterCollection>("clusters");
if (clusters.isValid()) {
Expand Down Expand Up @@ -121,9 +115,6 @@ void readCollection() {
} else {
throw std::runtime_error("Collection 'hits_subset' should be present");
}

store.clear();
reader.endOfEvent();
}
}

Expand Down

0 comments on commit 05f6041

Please sign in to comment.