From 5e3889279f7c045215508e012e2edb5d29a01113 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Fri, 17 Nov 2023 09:47:46 +0100 Subject: [PATCH] Make PodioInput not crash on non-existant collections --- k4FWCore/components/PodioInput.cpp | 6 +++++- k4FWCore/src/PodioDataSvc.cpp | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/k4FWCore/components/PodioInput.cpp b/k4FWCore/components/PodioInput.cpp index 2d336ae6..949a9053 100644 --- a/k4FWCore/components/PodioInput.cpp +++ b/k4FWCore/components/PodioInput.cpp @@ -193,8 +193,12 @@ void PodioInput::operator()() const { info() << "No EventHeader collection found in the event. Not reading it" << endmsg; } - for (auto& collName : m_collectionNames) { + for (const auto& collName : m_collectionNames) { debug() << "Registering collection to read " << collName << endmsg; + if (!m_podioDataSvc->hasCollection(collName)) { + warning() << "Collection " << collName << " is not available from file." << endmsg; + continue; + } auto type = m_podioDataSvc->getCollectionType(collName); if (m_readers.find(type) != m_readers.end()) { m_readers[type](collName); diff --git a/k4FWCore/src/PodioDataSvc.cpp b/k4FWCore/src/PodioDataSvc.cpp index 956ab2da..c93f7f04 100644 --- a/k4FWCore/src/PodioDataSvc.cpp +++ b/k4FWCore/src/PodioDataSvc.cpp @@ -153,6 +153,7 @@ const std::string_view PodioDataSvc::getCollectionType(const std::string& collNa const auto coll = m_eventframe.get(collName); if (coll == nullptr) { error() << "Collection " << collName << " does not exist." << endmsg; + return ""; } return coll->getTypeName(); }