@@ -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 ;
0 commit comments