Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-05 09:45:09

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 K4ACTSTRACKING_ACTSGAUDILOGGER_H
0020 #define K4ACTSTRACKING_ACTSGAUDILOGGER_H
0021 
0022 #include <Acts/Utilities/Logger.hpp>
0023 
0024 #include <GaudiKernel/CommonMessaging.h>
0025 #include <GaudiKernel/IMessageSvc.h>
0026 #include <GaudiKernel/MsgStream.h>
0027 
0028 #include <memory>
0029 #include <optional>
0030 #include <string>
0031 
0032 /// Print policy that forwards Acts logging calls to the Gaudi MsgStream
0033 class ActsGaudiPrintPolicy final : public Acts::Logging::OutputPrintPolicy {
0034 public:
0035   ActsGaudiPrintPolicy(IMessageSvc* svc, std::shared_ptr<MsgStream> msg, const std::string& name)
0036       : m_svc(svc), m_msg(msg), m_name(name) {}
0037 
0038   void flush(const Acts::Logging::Level& lvl, const std::string& input) override;
0039 
0040   const std::string& name() const override { return m_name; }
0041 
0042   std::unique_ptr<Acts::Logging::OutputPrintPolicy> clone(const std::string& name) const override;
0043 
0044 private:
0045   IMessageSvc*               m_svc{nullptr};
0046   std::shared_ptr<MsgStream> m_msg{nullptr};
0047   std::string                m_name{};
0048 };
0049 
0050 /// Filter policy that maps the Gaudi log levels to the Acts log levels
0051 class ActsGaudiFilterPolicy final : public Acts::Logging::OutputFilterPolicy {
0052 public:
0053   ActsGaudiFilterPolicy(std::shared_ptr<MsgStream> msg) : m_msg(msg) {}
0054 
0055   bool doPrint(const Acts::Logging::Level& lvl) const override;
0056 
0057   Acts::Logging::Level level() const override;
0058 
0059   std::unique_ptr<Acts::Logging::OutputFilterPolicy> clone(Acts::Logging::Level lvl) const override;
0060 
0061 private:
0062   std::shared_ptr<MsgStream> m_msg{nullptr};
0063 };
0064 
0065 /// Create an Acts logger wrapping the Gaudi facilities for use in Acts
0066 /// components used within the Gaudi framework
0067 std::unique_ptr<const Acts::Logger> makeActsGaudiLogger(const CommonMessagingBase* parent,
0068                                                         std::optional<std::string> name = std::nullopt);
0069 
0070 /// Create an Acts logger wrapping the Gaudi facilities for use in Acts
0071 /// components used within the Gaudi framework
0072 std::unique_ptr<const Acts::Logger> makeActsGaudiLogger(IMessageSvc* svc, const std::string& name, int level,
0073                                                         std::optional<std::string> parentName = std::nullopt);
0074 
0075 // Overload for accepting string literals
0076 inline std::unique_ptr<const Acts::Logger> makeActsGaudiLogger(const CommonMessagingBase* parent,
0077                                                                const std::string&         name) {
0078   return makeActsGaudiLogger(parent, std::optional<std::string>{name});
0079 }
0080 
0081 #endif  // K4ACTSTRACKING_ACTSGAUDILOGGER_H