ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalSimAlgCfg_local Namespace Reference

Functions

 GlobalSimulationAlgCfg (flags, dump, algName='GlobalSimTestAlg', OutputLevel=DEBUG)

Variables

 logger = logging.getLogger(__name__)
dict read_handles
dict write_handles

Function Documentation

◆ GlobalSimulationAlgCfg()

GlobalSimAlgCfg_local.GlobalSimulationAlgCfg ( flags,
dump,
algName = 'GlobalSimTestAlg',
OutputLevel = DEBUG )

Definition at line 91 of file GlobalSimAlgCfg_local.py.

94 OutputLevel=DEBUG):
95
96 logger.setLevel(OutputLevel)
97 cfg = ComponentAccumulator()
98
99 fn = os.environ.get('GS_CFG_FILE', None)
100 if fn is None:
101 logger.error('Please set export environment variable GS_CFG_FILE'\
102 'with the name of a GloblSim config xml file')
103
104
105 logger.info('GlobalSim local config, cfg file:' + fn)
106
107
108 def str_id(toolEl):
109 """ obtain a string id for each AlgTool"""
110
111 a_class = toolEl.attrib['class']
112 a_name = toolEl.attrib['name']
113 return '/'.join((a_class, a_name))
114
115 def classname_from_fullname(fullname):
116 return fullname.split('/')[0]
117
118
119 def configure_algtool(toolEl):
120 """
121 Set the AlgTool properties from configure file information.
122 Datahandles are not processed here.
123 """
124
125 a_class = toolEl.attrib['class']
126 a_name = toolEl.attrib['name']
127 prop_names = []
128 factory = getattr(CompFactory.GlobalSim, a_class)
129 tool = factory(a_name)
130
131 type_factories = {'int': int,
132 'float': float,
133 'str': str}
134
135 for prop in toolEl.iter('property'):
136 name = prop.attrib['name']
137 value = prop.attrib['value']
138 ptype = prop.attrib.get("type", None)
139 if ptype is not None:
140 value = type_factories[ptype](value)
141 setattr(tool, name, value)
142 prop_names.append(name)
143
144 logger.debug('configure_algtool: ' + str(tool))
145 return tool
146
147
148 def fill_alg_ids(root):
149 """
150 Assign an index to each AlgTool instance specified by
151 the configuration file.
152
153 Return this information in a dictionary.
154 """
155
156 alg_ids = {}
157 alg_ind = 1
158
159 alg_tools = {}
160
161 for toolType in ('TOBWriters', 'TIPWriters'):
162 for writerEl in root.iter(toolType):
163 for toolEl in writerEl.iter('AlgTool'):
164 f_name = str_id(toolEl)
165 if f_name in alg_ids:
166 raise AssertionError('Algorithm duplicated in ' + fn)
167 alg_ids[f_name] = alg_ind
168 alg_tools[alg_ind] = (configure_algtool(toolEl), toolType)
169 alg_ind += 1
170 return alg_ids, alg_tools, alg_ind
171
172 def fill_input_slots(root, alg_ids):
173 """
174 Create a dictionary
175 {par_alg_id:int || {input_slot:str || child_alg_id:int}}
176
177 Where is a generic name for the input location, eg "in0", and
178 is used by the config file. The actual location is
179 currently obtained using the read_handles dictionary at the top
180 of this file.
181 """
182
183 input_slots = defaultdict(dict)
184
185 for toolEl in root.iter('AlgTool'):
186 par_full_name = str_id(toolEl)
187 par_id = alg_ids[par_full_name]
188
189 for childEl in toolEl.iter('child'):
190 child_full_name = str_id(childEl)
191 child_id = alg_ids[child_full_name]
192 slot = childEl.attrib.get('slot', None)
193 if slot is None:
194 msg = ['No slot information for ',
195 par_full_name,
196 ' child ',
197 child_full_name]
198 raise AssertionError(' '.join(msg))
199
200 input_slots[par_id][child_id] = slot
201
202 return input_slots
203
204
205 def make_digraph(alg_ids, V):
206 """
207 Construct an Algtool Digraph.
208
209 Obtain parent child relations from the config XML file.
210
211 The graph knows only about
212 the AlgTool insances's indices, and so works from a
213 dictionary that associates the AlgoTool name (string) to its
214
215 ineger index.
216 """
217
218
219 logger.debug('make_digraph alg_ids: ', alg_ids)
220 logger.debug('make_digraph: V ' + str(V))
221
222 # Create an empty DAG
223 G = Digraph(V)
224
225
226 for toolType in ('TOBWriters', 'TIPWriters'):
227
228 for writerEl in root.iter(toolType):
229 for toolEl in writerEl.iter('AlgTool'):
230 f_name = str_id(toolEl)
231 logger.debug('make_digraph: toolType ' + toolType +
232 ' ' + f_name)
233
234
235 par_id = alg_ids[f_name]
236
237 for childEl in toolEl.iter('child'):
238 f_c_name = str_id(childEl)
239 if f_c_name not in alg_ids:
240 raise AssertionError('child ' + f_c_name +
241 ' not in ' + fn)
242
243 G.addEdge(par_id, alg_ids[f_c_name])
244
245 R = G.reverse()
246 roots = [n for n in range(R.V) if not R.adj(n) and n != 0]
247 return G, roots
248
249 def set_SGout_locations(tools):
250 """
251 Set the StoreGate locations to be written to. As the
252 same Algorithm may have > 1 instance, ensure that the
253 write locations differ.
254 """
255 # set the Storegate location each tool writes to.
256
257 out_index = 0
258 for indx, (tool, tooltype) in tools.items():
259 class_name = tool.__class__.__name__
260 handle = write_handles.get(class_name, None)
261
262 if handle is not None:
263 setattr(tool, handle, 'GlobalSim_'+str(out_index))
264 out_index += 1
265
266
267 def set_SGin_locations(tools, alg_ids, input_slots, G):
268 """"
269
270 Set locations read from by each Algorithm according to the
271 call graph G.
272
273 NOTE: currently we assume a tool has one output location
274 and one input location, which allows only "narrow chains".
275 This will be extended to allow multiple children in the near future.
276
277 alg_ids is a str:int map
278 tools is a int : (tool, toolType) map
279 """
280
281 for nid in range(1, G.V):
282 parent = tools[nid][0]
283 child_ids = G.adj(nid)
284 if len(child_ids) == 0:
285 continue
286
287 for child_id in child_ids:
288 slot = input_slots[nid][child_id] # eg 'in0'
289 child_tool = tools[child_id][0] # tools.values: (tool, tooltype)
290 w_handle_name = write_handles[child_tool.__class__.__name__]
291 read_handle = read_handles[parent.__class__.__name__][slot]
292 read_from = getattr(child_tool, w_handle_name)
293 setattr(parent, read_handle, read_from)
294
295
296 # parse the config XML file
297
298 tree = ET.parse(fn)
299 root = tree.getroot()
300
301 # extract tool information from the XML file
302 # alg_ids: str : int
303 # alg_tools: int : (tool, toolType), toolType is a string
304 # V number of vertices (including unused root vertex = 0
305 alg_ids, alg_tools, V= fill_alg_ids(root)
306 input_slots = fill_input_slots(root, alg_ids)
307 G, roots = make_digraph(alg_ids, V)
308 logger.debug('call graph ' + str(G))
309
310 topological = Topological(G, roots=roots)
311 if not topological.isDAG(): raise AssertionError(
312 'Call graph is not a DAG')
313
314 index_order = topological.order()
315 set_SGout_locations(tools=alg_tools)
316 set_SGin_locations(tools=alg_tools, alg_ids = alg_ids,
317 input_slots=input_slots, G=G)
318
319 logger.debug('DAG: ' + str(G))
320 logger.debug('order: ' + str(index_order))
321
322
323 toolType = 'TOBWriters'
324 orderedTOBWriters = [alg_tools[i][0] for i in index_order
325 if alg_tools[i][1] == toolType]
326
327 msg = [str(tool) for tool in orderedTOBWriters]
328 logger.debug(toolType + ': ' + '\n'.join(msg))
329
330
331 toolType = 'TIPWriters'
332 orderedTIPWriters = [alg_tools[i][0] for i in index_order
333 if alg_tools[i][1] == toolType]
334
335 tools = [alg_tools[i][0] for i in index_order]
336 msg = ['GlobalSim tool IO dump:']
337 for tool in tools:
338
339 tname = tool.__class__.__name__ + '/' + tool.name
340
341 logger.debug('GS tool name ' + tname)
342 logger.debug('GS r_handle str(tool)' , str(tool))
343
344 handle_name = read_handles.get(tool.__class__.__name__, None)
345 if handle_name is None:
346 logger.debug('GS r_handle not in table')
347 else:
348
349 logger.debug('GS r_handle from table: ', handle_name)
350 logger.debug('GS r_handle loc from tool: ' + tname + ' ' +
351 str(getattr(tool, handle_name['in0'])))
352
353 handle_name = write_handles.get(tool.__class__.__name__, None)
354 if handle_name is None:
355 logger.debug('GS w_handle not in table')
356 else:
357 logger.debug('GS w_handle from table: ' + handle_name)
358 logger.debug('GS w_handle loc from tool: ' + tname + ' ' +
359 str(getattr(tool, handle_name)))
360
361
362 alg = CompFactory.GlobalSim.GlobalSimulationAlg(algName)
363 alg.globalsim_algs = orderedTOBWriters
364 alg.TIPwriters = orderedTIPWriters
365 alg.OutputLevel = OutputLevel
366 alg.enableDumps = dump
367
368
369 from TrigCaloRec.TrigCaloRecConfig import hltCaloCellSeedlessMakerCfg
370 cfg.merge(hltCaloCellSeedlessMakerCfg(flags, roisKey=''))
371
372 cfg.addEventAlgo(alg)
373 return cfg

Variable Documentation

◆ logger

GlobalSimAlgCfg_local.logger = logging.getLogger(__name__)

Definition at line 50 of file GlobalSimAlgCfg_local.py.

◆ read_handles

dict GlobalSimAlgCfg_local.read_handles
Initial value:
1= {
2 'eFexCvtrAlgTool': {'in0': 'eFexEMRoIKey'},
3 'gFexRhoCvtrAlgTool': {'in0': 'gFexJetRoIKey'},
4 'Egamma1BDTAlgTool': {'in0': 'LArNeighborhoodTOBContainerReadKey'},
5 'GlobalCellTowerAlgTool': {'in0': 'GlobalLArCellsKey'},
6 'GlobalJet1AlgTool': {'in0': 'GlobalCellTowersKey'},
7 'eEmMultAlgTool': {'in0': 'eEmTOBs'},
8 'eEmEg1BDTMultAlgTool': {'in0': 'eEmEg1BDTTOBContainerKey'},
9 'CommonMultAlgTool': {'in0': 'CommonTOBsKey'},
10 }

Definition at line 72 of file GlobalSimAlgCfg_local.py.

◆ write_handles

dict GlobalSimAlgCfg_local.write_handles
Initial value:
1= {
2 'eFexCvtrAlgTool': 'eEmTOBs',
3 'gFexRhoCvtrAlgTool': 'gFexRhoTOBs',
4 'Egamma1BDTAlgTool': 'eEmEg1BDTTOBContainerKey',
5 'GlobalCellTowerAlgTool': 'GlobalCellTowersKey',
6 'GlobalJet1AlgTool': 'GlobalJet1JetsKey',
7}

Definition at line 83 of file GlobalSimAlgCfg_local.py.