ATLAS Offline Software
Loading...
Searching...
No Matches
HypoToolAnalyser.py
Go to the documentation of this file.
1# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2
3from collections import defaultdict
4
6 """ "Look inside" a jet hypo tool, and post its contents, including all
7 nested classes to two tables:
8 - self.node_table : a look up table of node id (int) to AlgTool
9 - self.connected: a look up table of connections. Keys are node ids,
10 values are the list of node ids of tool contained within the tool
11 with node id given by the key.
12
13 example (tool name replaces tool instance):
14
15 node_table:
16
17 0 HLT_j80_j60_L1J15
18 1 helper_tool_0
19 2 HelperToolConfigTool_0
20 3 RepeatedConditionConfigTool_0
21 4 all_0
22 5 RepeatedConditionConfigTool_2
23 6 eta_0
24 7 et_0
25 8 RepeatedConditionConfigTool_3
26 9 eta_1
27 10 et_1
28 11 RepeatedConditionConfigTool_1
29 12 RepeatedConditionConfigTool_4
30 13 RepeatedConditionConfigTool_5
31
32
33 connections:
34
35 0 [1]
36 1 [2]
37 2 [3, 5, 8, 11, 12, 13]
38 3 [4]
39 5 [6, 7]
40 8 [9, 10]
41"""
42 def __init__(self, tool):
43 self.connections = defaultdict(list)
44 self.node_table = {}
45 self.nid = 0
46 self.cid = 1
47
48 self._process(tool)
49
50 def _process(self, tool):
51
52 self.node_table[self.nid] = tool
53
54
55 children = []
56 for k, v in tool._properties.items():
57 if v.__class__.__name__ in (
58 'TrigJetHypoToolHelperNoGrouper',
59 'TrigJetHypoToolConfig_conditionfilter',
60 'TrigJetHypoToolConfig_passthroughfilter',
61 ):
62 children.append(v)
63
64 elif v.__class__.__name__== 'PrivateToolHandleArray':
65 children.extend(v)
66
67 pid = self.nid
68
69 for c in children:
70 self.nid += 1
71 self.connections[pid].append(self.nid)
72 self._process(c)
73
74 def tables(self):
75 return self.node_table, self.connections
76
77 def __str__(self):
78
79 s = [self.__class__.__name__, '\nnode_table:\n']
80 for k, v in self.node_table.items():
81 s.append('%3d: %s' % (k, v.name))
82
83 s.append('\nconnections:\n')
84
85 for k, v in self.connections.items():
86 s.append('%3d: %s' % (k, str(v)))
87
88 return ('\n'.join(s))
89