-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathat_reg.py
211 lines (194 loc) · 9.76 KB
/
at_reg.py
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
##############################################
# at_reg.py -
# A script to test the registers of a QIE card.
#
# Author: O. Kamer Koseyan - Novemer 11 - 12, 2015
##############################################
import sys
from random import randint
from hcal_teststand import *
from hcal_teststand.utilities import logger
from hcal_teststand.hcal_teststand import teststand
from ROOT import *
at = tests.acceptance(name="reg")
v = at.verbose
ts = at.ts # Create teststand object for ngfec.send_commands()
registers = [] # List of commands to be sent to ngFEC tool
names = [] # List of names ordered as in registers list.
fe_crate = at.fe_crate
fe_slot = at.fe_slot
n = at.n
numdic = {}
errdic = {}
def rand(size = 1):
output = ''
if size % 32:
output += hex(randint(0, 2**(size % 32-1))) + ' '
for i in range(int(size/32)):
output += hex(randint(0, 2**32-1)) + ' '
return output[:-1]
def register(name = None, size = 1, n = 5):
cmds = []
for i in range(n):
r = rand(size)
cmds += ['put {0} {1}'.format(name, r), 'get {0}'.format(name)]
return cmds
def create_plots(at = None, names = None, dic = None, k = 1):
gROOT.SetStyle("Plain")
gStyle.SetOptStat(0)
at.canvas.Divide(1, k)
tothist = []
rwhist = []
xhist = []
stacks = []
for i in range(k):
namespart = names[i*len(names)/k: (i+1)*len(names)/k] # On (i+1)*len(names)/n, first i*len(names) is done, then the division by n. By that way, i = k - 1 => (i+1)*len(names)/k = len(names). So we don't lose any bins because of integer division.
tothist.append(TH1F("Total_{0}".format(i+1), "", len(namespart), -0.5, len(namespart)-0.5))
rwhist.append(TH1F("R/W_{0}".format(i+1), "", len(namespart), -0.5, len(namespart)-0.5))
xhist.append(TH1F("Exec_{0}".format(i+1), "", len(namespart), -0.5, len(namespart)-0.5))
stacks.append(THStack("Error_{0}".format(i+1), ""))
tothist[i].SetFillColor(kGreen)
rwhist[i].SetFillColor(kRed)
xhist[i].SetFillColor(kOrange)
for j, name in enumerate(namespart):
tothist[i].GetXaxis().SetBinLabel(j+1, name)
rwhist[i].GetXaxis().SetBinLabel(j+1, name)
xhist[i].GetXaxis().SetBinLabel(j+1, name)
tothist[i].Fill(j, dic[name][1][0])
rwhist[i].Fill(j, dic[name][1][1])
xhist[i].Fill(j, dic[name][1][2])
tothist[i].GetXaxis().LabelsOption("vd")
rwhist[i].GetXaxis().LabelsOption("vd")
xhist[i].GetXaxis().LabelsOption("vd")
at.canvas.cd(i + 1)
# gPad.SetBottomMargin(-10)
# gPad.SetLogy(1)
tothist[i].GetXaxis().SetLabelOffset(0.02)
tothist[i].Write()
rwhist[i].Write()
xhist[i].Write()
stacks[i].Add(rwhist[i])
stacks[i].Add(xhist[i])
stacks[i].Write()
tothist[i].SetMaximum(1.15*n)
tothist[i].SetMinimum(0)
stacks[i].SetMaximum(1.15*n)
stacks[i].SetMinimum(0)
tothist[i].Draw()
stacks[i].Draw("SAME")
at.write()
# return 0
def main():
at.start(nouid=True)
print
for i_qie in range(1, 25):
registers.extend(
register("HF{0}-{1}-QIE{2}_Lvds".format(fe_crate, fe_slot, i_qie), 1, n) + # 1 bit
register("HF{0}-{1}-QIE{2}_Trim".format(fe_crate, fe_slot, i_qie), 2, n) + # 2 bits
register("HF{0}-{1}-QIE{2}_DiscOn".format(fe_crate, fe_slot, i_qie), 1, n) + # 1 bit
register("HF{0}-{1}-QIE{2}_TGain".format(fe_crate, fe_slot, i_qie), 1, n) + # 1 bit
register("HF{0}-{1}-QIE{2}_TimingThresholdDAC".format(fe_crate, fe_slot, i_qie), 8, n) + # 8 bits
register("HF{0}-{1}-QIE{2}_TimingIref".format(fe_crate, fe_slot, i_qie), 3, n) + # 3 bits
register("HF{0}-{1}-QIE{2}_PedestalDAC".format(fe_crate, fe_slot, i_qie), 6, n) + # 6 bits
register("HF{0}-{1}-QIE{2}_CapID0pedestal".format(fe_crate, fe_slot, i_qie), 4, n) + # 4 bits
register("HF{0}-{1}-QIE{2}_CapID1pedestal".format(fe_crate, fe_slot, i_qie), 4, n) + # 4 bits
register("HF{0}-{1}-QIE{2}_CapID2pedestal".format(fe_crate, fe_slot, i_qie), 4, n) + # 4 bits
register("HF{0}-{1}-QIE{2}_CapID3pedestal".format(fe_crate, fe_slot, i_qie), 4, n) + # 4 bits
register("HF{0}-{1}-QIE{2}_FixRange".format(fe_crate, fe_slot, i_qie), 1, n) + # 1 bit
register("HF{0}-{1}-QIE{2}_RangeSet".format(fe_crate, fe_slot, i_qie), 2, n) + # 2 bits
register("HF{0}-{1}-QIE{2}_ChargeInjectDAC".format(fe_crate, fe_slot, i_qie), 3, n) + # 3 bits
register("HF{0}-{1}-QIE{2}_RinSel".format(fe_crate, fe_slot, i_qie), 4, n) + # 4 bits
register("HF{0}-{1}-QIE{2}_Idcset".format(fe_crate, fe_slot, i_qie), 5, n) + # 5 bits
register("HF{0}-{1}-QIE{2}_CalMode".format(fe_crate, fe_slot, i_qie), 1, n) + # 1 bit
register("HF{0}-{1}-QIE{2}_CkOutEn".format(fe_crate, fe_slot, i_qie), 1, n) + # 1 bit
register("HF{0}-{1}-QIE{2}_TDCMode".format(fe_crate, fe_slot, i_qie), 1, n) + # 1 bit
register("HF{0}-{1}-Qie{2}_ck_ph".format(fe_crate, fe_slot, i_qie), 4, n) # 4 bits
)
registers.extend(
### Top:
register("HF{0}-{1}-iTop_CntrReg_CImode".format(fe_crate, fe_slot), 1, n) + # 1 bit
register("HF{0}-{1}-iTop_CntrReg_InternalQIER".format(fe_crate, fe_slot), 1, n) + # 1 bit
register("HF{0}-{1}-iTop_CntrReg_OrbHistoClear".format(fe_crate, fe_slot), 1, n) + # 1 bit
register("HF{0}-{1}-iTop_CntrReg_OrbHistoRun".format(fe_crate, fe_slot), 1, n) + # 1 bit
register("HF{0}-{1}-iTop_CntrReg_WrEn_InputSpy".format(fe_crate, fe_slot), 1, n) + # 1 bit
register("HF{0}-{1}-iTop_AddrToSERDES".format(fe_crate, fe_slot), 16, n) + # 16 bits
register("HF{0}-{1}-iTop_CtrlToSERDES_i2c_go".format(fe_crate, fe_slot), 1, n) + # 1 bit
register("HF{0}-{1}-iTop_CtrlToSERDES_i2c_write".format(fe_crate, fe_slot), 1, n) + # 1 bit
register("HF{0}-{1}-iTop_DataToSERDES".format(fe_crate, fe_slot), 32, n) + # 32 bits
register("HF{0}-{1}-iTop_LinkTestMode".format(fe_crate, fe_slot), 8, n) + # 8 bits
register("HF{0}-{1}-iTop_LinkTestPattern".format(fe_crate, fe_slot), 32, n) + # 32 bits
register("HF{0}-{1}-iTop_scratch".format(fe_crate, fe_slot), 32, n) + # 32 bits
register("HF{0}-{1}-iTop_UniqueID".format(fe_crate, fe_slot), 64, n) + # 64 bits
### Bottom:
register("HF{0}-{1}-iBot_CntrReg_CImode".format(fe_crate, fe_slot), 1, n) + # 1 bit
register("HF{0}-{1}-iBot_CntrReg_InternalQIER".format(fe_crate, fe_slot), 1, n) + # 1 bit
register("HF{0}-{1}-iBot_CntrReg_OrbHistoClear".format(fe_crate, fe_slot), 1, n) + # 1 bit
register("HF{0}-{1}-iBot_CntrReg_OrbHistoRun".format(fe_crate, fe_slot), 1, n) + # 1 bit
register("HF{0}-{1}-iBot_CntrReg_WrEn_InputSpy".format(fe_crate, fe_slot), 1, n) + # 1 bit
register("HF{0}-{1}-iBot_AddrToSERDES".format(fe_crate, fe_slot), 16, n) + # 16 bits
register("HF{0}-{1}-iBot_CtrlToSERDES_i2c_go".format(fe_crate, fe_slot), 1, n) + # 1 bit
register("HF{0}-{1}-iBot_CtrlToSERDES_i2c_write".format(fe_crate, fe_slot), 1, n) + # 1 bit
register("HF{0}-{1}-iBot_DataToSERDES".format(fe_crate, fe_slot), 32, n) + # 32 bits
register("HF{0}-{1}-iBot_LinkTestMode".format(fe_crate, fe_slot), 8, n) + # 8 bits
register("HF{0}-{1}-iBot_LinkTestPattern".format(fe_crate, fe_slot), 32, n) + # 32 bits
register("HF{0}-{1}-iBot_scratch".format(fe_crate, fe_slot), 32, n) + # 32 bits
register("HF{0}-{1}-iBot_UniqueID".format(fe_crate, fe_slot), 64, n) # 64 bits
)
for reg in registers[1::2*n]:
names.extend([reg[4:]])
output = ngfec.send_commands(ts, cmds = registers, script = False, progbar = True)
errlist = []
totaltests = 0
rwerr = 0
xerr = 0
for i, (put, get) in enumerate(zip(output[::2], output[1::2])):
# if ' '.join(put['cmd'].split()[2:]).replace('0x', '') == get['result'].replace('0x', ''):
totaltests += 1
if 'ERROR' in put['result'] or 'ERROR' in get['result']:
xerr += 1
elif ' '.join(put['cmd'].split()[2:]).replace('0x', '') != get['result'].replace('0x', ''):
rwerr += 1
errlist.append([' '.join(put['cmd'].split()[2:]).replace('0x', ''), get['result'].replace('0x', '')])
if 'ERROR' in put['result']:
errlist.append([put['cmd'], put['result']])
if 'ERROR' in get['result']:
errlist.append([get['cmd'], get['result']])
if not (i+1) % n:
errdic.update({get['cmd'][4:]: [errlist, [totaltests, rwerr, xerr]]})
errlist = []
totaltests = 0
rwerr = 0
xerr = 0
#---------------Last report of errors------------------
print "\n====== SUMMARY ============================"
if errdic.values().count([[], [n, 0, 0]]) == len(names):
print '[OK] There were no errors.'
else:
print 'R/W errors (put != get):'
for name in names:
for error in errdic[name][0]:
if (error[0] != error[1] and not 'ERROR' in error[1]):
print '\t*Register: ' + name + ' -> Data: 0x' + error[0].replace(' ', ' 0x') + ' != 0x' + error[1].replace(' ', ' 0x')
print '\nExecution errors:'
for name in names:
for error in errdic[name][0]:
if 'ERROR' in error[1]:
print '\t*Command: ' + error[0] + ' -> Result: ' + error[1]
print "\n===========================================\n"
#---------------Create histogram-----------------------
create_plots(at, names, errdic, 8)
if v:
for put, get in zip(output[::2], output[1::2]):
if ' '.join(put['cmd'].split()[2:]).replace('0x', '') == get['result'].replace('0x', '') and not 'ERROR' in put['result']:
at.silentlog('[OK] :: {0} -> {1} == {2} -> {3}\n'.format(put['cmd'], put['result'], get['cmd'], '0x' + get['result'].replace('0x', '').replace(' ', ' 0x')))
elif 'ERROR' in get['result']:
at.silentlog('[!!] :: {0} -> {1} != {2} -> {3}\n'.format(put['cmd'], put['result'], get['cmd'], get['result']))
elif ' '.join(put['cmd'].split()[2:]).replace('0x', '') == get['result'].replace('0x', '') and 'ERROR' in put['result']:
at.silentlog('[!!] :: {0} -> {1} == {2} -> {3}\n'.format(put['cmd'], put['result'], get['cmd'], '0x' + get['result'].replace('0x', '').replace(' ', ' 0x')))
else:
at.silentlog('[!!] :: {0} -> {1} != {2} -> {3}\n'.format(put['cmd'], put['result'], get['cmd'], '0x' + get['result'].replace('0x', '').replace(' ', ' 0x')))
print '\nPrinting raw comparisons into file: [OK]'
else:
print
if __name__ == "__main__":
main()