The Gaudi Framework  master (37c0b60a)
RenounceToolInputsVisitor.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #pragma once
12 #include <GaudiKernel/DataObjID.h>
14 #include <functional>
15 #include <string>
16 #include <type_traits>
17 #include <vector>
18 
19 #ifndef USAGE_IS_THREAD_SAFE
20 # define USAGE_IS_THREAD_SAFE
21 #endif
22 
23 class IAlgTool;
24 
28 public:
31  struct ILogger {
32  virtual ~ILogger() = default;
33  virtual void renounce( std::string_view tool_name, std::string_view key ) = 0;
34  };
35 
38  struct NoLogger : ILogger {
39  void renounce( std::string_view, std::string_view ) override {}
40  };
41 
42  class Logger final : public ILogger {
43  std::function<void( std::string_view, std::string_view )> m_func;
44 
45  public:
46  template <typename F,
47  typename = std::enable_if_t<std::is_invocable_r_v<void, F, std::string_view, std::string_view>>>
48  Logger( F func ) : m_func( std::move( func ) ) {}
49  void renounce( std::string_view tool_name, std::string_view key ) override { m_func( tool_name, key ); }
50  };
59  static Logger createLogger( std::function<void( std::string_view, std::string_view )> func ) {
60  return Logger{ std::move( func ) };
61  }
62 
70  : m_renounceKeys( std::move( input_keys ) )
71  , m_logger( &logger ) // @TODO possible source of use after delete
72  {}
73 
74  void operator()( IAlgTool* );
75 
76 private:
79 
80  static NoLogger s_noLogger USAGE_IS_THREAD_SAFE;
81 };
RenounceToolInputsVisitor::m_renounceKeys
std::vector< DataObjID > m_renounceKeys
Definition: RenounceToolInputsVisitor.h:77
RenounceToolInputsVisitor::m_logger
ILogger * m_logger
Definition: RenounceToolInputsVisitor.h:78
IAlgTool
Definition: IAlgTool.h:33
RenounceToolInputsVisitor::USAGE_IS_THREAD_SAFE
static NoLogger s_noLogger USAGE_IS_THREAD_SAFE
Definition: RenounceToolInputsVisitor.h:80
std::move
T move(T... args)
RenounceToolInputsVisitor::ILogger::renounce
virtual void renounce(std::string_view tool_name, std::string_view key)=0
RenounceToolInputsVisitor::NoLogger::renounce
void renounce(std::string_view, std::string_view) override
Definition: RenounceToolInputsVisitor.h:39
RenounceToolInputsVisitor::Logger::renounce
void renounce(std::string_view tool_name, std::string_view key) override
Definition: RenounceToolInputsVisitor.h:49
std::vector< DataObjID >
RenounceToolInputsVisitor::Logger::Logger
Logger(F func)
Definition: RenounceToolInputsVisitor.h:48
RenounceToolInputsVisitor::ILogger::~ILogger
virtual ~ILogger()=default
std::function
DataObjID.h
RenounceToolInputsVisitor::ILogger
Helper class interface to optionally log renounce operations.
Definition: RenounceToolInputsVisitor.h:31
cpluginsvc.func
func
Definition: cpluginsvc.py:235
RenounceToolInputsVisitor::createLogger
static Logger createLogger(std::function< void(std::string_view, std::string_view)> func)
Create a logger from a function.
Definition: RenounceToolInputsVisitor.h:59
Gaudi::PluginService::v1::Details::logger
GAUDIPS_API Logger & logger()
Return the current logger instance.
Definition: PluginServiceV1.cpp:318
RenounceToolInputsVisitor::NoLogger
A do-nothing helper class which implements the logger interface.
Definition: RenounceToolInputsVisitor.h:38
std
STL namespace.
RenounceToolInputsVisitor::operator()
void operator()(IAlgTool *)
Definition: RenounceToolInputsVisitor.cpp:15
RenounceToolInputsVisitor::Logger::m_func
std::function< void(std::string_view, std::string_view)> m_func
Definition: RenounceToolInputsVisitor.h:43
RenounceToolInputsVisitor::RenounceToolInputsVisitor
RenounceToolInputsVisitor(std::vector< DataObjID > input_keys, ILogger &logger=s_noLogger)
construct the renounce visitor helper object
Definition: RenounceToolInputsVisitor.h:69
RenounceToolInputsVisitor
Helper class to be used in conjunction with the recursive tool visitor to renounce certain inputs.
Definition: RenounceToolInputsVisitor.h:27
ToolVisitor.h
ProduceConsume.key
key
Definition: ProduceConsume.py:84
RenounceToolInputsVisitor::Logger
Definition: RenounceToolInputsVisitor.h:42