From 02709b220424aa179336ddfb25731d741b138540 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 28 Oct 2024 21:38:39 +0100 Subject: [PATCH] Retrieve unique_ptrs for collections produced by functional algorithms --- .../src/components/EDM4hep2Lcio.cpp | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/k4MarlinWrapper/src/components/EDM4hep2Lcio.cpp b/k4MarlinWrapper/src/components/EDM4hep2Lcio.cpp index cb87beaa..9a2785af 100644 --- a/k4MarlinWrapper/src/components/EDM4hep2Lcio.cpp +++ b/k4MarlinWrapper/src/components/EDM4hep2Lcio.cpp @@ -277,7 +277,6 @@ void EDM4hep2LcioTool::convertEventHeader(const std::string& e4h_coll_name, lcio } podio::CollectionBase* EDM4hep2LcioTool::getEDM4hepCollection(const std::string& collName) const { - podio::CollectionBase* collPtr{nullptr}; DataObject* p; auto sc = m_podioDataSvc->retrieveObject(collName, p); if (sc.isFailure()) { @@ -285,20 +284,25 @@ podio::CollectionBase* EDM4hep2LcioTool::getEDM4hepCollection(const std::string& } auto ptr = dynamic_cast(p); if (ptr) { - collPtr = ptr->collectionBase(); + return 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 - else { - auto nptr = dynamic_cast>*>(p); - if (!nptr) { - throw GaudiException("Collection could not be casted to the expected type", name(), StatusCode::FAILURE); - } else { - collPtr = dynamic_cast(nptr->getData().get()); - } + // We keep for a while the possibility of obtaining the collections from + // std::shared_ptr but this has been removed in k4FWCore so it can be deleted + // at some point + auto uptr = dynamic_cast>*>(p); + AnyDataWrapper>* sptr = nullptr; + if (!uptr) { + sptr = dynamic_cast>*>(p); + } else { + return uptr->getData().get(); + } + if (sptr) { + return sptr->getData().get(); } - return collPtr; + throw GaudiException("Collection could not be casted to the expected type", name(), StatusCode::FAILURE); } // Select the appropiate method to convert a collection given its type