ATLAS Offline Software
Loading...
Searching...
No Matches
python.DualUseConfig Namespace Reference

Functions

 createComponent (typeName, instanceName, componentType)
 createAlgorithm (typeName, instanceName)
 createReentrantAlgorithm (typeName, instanceName)
 createPublicTool (typeName, toolName)
 createService (typeName, serviceName, sequence=None)
 addPrivateTool (alg, toolName, typeName)
 addPrivateToolInArray (alg, toolName, typeName)

Variables

bool useComponentAccumulator = False
bool isAthena = False

Function Documentation

◆ addPrivateTool()

python.DualUseConfig.addPrivateTool ( alg,
toolName,
typeName )
Helper function for declaring a private tool for a dual-use algorithm

This function is meant to be used in the analysis algorithm sequence
configurations for setting up private tools on the analysis algorithms.
Private tools that could then be configured with a syntax shared between
Athena and EventLoop.

Keyword arguments:
  alg      -- The algorithm to set up the private tool on
  toolName -- The property name with which the tool handle was declared on
              the algorithm. Also the instance name of the tool.
  typeName -- The C++ type name of the private tool

Definition at line 171 of file DualUseConfig.py.

171def addPrivateTool( alg, toolName, typeName ):
172 """Helper function for declaring a private tool for a dual-use algorithm
173
174 This function is meant to be used in the analysis algorithm sequence
175 configurations for setting up private tools on the analysis algorithms.
176 Private tools that could then be configured with a syntax shared between
177 Athena and EventLoop.
178
179 Keyword arguments:
180 alg -- The algorithm to set up the private tool on
181 toolName -- The property name with which the tool handle was declared on
182 the algorithm. Also the instance name of the tool.
183 typeName -- The C++ type name of the private tool
184 """
185
186 if isAthena:
187
188 # First try to set up the private tool in an "Athena way".
189
190 # Tokenize the tool's name. In case it is a subtool of a tool, or
191 # something possibly even deeper.
192 toolNames = toolName.split( '.' )
193
194 # Look up the component that we need to set up the private tool on:
195 component = alg
196 for tname in toolNames[ 0 : -1 ]:
197 component = getattr( component, tname )
198 pass
199
200 # Now look up the Athena configurable describing this tool:
201 from AthenaConfiguration.ComponentFactory import CompFactory
202 toolClass = CompFactory.getComp(typeName)
203
204 # Finally, set up the tool handle property:
205 setattr( component, toolNames[ -1 ], toolClass( toolNames[ -1 ] ) )
206
207 else:
208
209 # If that failed, then we should be in an EventLoop environment. So
210 # let's rely on the standalone specific formalism for setting up the
211 # private tool.
212 alg.addPrivateTool( toolName, typeName )
213 pass
214
215 return
216
217

◆ addPrivateToolInArray()

python.DualUseConfig.addPrivateToolInArray ( alg,
toolName,
typeName )
Helper function for declaring a private tool in an array for a
dual-use algorithm

This function is meant to be used in the analysis algorithm
sequence configurations for setting up private tools in arrays on
the analysis algorithms.  Private tools that could then be
configured with a syntax shared between Athena and EventLoop.

Keyword arguments:
  alg      -- The algorithm to set up the private tool on
  toolName -- The property name with which the tool handle was declared on
              the algorithm. Also the instance name of the tool.
  typeName -- The C++ type name of the private tool

Definition at line 218 of file DualUseConfig.py.

218def addPrivateToolInArray( alg, toolName, typeName ):
219 """Helper function for declaring a private tool in an array for a
220 dual-use algorithm
221
222 This function is meant to be used in the analysis algorithm
223 sequence configurations for setting up private tools in arrays on
224 the analysis algorithms. Private tools that could then be
225 configured with a syntax shared between Athena and EventLoop.
226
227 Keyword arguments:
228 alg -- The algorithm to set up the private tool on
229 toolName -- The property name with which the tool handle was declared on
230 the algorithm. Also the instance name of the tool.
231 typeName -- The C++ type name of the private tool
232
233 """
234
235 if isAthena:
236
237 # First try to set up the private tool in an "Athena way".
238
239 # Tokenize the tool's name. In case it is a subtool of a tool, or
240 # something possibly even deeper.
241 toolNames = toolName.split( '.' )
242
243 # Look up the component that we need to set up the private tool on:
244 component = alg
245 for tname in toolNames[ 0 : -1 ]:
246 component = getattr( component, tname )
247 pass
248
249 # Now look up the Athena configurable describing this tool:
250 from AthenaConfiguration.ComponentFactory import CompFactory
251 toolClass = CompFactory.getComp(typeName)
252
253 # Finally, set up the tool handle property:
254 getattr( component, toolNames[ -1 ] ).append (toolClass( toolNames[ -1 ] ) )
255 return getattr( component, toolNames[ -1 ] )
256
257 else:
258
259 # If that failed, then we should be in an EventLoop environment. So
260 # let's rely on the standalone specific formalism for setting up the
261 # private tool.
262 return alg.addPrivateToolInArray( toolName, typeName )
263
264 return

◆ createAlgorithm()

python.DualUseConfig.createAlgorithm ( typeName,
instanceName )
Create an algorithm configurable

This function is used to create an algorithm "configurable" in a dual-use
way, either returning an actual Athena configurable, or an appropriately
configured EL::AnaAlgorithmConfig instance.

Keyword arguments:
  typeName     -- The C++ type name of the algorithm
  instanceName -- The instance name of the algorithm to create

Definition at line 53 of file DualUseConfig.py.

53def createAlgorithm( typeName, instanceName ):
54 """Create an algorithm configurable
55
56 This function is used to create an algorithm "configurable" in a dual-use
57 way, either returning an actual Athena configurable, or an appropriately
58 configured EL::AnaAlgorithmConfig instance.
59
60 Keyword arguments:
61 typeName -- The C++ type name of the algorithm
62 instanceName -- The instance name of the algorithm to create
63 """
64 return createComponent( typeName, instanceName, 'AnaAlgorithm' )
65
66

◆ createComponent()

python.DualUseConfig.createComponent ( typeName,
instanceName,
componentType )
Create a generic configurable

This function is used to create an component "configurable" in a
dual-use way, either returning an actual Athena configurable, or
an appropriately configured PythonConfig instance.

Keyword arguments:
  typeName      -- The C++ type name of the component
  instanceName  -- The instance name of the component to create
  componentType -- The type of component in AnalysisBase

Definition at line 16 of file DualUseConfig.py.

16def createComponent( typeName, instanceName, componentType ):
17 """Create a generic configurable
18
19 This function is used to create an component "configurable" in a
20 dual-use way, either returning an actual Athena configurable, or
21 an appropriately configured PythonConfig instance.
22
23 Keyword arguments:
24 typeName -- The C++ type name of the component
25 instanceName -- The instance name of the component to create
26 componentType -- The type of component in AnalysisBase
27
28 """
29
30 if isAthena:
31 # Try to get a configurable for this C++ class "from Athena".
32 # If this succeeds, we're obviously in an Athena environment.
33
34 # Look up the Athena configurable of this component:
35 from AthenaConfiguration.ComponentFactory import CompFactory
36 componentClass = CompFactory.getComp(typeName)
37
38 # Return the object:
39 return componentClass( instanceName )
40
41 else:
42 # If that didn't work, then apparently we're in an EventLoop
43 # environment, so we need to use PythonConfig as the base class
44 # for the user's class.
45 from AnaAlgorithm.PythonConfig import PythonConfig
46 component = PythonConfig( '%s/%s' % ( typeName, instanceName ) )
47 component.setComponentType( componentType )
48 return component
49
50 pass
51
52

◆ createPublicTool()

python.DualUseConfig.createPublicTool ( typeName,
toolName )
Helper function for setting up a public tool for a dual-use algorithm

This function is meant to be used in the analysis algorithm sequence
configurations for setting up public tools on the analysis algorithms.
Public tools that could then be configured with a syntax shared between
Athena and EventLoop.

Keyword arguments:
  typeName -- The C++ type name of the private tool
  toolName -- The property name with which the tool handle was declared on
              the algorithm. Also the instance name of the tool.

Definition at line 81 of file DualUseConfig.py.

81def createPublicTool( typeName, toolName ):
82 """Helper function for setting up a public tool for a dual-use algorithm
83
84 This function is meant to be used in the analysis algorithm sequence
85 configurations for setting up public tools on the analysis algorithms.
86 Public tools that could then be configured with a syntax shared between
87 Athena and EventLoop.
88
89 Keyword arguments:
90 typeName -- The C++ type name of the private tool
91 toolName -- The property name with which the tool handle was declared on
92 the algorithm. Also the instance name of the tool.
93 """
94
95 if isAthena:
96 # Look up the Athena configurable of this tool:
97 from AthenaConfiguration.ComponentFactory import CompFactory
98 toolClass = CompFactory.getComp( typeName )
99
100 if useComponentAccumulator:
101 # ComponentAccumulator will add the tool to ToolSvc
102 # Avoid importing AthenaCommon.AppMgr in a CA Athena job
103 # as it modifies Gaudi behaviour
104 return toolClass( toolName )
105 else:
106 # Add an instance of the tool to the ToolSvc:
107 from AthenaCommon.AppMgr import ToolSvc
108 if not hasattr( ToolSvc, toolName ):
109 ToolSvc += toolClass( toolName )
110 pass
111
112 # Return the member on the ToolSvc:
113 return getattr( ToolSvc, toolName )
114
115 else:
116 # If that didn't work, then apparently we're in an EventLoop
117 # environment, so let's use the EventLoop specific formalism.
118 return createComponent( typeName, toolName, 'AsgTool' )
119
120

◆ createReentrantAlgorithm()

python.DualUseConfig.createReentrantAlgorithm ( typeName,
instanceName )
Create a reentrant algorithm configurable

This function is used to create an algorithm "configurable" in a dual-use
way, either returning an actual Athena configurable, or an appropriately
configured EL::AnaAlgorithmConfig instance.

Keyword arguments:
  typeName     -- The C++ type name of the algorithm
  instanceName -- The instance name of the algorithm to create

Definition at line 67 of file DualUseConfig.py.

67def createReentrantAlgorithm( typeName, instanceName ):
68 """Create a reentrant algorithm configurable
69
70 This function is used to create an algorithm "configurable" in a dual-use
71 way, either returning an actual Athena configurable, or an appropriately
72 configured EL::AnaAlgorithmConfig instance.
73
74 Keyword arguments:
75 typeName -- The C++ type name of the algorithm
76 instanceName -- The instance name of the algorithm to create
77 """
78 return createComponent( typeName, instanceName, 'AnaReentrantAlgorithm' )
79
80

◆ createService()

python.DualUseConfig.createService ( typeName,
serviceName,
sequence = None )
Helper function for setting up a service for a dual-use algorithm

This function is meant to be used to set up services in a dual-use
manner, particularly for the common CP algorithms.  This allows to
use the same syntax in EventLoop and Athena, hiding the
differences internally.  Since in EventLoop the service gets added
to a sequence (but in Athena does not), that sequence needs to be
passed into this function.

Keyword arguments:
  typeName -- The C++ type name of the service
  serviceName -- The name with which the service handle was configured on
                the algorithm. Also the instance name of the service.
  sequence -- an optional argument of an algorithm sequence to add it to
              in EventLoop (ignored in Athena)

Definition at line 121 of file DualUseConfig.py.

121def createService( typeName, serviceName, sequence=None ):
122 """Helper function for setting up a service for a dual-use algorithm
123
124 This function is meant to be used to set up services in a dual-use
125 manner, particularly for the common CP algorithms. This allows to
126 use the same syntax in EventLoop and Athena, hiding the
127 differences internally. Since in EventLoop the service gets added
128 to a sequence (but in Athena does not), that sequence needs to be
129 passed into this function.
130
131 Keyword arguments:
132 typeName -- The C++ type name of the service
133 serviceName -- The name with which the service handle was configured on
134 the algorithm. Also the instance name of the service.
135 sequence -- an optional argument of an algorithm sequence to add it to
136 in EventLoop (ignored in Athena)
137
138 """
139
140 if isAthena:
141
142 # Look up the Athena configurable of this tool:
143 from AthenaConfiguration.ComponentFactory import CompFactory
144 serviceClass = CompFactory.getComp( typeName )
145
146 if useComponentAccumulator:
147 # ComponentAccumulator will add the tool to ToolSvc
148 # Avoid importing AthenaCommon.AppMgr in a CA Athena job
149 # as it modifies Gaudi behaviour
150 return serviceClass( serviceName )
151 else:
152 # Add an instance of the service to the ServiceMgr:
153 from AthenaCommon.AppMgr import ServiceMgr
154 if not hasattr( ServiceMgr, serviceName ):
155 ServiceMgr += serviceClass( serviceName )
156 pass
157
158 # Return the member on the ServiceMgr:
159 return getattr( ServiceMgr, serviceName )
160
161 else:
162 # If that didn't work, then apparently we're in an EventLoop
163 # environment, so let's use the EventLoop specific formalism.
164 service = createComponent( typeName, serviceName, 'AsgService' )
165 if sequence is not None :
166 sequence += service
167 pass
168 return service
169
170

Variable Documentation

◆ isAthena

bool python.DualUseConfig.isAthena = False

Definition at line 4 of file DualUseConfig.py.

◆ useComponentAccumulator

python.DualUseConfig.useComponentAccumulator = False

Definition at line 3 of file DualUseConfig.py.