11 from __future__
import print_function
21 "PublicToolHandleArray",
22 "PrivateToolHandleArray",
24 __doc__ =
"""The python module holding python bindings to XyzHandles"""
28 componentType =
"Unspecified"
33 if hasattr(typeAndName,
"toStringProperty"):
35 typeAndName = typeAndName.toStringProperty()
36 if not isinstance(typeAndName, str):
38 "Argument to %s must be a string. Got a %s instead"
39 % (self.__class__.__name__,
type(typeAndName).__name__)
61 """Get the 'type' part of the \"type/name\" string."""
71 """Get the 'name' part of the \"type/name\" string.
72 If only a type is given, this will be returned as the name.
73 If the \"type/name\" string is empty, it will return an emtpy string."""
94 componentType =
"AlgTool"
98 GaudiHandle.__init__(self, toolTypeAndName)
103 componentType =
"AlgTool"
107 GaudiHandle.__init__(self, toolTypeAndName)
112 componentType =
"Service"
116 GaudiHandle.__init__(self, serviceName)
125 """A list of GaudiHandles. Only handles of one type are allowed, as specified by self.__class__.handleType"""
130 if typesAndNames
is None:
134 if not isinstance(typesAndNames, list):
136 "Argument to %s must be a list. Got a %s instead"
137 % (self.__class__.__name__,
type(typesAndNames).__name__)
140 for tn
in typesAndNames:
144 """Return class name with list of type/name strings as argument"""
146 self.__class__.__name__
148 +
",".join(repr(h.toStringProperty())
for h
in self)
153 """Print in a form which can be parsed"""
160 if isinstance(index, str):
163 if h.getName() == index:
166 "%s does not have a %s with instance name %s"
167 % (self.__class__.__name__, self.
handleType.componentType, index)
170 return list.__getitem__(self, index)
173 super(GaudiHandleArray, self).
__delitem__(self.index(self[key]))
176 if isinstance(array, (list,
type(self))):
181 "Can not add a %s to a %s" % (
type(array).__name__,
type(self).__name__)
187 """Only allow appending compatible types. It accepts a string, a handle or a configurable."""
188 if isinstance(value, str):
191 elif isinstance(value, self.__class__.handleType):
193 elif isinstance(value, GaudiHandle):
196 "Can not add a %s to a %s"
197 % (value.__class__.__name__, self.__class__.__name__)
199 elif value.getGaudiType() != self.__class__.handleType.componentType:
202 "Can not append %s (%s) to a %s"
204 value.__class__.__name__,
205 value.getGaudiType(),
206 self.__class__.__name__,
209 elif hasattr(value,
"isPublic"):
211 pop = value.isPublic()
and "Public" or "Private"
212 if value.isPublic() != self.__class__.handleType.isPublic:
214 "Can not append %s (%s %s) to a %s"
216 value.__class__.__name__,
218 value.getGaudiType(),
219 self.__class__.__name__,
228 list.append(self, value)
231 "%s WARNING %r with instance name %r already in list. Not adding %r"
232 % (self.__class__.__name__, oldValue, oldValue.getName(), value)
236 return self.__class__.handleType.isPublic
242 return "[" +
",".join(repr(v.toStringProperty())
for v
in self) +
"]"
247 handleType = ServiceHandle
250 GaudiHandleArray.__init__(self, serviceTypesAndNames)
255 handleType = PublicToolHandle
258 GaudiHandleArray.__init__(self, toolTypesAndNames)
263 handleType = PrivateToolHandle
266 GaudiHandleArray.__init__(self, toolTypesAndNames)