1 #ifndef GAUDIKERNEL_GAUDIHANDLE_H 2 #define GAUDIKERNEL_GAUDIHANDLE_H 14 #include <type_traits> 21 return const_cast<std::remove_const_t<T>*
>( p );
36 : m_componentType(
std::move( myComponentType ) ), m_parentName(
std::move( myParentName ) ) {}
58 virtual std::string pythonPropertyClassName()
const = 0;
107 setTypeAndName(
std::move( myTypeAndName ) );
124 bool empty()
const {
return m_typeAndName.empty(); }
173 template <
typename CT = T,
typename NCT = std::remove_const_t<T>>
175 std::enable_if_t<std::is_const_v<CT> && !std::is_same_v<CT, NCT>>* =
nullptr )
177 m_pObject = other.
get();
188 template <
typename CT = T,
typename NCT = std::remove_const_t<T>>
189 std::enable_if_t<std::is_const_v<CT> && !std::is_same_v<CT, NCT>,
GaudiHandle&>
191 GaudiHandleBase::operator=( other );
194 m_pObject = other.
get();
202 GaudiHandleBase::operator=( other );
216 if ( sc && retrieve( m_pObject ).isFailure() ) {
228 sc = release( m_pObject );
237 return m_pObject || retrieve().isSuccess();
242 operator bool()
const {
248 T*
get() {
return m_pObject; }
251 std::add_const_t<T>*
get()
const {
return m_pObject; }
283 return ( defName.empty() ? getDefaultType() : defName );
321 mutable T* m_pObject =
nullptr;
374 virtual void clear() = 0;
377 virtual bool empty()
const = 0;
388 virtual bool retrieved()
const = 0;
438 for (
auto& h : m_handleArray ) baseArray.
push_back( &h );
444 for (
auto& h : m_handleArray ) baseArray.
push_back( &h );
465 void clear()
override { m_handleArray.clear(); }
467 bool empty()
const override {
return m_handleArray.empty(); }
471 const T&
operator[](
int index )
const {
return m_handleArray[index]; }
476 return it !=
end() ? &*it :
nullptr;
482 return it !=
end() ? &*it :
nullptr;
489 m_handleArray.push_back( myHandle );
496 for (
auto& i : *
this ) {
498 if ( i.retrieve().isFailure() ) {
503 if ( sc ) { m_retrieved =
true; }
510 for (
auto& i : *
this ) {
518 virtual bool retrieved()
const override {
return m_retrieved; }
525 bool m_retrieved{
false};
532 #endif // ! GAUDIKERNEL_GAUDIHANDLE_H
GaudiHandle & operator=(const GaudiHandle &other)
Assignment operator for correct ref-counting.
HandleVector::const_reference const_reference
const T * operator[](const std::string &name) const
Get const pointer (!) to ToolHandle by instance name.
HandleVector::value_type value_type
Handle to be used in lieu of naked pointers to gaudis.
StatusCode release() const
Release the component.
void clear() override
Clear the list of handles.
std::string getDefaultType()
Helper function to get default type string from the class type.
Define general base for Gaudi exception.
std::add_const_t< T > * get() const
Return the wrapped pointer, not calling retrieve() if null.
bool empty() const
Check if the handle has been set to empty string (i.e.
HandleVector::iterator iterator
GaudiHandleArrayBase::BaseHandleArray getBaseArray() override
Get a read-write vector of GaudiHandleBase* pointing to the real handles.
void setTypeAndName(std::string myTypeAndName)
The component "type/name" string.
const std::string & propertyName() const
name as used in declareProperty(name,gaudiHandle)
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.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
std::vector< T > HandleVector
std::string typeAndName() const
The full type and name: "type/name".
HandleVector::const_reverse_iterator const_reverse_iterator
void setComponentType(const std::string &componentType)
The component type.
std::string getDefaultName()
constexpr static const auto SUCCESS
StatusCode retrieve() const
Retrieve the component.
GaudiHandle(std::string myTypeAndName, std::string myComponentType, std::string myParentName)
void setDefaultType()
Helper function to set default type from the class type T.
std::string m_componentType
GaudiHandleArray(const std::vector< std::string > &myTypesAndNamesList, std::string myComponentType, std::string myParentName)
Generic constructor.
HandleVector::size_type size_type
GaudiHandleArray & operator=(const std::vector< std::string > &myTypesAndNamesList)
Set the array of GaudiHandles from typeAndNames given in vector of strings.
bool empty() const override
Return whether the list of tools is empty.
HandleVector::reference reference
virtual bool push_back(const T &myHandle)
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.
void setParentName(const std::string &parent)
The name of the parent.
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
const T & operator[](int index) const
auto operator *(const std::chrono::duration< Rep1, Period > &lhs, const std::chrono::duration< Rep2, Period > &rhs)
Multiplication of two std::chrono::duration objects with same Period.
std::add_const_t< T > * operator->() const
void push_back(Container &c, const Value &v, std::true_type)
void setDefaultTypeAndName()
Helper function to set default name and type.
virtual std::string pythonRepr() const =0
Python representation of handle, i.e.
HandleVector m_handleArray
StatusCode retrieve()
Retrieve all tools.
const_iterator rend() const
std::remove_const_t< T > * nonConst(T *p)
Cast a pointer to a non const type.
bool setTypesAndNames(const std::vector< std::string > &myTypesAndNamesList)
Set the array of handles from list of "type/name" strings in <myTypesAndNamesList>.
const_iterator end() const
This class is used for returning status codes from appropriate routines.
const std::string & parentName() const
The name of the parent.
virtual bool retrieved() const override
has Array been retreived?
T * get()
Return the wrapped pointer, not calling retrieve() if null.
GaudiHandleArrayBase::ConstBaseHandleArray getBaseArray() const override
Get a read-only vector of const GaudiHandleBase* pointing to the real handles.
std::string m_typeAndName
const_iterator rbegin() const
std::vector< const GaudiHandleBase * > ConstBaseHandleArray
void assertObject() const
Load the pointer to the component.
const std::string & componentType() const
HandleVector::const_iterator const_iterator
Base class of array's of various gaudihandles.
virtual StatusCode release(T *comp) const
Release the component.
virtual std::string pythonPropertyClassName() const =0
The python class name for the property in the genconf-generated configurables.
bool isSet() const
True if the wrapped pointer is not null.
std::string type() const
The concrete component class name: the part before the '/'.
GaudiHandleInfo(std::string myComponentType, std::string myParentName)
Some basic information and helper functions shared between various handles/arrays.
void setPropertyName(std::string propName)
set name as used in declareProperty(name,gaudiHandle).
HandleVector::reverse_iterator reverse_iterator
virtual bool push_back(const std::string &myHandleTypeAndName)=0
Add a handle to the array with "type/name" given in <myHandleTypeAndName>.
std::vector< GaudiHandleBase * > BaseHandleArray
constexpr static const auto FAILURE
std::ostream & operator<<(std::ostream &os, const GaudiHandleInfo &handle)
T & operator[](int index)
const_iterator begin() const
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
AttribStringParser::Iterator begin(const AttribStringParser &parser)
GaudiHandleArrayBase(std::string myComponentType, std::string myParentName)
T * operator[](const std::string &name)
Get pointer (!) to ToolHandle by instance name.
GaudiHandleBase(std::string myTypeAndName, std::string myComponentType, std::string myParentName)
Create a handle ('smart pointer') to a gaudi component.
std::string m_propertyName
GaudiHandle(const GaudiHandle &other)
Copy constructor needed for correct ref-counting.
bool isValid() const
Check if the handle is valid (try to retrive the object is not done yet).
T is the concrete handle type, e.g.
StatusCode release()
Release all tools.
GaudiHandleArray(const std::string &myComponentType, const std::string &myParentName)
Constructor creating an empty array.