94 algName='GlobalSimTestAlg',
97 logger.setLevel(OutputLevel)
98 cfg = ComponentAccumulator()
101 fn = os.environ.get(
'GS_CFG_FILE',
None)
103 logger.error(
'Please set export environment variable GS_CFG_FILE'
104 ' with the name of a GlobalSim config xml file')
107 logger.info(
'GlobalSim local config, cfg file: ' + fn)
110 """ obtain a string id for each AlgTool"""
112 a_class = toolEl.attrib[
'class']
113 a_name = toolEl.attrib[
'name']
114 return '/'.join((a_class, a_name))
116 def classname_from_fullname(fullname):
117 return fullname.split(
'/')[0]
120 def configure_algtool(toolEl):
122 Set the AlgTool properties from configure file information.
123 Datahandles are not processed here.
126 a_class = toolEl.attrib[
'class']
127 a_name = toolEl.attrib[
'name']
129 factory = getattr(CompFactory.GlobalSim, a_class)
130 tool = factory(a_name)
132 type_factories = {
'int': int,
136 for prop
in toolEl.iter(
'property'):
137 name = prop.attrib[
'name']
138 value = prop.attrib[
'value']
139 ptype = prop.attrib.get(
"type",
None)
140 if ptype
is not None:
141 value = type_factories[ptype](value)
142 setattr(tool, name, value)
143 prop_names.append(name)
145 logger.debug(
'configure_algtool: ' + str(tool))
149 def fill_alg_ids(root):
151 Assign an index to each AlgTool instance specified by
152 the configuration file.
154 Return this information in a dictionary.
162 for toolType
in (
'TOBWriters',
'TIPWriters'):
163 for writerEl
in root.iter(toolType):
164 for toolEl
in writerEl.iter(
'AlgTool'):
165 f_name = str_id(toolEl)
166 if f_name
in alg_ids:
167 raise AssertionError(
'Algorithm duplicated in ' + fn)
168 alg_ids[f_name] = alg_ind
169 alg_tools[alg_ind] = (configure_algtool(toolEl), toolType)
171 return alg_ids, alg_tools, alg_ind
173 def fill_input_slots(root, alg_ids):
176 {par_alg_id:int || {input_slot:str || child_alg_id:int}}
178 Where is a generic name for the input location, eg "in0", and
179 is used by the config file. The actual location is
180 currently obtained using the read_handles dictionary at the top
184 input_slots = defaultdict(dict)
186 for toolEl
in root.iter(
'AlgTool'):
187 par_full_name = str_id(toolEl)
188 par_id = alg_ids[par_full_name]
190 for childEl
in toolEl.iter(
'child'):
191 child_full_name = str_id(childEl)
192 child_id = alg_ids[child_full_name]
193 slot = childEl.attrib.get(
'slot',
None)
195 msg = [
'No slot information for ',
199 raise AssertionError(
' '.join(msg))
201 input_slots[par_id][child_id] = slot
206 def make_digraph(alg_ids, V):
208 Construct an Algtool Digraph.
210 Obtain parent child relations from the config XML file.
212 The graph knows only about
213 the AlgTool insances's indices, and so works from a
214 dictionary that associates the AlgoTool name (string) to its
220 logger.debug(
'make_digraph alg_ids: ', alg_ids)
221 logger.debug(
'make_digraph: V ' + str(V))
227 for toolType
in (
'TOBWriters',
'TIPWriters'):
229 for writerEl
in root.iter(toolType):
230 for toolEl
in writerEl.iter(
'AlgTool'):
231 f_name = str_id(toolEl)
232 logger.debug(
'make_digraph: toolType ' + toolType +
236 par_id = alg_ids[f_name]
238 for childEl
in toolEl.iter(
'child'):
239 f_c_name = str_id(childEl)
240 if f_c_name
not in alg_ids:
241 raise AssertionError(
'child ' + f_c_name +
244 G.addEdge(par_id, alg_ids[f_c_name])
247 roots = [n
for n
in range(R.V)
if not R.adj(n)
and n != 0]
250 def set_SGout_locations(tools):
252 Set the StoreGate locations to be written to. As the
253 same Algorithm may have > 1 instance, ensure that the
254 write locations differ.
259 for indx, (tool, tooltype)
in tools.items():
260 class_name = tool.__class__.__name__
261 handle = write_handles.get(class_name,
None)
263 if handle
is not None:
264 setattr(tool, handle,
'GlobalSim_'+str(out_index))
268 def set_SGin_locations(tools, alg_ids, input_slots, G):
271 Set locations read from by each Algorithm according to the
274 NOTE: currently we assume a tool has one output location
275 and one input location, which allows only "narrow chains".
276 This will be extended to allow multiple children in the near future.
278 alg_ids is a str:int map
279 tools is a int : (tool, toolType) map
282 for nid
in range(1, G.V):
283 parent = tools[nid][0]
284 child_ids = G.adj(nid)
285 if len(child_ids) == 0:
288 for child_id
in child_ids:
289 slot = input_slots[nid][child_id]
290 child_tool = tools[child_id][0]
291 w_handle_name = write_handles[child_tool.__class__.__name__]
292 read_handle = read_handles[parent.__class__.__name__][slot]
293 read_from = getattr(child_tool, w_handle_name)
294 setattr(parent, read_handle, read_from)
300 root = tree.getroot()
306 alg_ids, alg_tools, V= fill_alg_ids(root)
307 input_slots = fill_input_slots(root, alg_ids)
308 G, roots = make_digraph(alg_ids, V)
309 logger.debug(
'call graph ' + str(G))
311 topological = Topological(G, roots=roots)
312 if not topological.isDAG():
raise AssertionError(
313 'Call graph is not a DAG')
315 index_order = topological.order()
316 set_SGout_locations(tools=alg_tools)
317 set_SGin_locations(tools=alg_tools, alg_ids = alg_ids,
318 input_slots=input_slots, G=G)
320 logger.debug(
'DAG: ' + str(G))
321 logger.debug(
'order: ' + str(index_order))
324 toolType =
'TOBWriters'
325 orderedTOBWriters = [alg_tools[i][0]
for i
in index_order
326 if alg_tools[i][1] == toolType]
328 msg = [str(tool)
for tool
in orderedTOBWriters]
329 logger.debug(toolType +
': ' +
'\n'.join(msg))
332 toolType =
'TIPWriters'
333 orderedTIPWriters = [alg_tools[i][0]
for i
in index_order
334 if alg_tools[i][1] == toolType]
336 tools = [alg_tools[i][0]
for i
in index_order]
337 msg = [
'GlobalSim tool IO dump:']
340 tname = tool.__class__.__name__ +
'/' + tool.name
342 logger.debug(
'GS tool name ' + tname)
343 logger.debug(
'GS r_handle str(tool)' , str(tool))
345 handle_name = read_handles.get(tool.__class__.__name__,
None)
346 if handle_name
is None:
347 logger.debug(
'GS r_handle not in table')
350 logger.debug(
'GS r_handle from table: ', handle_name)
351 logger.debug(
'GS r_handle loc from tool: ' + tname +
' ' +
352 str(getattr(tool, handle_name[
'in0'])))
354 handle_name = write_handles.get(tool.__class__.__name__,
None)
355 if handle_name
is None:
356 logger.debug(
'GS w_handle not in table')
358 logger.debug(
'GS w_handle from table: ' + handle_name)
359 logger.debug(
'GS w_handle loc from tool: ' + tname +
' ' +
360 str(getattr(tool, handle_name)))
363 alg = CompFactory.GlobalSim.GlobalSimulationAlg(algName)
364 alg.globalsim_algs = orderedTOBWriters
365 alg.TIPwriters = orderedTIPWriters
366 alg.OutputLevel = OutputLevel
367 alg.enableDumps = dump
370 from TrigCaloRec.TrigCaloRecConfig
import hltCaloCellSeedlessMakerCfg
371 cfg.merge(hltCaloCellSeedlessMakerCfg(flags, roisKey=
''))
373 cfg.addEventAlgo(alg)