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());