forked from Teststandees/hcal_teststand_scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
linkPatternTest.py
128 lines (108 loc) · 3.73 KB
/
linkPatternTest.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
####################################################################
# Type: SCRIPT #
# #
# Description: [Add description] #
####################################################################
from hcal_teststand import *
from hcal_teststand.hcal_teststand import *
import sys
import numpy
"""
if everythings works out, you should see something like the following:
0 0FABC 03DE7 0BEEF 03DE7 0FEED 03DE7
1 0FABC 03DE8 0BEEF 03DE8 0FEED 03DE8
2 0FABC 03DE9 0BEEF 03DE9 0FEED 03DE9
3 0FABC 03DEA 0BEEF 03DEA 0FEED 03DEA
4 0FABC 03DEB 0BEEF 03DEB 0FEED 03DEB
"""
def decodeRawOutput( raw_output ) :
raw_data = []
output = raw_output.split("\n")
for i in range( len( output ) ) :
if output[i].find("N RAW 3 2 1 0") != -1 :
raw_data = output[i+1:i+1801]
dataBytes = []
for datum in raw_data :
words = datum.split(" ")
while "" in words :
words.remove("")
dataBytes.append( words[1] )
counter= 0
errors = 0
for i in range( len( dataBytes ) / 6 ) :
counter += 1
#print i,dataBytes[i*6+0],dataBytes[i*6+1],dataBytes[i*6+2],dataBytes[i*6+3],dataBytes[i*6+4],dataBytes[i*6+5]
if dataBytes[i*6][3:5] != "BC" :
print "ERROR: comma character not found!",dataBytes[i*6]
errors+=1
#if dataBytes[i*6][1:3] != "FA" :
# print "ERROR: strange data found in status bits!",dataBytes[i*6][1:3]
# errors+=1
if dataBytes[i*6+1] != dataBytes[i*6+3] or dataBytes[i*6+1] != dataBytes[i*6+5] or dataBytes[i*6+3] != dataBytes[i*6+5] :
print "ERROR: at least one of the counters is inconsistent with the others!"
print dataBytes[i*6+1]
print dataBytes[i*6+2]
print dataBytes[i*6+3]
print dataBytes[i*6+4]
print dataBytes[i*6+5]
errors+=1
if i > 0 :
if int( dataBytes[i*6+1] , 16 ) - int( dataBytes[i*6-5] , 16 ) != 1 :
print "ERROR: counter didn't increment correctly"
errors+=1
#print "AFTER",counter,"BXs"
#print "ERRORS FOUND:",errors
return errors
if __name__ == "__main__":
name = ""
if len(sys.argv) == 1:
name = "904"
numBx = 300
elif len(sys.argv) == 2:
name = sys.argv[1]
numBx = 300
elif len(sys.argv) == 3:
name = sys.argv[1]
numBx = int(sys.argv[2],10)
else:
name = "904"
numBx = 300
ts = teststand(name)
################
# get uHTR link mapping
################
# set_mode_all(ts, 2)
# # These won't work:
## ngccm.link_test_modeB(ts,1,2,True)
# ngccmLog = ngccm.set_unique_id(ts, 1, 2)
# uhtr_map = uhtr.map_links(ts.uhtr_ips[0])
# ngccm.link_test_modeB(ts,1,2,False)
# set unique ID on the FPGA for link mapping
set_mode_all(ts, 1) # Turn on particular string output.
for ip in ts.uhtr_ips:
active_links = uhtr.find_links(ip) # Initialize links and return list of active ones.
print active_links
# grab data from uHTR spy function for each active link:
for link in active_links:
print "==== Link {0} ====".format(link)
# link_.Print() # This isn't defined ATM ...
if numBx<=300 :
uhtr_read = uhtr.get_data(ip, numBx*3, link)
errors = decodeRawOutput(uhtr_read["output"])
print "ERRORS:", errors
else :
errors = 0
numBx_ = numBx
runningTally = 0
while numBx_ > 300 :
#print "not implemented for numBx>300"
uhtr_read = uhtr.get_data(ip, 300*3, link)
runningTally+=300
errors = errors + decodeRawOutput(uhtr_read["output"])
numBx_ = numBx_ - 300
uhtr_read = uhtr.get_data(ip, 300*3, link)
runningTally+=300
errors = errors + decodeRawOutput(uhtr_read["output"])
print "ERRORS:", errors,"out of",runningTally
# Return the FPGA to normal readout mode:
set_mode_all(ts, 0) # Turn on particular string output.