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