File indexing completed on 2025-12-16 10:19:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef FWCORE_IMETADATASERVICE_H
0020 #define FWCORE_IMETADATASERVICE_H
0021
0022 #include "GaudiKernel/IInterface.h"
0023
0024 #include "edm4hep/utils/ParticleIDUtils.h"
0025
0026 #include "podio/Frame.h"
0027
0028 class IMetadataSvc : virtual public IInterface {
0029 friend class Writer;
0030
0031 public:
0032 DeclareInterfaceID(IMetadataSvc, 1, 0);
0033
0034 virtual void setFrame(podio::Frame frame) = 0;
0035
0036 template <typename T>
0037 void put(const std::string& name, const T& obj) {
0038 getFrameForWrite()->putParameter(name, obj);
0039 }
0040
0041 template <typename T>
0042 std::optional<T> get(const std::string& name) const {
0043 const auto* frame = getFrame();
0044 if (!frame) {
0045 return std::nullopt;
0046 }
0047 return frame->getParameter<T>(name);
0048 }
0049
0050 protected:
0051 virtual podio::Frame* getFrame() = 0;
0052 virtual const podio::Frame* getFrame() const = 0;
0053
0054 private:
0055 podio::Frame* getFrameForWrite() {
0056 if (!getFrame()) {
0057 setFrame(podio::Frame());
0058 }
0059 return getFrame();
0060 }
0061 };
0062
0063 template <>
0064 inline void IMetadataSvc::put<edm4hep::utils::ParticleIDMeta>(const std::string& collName,
0065 const edm4hep::utils::ParticleIDMeta& pidMetaInfo) {
0066 edm4hep::utils::PIDHandler::setAlgoInfo(*getFrameForWrite(), collName, pidMetaInfo);
0067 }
0068
0069 template <>
0070 inline std::optional<edm4hep::utils::ParticleIDMeta>
0071 IMetadataSvc::get<edm4hep::utils::ParticleIDMeta>(const std::string& collName) const {
0072 const auto* frame = getFrame();
0073 if (!frame) {
0074 return std::nullopt;
0075 }
0076
0077 return edm4hep::utils::PIDHandler::getAlgoInfo(*frame, collName);
0078 }
0079
0080 #endif