diff --git a/k4MarlinWrapper/src/components/EDM4hep2Lcio.cpp b/k4MarlinWrapper/src/components/EDM4hep2Lcio.cpp index ed4aeef2..f6b3487d 100644 --- a/k4MarlinWrapper/src/components/EDM4hep2Lcio.cpp +++ b/k4MarlinWrapper/src/components/EDM4hep2Lcio.cpp @@ -282,18 +282,24 @@ void EDM4hep2LcioTool::convertEventHeader(const std::string& e4h_coll_name, lcio void EDM4hep2LcioTool::convertAdd(const std::string& e4h_coll_name, const std::string& lcio_coll_name, lcio::LCEventImpl* lcio_event, CollectionPairMappings& collection_pairs, std::vector& pidCollections) { - const auto& evtFrame = m_podioDataSvc->getEventFrame(); - const auto& metadata = m_podioDataSvc->getMetaDataFrame(); - auto collPtr = evtFrame.get(e4h_coll_name); + const auto& metadata = m_podioDataSvc->getMetaDataFrame(); + podio::CollectionBase* collPtr = nullptr; + DataObject* p; + auto sc = m_podioDataSvc->retrieveObject(e4h_coll_name, p); + if (sc.isFailure()) { + throw GaudiException("Collection not found", name(), StatusCode::FAILURE); + } + auto ptr = dynamic_cast(p); + if (ptr) { + collPtr = ptr->collectionBase(); + } // When the collection can't be retrieved from the frame // there is still the possibility that it was generated // from a functional algorithm - if (!collPtr) { - DataObject* p; - auto sc = m_podioDataSvc->retrieveObject(e4h_coll_name, p); - auto ptr = dynamic_cast>*>(p); - if (sc.isFailure() || !ptr) { - error() << "No collection with name: " << e4h_coll_name << " available for conversion" << endmsg; + else { + auto ptr = dynamic_cast>*>(p); + if (!ptr) { + throw GaudiException("Collection could not be casted to the expected type", name(), StatusCode::FAILURE); } else { collPtr = dynamic_cast(ptr->getData().get()); }