ATLAS Offline Software
getAlgData.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from graphAlgs import Topological
4 from dot import dot
5 
6 from AthenaCommon.Logging import logging
7 logger = logging.getLogger(__name__)
8 from AthenaCommon.Constants import VERBOSE
9 logger.setLevel(VERBOSE)
10 
11 
12 def algdata_from_menu(flags, do_dot=False, root_names=[]):
13  """algdata_from_menu uses a graph created from an L1Menu to created
14  an execution oredered sequence of AlgData objects. AlgData have
15  configuration information that is used to configure a GlobalSim
16  L1TopoAlgorithm AlgTool"""
17 
18  from l1MenuGraph import l1MenuGraph
19 
20  G, alg_data_list = l1MenuGraph(flags)
21 
22  algname2sn = {}
23  for ad in alg_data_list:
24  algname2sn[ad.name] = ad.sn
25 
26  assert len(algname2sn) == len(alg_data_list)
27 
28  # allow running of sub graphs.
29  # root_names contains the names of the roots of the subgraphs.
30  if root_names:
31  roots = [algname2sn[name] for name in root_names]
32  else:
33  # if no nodes are named as root nodes, use all
34  # nodes except the node with sn = 0 for now.
35  # this is because there is currently no need to tie together
36  # the different components, and leaving them unjoined to node 0
37  # facilitates the visualisation of the graph structure.i
38  roots = [i for i in range(1, G.V)]
39 
40  # find the executrion order of the AlgTools in terms of graph node
41  # identifiers (ints)
42  topo_m = Topological(G, roots)
43 
44  logger.debug('G is a DAG:' + str(topo_m.isDAG()))
45  order_sn = topo_m.order()
46  logger.debug('root nodes:' + str(roots))
47  logger.debug('Topological order [' + str(len(order_sn)) + ']')
48  logger.debug(str(order_sn))
49  if do_dot:
50  dot(G, "G_ordered.dot", order_sn)
51 
52  # convert ordered sequence from graph node identifiers to AlgData objects
53  sn2algData = {}
54  for ad in alg_data_list:
55  sn2algData[ad.sn] = ad
56 
57  assert len(sn2algData) == len(alg_data_list)
58 
59  ordered_algs = ['%d %s %s' % (i,
60  sn2algData[i].name,
61  sn2algData[i].klass,
62  ) for i in order_sn]
63  for e in ordered_algs:
64  logger.debug(str(e))
65 
66  ordered_algData = [sn2algData[sn] for sn in order_sn]
67  logger.verbose('ordered_algData:[' + str(len(ordered_algData))+']:')
68  for ad in ordered_algData:
69  logger.verbose(str(ad))
70 
71  return ordered_algData
72 
73 if __name__ == '__main__':
74  root_names = [#'SC111-CjJ40abpETA26',
75  'Mult_cTAU20M',
76  'Mult_cTAU30M',
77  'Mult_cTAU35M',
78  'Mult_cTAUSPARE2',
79  ]
80 
81  algdata_from_menu(root_names=root_names, do_dot=True)
graphAlgs.Topological
Definition: graphAlgs.py:83
l1MenuGraph
Definition: l1MenuGraph.py:1
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
getAlgData.algdata_from_menu
def algdata_from_menu(flags, do_dot=False, root_names=[])
Definition: getAlgData.py:12
Constants
some useful constants -------------------------------------------------—
dot
Definition: dot.py:1
str
Definition: BTagTrackIpAccessor.cxx:11