Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve unique_ptrs for collections produced by functional algorithms #204

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading