@@ -197,13 +197,18 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
197197 int level = originLevelMapping.empty () ? -1 : 0 ;
198198 auto fileCounter = std::make_shared<int >(0 );
199199 auto numTF = std::make_shared<int >(-1 );
200+ bool const skipInvalidReads = [] {
201+ auto const * envValue = getenv (" DPL_AOD_READER_SKIP_INVALID" );
202+ return envValue != nullptr && strcmp (envValue, " 0" ) != 0 && strcmp (envValue, " false" ) != 0 ;
203+ }();
200204 return adaptStateless ([TFNumberHeader,
201205 TFFileNameHeader,
202206 requestedTables,
203207 fileCounter,
204208 numTF,
205209 watchdog,
206210 maxRate,
211+ skipInvalidReads,
207212 didir, reportTFN, reportTFFileName, level](Monitoring& monitoring, DataAllocator& outputs, ControlService& control, DeviceSpec const & device, DataProcessingStats& dpstats, ArrowContext& arrowContext, MessageContext& messageContext, StringContext& stringContext) {
208213 // Each parallel reader device.inputTimesliceId reads the files fileCounter*device.maxInputTimeslices+device.inputTimesliceId
209214 // the TF to read is numTF
@@ -218,15 +223,10 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
218223 }
219224
220225 // loop over requested tables
221- bool first = true ;
222226 static size_t totalSizeUncompressed = 0 ;
223227 static size_t totalSizeCompressed = 0 ;
224228 static uint64_t totalDFSent = 0 ;
225229 static uint64_t totalInvalidReadSkipped = 0 ;
226- static bool skipInvalidReads = [] {
227- auto const * envValue = getenv (" DPL_AOD_READER_SKIP_INVALID" );
228- return envValue != nullptr && strcmp (envValue, " 0" ) != 0 && strcmp (envValue, " false" ) != 0 ;
229- }();
230230
231231 // check if RuntimeLimit is reached
232232 if (!watchdog->update ()) {
@@ -252,6 +252,14 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
252252 *fileCounter = (fcnt - device.inputTimesliceId ) / device.maxInputTimeslices ;
253253 *numTF = ntf;
254254 };
255+ enum class ReadState {
256+ BEFORE_FIRST_READ ,
257+ FIRST_READ ,
258+ READ ,
259+ NOT_READ_AND_FIRST ,
260+ NOT_READ_AND_MIDDLE ,
261+ };
262+ auto readState = ReadState::BEFORE_FIRST_READ ;
255263 for (auto & route : requestedTables) {
256264 if ((device.inputTimesliceId % route.maxTimeslices ) != route.timeslice ) {
257265 continue ;
@@ -262,17 +270,11 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
262270 auto dh = header::DataHeader (concrete.description , concrete.origin , concrete.subSpec );
263271 bool wasAOD = std::ranges::any_of (route.matcher .metadata , [](ConfigParamSpec const & p) { return p.name .starts_with (" aod-origin-replaced" ); });
264272
265- enum class ReadState {
266- READ ,
267- NOT_READ_AND_FIRST ,
268- NOT_READ_AND_MIDDLE ,
269- };
270- ReadState readState;
271273 try {
272274 if (didir->readTree (outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed, wasAOD)) {
273- readState = ReadState::READ ;
275+ readState = readState == ReadState:: BEFORE_FIRST_READ ? ReadState:: FIRST_READ : ReadState::READ ;
274276 } else {
275- readState = first ? ReadState::NOT_READ_AND_FIRST : ReadState::NOT_READ_AND_MIDDLE ;
277+ readState = readState == ReadState:: BEFORE_FIRST_READ ? ReadState::NOT_READ_AND_FIRST : ReadState::NOT_READ_AND_MIDDLE ;
276278 }
277279 } catch (InvalidAODReadError const & e) {
278280 if (!skipInvalidReads) {
@@ -283,6 +285,7 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
283285 }
284286
285287 switch (readState) {
288+ case ReadState::FIRST_READ :
286289 case ReadState::READ :
287290 break ;
288291 case ReadState::NOT_READ_AND_MIDDLE :
@@ -313,10 +316,13 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
313316 skipInvalidRead (concrete.origin , e);
314317 return ;
315318 }
319+ readState = ReadState::FIRST_READ ;
316320 break ;
321+ case ReadState::BEFORE_FIRST_READ :
322+ throw std::logic_error (" Invalid AOD read state" );
317323 }
318324
319- if (first ) {
325+ if (readState == ReadState:: FIRST_READ ) {
320326 if (reportTFN) {
321327 // TF number
322328 auto timeFrameNumber = didir->getTimeFrameNumber (dh, fcnt, ntf);
@@ -339,7 +345,7 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
339345 outputs.make <std::string>(o2) = currentFilename;
340346 }
341347 }
342- first = false ;
348+ readState = ReadState:: READ ;
343349 }
344350 int64_t stopSize = totalSizeCompressed;
345351 int64_t bytesDelta = stopSize - startSize;
0 commit comments