From 43223a4ec63044882b54165a48222a4233ae25b4 Mon Sep 17 00:00:00 2001 From: swenzel Date: Wed, 8 Jan 2025 14:04:04 +0100 Subject: [PATCH] Check presence of hit files before adding to TChain This reduces bogus error messages about missing hit files (in particular for ZDC) and improves the handling of setting up the hits for digitization. --- .../include/SimulationDataFormat/DigitizationContext.h | 3 +++ DataFormats/simulation/src/DigitizationContext.cxx | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/DataFormats/simulation/include/SimulationDataFormat/DigitizationContext.h b/DataFormats/simulation/include/SimulationDataFormat/DigitizationContext.h index 4bd5dfa2ab76c..5e1f5f66b3f65 100644 --- a/DataFormats/simulation/include/SimulationDataFormat/DigitizationContext.h +++ b/DataFormats/simulation/include/SimulationDataFormat/DigitizationContext.h @@ -209,6 +209,9 @@ inline void DigitizationContext::retrieveHits(std::vector const& chains int entryID, std::vector* hits) const { + if (chains.size() <= sourceID) { + return; + } auto br = chains[sourceID]->GetBranch(brname); if (!br) { LOG(error) << "No branch found with name " << brname; diff --git a/DataFormats/simulation/src/DigitizationContext.cxx b/DataFormats/simulation/src/DigitizationContext.cxx index f3c993c9508b7..975458c41fcb3 100644 --- a/DataFormats/simulation/src/DigitizationContext.cxx +++ b/DataFormats/simulation/src/DigitizationContext.cxx @@ -99,6 +99,14 @@ bool DigitizationContext::initSimChains(o2::detectors::DetID detid, std::vector< return false; } + // check that all files are present, otherwise quit + for (int source = 0; source < mSimPrefixes.size(); ++source) { + if (!std::filesystem::exists(o2::base::DetectorNameConf::getHitsFileName(detid, mSimPrefixes[source].data()))) { + LOG(info) << "Not hit file present for " << detid.getName() << " (exiting SimChain setup)"; + return false; + } + } + simchains.emplace_back(new TChain("o2sim")); // add the main (background) file simchains.back()->AddFile(o2::base::DetectorNameConf::getHitsFileName(detid, mSimPrefixes[0].data()).c_str());