1 #ifndef GAUDIKERNEL_GAUDIHANDLE_H 2 #define GAUDIKERNEL_GAUDIHANDLE_H 14 #include <type_traits> 23 return const_cast<std::remove_const_t<T>*
>( p );
39 : m_componentType(
std::move( myComponentType ) ), m_parentName(
std::move( myParentName ) )
63 virtual std::string pythonPropertyClassName()
const = 0;
114 setTypeAndName(
std::move( myTypeAndName ) );
131 bool empty()
const {
return m_typeAndName.empty(); }
142 std::string pythonPropertyClassName()
const override;
188 m_pObject = other.
get();
207 m_pObject = other.
get();
229 if ( m_pObject && release().isFailure() ) {
232 if ( sc && retrieve( m_pObject ).isFailure() ) {
244 sc = release( m_pObject );
253 return m_pObject || retrieve().isSuccess();
258 operator bool()
const 264 T*
get() {
return m_pObject; }
270 bool isSet()
const {
return get(); }
304 return ( defName.empty() ? getDefaultType() : defName );
336 throw GaudiException(
"Failed to retrieve " + componentType() +
": " + typeAndName(),
345 mutable T* m_pObject =
nullptr;
388 std::string pythonPropertyClassName()
const override;
401 virtual void clear() = 0;
404 virtual bool empty()
const = 0;
408 virtual ConstBaseHandleArray getBaseArray()
const = 0;
412 virtual BaseHandleArray getBaseArray() = 0;
415 virtual bool retrieved()
const = 0;
448 setTypesAndNames( myTypesAndNamesList );
466 setTypesAndNames( myTypesAndNamesList );
473 iterator it =
begin(), itEnd =
end();
474 for ( ; it != itEnd; ++it ) baseArray.
push_back( &*it );
481 const_iterator it =
begin(), itEnd =
end();
482 for ( ; it != itEnd; ++it ) baseArray.
push_back( &*it );
489 iterator
begin() {
return m_handleArray.begin(); }
491 iterator
end() {
return m_handleArray.end(); }
493 const_iterator
begin()
const {
return m_handleArray.begin(); }
495 const_iterator
end()
const {
return m_handleArray.end(); }
497 const_iterator
rbegin()
const {
return m_handleArray.rbegin(); }
499 const_iterator
rend()
const {
return m_handleArray.rend(); }
501 size_type
size()
const {
return m_handleArray.size(); }
503 void clear()
override { m_handleArray.clear(); }
505 bool empty()
const override {
return m_handleArray.empty(); }
509 const T&
operator[](
int index )
const {
return m_handleArray[index]; }
515 return it !=
end() ? &*it :
nullptr;
522 return it !=
end() ? &*it :
nullptr;
530 m_handleArray.push_back( myHandle );
538 for (
auto& i : *
this ) {
540 if ( i.retrieve().isFailure() ) {
555 for (
auto& i : *
this ) {
563 virtual bool retrieved()
const override {
return m_retrieved; }
570 bool m_retrieved{
false};
577 #endif // ! GAUDIKERNEL_GAUDIHANDLE_H
GaudiHandle & operator=(const GaudiHandle &other)
Assignment operator for correct ref-counting.
HandleVector::const_reference const_reference
constexpr static const auto FAILURE
HandleVector::value_type value_type
Handle to be used in lieu of naked pointers to gaudis.
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.
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.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
GaudiHandleArrayBase::ConstBaseHandleArray getBaseArray() const override
Get a read-only vector of const GaudiHandleBase* pointing to the real handles.
auto end(reverse_wrapper< T > &w)
std::vector< T > HandleVector
const_iterator rend() const
HandleVector::const_reverse_iterator const_reverse_iterator
void setComponentType(const std::string &componentType)
The component type.
std::string getDefaultName()
GaudiHandle(std::string myTypeAndName, std::string myComponentType, std::string myParentName)
const std::string & parentName() const
The name of the parent.
void setDefaultType()
Helper function to set default type from the class type T.
void assertObject() const
Load the pointer to the component.
std::string m_componentType
virtual bool retrieved() const override
has Array been retreived?
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.
HandleVector::reference reference
virtual bool push_back(const T &myHandle)
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::enable_if< std::is_const< CT >::value &&!std::is_same< CT, NCT >::value, GaudiHandle & >::type operator=(const GaudiHandle< NCT > &other)
Assignment operator for correct ref-counting.
PropertyMgr & operator=(const PropertyMgr &)=delete
std::add_const< T >::type * operator->() const
void setDefaultTypeAndName()
Helper function to set default name and type.
const T & operator[](int index) const
const std::string & propertyName() const
name as used in declareProperty(name,gaudiHandle)
HandleVector m_handleArray
StatusCode retrieve()
Retrieve all tools.
const_iterator begin() const
std::add_const< T >::type & operator*() const
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.
T * get()
Return the wrapped pointer, not calling retrieve() if null.
StatusCode retrieve() const
Retrieve the component.
std::string m_typeAndName
std::vector< const GaudiHandleBase * > ConstBaseHandleArray
constexpr static const auto SUCCESS
bool empty() const override
Return whether the list of tools is empty.
HandleVector::const_iterator const_iterator
bool isValid() const
Check if the handle is valid (try to retrive the object is not done yet).
Base class of array's of various gaudihandles.
const_iterator rbegin() const
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).
bool isSet() const
True if the wrapped pointer is not null.
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
auto begin(reverse_wrapper< T > &w)
virtual StatusCode release(T *comp) const
Release the component.
std::string type() const
The concrete component class name: the part before the '/'.
std::ostream & operator<<(std::ostream &os, const GaudiHandleInfo &handle)
T & operator[](int index)
const T * operator[](const std::string &name) const
Get const pointer (!) to ToolHandle by instance name.
const_iterator end() const
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".
GaudiHandleArrayBase(std::string myComponentType, std::string myParentName)
T * operator[](const std::string &name)
Get pointer (!) to ToolHandle by instance name.
GaudiHandle(const GaudiHandle< NCT > &other, typename std::enable_if< std::is_const< CT >::value &&!std::is_same< CT, NCT >::value >::type *=nullptr)
Copy constructor needed for correct ref-counting.
const std::string & componentType() const
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 empty() const
Check if the handle has been set to empty string (i.e.
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.