Skip to content

Commit

Permalink
Drop support for the legacy reader and use a podio::Reader instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell committed Jul 24, 2024
1 parent 72265af commit d94670c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 30 deletions.
13 changes: 5 additions & 8 deletions tools/include/edm4hep2json.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

// podio specific includes
#include "podio/Frame.h"
#include "podio/Reader.h"
#include "podio/UserDataCollection.h"
#include "podio/podioVersion.h"

Expand All @@ -43,7 +44,6 @@
// STL
#include <cassert>
#include <cstdint>
#include <exception>
#include <fstream>
#include <iostream>
#include <sstream>
Expand Down Expand Up @@ -173,13 +173,10 @@ std::vector<std::string> splitString(const std::string& inString) {

return outString;
}

template <typename ReaderT>
int read_frames(const std::string& filename, const std::string& jsonFile, const std::string& requestedCollections,
const std::string& requestedEvents, const std::string& frameName, int nEventsMax = -1,
bool verboser = false) {
ReaderT reader;
reader.openFile(filename);
podio::Reader reader = podio::makeReader(filename);

nlohmann::json allEventsDict;

Expand All @@ -196,7 +193,7 @@ int read_frames(const std::string& filename, const std::string& jsonFile, const

auto collList = splitString(requestedCollections);
if (collList.empty()) {
auto frame = podio::Frame(reader.readEntry(frameName, 0));
auto frame = podio::Frame(reader.readFrame(frameName, 0));
collList = frame.getAvailableCollections();
}
if (collList.empty()) {
Expand Down Expand Up @@ -272,13 +269,13 @@ int read_frames(const std::string& filename, const std::string& jsonFile, const
std::cout << "INFO: Reading event " << i << std::endl;
}

auto frame = podio::Frame(reader.readEntry(frameName, i));
auto frame = podio::Frame(reader.readFrame(frameName, i));
auto eventDict = processEvent(frame, collList, reader.currentFileVersion());
allEventsDict["Event " + std::to_string(i)] = eventDict;
}
} else {
for (auto& i : eventVec) {
auto frame = podio::Frame(reader.readEntry(frameName, i));
auto frame = podio::Frame(reader.readFrame(frameName, i));
auto eventDict = processEvent(frame, collList, reader.currentFileVersion());
allEventsDict["Event " + std::to_string(i)] = eventDict;
}
Expand Down
26 changes: 4 additions & 22 deletions tools/src/edm4hep2json.cxx
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#include "podio/FrameCategories.h"

// EDM4hep
#include "edm4hep2json.hxx"

// ROOT
#include "TFile.h"

// podio
#include "podio/ROOTLegacyReader.h"
#include "podio/ROOTReader.h"

// std
#include <filesystem>

Expand Down Expand Up @@ -35,7 +30,7 @@ int main(int argc, char** argv) {
std::filesystem::path outFilePath;
std::string requestedCollections;
std::string requestedEvents;
std::string frameName = "events";
std::string frameName = podio::Category::Event;
bool verboser = false;
int nEventsMax = -1;

Expand Down Expand Up @@ -120,20 +115,7 @@ int main(int argc, char** argv) {
outFilePath = std::filesystem::path(outFileStr + ".edm4hep.json");
}

bool legacyReader = false;
{
std::unique_ptr<TFile> inFile(TFile::Open(inFilePath.c_str(), "READ"));
legacyReader = !inFile->GetListOfKeys()->FindObject("podio_metadata");
}

if (legacyReader) {
std::cout << "WARNING: Reading legacy file, some collections might not be recognized!" << std::endl;
return read_frames<podio::ROOTLegacyReader>(inFilePath, outFilePath, requestedCollections, requestedEvents,
frameName, nEventsMax, verboser);
} else {
return read_frames<podio::ROOTReader>(inFilePath, outFilePath, requestedCollections, requestedEvents, frameName,
nEventsMax, verboser);
}
return read_frames(inFilePath, outFilePath, requestedCollections, requestedEvents, frameName, nEventsMax, verboser);

return EXIT_SUCCESS;
}

0 comments on commit d94670c

Please sign in to comment.