Skip to content

Commit

Permalink
Drop support for the ROOTLegacyReader when converting to JSON (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell authored Aug 9, 2024
1 parent ef68f1b commit 06986a3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
2 changes: 1 addition & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 5 additions & 7 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 Down Expand Up @@ -170,13 +171,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 @@ -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()) {
Expand Down Expand Up @@ -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;
}
Expand Down
31 changes: 11 additions & 20 deletions tools/src/edm4hep2json.cxx
Original file line number Diff line number Diff line change
@@ -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 <filesystem>

// *nix
#include <getopt.h>

#include "TFile.h"

void printHelp() {
std::cout << "Usage: edm4hep2json [olenfvh] FILEPATH\n"
<< " -o/--out-file output file path\n"
Expand All @@ -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;

Expand Down Expand Up @@ -120,20 +117,14 @@ 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);
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);
}

0 comments on commit 06986a3

Please sign in to comment.