Skip to content

Commit

Permalink
Add two checks not to crash when a file doesn't exist or can't be opened
Browse files Browse the repository at this point in the history
and when an empty list is passed to makeReader.
  • Loading branch information
jmcarcell committed Sep 6, 2024
1 parent e712d45 commit 17bcea2
Showing 1 changed file with 8 additions and 0 deletions.
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

0 comments on commit 17bcea2

Please sign in to comment.