diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index f27b41c1d..0f79fbe32 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -12,7 +12,7 @@ if (nlohmann_json_FOUND) target_link_libraries(edm4hep2json PUBLIC ROOT::Core ROOT::Tree podio::podio - podio::podioRootIO + podio::podioIO edm4hep nlohmann_json::nlohmann_json) diff --git a/tools/include/edm4hep2json.hxx b/tools/include/edm4hep2json.hxx index b4fbb3452..799e839fc 100644 --- a/tools/include/edm4hep2json.hxx +++ b/tools/include/edm4hep2json.hxx @@ -34,6 +34,7 @@ // podio specific includes #include "podio/Frame.h" +#include "podio/Reader.h" #include "podio/UserDataCollection.h" #include "podio/podioVersion.h" @@ -170,13 +171,10 @@ std::vector splitString(const std::string& inString) { return outString; } - -template 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; @@ -193,7 +191,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 = reader.readFrame(frameName, 0); collList = frame.getAvailableCollections(); } if (collList.empty()) { @@ -269,13 +267,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 = 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 = reader.readFrame(frameName, i); auto eventDict = processEvent(frame, collList, reader.currentFileVersion()); allEventsDict["Event " + std::to_string(i)] = eventDict; } diff --git a/tools/src/edm4hep2json.cxx b/tools/src/edm4hep2json.cxx index c6e1f1686..399196d5b 100644 --- a/tools/src/edm4hep2json.cxx +++ b/tools/src/edm4hep2json.cxx @@ -1,19 +1,16 @@ +#include "podio/FrameCategories.h" + // EDM4hep #include "edm4hep2json.hxx" -// ROOT -#include "TFile.h" - -// podio -#include "podio/ROOTLegacyReader.h" -#include "podio/ROOTReader.h" - // std #include // *nix #include +#include "TFile.h" + void printHelp() { std::cout << "Usage: edm4hep2json [olenfvh] FILEPATH\n" << " -o/--out-file output file path\n" @@ -35,7 +32,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; @@ -120,20 +117,14 @@ int main(int argc, char** argv) { outFilePath = std::filesystem::path(outFileStr + ".edm4hep.json"); } - bool legacyReader = false; { std::unique_ptr 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(inFilePath, outFilePath, requestedCollections, requestedEvents, - frameName, nEventsMax, verboser); - } else { - return read_frames(inFilePath, outFilePath, requestedCollections, requestedEvents, frameName, - nEventsMax, verboser); + if (!inFile->GetListOfKeys()->FindObject("podio_metadata")) { + std::cout << "ERROR: Reading file produced with an incompatible version of EDM4hep. Aborting..." << std::endl; + return 1; + } + inFile->Close(); } - return EXIT_SUCCESS; + return read_frames(inFilePath, outFilePath, requestedCollections, requestedEvents, frameName, nEventsMax, verboser); }