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

Add conversion of associations to LCRelations #189

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion k4MarlinWrapper/k4MarlinWrapper/converters/EDM4hep2Lcio.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class EDM4hep2LcioTool : public GaudiTool, virtual public IEDMConverter {
void convertAdd(const std::string& e4h_coll_name, const std::string& lcio_coll_name, lcio::LCEventImpl* lcio_event,
CollectionPairMappings& collection_pairs,
std::vector<EDM4hep2LCIOConv::ParticleIDConvData>& pidCollections);
};

/// Get an EDM4hep collection by name, consulting either the podio based data
/// svc or the IOSvc
podio::CollectionBase* getEDM4hepCollection(const std::string& name) const;
};
#endif
35 changes: 27 additions & 8 deletions k4MarlinWrapper/src/components/EDM4hep2Lcio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,10 @@ void EDM4hep2LcioTool::convertEventHeader(const std::string& e4h_coll_name, lcio
EDM4hep2LCIOConv::convertEventHeader(header_coll, lcio_event);
}

// Select the appropiate method to convert a collection given its type
void EDM4hep2LcioTool::convertAdd(const std::string& e4h_coll_name, const std::string& lcio_coll_name,
lcio::LCEventImpl* lcio_event, CollectionPairMappings& collection_pairs,
std::vector<EDM4hep2LCIOConv::ParticleIDConvData>& pidCollections) {
const auto& metadata = m_podioDataSvc->getMetaDataFrame();
podio::CollectionBase* collPtr = nullptr;
podio::CollectionBase* EDM4hep2LcioTool::getEDM4hepCollection(const std::string& collName) const {
podio::CollectionBase* collPtr{nullptr};
DataObject* p;
auto sc = m_podioDataSvc->retrieveObject(e4h_coll_name, p);
auto sc = m_podioDataSvc->retrieveObject(collName, p);
if (sc.isFailure()) {
throw GaudiException("Collection not found", name(), StatusCode::FAILURE);
}
Expand All @@ -304,7 +300,17 @@ void EDM4hep2LcioTool::convertAdd(const std::string& e4h_coll_name, const std::s
collPtr = dynamic_cast<podio::CollectionBase*>(ptr->getData().get());
}
}
const auto fulltype = collPtr->getValueTypeName();

return collPtr;
}

// Select the appropiate method to convert a collection given its type
void EDM4hep2LcioTool::convertAdd(const std::string& e4h_coll_name, const std::string& lcio_coll_name,
lcio::LCEventImpl* lcio_event, CollectionPairMappings& collection_pairs,
std::vector<EDM4hep2LCIOConv::ParticleIDConvData>& pidCollections) {
const auto& metadata = m_podioDataSvc->getMetaDataFrame();
const auto collPtr = getEDM4hepCollection(e4h_coll_name);
const auto fulltype = collPtr->getValueTypeName();

debug() << "Converting type " << fulltype << " from input " << e4h_coll_name << endmsg;

Expand Down Expand Up @@ -373,7 +379,15 @@ StatusCode EDM4hep2LcioTool::convertCollections(lcio::LCEventImpl* lcio_event) {
CollectionPairMappings collection_pairs{};
std::vector<EDM4hep2LCIOConv::ParticleIDConvData> pidCollections{};

std::vector<std::tuple<std::string, const podio::CollectionBase*>> associations{};

for (const auto& [edm4hepName, lcioName] : collsToConvert) {
const auto coll = getEDM4hepCollection(edm4hepName);
if (coll->getTypeName().find("Association") != std::string_view::npos) {
debug() << edm4hepName << " is an association collection, converting it later" << endmsg;
associations.emplace_back(lcioName, coll);
continue;
}
debug() << "Converting collection " << edm4hepName << " (storing it as " << lcioName << ")" << endmsg;
if (!EDM4hep2LCIOConv::collectionExist(lcioName, lcio_event)) {
convertAdd(edm4hepName, lcioName, lcio_event, collection_pairs, pidCollections);
Expand Down Expand Up @@ -413,5 +427,10 @@ StatusCode EDM4hep2LcioTool::convertCollections(lcio::LCEventImpl* lcio_event) {

EDM4hep2LCIOConv::resolveRelations(collection_pairs, globalObjMap);

// Now we can convert the assocations and add them to the event
for (auto& [name, coll] : EDM4hep2LCIOConv::createLCRelationCollections(associations, globalObjMap)) {
lcio_event->addCollection(coll.release(), name);
}

return StatusCode::SUCCESS;
}
Loading