Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:19:17

0001 /*
0002  * Copyright (c) 2014-2024 Key4hep-Project.
0003  *
0004  * This file is part of Key4hep.
0005  * See https://key4hep.github.io/key4hep-doc/ for further info.
0006  *
0007  * Licensed under the Apache License, Version 2.0 (the "License");
0008  * you may not use this file except in compliance with the License.
0009  * You may obtain a copy of the License at
0010  *
0011  *     http://www.apache.org/licenses/LICENSE-2.0
0012  *
0013  * Unless required by applicable law or agreed to in writing, software
0014  * distributed under the License is distributed on an "AS IS" BASIS,
0015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016  * See the License for the specific language governing permissions and
0017  * limitations under the License.
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