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

Add two checks not to crash when a file doesn't exist or can't be opened #666

Merged
merged 1 commit into from
Sep 6, 2024
Merged
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
8 changes: 8 additions & 0 deletions src/Reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Reader makeReader(const std::string& filename) {

Reader makeReader(const std::vector<std::string>& filenames) {

if (filenames.empty()) {
throw std::runtime_error("No files given to create a Podio Reader");
}

auto suffix = filenames[0].substr(filenames[0].find_last_of(".") + 1);
for (size_t i = 1; i < filenames.size(); ++i) {
if (filenames[i].substr(filenames[i].find_last_of(".") + 1) != suffix) {
Expand All @@ -35,6 +39,10 @@ Reader makeReader(const std::vector<std::string>& filenames) {
TFile* file = TFile::Open(filenames[0].c_str());
bool hasRNTuple = false;

if (!file) {
throw std::runtime_error("Could not open file: " + filenames[0]);
}

for (auto key : *file->GetListOfKeys()) {
auto tkey = dynamic_cast<TKey*>(key);

Expand Down