1 #ifndef GAUDIKERNEL_TOOLHANDLE_H 2 #define GAUDIKERNEL_TOOLHANDLE_H 14 #include <type_traits> 27 using DisableTool = Gaudi::tagged_bool<class DisableTool_tag>;
28 using EnableTool = Gaudi::tagged_bool<class EnableTool_tag>;
35 : m_parent( parent ), m_createIf( createIf ) {}
40 bool isPublic() const noexcept {
return !m_parent; }
42 bool createIf() const noexcept {
return m_createIf; }
53 auto* pNamed = ( parent ?
dynamic_cast<const INamedInterface*
>( parent ) :
nullptr );
54 return ( !parent ?
"ToolSvc" : ( pNamed ? pNamed->name() :
"" ) );
59 bool m_createIf{
true};
83 const IAlgTool*
get()
const {
return getAsIAlgTool(); }
93 return ( m_enabled && !typeAndName().empty() ) ||
get();
96 inline void enable() { m_enabled =
true; }
98 inline void disable() { m_enabled =
false; }
101 auto old = m_enabled;
107 virtual const IAlgTool* getAsIAlgTool()
const = 0;
109 virtual IAlgTool* getAsIAlgTool() = 0;
111 bool m_enabled =
true;
137 ,
GaudiHandle<T>(
"", toolComponentType( parent ), toolParentName( parent ) )
172 #if defined( TOOLHANDLE_DEPR_WARN ) 174 # pragma message( "Untracked ToolHandle: Migrate explicit DataHandle constructor to declareTool Algorithm Property" ) 181 ,
GaudiHandle<T>( toolTypeAndName, toolComponentType( parent ), toolParentName( parent ) )
187 template <class OWNER, typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>>
193 if ( !toolType.
empty() and toolType.
find(
'/' ) == std::string::npos ) { toolType +=
'/' + toolType; }
194 owner->declareTool( *
this,
std::move( toolType ) ).ignore();
195 auto p = owner->OWNER::PropertyHolderImpl::declareProperty(
std::move( propName ), *
this,
std::move( doc ) );
196 p->template setOwnerType<OWNER>();
201 bool createIf =
true ) {
208 m_createIf = createIf;
229 if ( isEnabled() && sd ==
EnableTool{
true} ) {
248 algTool =
dynamic_cast<T*
>( iface );
249 if ( algTool ==
nullptr ) {
250 throw GaudiException(
"unable to dcast AlgTool " + typeAndName() +
" to interface " +
267 #ifdef ALLOW_TOOLHANDLE_NONCONSTNESS 276 [[
deprecated(
"FIXME!! should not call non-const method from a const ToolHandle" )]]
ToolHandle<T>& unConst()
const {
314 :
ToolHandle<T>( toolTypeAndName, nullptr, createIf ) {}
324 template <class OWNER, typename = typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>
::type>
330 if ( !toolType.
empty() and toolType.
find(
'/' ) == std::string::npos ) { toolType +=
'/' + toolType; }
331 owner->declareTool( *
this,
std::move( toolType ) ).ignore();
332 auto p = owner->OWNER::PropertyHolderImpl::declareProperty(
std::move( propName ), *
this,
std::move( doc ) );
333 p->template setOwnerType<OWNER>();
362 bool createIf =
true )
391 template <class OWNER, typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>>
395 owner->addToolsArray( *
this );
396 auto p = owner->OWNER::PropertyHolderImpl::declareProperty(
std::move( name ), *
this,
std::move( doc ) );
397 p->template setOwnerType<OWNER>();
413 template <class OWNER, typename = typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>
::type>
417 owner->addToolsArray( *
this );
418 auto p = owner->OWNER::PropertyHolderImpl::declareProperty(
std::move( name ), *
this,
std::move( doc ) );
419 p->template setOwnerType<OWNER>();
424 inline std::ostream& operator<<( std::ostream& os, const ToolHandle<T>& handle ) {
425 return operator<<( os, static_cast<const GaudiHandleInfo&>( handle ) );
429 inline std::ostream& operator<<( std::ostream& os, const ToolHandleArray<T>& handle ) {
430 return operator<<( os, static_cast<const GaudiHandleInfo&>( handle ) );
433 #endif // ! GAUDIKERNEL_TOOLHANDLE_H
Handle to be used in lieu of naked pointers to gaudis.
Define general base for Gaudi exception.
void setTypeAndName(std::string myTypeAndName)
The component "type/name" string.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
void setComponentType(const std::string &componentType)
The component type.
struct deprecated("use MergingTransformer instead")]] ListTransformer
constexpr static const auto SUCCESS
const std::string & parentName() const
The name of the parent.
void setParentName(const std::string &parent)
The name of the parent.
StatusCode release() const
Release the component.
void push_back(Container &c, const Value &v, std::true_type)
std::remove_const_t< T > * nonConst(T *p)
Cast a pointer to a non const type.
This class is used for returning status codes from appropriate routines.
Definition of the basic interface.
T * get()
Return the wrapped pointer, not calling retrieve() if null.
StatusCode retrieve() const
Retrieve the component.
Alias for backward compatibility.
IInterface compliant class extending IInterface with the name() method.
Base class from which all concrete algorithm classes should be derived.
constexpr static const auto FAILURE
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
std::string typeAndName() const
The full type and name: "type/name".
Base class for all services.
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
Helper functions to set/get the application return code.
T is the concrete handle type, e.g.