ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
drawModuleConnections.py
Go to the documentation of this file.
1#!/bin/python3
2
3import xml.etree.ElementTree as ET
4import sys
5
6ns = "{https://github.com/ChimeraTK/ApplicationCore}"
7
8moduleConnections = {}
9
10def parseVariable(node) :
11 varDir = node.find(ns+'direction').text
12
13 feeder = None
14 moduleList = set()
15
16 if varDir == 'control_system_to_application' or varDir == 'control_system_to_application_with_return' :
17 return
18 feeder = 'ControlSystem'
19# else :
20# moduleList.add("ControlSystem")
21
22 for peer in node.find(ns+'connections') :
23 peerType = peer.attrib['type']
24 peerDir = peer.attrib['direction']
25 if peerType == "ApplicationModule" or peerType == "Device" :
26 if peerType == "ApplicationModule" :
27 peerName = peer.attrib['class']
28 else :
29 peerName = 'Device:'+peer.attrib['name']
30 if peerDir == 'consuming' :
31 moduleList.add(peerName)
32 else :
33 if feeder != None :
34 print("ERROR: Found two feeders!")
35 print(node.attrib['name'])
36 sys.exit(1)
37 feeder = peerName
38
39 if feeder == None :
40 print("ERROR: No feeders found!")
41 print(node.attrib['name'])
42 sys.exit(1)
43
44
45 for m in moduleList :
46 if not m in moduleConnections.keys():
47 moduleConnections[m] = set()
48 if not feeder in moduleConnections.keys():
49 moduleConnections[feeder] = set()
50
51 for m in moduleList :
52 moduleConnections[feeder].add(m)
53
54
55def parseDirectory(subtree) :
56
57 for node in subtree :
58
59 if node.tag == ns+'directory' :
60 parseDirectory(node)
61 elif node.tag == ns+'variable' :
62 parseVariable(node)
63
64
65tree = ET.parse('llrfctrl.xml')
66root = tree.getroot()
67
69
70print("digraph {")
71
72def makeNodeName(label) :
73 name = label.replace(':', '_')
74 name = name.replace('/', '_')
75 name = name.replace('<', '_')
76 name = name.replace('>', '_')
77 name = name.replace(',', '_')
78 name = name.replace(' ', '_')
79 return name
80
81
82def defineNode(label) :
83 if not label in nodeIds.keys() :
84 nodeIds[label] = makeNodeName(label)
85 print(nodeIds[label] + ' [label="'+label+'", style=filled', end="")
86 if label.startswith("Device:") :
87 print(', fillcolor=silver', end="")
88 else :
89 print(', fillcolor=lightgreen', end="")
90 print(']')
91
92
93nodeIds = {}
94for source in moduleConnections.keys() :
95 defineNode(source)
96 for target in moduleConnections[source] :
97 defineNode(target)
98
99
100for source in moduleConnections.keys() :
101 if source == None :
102 continue
103 print(nodeIds[source] + ' -> { ', end="")
104 for target in moduleConnections[source] :
105 print(nodeIds[target]+' ', end="")
106 print('}')
107
108print('}')
109