ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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 More...
 
StatusCode retrieve ()
 initialize the tool, will succeed if the tool was already initialized More...
 
const ToolHandle< std::remove_const_t< T > > & getHandle ()
 get the contained handle More...
 
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 More...
 
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 More...
 
void checkIsInitialized () const
 check that we are initialized, forcing in-place initialization if necessary More...
 

Private Attributes

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

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.

51  : m_config (typeAndName) {}

Member Function Documentation

◆ checkIsInitialized()

template<typename T >
void asg::StandaloneToolHandle< T >::checkIsInitialized
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  }

◆ checkNotInitialized()

template<typename T >
void asg::StandaloneToolHandle< T >::checkNotInitialized
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);}

◆ 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;}

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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.

◆ 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.

◆ 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:
asg::StandaloneToolHandle::checkIsInitialized
void checkIsInitialized() const
check that we are initialized, forcing in-place initialization if necessary
Definition: StandaloneToolHandle.h:188
asg::StandaloneToolHandle::m_toolHandle
ToolHandle< std::remove_const_t< T > > m_toolHandle
the ToolHandle holding the tool after initialization
Definition: StandaloneToolHandle.h:124
athena.value
value
Definition: athena.py:122
asg::StandaloneToolHandle::m_config
AsgToolConfig m_config
the actual configuration of the tool
Definition: StandaloneToolHandle.h:130
asg::StandaloneToolHandle::m_pointer
T * m_pointer
the cached pointer to the tool
Definition: StandaloneToolHandle.h:121
asg::StandaloneToolHandle::initialize
StatusCode initialize()
initialize the tool, will fail if the tool was already initialized
Definition: StandaloneToolHandle.h:158
asg::StandaloneToolHandle::name
auto name() const
Definition: StandaloneToolHandle.h:99
asg::AsgComponentConfig::setTypeAndName
void setTypeAndName(const std::string &val_typeAndName)
set type and name at the same time
Definition: AsgComponentConfig.cxx:116
asg::StandaloneToolHandle::checkNotInitialized
void checkNotInitialized() const
check that we are not initialized yet
Definition: StandaloneToolHandle.h:179
asg::AsgComponentConfig::setProperty
StatusCode setProperty(const std::string &name, const T &value)
set the given property
asg::AsgComponentConfig::typeAndName
std::string typeAndName() const
get type and name at the same time
Definition: AsgComponentConfig.cxx:106
asg::StandaloneToolHandle::m_cleanup
std::shared_ptr< void > m_cleanup
the tool-cleanup pointer
Definition: StandaloneToolHandle.h:127
asg::AsgComponentConfig::name
const std::string & name() const noexcept
the name of the component
Definition: AsgComponentConfig.cxx:90
asg::StandaloneToolHandle::typeAndName
auto typeAndName() const
Definition: StandaloneToolHandle.h:97
asg::AsgToolConfig::makeTool
::StatusCode makeTool(ToolHandle< T > &toolHandle, std::shared_ptr< void > &cleanup, bool allowNestedName=false) const
make a tool with the given configuration
asg::AsgComponentConfig::createPrivateTool
StatusCode createPrivateTool(const std::string &name, const std::string &toolType)
create a private tool of the given name and type
Definition: AsgComponentConfig.cxx:150