-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdumpAos.py
More file actions
107 lines (90 loc) · 2.81 KB
/
dumpAos.py
File metadata and controls
107 lines (90 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from MDSplus import *
import array
import numpy as np
import sys
def getTabs(tabs):
line = ''
for i in range(0, tabs):
line = line + ' '
return line
def dumpStruct(s, tabs):
if s.__class__.__name__ == 'EmptyData':
print getTabs(tabs) + 'None'
return
print getTabs(tabs) + s[0] + ':'
for i in range(1, len(s)):
if isinstance(s[i], Apd):
if isinstance(s[i][0], Apd): #AoS
dumpAoS(s[i], tabs+1)
else:
dumpStruct(s[i], tabs+1)
else:
if isinstance(s[i], TreeNode):
print getTabs(tabs+1)+s[i].decompile()+':'
if (s[i].getNumSegments() > 0 and (s[i].getDtype() == 'DTYPE_B' or s[i].getDtype() == 'DTYPE_BU')):
dumpSlicedAoS(s[i], tabs+1)
else:
try:
d = s[i].getData()
if isinstance(d, Apd):
print('INTERNAL ERROR: Reference canno be APD')
return
print getTabs(tabs+1) + d.decompile()
except:
print getTabs(tabs) + 'None'
else:
if isinstance(s[i], Int8Array) or isinstance(s[i], Uint8Array):
print getTabs(tabs+1) + '"'+array.array('B', s[i].data()).tostring()+'"'
else:
print getTabs(tabs+1) + s[i].decompile()
#endif
#endfor
def dumpAoS(s, tabs):
for i in range(0, len(s)):
print getTabs(tabs)+'['+str(i)+']'
dumpStruct(s[i], tabs+1)
def dumpSlicedAoS(n, tabs):
aosArr = []
numSegments = n.getNumSegments()
for i in range(0, numSegments):
s = n.getSegment(i)
if np.isscalar(s.getDimensionAt(0).data()):
dim = 1
else:
dim = len(s.getDimensionAt(0).data())
serialized = s.data()
if(dim == 1):
try:
aosArr.append(Data.deserialize(serialized))
except:
aosArr.append(Data.deserialize(serialized[4:]))
else:
idx = 0
buf = np.getbuffer(serialized)
for j in range(0, dim):
currSize = (np.frombuffer(buf, dtype = 'uint32', offset = idx, count = 1))[0]
idx = idx+4
currSerialized = np.frombuffer(np.getbuffer(buf, offset = idx, size = currSize), dtype='uint8')
aosArr.append(Data.deserialize(currSerialized))
idx = idx + currSize
for sliceIdx in range(0, len(aosArr)):
print getTabs(tabs+1) + '['+str(sliceIdx)+']'
dumpStruct(aosArr[sliceIdx], tabs+2)
def dump(s):
if(isinstance(s, Apd)):
dumpAoS(s, 0)
else:
print s
if len(sys.argv) != 3:
print('Usage: python dumpAps.py <pulse> <AoS path>')
sys.exit(0)
pulse = int(sys.argv[1])
path = '\\'+ sys.argv[2]+':STATIC'
t=Tree('ids',pulse)
#t=Tree('ids',440334)
#n=t.getNode('\IDS::TOP.EDGE_SOURCES.SOURCE:STATIC')
print(path)
n=t.getNode(path)
#'\IDS::TOP.DISTRIBUTION._SOURCES.SOURCE:STATIC')
d = n.getData()
dumpAoS(d, 0)