From 36246bb62ae35932f46725154ad240e1d51d92c9 Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Thu, 19 Dec 2024 20:35:14 +0100 Subject: [PATCH] Add overloads for handling ParticleIDMeta --- k4FWCore/CMakeLists.txt | 2 +- k4FWCore/include/k4FWCore/IMetadataSvc.h | 34 +++++++++++++++++++----- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/k4FWCore/CMakeLists.txt b/k4FWCore/CMakeLists.txt index e9b8bc03..6797bb6a 100644 --- a/k4FWCore/CMakeLists.txt +++ b/k4FWCore/CMakeLists.txt @@ -31,7 +31,7 @@ gaudi_install(PYTHON) gaudi_add_library(k4FWCore SOURCES src/PodioDataSvc.cpp src/KeepDropSwitch.cpp - LINK Gaudi::GaudiKernel podio::podioIO ROOT::Core ROOT::RIO ROOT::Tree + LINK Gaudi::GaudiKernel podio::podioIO ROOT::Core ROOT::RIO ROOT::Tree EDM4HEP::utils ) target_include_directories(k4FWCore PUBLIC $ diff --git a/k4FWCore/include/k4FWCore/IMetadataSvc.h b/k4FWCore/include/k4FWCore/IMetadataSvc.h index 65748d6e..897581eb 100644 --- a/k4FWCore/include/k4FWCore/IMetadataSvc.h +++ b/k4FWCore/include/k4FWCore/IMetadataSvc.h @@ -21,6 +21,8 @@ #include "GaudiKernel/IInterface.h" +#include "edm4hep/utils/ParticleIDUtils.h" + #include "podio/Frame.h" class IMetadataSvc : virtual public IInterface { @@ -31,12 +33,7 @@ class IMetadataSvc : virtual public IInterface { virtual void setFrame(podio::Frame frame) = 0; - template void put(const std::string& name, const T& obj) { - if (!getFrame()) { - setFrame(podio::Frame{}); - } - getFrame()->putParameter(name, obj); - } + template void put(const std::string& name, const T& obj) { getFrameForWrite()->putParameter(name, obj); } template std::optional get(const std::string& name) const { const auto* frame = getFrame(); @@ -49,6 +46,31 @@ class IMetadataSvc : virtual public IInterface { protected: virtual podio::Frame* getFrame() = 0; virtual const podio::Frame* getFrame() const = 0; + +private: + podio::Frame* getFrameForWrite() { + if (!getFrame()) { + setFrame(podio::Frame()); + } + return getFrame(); + } }; +template <> +inline void IMetadataSvc::put(const std::string& collName, + const edm4hep::utils::ParticleIDMeta& pidMetaInfo) { + edm4hep::utils::PIDHandler::setAlgoInfo(*getFrameForWrite(), collName, pidMetaInfo); +} + +template <> +inline std::optional IMetadataSvc::get( + const std::string& collName) const { + const auto* frame = getFrame(); + if (!frame) { + return std::nullopt; + } + + return edm4hep::utils::PIDHandler::getAlgoInfo(*frame, collName); +} + #endif