Skip to content

Commit

Permalink
Retrieve unique_ptrs for collections produced by functional algorithms (
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell authored Oct 28, 2024
1 parent fd75a93 commit 5d6ce48
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions k4MarlinWrapper/src/components/EDM4hep2Lcio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,28 +277,30 @@ 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);
DataObject* p;
auto sc = m_podioDataSvc->retrieveObject(collName, p);
if (sc.isFailure()) {
throw GaudiException("Collection not found", name(), StatusCode::FAILURE);
}
auto ptr = dynamic_cast<DataWrapperBase*>(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<AnyDataWrapper<std::shared_ptr<podio::CollectionBase>>*>(p);
if (!nptr) {
throw GaudiException("Collection could not be casted to the expected type", name(), StatusCode::FAILURE);
} else {
collPtr = dynamic_cast<podio::CollectionBase*>(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<AnyDataWrapper<std::unique_ptr<podio::CollectionBase>>*>(p);
if (uptr) {
return uptr->getData().get();
}
auto sptr = dynamic_cast<AnyDataWrapper<std::shared_ptr<podio::CollectionBase>>*>(p);
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
Expand Down

0 comments on commit 5d6ce48

Please sign in to comment.