diff --git a/k4MarlinWrapper/k4MarlinWrapper/converters/Lcio2EDM4hep.h b/k4MarlinWrapper/k4MarlinWrapper/converters/Lcio2EDM4hep.h index 3b6b24d8..31308e05 100644 --- a/k4MarlinWrapper/k4MarlinWrapper/converters/Lcio2EDM4hep.h +++ b/k4MarlinWrapper/k4MarlinWrapper/converters/Lcio2EDM4hep.h @@ -26,6 +26,8 @@ #include "k4MarlinWrapper/converters/IEDMConverter.h" +#include + #include #include @@ -64,6 +66,9 @@ class Lcio2EDM4hepTool : public AlgTool, virtual public IEDMConverter { SmartIF m_metadataSvc; PodioDataSvc* m_podioDataSvc; + std::map m_cellIDEncodings{}; + std::map m_pidMetas{}; + // ********************************** // Check if a collection was already registered to skip it // ********************************** diff --git a/k4MarlinWrapper/src/components/Lcio2EDM4hep.cpp b/k4MarlinWrapper/src/components/Lcio2EDM4hep.cpp index baf18dc8..ddc3fab7 100644 --- a/k4MarlinWrapper/src/components/Lcio2EDM4hep.cpp +++ b/k4MarlinWrapper/src/components/Lcio2EDM4hep.cpp @@ -64,7 +64,15 @@ StatusCode Lcio2EDM4hepTool::initialize() { return AlgTool::initialize(); } -StatusCode Lcio2EDM4hepTool::finalize() { return AlgTool::finalize(); } +StatusCode Lcio2EDM4hepTool::finalize() { + for (const auto& [key, value] : m_cellIDEncodings) { + k4FWCore::putParameter(key, value, this); + } + for (const auto& [coll, pidMeta] : m_pidMetas) { + k4FWCore::putParameter(coll, pidMeta, this); + } + return AlgTool::finalize(); +} // ********************************** // Check if a collection was already registered to skip it @@ -115,8 +123,7 @@ void Lcio2EDM4hepTool::registerCollection( mdFrame.putParameter(podio::collMetadataParamName(name, edm4hep::labels::CellIDEncoding), lcio_coll_cellid_str); } else { - k4FWCore::putParameter(podio::collMetadataParamName(name, edm4hep::labels::CellIDEncoding), - lcio_coll_cellid_str); + m_cellIDEncodings[podio::collMetadataParamName(name, edm4hep::labels::CellIDEncoding)] = lcio_coll_cellid_str; } debug() << "Storing CellIDEncoding " << podio::collMetadataParamName(name, edm4hep::labels::CellIDEncoding) << " value: " << lcio_coll_cellid_str << endmsg; @@ -191,8 +198,6 @@ StatusCode Lcio2EDM4hepTool::convertCollections(lcio::LCEventImpl* the_event) { // were empty bool needCaloHitContribs = false; - std::map pidInfos{}; - for (const auto& [lcioName, edm4hepName] : collsToConvert) { try { auto* lcio_coll = the_event->getCollection(lcioName); @@ -217,7 +222,7 @@ StatusCode Lcio2EDM4hepTool::convertCollections(lcio::LCEventImpl* the_event) { // Collect the ParticleID meta information because that has to go to the // ParticleID collections for (const auto& pidInfo : LCIO2EDM4hepConv::getPIDMetaInfo(lcio_coll)) { - pidInfos.try_emplace(LCIO2EDM4hepConv::getPIDCollName(lcioName, pidInfo.algoName), pidInfo); + m_pidMetas.try_emplace(LCIO2EDM4hepConv::getPIDCollName(lcioName, pidInfo.algoName), pidInfo); } } @@ -237,18 +242,6 @@ StatusCode Lcio2EDM4hepTool::convertCollections(lcio::LCEventImpl* the_event) { } } - // Set the ParticleID meta information - if (m_podioDataSvc) { - auto& metadataFrame = m_podioDataSvc->getMetaDataFrame(); - for (const auto& [collName, pidInfo] : pidInfos) { - edm4hep::utils::PIDHandler::setAlgoInfo(metadataFrame, collName, pidInfo); - } - } else { - for (const auto& [collName, pidInfo] : pidInfos) { - m_metadataSvc->put(collName, pidInfo); - } - } - auto& globalObjMap = getGlobalObjectMap(this); globalObjMap.update(lcio2edm4hepMaps);