Skip to content

Commit 03f7f11

Browse files
committed
merge AOD read errors into one class with a kind
1 parent d64a0fc commit 03f7f11

3 files changed

Lines changed: 35 additions & 32 deletions

File tree

‎Framework/AnalysisSupport/src/AODJAlienReaderHelpers.cxx‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
282282
messageContext.discard();
283283
stringContext.clear();
284284
};
285-
auto skipInvalidRead = [&fcnt, &ntf, &discardTimeframe, &dpstats, &fileCounter, &numTF, &device](ConcreteDataMatcher const& concrete, InvalidAODReadError const& e) {
285+
auto skipInvalidRead = [&fcnt, &ntf, &discardTimeframe, &dpstats, &fileCounter, &numTF, &device](ConcreteDataMatcher const& concrete, AODReadError const& e) {
286286
auto skippedTimeframes = ++totalInvalidReadSkipped;
287287
LOGP(error, "Invalid AOD read for table {}: fileCounter {}, timeFrame {}. Skipping timeframe (skipped timeframes: {}). Reason: {}",
288288
concrete.origin.as<std::string>(), fcnt, ntf, skippedTimeframes, describeException(e));
@@ -372,22 +372,24 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
372372
if (!didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed, wasAOD)) {
373373
return TFReaderState::TRY_NEXT_FILE;
374374
}
375-
} catch (AODFileOpenError const& e) {
375+
} catch (AODReadError const& e) {
376376
if (!skipInvalidReads) {
377377
throw;
378378
}
379-
auto skippedFiles = ++totalFileOpenSkipped;
380-
LOGP(error, "Unable to open AOD input for table {}: fileCounter {}, timeFrame {}. Skipping file (skipped files: {}). Reason: {}",
381-
concrete.origin.as<std::string>(), fcnt, ntf, skippedFiles, describeException(e));
382-
discardTimeframe();
383-
dpstats.updateStats({static_cast<short>(ProcessingStatsId::AOD_FILE_OPEN_SKIPPED_FILES), DataProcessingStats::Op::Add, 1});
384-
return TFReaderState::INVALID_FILE;
385-
} catch (InvalidAODReadError const& e) {
386-
if (!skipInvalidReads) {
387-
throw;
379+
switch (e.getKind()) {
380+
case AODReadError::Kind::InvalidTimeframe:
381+
skipInvalidRead(concrete, e);
382+
return TFReaderState::INVALID_TIMEFRAME;
383+
case AODReadError::Kind::FileOpen: {
384+
auto skippedFiles = ++totalFileOpenSkipped;
385+
LOGP(error, "Unable to open AOD input for table {}: fileCounter {}, timeFrame {}. Skipping file (skipped files: {}). Reason: {}",
386+
concrete.origin.as<std::string>(), fcnt, ntf, skippedFiles, describeException(e));
387+
discardTimeframe();
388+
dpstats.updateStats({static_cast<short>(ProcessingStatsId::AOD_FILE_OPEN_SKIPPED_FILES), DataProcessingStats::Op::Add, 1});
389+
return TFReaderState::INVALID_FILE;
390+
}
388391
}
389-
skipInvalidRead(concrete, e);
390-
return TFReaderState::INVALID_TIMEFRAME;
392+
throw;
391393
}
392394

393395
if (currentState == TFReaderState::READ_FIRST_TABLE || currentState == TFReaderState::READ_FIRST_TABLE_FROM_NEXT_FILE) {

‎Framework/AnalysisSupport/src/DataInputDirector.cxx‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ bool DataInputDescriptor::setFile(int counter, int wantedParentLevel, std::strin
165165
if (tfile && !externalFile) {
166166
delete tfile;
167167
}
168-
throw AODFileOpenError(fmt::format("Couldn't open file \"{}\"!", filename));
168+
throw AODReadError(AODReadError::Kind::FileOpen, fmt::format("Couldn't open file \"{}\"!", filename));
169169
}
170170
mCurrentFilesystem = std::make_shared<TFileFileSystem>(tfile, 50 * 1024 * 1024, mFactory, !externalFile);
171171
rootFS = std::dynamic_pointer_cast<TFileFileSystem>(mCurrentFilesystem);
@@ -363,7 +363,7 @@ std::shared_ptr<DataInputDescriptor> DataInputDescriptor::getParentFile(int coun
363363
// The current DF is not found in the parent map (this should not happen and is a fatal error)
364364
auto rootFS = std::dynamic_pointer_cast<TFileFileSystem>(mCurrentFilesystem);
365365
if (!parentFileName) {
366-
throw InvalidAODReadError(fmt::format(R"(parent file map exists but does not contain the current DF "{}" in file "{}")", folderName.c_str(), rootFS->GetFile()->GetName()));
366+
throw AODReadError(AODReadError::Kind::InvalidTimeframe, fmt::format(R"(parent file map exists but does not contain the current DF "{}" in file "{}")", folderName.c_str(), rootFS->GetFile()->GetName()));
367367
}
368368

369369
if (mParentFile) {
@@ -392,7 +392,7 @@ std::shared_ptr<DataInputDescriptor> DataInputDescriptor::getParentFile(int coun
392392
}
393393
} catch (...) {
394394
mParentFile.reset();
395-
std::throw_with_nested(InvalidAODReadError(fmt::format("Unable to open parent file \"{}\" for {}", parentFileName->GetString().Data(), folderName)));
395+
std::throw_with_nested(AODReadError(AODReadError::Kind::InvalidTimeframe, fmt::format("Unable to open parent file \"{}\" for {}", parentFileName->GetString().Data(), folderName)));
396396
}
397397
return mParentFile;
398398
}
@@ -575,11 +575,11 @@ try {
575575
}
576576
if (parentFile == nullptr) {
577577
auto rootFS = std::dynamic_pointer_cast<TFileFileSystem>(mCurrentFilesystem);
578-
throw InvalidAODReadError(fmt::format(R"(No parent file found for "{}" while looking for level {} in "{}")", treename, wantedLevel, rootFS->GetFile()->GetName()));
578+
throw AODReadError(AODReadError::Kind::InvalidTimeframe, fmt::format(R"(No parent file found for "{}" while looking for level {} in "{}")", treename, wantedLevel, rootFS->GetFile()->GetName()));
579579
}
580580
if (parentNumTF == -1) {
581581
auto parentRootFS = std::dynamic_pointer_cast<TFileFileSystem>(parentFile->mCurrentFilesystem);
582-
throw InvalidAODReadError(fmt::format(R"(DF not found in parent file "{}")", parentRootFS->GetFile()->GetName()));
582+
throw AODReadError(AODReadError::Kind::InvalidTimeframe, fmt::format(R"(DF not found in parent file "{}")", parentRootFS->GetFile()->GetName()));
583583
}
584584
t.deactivate();
585585
return parentFile->readTree(outputs, dh, 0, parentNumTF, treename, totalSizeCompressed, totalSizeUncompressed);
@@ -634,15 +634,15 @@ try {
634634
int parentNumTF = parentFile->findDFNumber(0, folder.path());
635635
if (parentNumTF == -1) {
636636
auto parentRootFS = std::dynamic_pointer_cast<TFileFileSystem>(parentFile->mCurrentFilesystem);
637-
throw InvalidAODReadError(fmt::format(R"(DF {} listed in parent file map but not found in the corresponding file "{}")", folder.path(), parentRootFS->GetFile()->GetName()));
637+
throw AODReadError(AODReadError::Kind::InvalidTimeframe, fmt::format(R"(DF {} listed in parent file map but not found in the corresponding file "{}")", folder.path(), parentRootFS->GetFile()->GetName()));
638638
}
639639
// first argument is 0 as the parent file object contains only 1 file
640640
return parentFile->readTree(outputs, dh, 0, parentNumTF, treename, totalSizeCompressed, totalSizeUncompressed);
641641
}
642642

643643
auto schemaOpt = format->Inspect(fullpath);
644644
if (!schemaOpt.ok()) {
645-
throw InvalidAODReadError(fmt::format("Unable to inspect tree {}: {}", treename, schemaOpt.status().ToString()));
645+
throw AODReadError(AODReadError::Kind::InvalidTimeframe, fmt::format("Unable to inspect tree {}: {}", treename, schemaOpt.status().ToString()));
646646
}
647647
auto physicalSchema = schemaOpt;
648648
std::vector<std::shared_ptr<arrow::Field>> fields;
@@ -673,16 +673,16 @@ try {
673673
f2b.release();
674674
} catch (...) {
675675
f2b.discard();
676-
std::throw_with_nested(InvalidAODReadError(fmt::format("Unable to {} tree {}", operation, treename)));
676+
std::throw_with_nested(AODReadError(AODReadError::Kind::InvalidTimeframe, fmt::format("Unable to {} tree {}", operation, treename)));
677677
}
678678

679679
return true;
680-
} catch (InvalidAODReadError const&) {
680+
} catch (AODReadError const& e) {
681681
auto rootFS = std::dynamic_pointer_cast<TFileFileSystem>(mCurrentFilesystem);
682682
auto filename = rootFS ? std::string(rootFS->GetFile()->GetName()) : mfilenames.at(counter).fileName;
683683
auto const& dfs = mfilenames.at(counter).listOfTimeFrameNumbers;
684684
auto df = numTF >= 0 && static_cast<size_t>(numTF) < dfs.size() ? fmt::format("DF_{}", dfs[numTF]) : fmt::format("timeframe index {}", numTF);
685-
std::throw_with_nested(InvalidAODReadError(fmt::format("Reading tree {} in {} from file \"{}\" at parent level {}", treename, df, filename, mLevel)));
685+
std::throw_with_nested(AODReadError(e.getKind(), fmt::format("Reading tree {} in {} from file \"{}\" at parent level {}", treename, df, filename, mLevel)));
686686
}
687687

688688
DataInputDirector::DataInputDirector(std::vector<std::string> inputFiles, DataInputDirectorContext&& context)

‎Framework/AnalysisSupport/src/DataInputDirector.h‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ class Monitoring;
3333
namespace o2::framework
3434
{
3535

36-
class InvalidAODReadError : public std::runtime_error
36+
class AODReadError : public std::runtime_error
3737
{
3838
public:
39-
using std::runtime_error::runtime_error;
40-
};
39+
enum class Kind {
40+
InvalidTimeframe, // skip the timeframe
41+
FileOpen, // skip the file, its timeframes are unknown
42+
};
4143

42-
// Opening an input file can fail before its timeframes are known. The reader
43-
// must advance to the next file rather than retrying subsequent timeframe indices.
44-
class AODFileOpenError : public std::runtime_error
45-
{
46-
public:
47-
using std::runtime_error::runtime_error;
44+
AODReadError(Kind kind, std::string const& what) : std::runtime_error(what), mKind(kind) {}
45+
Kind getKind() const { return mKind; }
46+
47+
private:
48+
Kind mKind;
4849
};
4950

5051
struct FileNameHolder {

0 commit comments

Comments
 (0)