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"
24 GaudiHandleInfo(
const std::string& myComponentType,
const std::string& myParentName )
25 : m_componentType(myComponentType), m_parentName(myParentName)
33 const std::string& componentType()
const {
34 return m_componentType;
38 const std::string& propertyName()
const {
39 return m_propertyName;
43 void setPropertyName(
const std::string& propName ) {
44 m_propertyName = propName;
48 const std::string& parentName()
const {
55 virtual const std::string pythonPropertyClassName()
const = 0;
61 virtual const std::string pythonRepr()
const = 0;
67 std::string m_componentType;
68 std::string m_propertyName;
69 std::string m_parentName;
96 GaudiHandleBase(
const std::string& myTypeAndName,
const std::string& myComponentType,
97 const std::string& myParentName )
100 setTypeAndName(myTypeAndName);
107 std::string typeAndName()
const {
108 return m_typeAndName;
112 std::string
type()
const;
115 std::string name()
const;
119 return m_typeAndName.empty();
123 void setTypeAndName(
const std::string& myTypeAndName );
126 void setName(
const std::string& myName );
134 const std::string messageName()
const;
145 std::string m_typeAndName;
163 GaudiHandle(
const std::string& myTypeAndName,
const std::string& myComponentType,
164 const std::string& myParentName )
165 :
GaudiHandleBase(myTypeAndName, myComponentType, myParentName), m_pObject(0)
173 if ( m_pObject ) m_pObject->addRef();
178 GaudiHandleBase::operator=( other );
183 if ( m_pObject ) m_pObject->addRef();
190 if ( retrieve( m_pObject ).isFailure() ) {
208 bool isValid()
const {
209 return m_pObject || retrieve().isSuccess();
214 operator bool()
const {
238 T& operator*()
const {
243 T* operator->()
const {
249 std::string getDefaultType() {
253 std::string getDefaultName() {
255 if ( defName.empty() ) defName = getDefaultType();
272 void setDefaultTypeAndName() {
273 const std::string& myType = getDefaultType();
278 void setDefaultType() {
284 void assertObject()
const {
293 mutable T* m_pObject;
309 typedef std::vector< GaudiHandleBase* > BaseHandleArray;
310 typedef std::vector< const GaudiHandleBase* > ConstBaseHandleArray;
314 bool setTypesAndNames(
const std::vector< std::string >& myTypesAndNamesList );
318 const std::vector< std::string > typesAndNames()
const;
321 const std::vector< std::string > types()
const;
324 const std::vector< std::string >
names()
const;
328 const std::vector< std::string > getBaseInfos( std::string (
GaudiHandleBase::*pMemFunc)()
const )
const;
343 virtual bool push_back(
const std::string& myHandleTypeAndName ) = 0;
346 virtual void clear() = 0;
349 virtual bool empty()
const = 0;
353 virtual ConstBaseHandleArray getBaseArray()
const = 0;
357 virtual BaseHandleArray getBaseArray() = 0;
368 typedef std::vector< T > HandleVector;
369 typedef typename HandleVector::value_type value_type;
370 typedef typename HandleVector::size_type size_type;
372 typedef typename HandleVector::const_reference const_reference;
373 typedef typename HandleVector::iterator iterator;
374 typedef typename HandleVector::const_iterator const_iterator;
375 typedef typename HandleVector::reverse_iterator reverse_iterator;
376 typedef typename HandleVector::const_reverse_iterator const_reverse_iterator;
387 const std::string& myComponentType,
const std::string& myParentName )
397 GaudiHandleArray(
const std::string& myComponentType,
const std::string& myParentName )
405 GaudiHandleArray& operator=(
const std::vector< std::string >& myTypesAndNamesList ) {
412 iterator it = begin(), itEnd =
end();
413 for ( ; it != itEnd; ++it ) baseArray.push_back( &*it );
419 const_iterator it = begin(), itEnd =
end();
420 for ( ; it != itEnd; ++it ) baseArray.push_back( &*it );
428 return m_handleArray.begin();
432 return m_handleArray.end();
435 const_iterator begin()
const {
436 return m_handleArray.begin();
439 const_iterator
end()
const {
440 return m_handleArray.end();
443 const_iterator rbegin()
const {
444 return m_handleArray.rbegin();
447 const_iterator rend()
const {
448 return m_handleArray.rend();
451 size_type size()
const {
452 return m_handleArray.size();
455 virtual void clear() {
456 m_handleArray.clear();
459 virtual bool empty()
const {
460 return m_handleArray.empty();
463 T& operator[](
int index ) {
464 return m_handleArray[index];
467 const T& operator[](
int index )
const {
468 return m_handleArray[index];
472 T* operator[](
const std::string& name ) {
473 iterator it = begin(), itEnd =
end();
474 for ( ; it != itEnd; ++it ) {
475 if ( it->name() == name )
return &*it;
482 const T* operator[](
const std::string& name )
const {
483 const_iterator it = begin(), itEnd =
end();
484 for ( ; it != itEnd; ++it ) {
485 if ( it->name() == name )
return &*it;
494 virtual bool push_back(
const T& myHandle ) {
495 m_handleArray.push_back( myHandle );
501 iterator it = begin(), itEnd =
end();
502 for ( ; it != itEnd; ++it ) {
503 if ( it->retrieve().isFailure() ) {
514 iterator it = begin(), itEnd =
end();
515 for ( ; it != itEnd; ++it ) {
516 if ( it->release().isFailure() ) {
528 HandleVector m_handleArray;
535 #endif // ! GAUDIKERNEL_GAUDIHANDLE_H
Handle to be used in lieu of naked pointers to gaudis.
Define general base for Gaudi exception.
virtual const std::string pythonPropertyClassName() const =0
The python class name for the property in the genconf-generated configurables.
std::vector< const GaudiHandleBase * > ConstBaseHandleArray
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.
std::vector< GaudiHandleBase * > BaseHandleArray
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 bool push_back(const std::string &myHandleTypeAndName)=0
Add a handle to the array with "type/name" given in .
void setTypeAndName(const std::string &myTypeAndName)
The component "type/name" string.
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)
virtual const std::string pythonRepr() const =0
Python representation of handle, i.e.
const std::string & componentType() const
TO * reference(FROM *from)
T is the concrete handle type, e.g.