Go to the documentation of this file.
11 #ifndef GAUDIKERNEL_GAUDIHANDLE_H
12 #define GAUDIKERNEL_GAUDIHANDLE_H
23 #include <type_traits>
30 return const_cast<std::remove_const_t<T>*
>( p );
45 : m_componentType(
std::move( myComponentType ) ), m_parentName(
std::move( myParentName ) ) {}
123 setTypeAndName(
std::move( myTypeAndName ) );
140 bool empty()
const {
return m_typeAndName.empty(); }
146 void setName( std::string_view myName );
189 template <
typename CT = T,
typename NCT = std::remove_const_t<T>>
191 std::enable_if_t<std::is_const_v<CT> && !std::is_same_v<CT, NCT>>* =
nullptr )
193 m_pObject = other.
get();
204 template <
typename CT = T,
typename NCT = std::remove_const_t<T>>
205 std::enable_if_t<std::is_const_v<CT> && !std::is_same_v<CT, NCT>,
GaudiHandle&>
207 GaudiHandleBase::operator=( other );
210 m_pObject = other.
get();
218 GaudiHandleBase::operator=( other );
255 return m_pObject || retrieve().isSuccess();
260 operator bool()
const {
266 T*
get() {
return m_pObject; }
269 std::add_const_t<T>*
get()
const {
return m_pObject; }
301 return ( defName.empty() ? getDefaultType() : defName );
456 for (
auto&
h : m_handleArray ) baseArray.
push_back( &
h );
462 for (
auto&
h : m_handleArray ) baseArray.
push_back( &
h );
483 void clear()
override { m_handleArray.clear(); }
485 bool empty()
const override {
return m_handleArray.empty(); }
494 return it !=
end() ? &*it :
nullptr;
500 return it !=
end() ? &*it :
nullptr;
507 m_handleArray.push_back( myHandle );
514 for (
auto& i : *
this ) {
516 if ( i.retrieve().isFailure() ) {
521 if ( sc ) { m_retrieved =
true; }
528 for (
auto& i : *
this ) {
536 virtual bool retrieved()
const override {
return m_retrieved; }
543 bool m_retrieved{
false };
546 #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.
get
decorate the vector of properties
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.
AttribStringParser::Iterator begin(const AttribStringParser &parser)
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.
std::ostream & operator<<(std::ostream &o, const Catalog &c)
printout operator
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::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.
Generator[dict, None, None] reference(request, Optional[Path] reference_path)
const std::string & typeAndName() const
The full type and name: "type/name".
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
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.
size_t index(const Gaudi::ParticleProperty *property, const Gaudi::Interfaces::IParticlePropertySvc *service)
helper utility for mapping of Gaudi::ParticleProperty object into non-negative integral sequential id...
void setTypeAndName(std::string myTypeAndName)
The component "type/name" string.
virtual bool empty() const =0
Return whether the list of tools is empty.