1 #ifndef GAUDIKERNEL_GAUDIHANDLE_H
2 #define GAUDIKERNEL_GAUDIHANDLE_H
5 #include "GaudiKernel/IInterface.h"
6 #include "GaudiKernel/System.h"
7 #include "GaudiKernel/GaudiException.h"
25 GaudiHandleInfo( std::string myComponentType, std::string myParentName )
26 : m_componentType(
std::move(myComponentType)), m_parentName(
std::move(myParentName))
34 const std::string& componentType()
const {
35 return m_componentType;
39 const std::string& propertyName()
const {
40 return m_propertyName;
44 void setPropertyName( std::string propName ) {
45 m_propertyName = std::move(propName);
49 const std::string& parentName()
const {
56 virtual std::string pythonPropertyClassName()
const = 0;
62 virtual std::string pythonRepr()
const = 0;
68 std::string m_componentType;
69 std::string m_propertyName;
70 std::string m_parentName;
97 GaudiHandleBase( std::string myTypeAndName, std::string myComponentType,
98 std::string myParentName )
101 setTypeAndName(std::move(myTypeAndName));
108 std::string typeAndName()
const {
109 return m_typeAndName;
113 std::string
type()
const;
116 std::string
name()
const;
120 return m_typeAndName.empty();
124 void setTypeAndName( std::string myTypeAndName );
127 void setName(
const std::string& myName );
135 std::string messageName()
const;
146 std::string m_typeAndName;
164 GaudiHandle( std::string myTypeAndName, std::string myComponentType,
165 std::string myParentName )
174 if ( m_pObject ) m_pObject->addRef();
179 GaudiHandleBase::operator=( other );
184 if ( m_pObject ) m_pObject->addRef();
191 if ( retrieve( m_pObject ).isFailure() ) {
209 bool isValid()
const {
210 return m_pObject || retrieve().isSuccess();
215 operator bool()
const {
239 T& operator*()
const {
244 T* operator->()
const {
250 std::string getDefaultType() {
254 std::string getDefaultName() {
256 if ( defName.empty() ) defName = getDefaultType();
273 void setDefaultTypeAndName() {
274 const std::string& myType = getDefaultType();
279 void setDefaultType() {
285 void assertObject()
const {
294 mutable T* m_pObject =
nullptr;
310 typedef std::vector< GaudiHandleBase* > BaseHandleArray;
311 typedef std::vector< const GaudiHandleBase* > ConstBaseHandleArray;
315 bool setTypesAndNames(
const std::vector< std::string >& myTypesAndNamesList );
319 const std::vector< std::string > typesAndNames()
const;
322 const std::vector< std::string > types()
const;
325 const std::vector< std::string > names()
const;
329 const std::vector< std::string > getBaseInfos( std::string (
GaudiHandleBase::*pMemFunc)()
const )
const;
344 virtual bool push_back(
const std::string& myHandleTypeAndName ) = 0;
347 virtual void clear() = 0;
350 virtual bool empty()
const = 0;
354 virtual ConstBaseHandleArray getBaseArray()
const = 0;
358 virtual BaseHandleArray getBaseArray() = 0;
369 typedef std::vector< T > HandleVector;
370 typedef typename HandleVector::value_type value_type;
371 typedef typename HandleVector::size_type size_type;
373 typedef typename HandleVector::const_reference const_reference;
374 typedef typename HandleVector::iterator iterator;
375 typedef typename HandleVector::const_iterator const_iterator;
376 typedef typename HandleVector::reverse_iterator reverse_iterator;
377 typedef typename HandleVector::const_reverse_iterator const_reverse_iterator;
388 std::string myComponentType, std::string myParentName )
398 GaudiHandleArray(
const std::string& myComponentType,
const std::string& myParentName )
406 GaudiHandleArray& operator=(
const std::vector< std::string >& myTypesAndNamesList ) {
413 iterator it =
begin(), itEnd =
end();
414 for ( ; it != itEnd; ++it ) baseArray.push_back( &*it );
420 const_iterator it =
begin(), itEnd =
end();
421 for ( ; it != itEnd; ++it ) baseArray.push_back( &*it );
429 return m_handleArray.begin();
433 return m_handleArray.end();
436 const_iterator
begin()
const {
437 return m_handleArray.begin();
440 const_iterator
end()
const {
441 return m_handleArray.end();
444 const_iterator rbegin()
const {
445 return m_handleArray.rbegin();
448 const_iterator rend()
const {
449 return m_handleArray.rend();
452 size_type size()
const {
453 return m_handleArray.size();
456 void clear()
override {
457 m_handleArray.clear();
460 bool empty()
const override {
461 return m_handleArray.empty();
464 T& operator[](
int index ) {
465 return m_handleArray[index];
468 const T& operator[](
int index )
const {
469 return m_handleArray[index];
473 T* operator[](
const std::string&
name ) {
474 auto it = std::find_if(
begin(),
end(),[&](const_reference r) {
475 return r.name() ==
name;
477 return it !=
end() ? &*it :
nullptr;
481 const T* operator[](
const std::string& name )
const {
482 auto it = std::find_if(
begin(),
end(),[&](const_reference r) {
483 return r.name() ==
name;
485 return it !=
end() ? &*it :
nullptr;
491 virtual bool push_back(
const T& myHandle ) {
492 m_handleArray.push_back( myHandle );
498 for (
auto&
i : *
this) {
508 for (
auto&
i : *
this ) {
519 HandleVector m_handleArray;
526 #endif // ! GAUDIKERNEL_GAUDIHANDLE_H
Handle to be used in lieu of naked pointers to gaudis.
Define general base for Gaudi exception.
void setTypeAndName(std::string myTypeAndName)
The component "type/name" string.
std::vector< const GaudiHandleBase * > ConstBaseHandleArray
auto begin(reverse_wrapper< T > &w)
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
virtual ConstBaseHandleArray getBaseArray() const =0
Get a read-only vector of const GaudiHandleBase* pointing to the real handles.
virtual std::string pythonRepr() const =0
Python representation of handle, i.e.
std::vector< GaudiHandleBase * > BaseHandleArray
auto end(reverse_wrapper< T > &w)
bool setTypesAndNames(const std::vector< std::string > &myTypesAndNamesList)
Set the array of handles from list of "type/name" strings in .
This class is used for returning status codes from appropriate routines.
virtual void clear()=0
Clear the list of handles.
Base class of array's of various gaudihandles.
virtual std::string pythonPropertyClassName() const =0
The python class name for the property in the genconf-generated configurables.
virtual bool push_back(const std::string &myHandleTypeAndName)=0
Add a handle to the array with "type/name" given in .
virtual bool empty() const =0
Return whether the list of tools is empty.
std::string type() const
The concrete component class name: the part before the '/'.
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".
std::ostream & operator<<(std::ostream &os, const GaudiHandleInfo &handle)
const std::string & componentType() const
TO * reference(FROM *from)
T is the concrete handle type, e.g.