Reading Files¶
Basic Event Loop¶
hipo::reader reader;
reader.open("data.hipo");
hipo::dictionary dict;
reader.readDictionary(dict);
hipo::bank particles(dict.getSchema("REC::Particle"));
hipo::event event;
while (reader.next()) {
reader.read(event);
event.read(particles);
for (int row = 0; row < particles.getRows(); row++) {
int pid = particles.getInt("pid", row);
float px = particles.getFloat("px", row);
}
}
Banklist Pattern (Preferred)¶
The banklist pattern is cleaner when reading multiple banks:
hipo::reader reader;
reader.open("data.hipo");
auto list = reader.getBanks({"REC::Particle", "REC::Event", "REC::Calorimeter"});
while (reader.next(list)) {
auto& particles = list[0];
auto& recEvent = list[1];
auto& calos = list[2];
for (int row = 0; row < particles.getRows(); row++) {
int pid = particles.getInt("pid", row);
}
}
hipoeventfile (Simplest)¶
hipo::hipoeventfile file("data.hipo");
hipo::bank particles(file.dictionary().getSchema("REC::Particle"));
for (auto& event : file) {
event.read(particles);
// process...
}
Random Access¶
Jump to a specific event by number:
reader.gotoEvent(5000);
reader.read(event);
event.read(particles);
Or jump to a specific record:
reader.gotoRecord(10);
// then iterate from there
while (reader.next()) { ... }
Tag Filtering¶
Only read events with specific tags:
reader.setTags({1, 2}); // set before iterating
while (reader.next()) {
reader.read(event);
// only events with tag 1 or 2 are returned
}
Column Index Caching¶
For performance-critical loops, cache column indices:
hipo::bank particles(dict.getSchema("REC::Particle"));
int pidCol = particles.getSchema().getEntryOrder("pid");
int pxCol = particles.getSchema().getEntryOrder("px");
int pyCol = particles.getSchema().getEntryOrder("py");
int pzCol = particles.getSchema().getEntryOrder("pz");
while (reader.next(list)) {
for (int row = 0; row < particles.getRows(); row++) {
int pid = particles.getInt(pidCol, row);
float px = particles.getFloat(pxCol, row);
float py = particles.getFloat(pyCol, row);
float pz = particles.getFloat(pzCol, row);
}
}
Reading User Configuration¶
hipo::reader reader;
reader.open("data.hipo");
std::string runNumber = reader.readUserConfig("run");
printf("Run: %s\n", runNumber.c_str());
Listing Available Banks¶
hipo::dictionary dict;
reader.readDictionary(dict);
for (auto& name : dict.getSchemaList()) {
printf("Bank: %s\n", name.c_str());
dict.getSchema(name.c_str()).show();
}
Handling Missing Banks¶
A bank with 0 rows means it wasn't present in the event:
event.read(particles);
if (particles.getRows() == 0) {
// REC::Particle not in this event
continue;
}
Check if a schema exists before creating a bank:
if (dict.hasSchema("REC::Particle")) {
hipo::bank particles(dict.getSchema("REC::Particle"));
}