85 algName = 'GlobalSimTestAlg',
88 logger.setLevel(OutputLevel)
89 cfg = ComponentAccumulator()
91 fn = os.environ.get(
'GS_CFG_FILE',
None)
93 logger.error(
'Please set export environment variable GS_CFG_FILE'\
94 'with the name of a GloblSim config xml file')
97 logger.info(
'GlobalSim local config, cfg file:' + fn)
101 """ obtain a string id for each AlgTool"""
103 a_class = toolEl.attrib[
'class']
104 a_name = toolEl.attrib[
'name']
105 return '/'.join((a_class, a_name))
107 def classname_from_fullname(fullname):
108 return fullname.split(
'/')[0]
111 def configure_algtool(toolEl):
113 Set the AlgTool properties from configure file information.
114 Datahandles are not processed here.
117 a_class = toolEl.attrib[
'class']
118 a_name = toolEl.attrib[
'name']
120 factory = getattr(CompFactory.GlobalSim, a_class)
121 tool = factory(a_name)
123 type_factories = {
'int': int,
127 for prop
in toolEl.iter(
'property'):
128 name = prop.attrib[
'name']
129 value = prop.attrib[
'value']
130 ptype = prop.attrib.get(
"type",
None)
131 if ptype
is not None:
132 value = type_factories[ptype](value)
133 setattr(tool, name, value)
134 prop_names.append(name)
136 logger.debug(
'configure_algtool: ' + str(tool))
140 def fill_alg_ids(root):
142 Assign an index to each AlgTool instance specified by
143 the configuration file.
145 Return this information in a dictionary.
153 for toolType
in (
'TOBWriters',
'TIPWriters'):
154 for writerEl
in root.iter(toolType):
155 for toolEl
in writerEl.iter(
'AlgTool'):
156 f_name = str_id(toolEl)
157 if f_name
in alg_ids:
158 raise AssertionError(
'Algorithm duplicated in ' + fn)
159 alg_ids[f_name] = alg_ind
160 alg_tools[alg_ind] = (configure_algtool(toolEl), toolType)
162 return alg_ids, alg_tools, alg_ind
164 def fill_input_slots(root, alg_ids):
167 {par_alg_id:int || {input_slot:str || child_alg_id:int}}
169 Where is a generic name for the input location, eg "in0", and
170 is used by the config file. The actual location is
171 currently obtained using the read_handles dictionary at the top
175 input_slots = defaultdict(dict)
177 for toolEl
in root.iter(
'AlgTool'):
178 par_full_name = str_id(toolEl)
179 par_id = alg_ids[par_full_name]
181 for childEl
in toolEl.iter(
'child'):
182 child_full_name = str_id(childEl)
183 child_id = alg_ids[child_full_name]
184 slot = childEl.attrib.get(
'slot',
None)
186 msg = [
'No slot information for ',
190 raise AssertionError(
' '.join(msg))
192 input_slots[par_id][child_id] = slot
197 def make_digraph(alg_ids, V):
199 Construct an Algtool Digraph.
201 Obtain parent child relations from the config XML file.
203 The graph knows only about
204 the AlgTool insances's indices, and so works from a
205 dictionary that associates the AlgoTool name (string) to its
211 logger.debug(
'make_digraph alg_ids: ', alg_ids)
212 logger.debug(
'make_digraph: V ' + str(V))
218 for toolType
in (
'TOBWriters',
'TIPWriters'):
220 for writerEl
in root.iter(toolType):
221 for toolEl
in writerEl.iter(
'AlgTool'):
222 f_name = str_id(toolEl)
223 logger.debug(
'make_digraph: toolType ' + toolType +
227 par_id = alg_ids[f_name]
229 for childEl
in toolEl.iter(
'child'):
230 f_c_name = str_id(childEl)
231 if f_c_name
not in alg_ids:
232 raise AssertionError(
'child ' + f_c_name +
235 G.addEdge(par_id, alg_ids[f_c_name])
238 roots = [n
for n
in range(R.V)
if not R.adj(n)
and n != 0]
241 def set_SGout_locations(tools):
243 Set the StoreGate locations to be written to. As the
244 same Algorithm may have > 1 instance, ensure that the
245 write locations differ.
250 for indx, (tool, tooltype)
in tools.items():
251 class_name = tool.__class__.__name__
252 handle = write_handles.get(class_name,
None)
254 if handle
is not None:
255 setattr(tool, handle,
'GlobalSim_'+str(out_index))
259 def set_SGin_locations(tools, alg_ids, input_slots, G):
262 Set locations read from by each Algorithm according to the
265 NOTE: currently we assume a tool has one output location
266 and one input location, which allows only "narrow chains".
267 This will be extended to allow multiple children in the near future.
269 alg_ids is a str:int map
270 tools is a int : (tool, toolType) map
273 for nid
in range(1, G.V):
274 parent = tools[nid][0]
275 child_ids = G.adj(nid)
276 if len(child_ids) == 0:
279 for child_id
in child_ids:
280 slot = input_slots[nid][child_id]
281 child_tool = tools[child_id][0]
282 w_handle_name = write_handles[child_tool.__class__.__name__]
283 read_handle = read_handles[parent.__class__.__name__][slot]
284 read_from = getattr(child_tool, w_handle_name)
285 setattr(parent, read_handle, read_from)
291 root = tree.getroot()
297 alg_ids, alg_tools, V= fill_alg_ids(root)
298 input_slots = fill_input_slots(root, alg_ids)
299 G, roots = make_digraph(alg_ids, V)
300 logger.debug(
'call graph ' + str(G))
302 topological = Topological(G, roots=roots)
303 if not topological.isDAG():
raise AssertionError(
304 'Call graph is not a DAG')
306 index_order = topological.order()
307 set_SGout_locations(tools=alg_tools)
308 set_SGin_locations(tools=alg_tools, alg_ids = alg_ids,
309 input_slots=input_slots, G=G)
311 logger.debug(
'DAG: ' + str(G))
312 logger.debug(
'order: ' + str(index_order))
315 toolType =
'TOBWriters'
316 orderedTOBWriters = [alg_tools[i][0]
for i
in index_order
317 if alg_tools[i][1] == toolType]
319 msg = [str(tool)
for tool
in orderedTOBWriters]
320 logger.debug(toolType +
': ' +
'\n'.join(msg))
323 toolType =
'TIPWriters'
324 orderedTIPWriters = [alg_tools[i][0]
for i
in index_order
325 if alg_tools[i][1] == toolType]
327 tools = [alg_tools[i][0]
for i
in index_order]
328 msg = [
'GlobalSim tool IO dump:']
331 tname = tool.__class__.__name__ +
'/' + tool.name
333 logger.debug(
'GS tool name ' + tname)
334 logger.debug(
'GS r_handle str(tool)' , str(tool))
336 handle_name = read_handles.get(tool.__class__.__name__,
None)
337 if handle_name
is None:
338 logger.debug(
'GS r_handle not in table')
341 logger.debug(
'GS r_handle from table: ', handle_name)
342 logger.debug(
'GS r_handle loc from tool: ' + tname +
' ' +
343 str(getattr(tool, handle_name[
'in0'])))
345 handle_name = write_handles.get(tool.__class__.__name__,
None)
346 if handle_name
is None:
347 logger.debug(
'GS w_handle not in table')
349 logger.debug(
'GS w_handle from table: ' + handle_name)
350 logger.debug(
'GS w_handle loc from tool: ' + tname +
' ' +
351 str(getattr(tool, handle_name)))
354 alg = CompFactory.GlobalSim.GlobalSimulationAlg(algName)
355 alg.globalsim_algs = orderedTOBWriters
356 alg.TIPwriters = orderedTIPWriters
357 alg.OutputLevel = OutputLevel
358 alg.enableDumps = dump
361 from TrigCaloRec.TrigCaloRecConfig
import hltCaloCellSeedlessMakerCfg
362 cfg.merge(hltCaloCellSeedlessMakerCfg(flags, roisKey=
''))
364 cfg.addEventAlgo(alg)