Skip to content

Commit

Permalink
Add overloads for handling ParticleIDMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Dec 20, 2024
1 parent 5abd44d commit 36246bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion k4FWCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
Expand Down
34 changes: 28 additions & 6 deletions k4FWCore/include/k4FWCore/IMetadataSvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "GaudiKernel/IInterface.h"

#include "edm4hep/utils/ParticleIDUtils.h"

#include "podio/Frame.h"

class IMetadataSvc : virtual public IInterface {
Expand All @@ -31,12 +33,7 @@ class IMetadataSvc : virtual public IInterface {

virtual void setFrame(podio::Frame frame) = 0;

template <typename T> void put(const std::string& name, const T& obj) {
if (!getFrame()) {
setFrame(podio::Frame{});
}
getFrame()->putParameter(name, obj);
}
template <typename T> void put(const std::string& name, const T& obj) { getFrameForWrite()->putParameter(name, obj); }

template <typename T> std::optional<T> get(const std::string& name) const {
const auto* frame = getFrame();
Expand All @@ -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<edm4hep::utils::ParticleIDMeta>(const std::string& collName,
const edm4hep::utils::ParticleIDMeta& pidMetaInfo) {
edm4hep::utils::PIDHandler::setAlgoInfo(*getFrameForWrite(), collName, pidMetaInfo);
}

template <>
inline std::optional<edm4hep::utils::ParticleIDMeta> IMetadataSvc::get<edm4hep::utils::ParticleIDMeta>(
const std::string& collName) const {
const auto* frame = getFrame();
if (!frame) {
return std::nullopt;
}

return edm4hep::utils::PIDHandler::getAlgoInfo(*frame, collName);
}

#endif

0 comments on commit 36246bb

Please sign in to comment.