Go to the documentation of this file.
11 #ifndef GAUDIKERNEL_GAUDIHANDLE_H
12 #define GAUDIKERNEL_GAUDIHANDLE_H
24 #include <type_traits>
31 return const_cast<std::remove_const_t<T>*
>( p );
46 : m_componentType(
std::move( myComponentType ) ), m_parentName(
std::move( myParentName ) ) {}
120 setTypeAndName(
std::move( myTypeAndName ) );
137 bool empty()
const {
return m_typeAndName.empty(); }
143 void setName( std::string_view myName );
186 template <
typename CT = T,
typename NCT = std::remove_const_t<T>>
188 std::enable_if_t<std::is_const_v<CT> && !std::is_same_v<CT, NCT>>* =
nullptr )
190 m_pObject = other.
get();
201 template <
typename CT = T,
typename NCT = std::remove_const_t<T>>
202 std::enable_if_t<std::is_const_v<CT> && !std::is_same_v<CT, NCT>,
GaudiHandle&>
204 GaudiHandleBase::operator=( other );
207 m_pObject = other.
get();
215 GaudiHandleBase::operator=( other );
252 return m_pObject || retrieve().isSuccess();
257 operator bool()
const {
263 T*
get() {
return m_pObject; }
266 std::add_const_t<T>*
get()
const {
return m_pObject; }
298 return ( defName.empty() ? getDefaultType() : defName );
453 for (
auto&
h : m_handleArray ) baseArray.
push_back( &
h );
459 for (
auto&
h : m_handleArray ) baseArray.
push_back( &
h );
480 void clear()
override { m_handleArray.clear(); }
482 bool empty()
const override {
return m_handleArray.empty(); }
486 const T&
operator[](
int index )
const {
return m_handleArray[index]; }
491 return it !=
end() ? &*it :
nullptr;
497 return it !=
end() ? &*it :
nullptr;
504 m_handleArray.push_back( myHandle );
511 for (
auto& i : *
this ) {
513 if ( i.retrieve().isFailure() ) {
518 if ( sc ) { m_retrieved =
true; }
525 for (
auto& i : *
this ) {
533 virtual bool retrieved()
const override {
return m_retrieved; }
540 bool m_retrieved{
false };
547 #endif // ! GAUDIKERNEL_GAUDIHANDLE_H
bool isSet() const
True if the wrapped pointer is not null.
T * operator[](std::string_view name)
Get pointer (!) to ToolHandle by instance name.
const std::string & parentName() const
The name of the parent.
const_iterator begin() const
const T & operator[](int index) const
void setDefaultTypeAndName()
Helper function to set default name and type.
StatusCode retrieve()
Retrieve all tools.
virtual bool push_back(const T &myHandle)
std::string getDefaultType()
Helper function to get default type string from the class type.
std::add_const_t< T > & operator*() const
bool empty() const override
Return whether the list of tools is empty.
bool empty() const
Check if the handle has been set to empty string (i.e.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
const std::string & componentType() const
std::vector< const GaudiHandleBase * > ConstBaseHandleArray
GaudiHandle & operator=(const GaudiHandle &other)
Assignment operator for correct ref-counting.
GaudiHandle(std::string myTypeAndName, std::string myComponentType, std::string myParentName)
void setParentName(std::string parent)
The name of the parent.
T & operator[](int index)
StatusCode release()
Release all tools.
GaudiHandleArray(const std::vector< std::string > &myTypesAndNamesList, std::string myComponentType, std::string myParentName)
Generic constructor.
GaudiHandleArrayBase::BaseHandleArray getBaseArray() override
Get a read-write vector of GaudiHandleBase* pointing to the real handles.
HandleVector::reference reference
const_iterator rend() const
const_iterator end() const
T * get()
Return the wrapped pointer, not calling retrieve() if null.
std::vector< T > HandleVector
virtual StatusCode release(T *comp) const
Release the component.
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
HandleVector::const_iterator const_iterator
std::remove_const_t< T > * nonConst(T *p)
Cast a pointer to a non const type.
GaudiHandle(const GaudiHandle &other)
Copy constructor needed for correct ref-counting.
double * begin(CLHEP::HepVector &v)
std::string m_typeAndName
const std::string & propertyName() const
name as used in declareProperty(name,gaudiHandle)
virtual StatusCode retrieve(T *&) const =0
Retrieve the component.
std::string m_propertyName
HandleVector::size_type size_type
GaudiHandleArray(const std::string &myComponentType, const std::string &myParentName)
Constructor creating an empty array.
std::string typeAndName() const
The full type and name: "type/name".
std::atomic< T * > m_pObject
virtual void clear()=0
Clear the list of handles.
GaudiHandleArray & operator=(const std::vector< std::string > &myTypesAndNamesList)
Set the array of GaudiHandles from typeAndNames given in vector of strings.
virtual bool retrieved() const =0
To be able to tell if Array was ever retreived.
virtual ConstBaseHandleArray getBaseArray() const =0
Get a read-only vector of const GaudiHandleBase* pointing to the real handles.
void clear() override
Clear the list of handles.
virtual bool retrieved() const override
has Array been retreived?
std::enable_if_t< std::is_const_v< CT > &&!std::is_same_v< CT, NCT >, GaudiHandle & > operator=(const GaudiHandle< NCT > &other)
Assignment operator for correct ref-counting.
Base class of array's of various gaudihandles.
GaudiHandleInfo(std::string myComponentType, std::string myParentName)
Some basic information and helper functions shared between various handles/arrays.
bool isValid() const
Check if the handle is valid (try to retrive the object is not done yet).
bool setTypesAndNames(const std::vector< std::string > &myTypesAndNamesList)
Set the array of handles from list of "type/name" strings in <myTypesAndNamesList>.
virtual ~GaudiHandleInfo()
virtual destructor so that derived class destructor is called.
HandleVector::const_reference const_reference
std::add_const_t< T > * operator->() const
std::string type() const
The concrete component class name: the part before the '/'.
constexpr static const auto SUCCESS
HandleVector m_handleArray
std::vector< GaudiHandleBase * > BaseHandleArray
std::string getDefaultName()
virtual bool push_back(const std::string &myHandleTypeAndName)=0
Add a handle to the array with "type/name" given in <myHandleTypeAndName>.
virtual std::string pythonPropertyClassName() const =0
The python class name for the property in the genconf-generated configurables.
void setDefaultType()
Helper function to set default type from the class type T.
HandleVector::reverse_iterator reverse_iterator
void setComponentType(std::string componentType)
The component type.
GaudiHandleBase(std::string myTypeAndName, std::string myComponentType, std::string myParentName)
Create a handle ('smart pointer') to a gaudi component.
GaudiHandle(const GaudiHandle< NCT > &other, std::enable_if_t< std::is_const_v< CT > &&!std::is_same_v< CT, NCT >> *=nullptr)
Copy constructor needed for correct ref-counting.
GaudiHandleArrayBase(std::string myComponentType, std::string myParentName)
HandleVector::iterator iterator
std::ostream & operator<<(std::ostream &os, const GaudiHandleInfo &handle)
virtual BaseHandleArray getBaseArray()=0
Get a read-write vector of GaudiHandleBase* pointing to the real handles.
const T * operator[](std::string_view name) const
Get const pointer (!) to ToolHandle by instance name.
HandleVector::const_reverse_iterator const_reverse_iterator
const_iterator rbegin() const
constexpr static const auto FAILURE
void setPropertyName(std::string propName)
set name as used in declareProperty(name,gaudiHandle).
std::string m_componentType
virtual std::string pythonRepr() const =0
Python representation of handle, i.e.
GaudiHandleArrayBase::ConstBaseHandleArray getBaseArray() const override
Get a read-only vector of const GaudiHandleBase* pointing to the real handles.
T is the concrete handle type, e.g.
void assertObject() const
Load the pointer to the component.
StatusCode retrieve() const
Retrieve the component.
std::add_const_t< T > * get() const
Return the wrapped pointer, not calling retrieve() if null.
HandleVector::value_type value_type
StatusCode release() const
Release the component.
void setTypeAndName(std::string myTypeAndName)
The component "type/name" string.
virtual bool empty() const =0
Return whether the list of tools is empty.