Skip to content

Commit d64a0fc

Browse files
committed
DPL Analysis: skip input files which cannot be opened
1 parent 27f5bda commit d64a0fc

6 files changed

Lines changed: 44 additions & 6 deletions

File tree

‎Framework/AnalysisSupport/src/AODJAlienReaderHelpers.cxx‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
260260
static size_t totalSizeCompressed = 0;
261261
static uint64_t totalDFSent = 0;
262262
static uint64_t totalInvalidReadSkipped = 0;
263+
static uint64_t totalFileOpenSkipped = 0;
263264

264265
// check if RuntimeLimit is reached
265266
if (!watchdog->update()) {
@@ -274,15 +275,18 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
274275

275276
int64_t startTime = uv_hrtime();
276277
int64_t startSize = totalSizeCompressed;
277-
auto skipInvalidRead = [&](ConcreteDataMatcher const& concrete, InvalidAODReadError const& e) {
278-
auto skippedTimeframes = ++totalInvalidReadSkipped;
279-
LOGP(error, "Invalid AOD read for table {}: fileCounter {}, timeFrame {}. Skipping timeframe (skipped timeframes: {}). Reason: {}",
280-
concrete.origin.as<std::string>(), fcnt, ntf, skippedTimeframes, describeException(e));
278+
auto discardTimeframe = [&didir, &arrowContext, &messageContext, &stringContext]() {
281279
clean_all_runtime_errors();
282280
didir->finishTimeFrame(true);
283281
arrowContext.clear();
284282
messageContext.discard();
285283
stringContext.clear();
284+
};
285+
auto skipInvalidRead = [&fcnt, &ntf, &discardTimeframe, &dpstats, &fileCounter, &numTF, &device](ConcreteDataMatcher const& concrete, InvalidAODReadError const& e) {
286+
auto skippedTimeframes = ++totalInvalidReadSkipped;
287+
LOGP(error, "Invalid AOD read for table {}: fileCounter {}, timeFrame {}. Skipping timeframe (skipped timeframes: {}). Reason: {}",
288+
concrete.origin.as<std::string>(), fcnt, ntf, skippedTimeframes, describeException(e));
289+
discardTimeframe();
286290
dpstats.updateStats({static_cast<short>(ProcessingStatsId::AOD_INVALID_READ_SKIPPED_TIMEFRAMES), DataProcessingStats::Op::Add, 1});
287291
*fileCounter = (fcnt - device.inputTimesliceId) / device.maxInputTimeslices;
288292
*numTF = ntf;
@@ -294,6 +298,7 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
294298
TRY_NEXT_FILE,
295299
TIMEFRAME_READ,
296300
INVALID_TIMEFRAME,
301+
INVALID_FILE,
297302
};
298303
auto readState = TFReaderState::READ_FIRST_TABLE;
299304
[[maybe_unused]] auto stateName = [](TFReaderState state) -> char const* {
@@ -310,6 +315,8 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
310315
return "TIMEFRAME_READ";
311316
case TFReaderState::INVALID_TIMEFRAME:
312317
return "INVALID_TIMEFRAME";
318+
case TFReaderState::INVALID_FILE:
319+
return "INVALID_FILE";
313320
}
314321
return "UNKNOWN";
315322
};
@@ -344,7 +351,7 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
344351
outputs.make<std::string>(o2) = currentFilename;
345352
}
346353
};
347-
auto tryReadTable = [&device, &didir, &fcnt, &ntf, &outputs, &reportTimeframe, &requestedTables, &routeIndex, &skipInvalidRead, skipInvalidReads](TFReaderState currentState) -> TFReaderState {
354+
auto tryReadTable = [&device, &didir, &fcnt, &ntf, &outputs, &reportTimeframe, &requestedTables, &routeIndex, &skipInvalidRead, &discardTimeframe, &dpstats, skipInvalidReads](TFReaderState currentState) -> TFReaderState {
348355
while (routeIndex < requestedTables.size() &&
349356
(device.inputTimesliceId % requestedTables[routeIndex].maxTimeslices) != requestedTables[routeIndex].timeslice) {
350357
++routeIndex;
@@ -365,6 +372,16 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
365372
if (!didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed, wasAOD)) {
366373
return TFReaderState::TRY_NEXT_FILE;
367374
}
375+
} catch (AODFileOpenError const& e) {
376+
if (!skipInvalidReads) {
377+
throw;
378+
}
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;
368385
} catch (InvalidAODReadError const& e) {
369386
if (!skipInvalidReads) {
370387
throw;
@@ -394,6 +411,10 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
394411
throw std::runtime_error("Processing is stopped!");
395412
}
396413
break;
414+
case TFReaderState::INVALID_FILE:
415+
// Undo the discard so outputs read from the next file are checked as usual
416+
messageContext.clear();
417+
[[fallthrough]];
397418
case TFReaderState::TRY_NEXT_FILE:
398419
didir->finishTimeFrame();
399420
fcnt += device.maxInputTimeslices;

‎Framework/AnalysisSupport/src/DataInputDirector.cxx‎

Lines changed: 1 addition & 1 deletion
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 std::runtime_error(fmt::format("Couldn't open file \"{}\"!", filename));
168+
throw AODFileOpenError(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);

‎Framework/AnalysisSupport/src/DataInputDirector.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ class InvalidAODReadError : public std::runtime_error
3939
using std::runtime_error::runtime_error;
4040
};
4141

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;
48+
};
49+
4250
struct FileNameHolder {
4351
std::string fileName;
4452
int numberOfTimeFrames = 0;

‎Framework/Core/include/Framework/DataProcessingStats.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ enum struct ProcessingStatsId : short {
7575
CCDB_CACHE_FETCHED_BYTES,
7676
CCDB_CACHE_REQUESTED_BYTES,
7777
AOD_INVALID_READ_SKIPPED_TIMEFRAMES,
78+
AOD_FILE_OPEN_SKIPPED_FILES,
7879
AVAILABLE_MANAGED_SHM_BASE = 512,
7980
};
8081

‎Framework/Core/src/CommonServices.cxx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,13 @@ o2::framework::ServiceSpec CommonServices::dataProcessingStats()
11271127
.minPublishInterval = 0,
11281128
.maxRefreshLatency = 10000,
11291129
.sendInitialValue = true},
1130+
MetricSpec{.name = "aod-file-open-skipped-files",
1131+
.metricId = static_cast<short>(ProcessingStatsId::AOD_FILE_OPEN_SKIPPED_FILES),
1132+
.kind = Kind::UInt64,
1133+
.scope = Scope::DPL,
1134+
.minPublishInterval = 0,
1135+
.maxRefreshLatency = 10000,
1136+
.sendInitialValue = true},
11301137
MetricSpec{.name = "arrow-bytes-destroyed",
11311138
.enabled = arrowAndResourceLimitingMetrics,
11321139
.metricId = static_cast<short>(ProcessingStatsId::ARROW_BYTES_DESTROYED),

‎Framework/Core/src/runDataProcessing.cxx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,7 @@ std::vector<std::regex> getDumpableMetrics()
12541254
dumpableMetrics.emplace_back("^aod-file-read-info$");
12551255
dumpableMetrics.emplace_back("^aod-largest-object-written$");
12561256
dumpableMetrics.emplace_back("^aod-invalid-read-skipped-timeframes$");
1257+
dumpableMetrics.emplace_back("^aod-file-open-skipped-files$");
12571258
dumpableMetrics.emplace_back("^table-bytes-.*");
12581259
dumpableMetrics.emplace_back("^total-timeframes.*");
12591260
dumpableMetrics.emplace_back("^device_state.*");

0 commit comments

Comments
 (0)