From 5d65fd03b865b07cd9e3fd824ea073a98dc7d9d8 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Tue, 26 Sep 2023 10:31:40 +0200 Subject: [PATCH] fix: Fix `RootSimHitReader` for empty events (#2478) Looking at the writer this can happen for non recorded hits so the reader should also support that. I discovered this while simulating single particles with Geant4 in our Examples framework --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- Examples/Io/Root/src/RootSimHitReader.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Examples/Io/Root/src/RootSimHitReader.cpp b/Examples/Io/Root/src/RootSimHitReader.cpp index d1ca6fd70ca..6431f5fcf1e 100644 --- a/Examples/Io/Root/src/RootSimHitReader.cpp +++ b/Examples/Io/Root/src/RootSimHitReader.cpp @@ -112,9 +112,20 @@ ActsExamples::ProcessCode ActsExamples::RootSimHitReader::read( m_eventMap.begin(), m_eventMap.end(), [&](const auto& a) { return std::get<0>(a) == context.eventNumber; }); - if (m_inputChain == nullptr || it == m_eventMap.end()) { - ACTS_ERROR("Cannot read hits of event " << context.eventNumber); - return ActsExamples::ProcessCode::ABORT; + if (it == m_eventMap.end()) { + // explicitly warn if it happens for the first or last event as that might + // indicate a human error + if ((context.eventNumber == availableEvents().first) && + (context.eventNumber == availableEvents().second - 1)) { + ACTS_WARNING("Reading empty event: " << context.eventNumber); + } else { + ACTS_DEBUG("Reading empty event: " << context.eventNumber); + } + + m_outputSimHits(context, {}); + + // Return success flag + return ActsExamples::ProcessCode::SUCCESS; } // lock the mutex