3 import GaudiConfig2.semantics
4 from GaudiKernel.GaudiHandles
import PrivateToolHandleArray, PublicToolHandle, ServiceHandle
5 from GaudiKernel.DataHandle
import DataHandle
8 from collections.abc
import Sequence
13 Extend the sequence-semantics with a merge-method that appends the lists
14 Use 'appendList<T>' as fifth parameter of the Gaudi::Property<T> constructor
15 to invoke this merging method. The template parameter is important, also
16 in the string that forms the fifth argument.
18 __handled_types__ = (re.compile(
r"^appendList<.*>$"),)
20 super(AppendListSemantics, self).
__init__(cpp_type)
28 Extend the mapping-semantics with a merge-method that merges two mappings as long as they do not have different values for the same key
29 Use 'mapMergeNoReplace<T>' as fifth parameter of the Gaudi::Property<T> constructor
30 to invoke this merging method.
32 __handled_types__ = (re.compile(
r"^mapMergeNoReplace<.*>$"),)
34 super(MapMergeNoReplaceSemantics, self).
__init__(cpp_type)
38 if k
in a
and b[k] != a[k]:
39 raise ValueError(
'conflicting values in map under key %r and %r %r' % (k, b[k], a[k]))
46 Semantics for all data handle keys (Read, Write, Decor, Cond).
48 __handled_types__ = (re.compile(
r"SG::.*HandleKey<.*>$"),)
53 self.
_type =
next(GaudiConfig2.semantics.extract_template_args(cpp_type))
56 if cpp_type.startswith(
"SG::Read"):
58 elif cpp_type.startswith(
"SG::Write"):
61 raise TypeError(f
"C++ type {cpp_type} not supported")
64 if isinstance(value, DataHandle):
66 elif isinstance(value, str):
69 raise TypeError(f
"cannot assign {value!r} ({type(value)}) to {self.name}"
70 ", expected string or DataHandle")
76 Treat VarHandleKeyArrays like arrays of strings
78 __handled_types__ = (
"SG::VarHandleKeyArray",)
81 """Semantics for an item (DataHandle) in a VarHandleKeyArray converting to string"""
87 if isinstance(value, DataHandle):
89 elif isinstance(value, str):
92 raise TypeError(f
"cannot assign {value!r} ({type(value)}) to {self.name}"
93 ", expected string or DataHandle")
107 Private alg-tools need recusive merging (de-duplication):
109 __handled_types__ = (
"PrivateToolHandle",)
111 super(ToolHandleSemantics, self).
__init__(cpp_type)
116 if a
is None or a==
'':
return b
117 if b
is None or b==
'':
return a
122 ServiceHandles (and the deprecated PublicToolHandles) are assigned as strings
124 __handled_types__ = (
"PublicToolHandle",
"ServiceHandle")
127 super(PublicHandleSemantics, self).
__init__(cpp_type)
130 return value.typeAndName
133 if isinstance(value,str):
139 if not hasattr(value,
"__component_type__"):
140 raise TypeError(
"Got {}, expected Tool or Service in assignment to {}".
format(
type(value),self.name))
142 if value.__component_type__
not in (
'Service',
'AlgTool'):
143 raise TypeError(
'{} expected, got {!r} in assignemnt to {}'.\
144 format(value.__component_type__,value, self.name))
150 return "{}/{}".
format(value.__cpp_type__,value.name)
154 Semantics for arrays of string-based pointers to components defined elsewhere
156 __handled_types__ = (
"PublicToolHandleArray",
"ServiceHandleArray")
158 super(PublicHandleArraySemantics, self).
__init__(cpp_type)
161 if not isinstance(value,Sequence)
and not isinstance(value,set):
166 if isinstance(v,GaudiConfig2._configurables.Configurable):
167 if v.__component_type__
not in (
'Service',
'AlgTool'):
168 raise TypeError(
'{} expected, got {!r} in assignemnt to {}'.\
169 format(value.__component_type__,v, self.name))
171 newValue.append(
"{}/{}".
format(v.__cpp_type__,v.name))
173 elif isinstance(v,(PublicToolHandle,ServiceHandle)):
174 newValue.append(
"{}/{}".
format(v.getType(),v.getName()))
176 elif isinstance(v,str):
181 raise TypeError(
'Configurable expected, got {!r} in assignment to {}'.\
186 return copy.copy(value)
200 Private alg-tools need recusive merging (de-duplication):
202 __handled_types__ = (
"PrivateToolHandleArray",)
204 super(ToolHandleArraySemantics, self).
__init__(cpp_type)
207 return copy.copy(value)
210 if not isinstance(value,PrivateToolHandleArray):
212 value=PrivateToolHandleArray(value)
219 a.__getitem__(bTool.getName()).
merge(bTool)
226 __handled_types__ = (
"SubAlgorithm",)
228 super(SubAlgoSemantics, self).
__init__(cpp_type)
231 if not isinstance(value,Sequence):
235 if v.__component_type__ !=
'Algorithm':
236 raise TypeError(
'Algorithm expected, got {!r} in assignemnt to {}'.\
247 from AthenaServices.ItemListSemantics
import OutputStreamItemListSemantics
249 GaudiConfig2.semantics.SEMANTICS.append(AppendListSemantics)
250 GaudiConfig2.semantics.SEMANTICS.append(VarHandleKeySemantics)
251 GaudiConfig2.semantics.SEMANTICS.append(VarHandleArraySematics)
252 GaudiConfig2.semantics.SEMANTICS.append(ToolHandleSemantics)
253 GaudiConfig2.semantics.SEMANTICS.append(ToolHandleArraySemantics)
254 GaudiConfig2.semantics.SEMANTICS.append(PublicHandleSemantics)
255 GaudiConfig2.semantics.SEMANTICS.append(PublicHandleArraySemantics)
256 GaudiConfig2.semantics.SEMANTICS.append(SubAlgoSemantics)
257 GaudiConfig2.semantics.SEMANTICS.append(MapMergeNoReplaceSemantics)
258 GaudiConfig2.semantics.SEMANTICS.append(OutputStreamItemListSemantics)