4 "PublicToolHandle",
"PrivateToolHandle",
8 "PublicToolHandleArray",
"PrivateToolHandleArray",
10 __version__ =
"$Revision: 1.6 $"
11 __doc__ =
"""The python module holding python bindings to XyzHandles"""
13 from os
import linesep
16 componentType =
"Unspecified"
21 if hasattr(typeAndName,
"toStringProperty"):
23 typeAndName = typeAndName.toStringProperty()
24 if type(typeAndName) != str:
25 raise TypeError(
"Argument to %s must be a string. Got a %s instead" % \
26 ( self.__class__.__name__,
type(typeAndName).__name__) )
44 """Get the 'type' part of the \"type/name\" string."""
45 slash = self.typeAndName.find(
'/')
54 """Get the 'name' part of the \"type/name\" string.
55 If only a type is given, this will be returned as the name.
56 If the \"type/name\" string is empty, it will return an emtpy string."""
57 slash = self.typeAndName.find(
'/')
73 componentType =
"AlgTool"
77 GaudiHandle.__init__( self, toolTypeAndName )
82 componentType =
"AlgTool"
86 GaudiHandle.__init__( self, toolTypeAndName )
91 componentType =
"Service"
95 GaudiHandle.__init__( self, serviceName )
101 """A list of GaudiHandles. Only handles of one type are allowed, as specified by self.__class__.handleType
103 __slots__ = (
'typesAndNames' )
107 if typesAndNames
is None: typesAndNames = []
110 if type(typesAndNames) != list:
111 raise TypeError(
"Argument to %s must be a list. Got a %s instead" % \
112 ( self.__class__.__name__,
type(typesAndNames).__name__) )
114 for tn
in typesAndNames: self.
append( tn )
117 """Return class name with list of type/name strings as argument"""
118 rep = self.__class__.__name__ +
'(['
120 rep += repr(h.toStringProperty()) +
','
122 if rep[-1] ==
',': rep = rep[:-1]
126 """Print entries, one per line"""
127 shortName = self.__class__.__name__
128 return "%s:%s" % (shortName, linesep + linesep.join([str(s)
for s
in self]))
131 if type(index) == str:
134 if h.getName() == index:
136 raise IndexError(
"%s does not have a %s with instance name %s" % \
137 (self.__class__.__name__, self.handleType.componentType, index) )
139 return list.__getitem__(self,index)
142 super( GaudiHandleArray, self ).
__delitem__( self.index(self[key]) )
145 arrayType =
type(array)
146 if arrayType == list
or arrayType ==
type(self):
150 raise TypeError(
"Can not add a %s to a %s" % (arrayType.__name__, self.__class__.__name__) )
155 """Only allow appending compatible types. It accepts a string, a handle or a configurable."""
156 if type(value) == str:
158 value = self.__class__.handleType(value)
159 elif type(value) == self.__class__.handleType:
161 elif isinstance( value, GaudiHandle ):
163 raise TypeError(
"Can not add a %s to a %s" % (value.__class__.__name__, self.__class__.__name__) )
164 elif value.getGaudiType() != self.__class__.handleType.componentType:
166 raise TypeError(
"Can not append %s (%s) to a %s" % \
167 (value.__class__.__name__, value.getGaudiType(), self.__class__.__name__) )
168 elif hasattr(value,
'isPublic'):
170 pop = value.isPublic()
and 'Public' or 'Private'
171 if value.isPublic() != self.__class__.handleType.isPublic:
172 raise TypeError(
"Can not append %s (%s %s) to a %s" % \
173 (value.__class__.__name__, pop, value.getGaudiType(), self.__class__.__name__) )
180 list.append( self, value )
182 print "%s WARNING %r with instance name %r already in list. Not adding %r" % \
183 (self.__class__.__name__, oldValue, oldValue.getName(), value)
187 return self.__class__.handleType.isPublic
196 rep += repr( v.toStringProperty() ) +
','
198 if rep[-1] ==
',': rep = rep[:-1]
211 handleType = ServiceHandle
214 GaudiHandleArray.__init__( self, serviceTypesAndNames )
218 handleType = PublicToolHandle
221 GaudiHandleArray.__init__( self, toolTypesAndNames )
226 handleType = PrivateToolHandle
229 GaudiHandleArray.__init__( self, toolTypesAndNames )