ATLAS Offline Software
Loading...
Searching...
No Matches
asg::StandaloneToolHandle< T > Class Template Referencefinal

an "initializing" ToolHandle for stand-alone applications More...

#include <StandaloneToolHandle.h>

Collaboration diagram for asg::StandaloneToolHandle< T >:

Public Member Functions

 StandaloneToolHandle ()=default
 StandaloneToolHandle (const std::string &typeAndName)
StatusCode initialize ()
 initialize the tool, will fail if the tool was already initialized
StatusCode retrieve ()
 initialize the tool, will succeed if the tool was already initialized
const ToolHandle< std::remove_const_t< T > > & getHandle ()
 get the contained handle
auto typeAndName () const
auto name () const
void setTypeAndName (const std::string &typeAndName)
template<typename T2>
StatusCode setProperty (const std::string &name, T2 &&value)
StatusCode createPrivateTool (const std::string &name, const std::string &toolType)
T * get ()
 access the wrapped tool
const T * get () const
T * operator-> ()
const T * operator-> () const
T & operator* ()
const T & operator* () const

Private Member Functions

void checkNotInitialized () const
 check that we are not initialized yet
void checkIsInitialized () const
 check that we are initialized, forcing in-place initialization if necessary

Private Attributes

T * m_pointer {nullptr}
 the cached pointer to the tool
ToolHandle< std::remove_const_t< T > > m_toolHandle
 the ToolHandle holding the tool after initialization
std::shared_ptr< void > m_cleanup
 the tool-cleanup pointer
AsgToolConfig m_config
 the actual configuration of the tool

Detailed Description

template<typename T>
class asg::StandaloneToolHandle< T >

an "initializing" ToolHandle for stand-alone applications

The purpose of this class is to make it easy to configure and instantiate a tool using the proper factory methods, so that they can readily be used within standalone applications. It is not meant to be used within any tools, algorithms or inside a regular Athena or EventLoop job in general. Those should use a regular ToolHandle (possibly combined with AsgToolConfig if a default configuration is desired).

This is meant to replace the legacy AnaToolHandle class as a drop-in replacement, that avoids a lot of the extra functionality that can be problematic, in particular it can not be used as a property and it does not try to manage public tools behind the scenes.

Note that the template argument can be const qualified, to force that it can only be accessed via a const pointer after it has been created.

\warn The cleanup behavior of this class is essentially undefined, and code should not try to access the tool after this object goes out of scope, nor should it rely on the tool being destroyed when this object is. In AnalysisBase the tool will be destroyed and removed when the object goes out of scope. In Athena the tool will still be owned by the ToolSvc and be released at a later point.

Definition at line 43 of file StandaloneToolHandle.h.

Constructor & Destructor Documentation

◆ StandaloneToolHandle() [1/2]

template<typename T>
asg::StandaloneToolHandle< T >::StandaloneToolHandle ( )
default

Public Members

◆ StandaloneToolHandle() [2/2]

template<typename T>
asg::StandaloneToolHandle< T >::StandaloneToolHandle ( const std::string & typeAndName)
inline

Definition at line 50 of file StandaloneToolHandle.h.

AsgToolConfig m_config
the actual configuration of the tool

Member Function Documentation

◆ checkIsInitialized()

template<typename T>
void asg::StandaloneToolHandle< T >::checkIsInitialized ( ) const
private

check that we are initialized, forcing in-place initialization if necessary

This is not truly const, but this convention matches the gaudi ToolHandle behavior.

Definition at line 187 of file StandaloneToolHandle.h.

189 {
190 if (m_pointer == nullptr)
191 throw std::logic_error ("trying to use StandaloneToolHandle that was never initialized/retrieved");
192 }
an "initializing" ToolHandle for stand-alone applications
T * m_pointer
the cached pointer to the tool

◆ checkNotInitialized()

template<typename T>
void asg::StandaloneToolHandle< T >::checkNotInitialized ( ) const
private

check that we are not initialized yet

Definition at line 178 of file StandaloneToolHandle.h.

180 {
181 if (m_pointer)
182 throw std::logic_error ("trying to configure StandaloneToolHandle after it was initialized/retrieved");
183 }

◆ createPrivateTool()

template<typename T>
StatusCode asg::StandaloneToolHandle< T >::createPrivateTool ( const std::string & name,
const std::string & toolType )
inline

Definition at line 108 of file StandaloneToolHandle.h.

109 {
111 return m_config.createPrivateTool (name, toolType);}
void checkNotInitialized() const
check that we are not initialized yet

◆ get() [1/2]

template<typename T>
T * asg::StandaloneToolHandle< T >::get ( )
inline

access the wrapped tool

Definition at line 64 of file StandaloneToolHandle.h.

64 {
65 checkIsInitialized (); return m_pointer;}
void checkIsInitialized() const
check that we are initialized, forcing in-place initialization if necessary

◆ get() [2/2]

template<typename T>
const T * asg::StandaloneToolHandle< T >::get ( ) const
inline

Definition at line 66 of file StandaloneToolHandle.h.

66 {
67 checkIsInitialized (); return m_pointer;}

◆ getHandle()

template<typename T>
const ToolHandle< std::remove_const_t< T > > & asg::StandaloneToolHandle< T >::getHandle ( )

get the contained handle

Note that this is probably not ideal, but it is kept around for legacy code that is using it.

Definition at line 169 of file StandaloneToolHandle.h.

171 {
173 return m_toolHandle;
174 }
ToolHandle< std::remove_const_t< T > > m_toolHandle
the ToolHandle holding the tool after initialization

◆ initialize()

template<typename T>
StatusCode asg::StandaloneToolHandle< T >::initialize ( )

initialize the tool, will fail if the tool was already initialized

Definition at line 157 of file StandaloneToolHandle.h.

159 {
161 if (m_config.makeTool (m_toolHandle, m_cleanup, true).isFailure())
162 return StatusCode::FAILURE;
164 return StatusCode::SUCCESS;
165 }
std::shared_ptr< void > m_cleanup
the tool-cleanup pointer

◆ name()

template<typename T>
auto asg::StandaloneToolHandle< T >::name ( ) const
inline

Definition at line 99 of file StandaloneToolHandle.h.

99 {
100 return m_config.name();}

◆ operator*() [1/2]

template<typename T>
T & asg::StandaloneToolHandle< T >::operator* ( )
inline

Definition at line 72 of file StandaloneToolHandle.h.

72 {
73 checkIsInitialized (); return *m_pointer;}

◆ operator*() [2/2]

template<typename T>
const T & asg::StandaloneToolHandle< T >::operator* ( ) const
inline

Definition at line 74 of file StandaloneToolHandle.h.

74 {
75 checkIsInitialized (); return *m_pointer;}

◆ operator->() [1/2]

template<typename T>
T * asg::StandaloneToolHandle< T >::operator-> ( )
inline

Definition at line 68 of file StandaloneToolHandle.h.

68 {
69 checkIsInitialized (); return m_pointer;}

◆ operator->() [2/2]

template<typename T>
const T * asg::StandaloneToolHandle< T >::operator-> ( ) const
inline

Definition at line 70 of file StandaloneToolHandle.h.

70 {
71 checkIsInitialized (); return m_pointer;}

◆ retrieve()

template<typename T>
StatusCode asg::StandaloneToolHandle< T >::retrieve ( )

initialize the tool, will succeed if the tool was already initialized

Definition at line 146 of file StandaloneToolHandle.h.

148 {
149 if (m_pointer == nullptr)
150 return initialize ();
151 else
152 return StatusCode::SUCCESS;
153 }
StatusCode initialize()
initialize the tool, will fail if the tool was already initialized

◆ setProperty()

template<typename T>
template<typename T2>
StatusCode asg::StandaloneToolHandle< T >::setProperty ( const std::string & name,
T2 && value )
inline

Definition at line 105 of file StandaloneToolHandle.h.

105 {
107 return m_config.setProperty (name, value);}

◆ setTypeAndName()

template<typename T>
void asg::StandaloneToolHandle< T >::setTypeAndName ( const std::string & typeAndName)
inline

Definition at line 101 of file StandaloneToolHandle.h.

101 {
103 m_config.setTypeAndName (typeAndName);}

◆ typeAndName()

template<typename T>
auto asg::StandaloneToolHandle< T >::typeAndName ( ) const
inline

Forwarding Members From AsgToolConfig

These are mostly direct forwards of the members of AsgToolConfig to avoid directly exposing the member object to the user. It is generally forbidden to try to change the configuration after the tool has been initialized, but read accessor may still be called.

Definition at line 97 of file StandaloneToolHandle.h.

97 {
98 return m_config.typeAndName();}

Member Data Documentation

◆ m_cleanup

template<typename T>
std::shared_ptr<void> asg::StandaloneToolHandle< T >::m_cleanup
private

the tool-cleanup pointer

Definition at line 127 of file StandaloneToolHandle.h.

◆ m_config

template<typename T>
AsgToolConfig asg::StandaloneToolHandle< T >::m_config
private

the actual configuration of the tool

Definition at line 130 of file StandaloneToolHandle.h.

◆ m_pointer

template<typename T>
T* asg::StandaloneToolHandle< T >::m_pointer {nullptr}
private

the cached pointer to the tool

Private Members

Definition at line 121 of file StandaloneToolHandle.h.

121{nullptr};

◆ m_toolHandle

template<typename T>
ToolHandle<std::remove_const_t<T> > asg::StandaloneToolHandle< T >::m_toolHandle
private

the ToolHandle holding the tool after initialization

Definition at line 124 of file StandaloneToolHandle.h.


The documentation for this class was generated from the following file: