Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-05-11 08:57:27

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 "podio/Frame.h"
0025 
0026 class IMetadataSvc : virtual public IInterface {
0027   friend class Writer;
0028 
0029 public:
0030   DeclareInterfaceID(IMetadataSvc, 1, 0);
0031 
0032   virtual void setFrame(podio::Frame&& frame) = 0;
0033 
0034   template <typename T> void put(const std::string& name, const T& obj) {
0035     if (!getFrame()) {
0036       setFrame(podio::Frame{});
0037     }
0038     getFrame()->putParameter(name, obj);
0039   }
0040 
0041   template <typename T> std::optional<T> get(const std::string& name) const {
0042     const auto* frame = getFrame();
0043     if (!frame) {
0044       return std::nullopt;
0045     }
0046     return frame->getParameter<T>(name);
0047   }
0048 
0049 protected:
0050   virtual podio::Frame*       getFrame()       = 0;
0051   virtual const podio::Frame* getFrame() const = 0;
0052 };
0053 
0054 #endif