Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for the ROOTLegacyReader when converting to JSON #342

Merged
merged 4 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading