The Gaudi Framework  master (e68eea06)
Loading...
Searching...
No Matches
RenounceToolInputsVisitor.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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
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
23class IAlgTool;
24
28public:
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 <std::invocable<std::string_view, std::string_view> F>
47 Logger( F func ) : m_func( std::move( func ) ) {}
48 void renounce( std::string_view tool_name, std::string_view key ) override { m_func( tool_name, key ); }
49 };
50
58 static Logger createLogger( std::function<void( std::string_view, std::string_view )> func ) {
59 return Logger{ std::move( func ) };
60 }
61
68 RenounceToolInputsVisitor( std::vector<DataObjID> input_keys, ILogger& logger = s_noLogger )
69 : m_renounceKeys( std::move( input_keys ) )
70 , m_logger( &logger ) // @TODO possible source of use after delete
71 {}
72
73 void operator()( IAlgTool* );
74
75private:
76 std::vector<DataObjID> m_renounceKeys;
78
79 static NoLogger s_noLogger USAGE_IS_THREAD_SAFE;
80};
The interface implemented by the AlgTool base class.
Definition IAlgTool.h:29
std::function< void(std::string_view, std::string_view)> m_func
void renounce(std::string_view tool_name, std::string_view key) override
static NoLogger s_noLogger USAGE_IS_THREAD_SAFE
std::vector< DataObjID > m_renounceKeys
RenounceToolInputsVisitor(std::vector< DataObjID > input_keys, ILogger &logger=s_noLogger)
construct the renounce visitor helper object
static Logger createLogger(std::function< void(std::string_view, std::string_view)> func)
Create a logger from a function.
STL namespace.
Helper class interface to optionally log renounce operations.
virtual void renounce(std::string_view tool_name, std::string_view key)=0
A do-nothing helper class which implements the logger interface.
void renounce(std::string_view, std::string_view) override