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 ) ) {}
62 void setPropertyName( std::string propName ) { m_propertyName = std::move( propName ); }
65 const std::string&
parentName()
const {
return m_parentName; }
84 void setComponentType( std::string componentType ) { m_componentType = std::move( componentType ); }
87 void setParentName( std::string parent ) { m_parentName = std::move( parent ); }
121 GaudiHandleBase( std::string myTypeAndName, std::string myComponentType, std::string myParentName )
123 setTypeAndName( std::move( myTypeAndName ) );
134 std::string
type()
const;
137 std::string
name()
const;
140 bool empty()
const {
return m_typeAndName.empty(); }
143 void setTypeAndName( std::string myTypeAndName );
146 void setName( std::string_view myName );
154 std::string messageName()
const;
184 GaudiHandle( std::string myTypeAndName, std::string myComponentType, std::string myParentName )
189 template <
typename CT = T,
typename NCT = std::remove_const_t<T>>
191 requires( std::is_const_v<CT> && !std::is_same_v<CT, NCT> )
202 template <
typename CT = T,
typename NCT = std::remove_const_t<T>>
203 requires( std::is_const_v<CT> && !std::is_same_v<CT, NCT> )
205 GaudiHandleBase::operator=( other );
208 m_pObject = other.get();
216 GaudiHandleBase::operator=( other );
251 bool isValid()
const {
253 return m_pObject || retrieve().
isSuccess();
258 operator bool()
const {
264 T*
get() {
return m_pObject; }
267 std::add_const_t<T>*
get()
const {
return m_pObject; }
270 bool isSet()
const {
return get(); }
288 std::add_const_t<T>* operator->()
const {
297 std::string getDefaultName() {
299 return ( defName.empty() ? getDefaultType() : defName );
328 mutable std::atomic<T*> m_pObject =
nullptr;
349 bool setTypesAndNames(
const std::vector<std::string>& myTypesAndNamesList );
353 const std::vector<std::string> typesAndNames()
const;
356 const std::vector<std::string>
types()
const;
359 const std::vector<std::string> names()
const;
363 const std::vector<std::string> getBaseInfos(
auto (
GaudiHandleBase::*pMemFunc )()
const )
const;
378 virtual bool push_back(
const std::string& myHandleTypeAndName ) = 0;
423 GaudiHandleArray(
const std::vector<std::string>& myTypesAndNamesList, std::string myComponentType,
424 std::string myParentName )
445 for (
auto&
h : m_handleArray ) baseArray.push_back( &
h );
451 for (
auto&
h : m_handleArray ) baseArray.push_back( &
h );
472 void clear()
override { m_handleArray.clear(); }
474 bool empty()
const override {
return m_handleArray.empty(); }
483 return it !=
end() ? &*it :
nullptr;
489 return it !=
end() ? &*it :
nullptr;
496 m_handleArray.push_back( myHandle );
503 for (
auto& i : *
this ) {
505 if ( i.retrieve().isFailure() ) {
510 if ( sc ) { m_retrieved =
true; }
517 for (
auto& i : *
this ) {
525 virtual bool retrieved()
const override {
return m_retrieved; }
532 bool m_retrieved{
false };
535 #endif // ! GAUDIKERNEL_GAUDIHANDLE_H
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
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.
const T & operator[](int index) const
StatusCode retrieve()
Retrieve all tools.
virtual bool push_back(const T &myHandle)
get
decorate the vector of properties
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(const GaudiHandle< NCT > &other) requires(std
Copy constructor needed 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
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)
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?
Base class of array's of various gaudihandles.
requires(std::is_const_v< CT > &&!std::is_same_v< CT, NCT >) GaudiHandle &operator
Assignment operator for correct ref-counting.
GaudiHandleInfo(std::string myComponentType, std::string myParentName)
Some basic information and helper functions shared between various handles/arrays.
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::string type() const
The concrete component class name: the part before the '/'.
constexpr static const auto SUCCESS
HandleVector m_handleArray
std::vector< GaudiHandleBase * > BaseHandleArray
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.
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.
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.
HandleVector::value_type value_type
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...
virtual bool empty() const =0
Return whether the list of tools is empty.