1 |
#!/usr/bin/env python
|
2 |
#
|
3 |
# $Id: plot_rate_singlecanvas.py,v 1.2 2008/09/24 09:03:04 wangdy Exp $
|
4 |
#
|
5 |
|
6 |
"""
|
7 |
CSC TF monitorable plotting
|
8 |
|
9 |
this script plots the interesting distributions of CSC TF online
|
10 |
monitoralbes from the log files.
|
11 |
Input: log files in localConditions/MonitoringData
|
12 |
Requirements: matplotlib
|
13 |
|
14 |
"""
|
15 |
import matplotlib
|
16 |
|
17 |
matplotlib.use('Agg')
|
18 |
|
19 |
from matplotlib.pylab import *
|
20 |
import os
|
21 |
import time
|
22 |
|
23 |
|
24 |
f_log=open("logfile","r")
|
25 |
|
26 |
pat_logtime="logging time"
|
27 |
lines=f_log.readlines()
|
28 |
width_data=6
|
29 |
cfunc=int
|
30 |
f_log.close()
|
31 |
supprange=False
|
32 |
SUP_YMAX=55.0 # maximum y range for suppressed plots;mainly for vprates
|
33 |
SUP_YMAX1=500.0 # maximum y range for tot:stub
|
34 |
SUP_YMAX2=35.0 # maximum y range for tot:track
|
35 |
SUP_YMAX3=50.0 # maximum y range for tot:halo
|
36 |
isSummary=False # is this rate counter summary?
|
37 |
isTotalrate=False
|
38 |
ratelabel=["Stubs","Tracks","Halos"]
|
39 |
|
40 |
def settimestamp():
|
41 |
global index_startstamp, time_stamp, l_logtime
|
42 |
|
43 |
l_logtime=[]
|
44 |
for jj in lines:
|
45 |
if pat_logtime in jj:
|
46 |
l_logtime.append(jj[25:-1])
|
47 |
|
48 |
if os.path.exists('laststamp'):
|
49 |
tstamp_last_old=open("laststamp","r").readline()
|
50 |
else:
|
51 |
tstamp_last_old='00000000000000'
|
52 |
|
53 |
time_stamp = []
|
54 |
time_stampfl = []
|
55 |
for jt in l_logtime:
|
56 |
tlocal=time.strptime(jt,"%b %d %H:%M:%S %Y")
|
57 |
tstamp=time.strftime("%H:%M",tlocal)
|
58 |
tstamp_fl=time.strftime("%Y%m%d%H%M%S",tlocal)
|
59 |
time_stamp.append(tstamp)
|
60 |
time_stampfl.append(tstamp_fl)
|
61 |
|
62 |
if (time_stampfl[-1] > tstamp_last_old):
|
63 |
file_last=open("laststamp","w")
|
64 |
file_last.write(time_stampfl[-1])
|
65 |
file_last.close()
|
66 |
|
67 |
if (time_stampfl[0] < tstamp_last_old):
|
68 |
index_startstamp=time_stampfl.index(tstamp_last_old)
|
69 |
else:
|
70 |
index_startstamp=0
|
71 |
del time_stamp[:index_startstamp]
|
72 |
|
73 |
|
74 |
|
75 |
def plot_linkhistory(nlink, pat_ewc, isp):
|
76 |
global width_data, index_startstamp, time_stamp, l_logtime
|
77 |
|
78 |
ind_ewc_old=0
|
79 |
c_ewc=0
|
80 |
ewc={}
|
81 |
|
82 |
|
83 |
for jj in lines:
|
84 |
if pat_ewc in jj:
|
85 |
ind_ewc=lines.index(jj, ind_ewc_old+1)
|
86 |
try:
|
87 |
if isSummary:
|
88 |
presentline=lines[isp+2+ind_ewc]
|
89 |
else:
|
90 |
presentline=lines[isp+1+ind_ewc]
|
91 |
except IndexError :
|
92 |
continue
|
93 |
|
94 |
rawlist=[]
|
95 |
for kk in xrange(nlink):
|
96 |
rawlist.append(cfunc(presentline[16+kk*width_data:16+(kk+1)*width_data]))
|
97 |
# print rawlist
|
98 |
ewc[c_ewc]=rawlist
|
99 |
ind_ewc_old=ind_ewc
|
100 |
c_ewc+=1
|
101 |
|
102 |
for jkey in xrange(index_startstamp):
|
103 |
del ewc[jkey]
|
104 |
|
105 |
ewc.keys().sort()
|
106 |
|
107 |
ewc_content={}
|
108 |
|
109 |
ewc_content[2]=[]
|
110 |
for nn in ewc.keys():
|
111 |
ewc_content[2].append(ewc[nn][2])
|
112 |
|
113 |
subplots_adjust(bottom=0.18)
|
114 |
subplot(3,2,isp-6)
|
115 |
plot(ewc_content[2],linestyle='steps')
|
116 |
ind_tick=xrange(0,len(time_stamp),5)
|
117 |
xticks(ind_tick,time_stamp[::5],rotation=90)
|
118 |
xlabel('time stamp(/10s), from %s to %s' %(l_logtime[index_startstamp],l_logtime[-1]))
|
119 |
ylabel(pat_ewc)
|
120 |
linklabel=''
|
121 |
linklabel="link_M%d" %(3)
|
122 |
savefig(pat_ewc+'_'+linklabel+'.png')
|
123 |
|
124 |
if isTotalrate:
|
125 |
title("History of Total Rates for "+ratelabel[2])
|
126 |
elif isSummary:
|
127 |
title(pat_ewc+' history for SP#%s: %s' %(isp, ratelabel[2]))
|
128 |
else:
|
129 |
title(pat_ewc+' history for SP#%s %s' %(isp, linklabel))
|
130 |
if(supprange):
|
131 |
if isSummary:
|
132 |
axis(ymax=SUP_YMAX3)
|
133 |
else:
|
134 |
axis(ymax=SUP_YMAX)
|
135 |
savefig(pat_ewc+'_sp'+str(isp)+'_'+linklabel+'.png')
|
136 |
clf()
|
137 |
|
138 |
|
139 |
|
140 |
#
|
141 |
##------------------------------------------------------------------------
|
142 |
if __name__ == '__main__':
|
143 |
list15=["CSR_AF_EmptyFlag","CSR_AF_WordCount","CSR_LEC_CarrierExtend",
|
144 |
"CSR_LEC_ErrorWord","CSR_LEC_SignalLoss","CSR_LNK_RXSDStatus",
|
145 |
"CSR_OSY_AFUCount","CSR_OSY_BCLCount","CSR_OSY_BCECount","CSR_OSY_BXMCount"]
|
146 |
list5=["CSR_CM1_LCK1Count","CSR_CM2_LCK2Count",
|
147 |
"CSR_LF_EmptyFlag","CSR_LF_FullFlag","CSR_LF_WordCount"]
|
148 |
list1=["CSR_QDB_DB_LLCK","CSR_QDB_LCKD","CSR_QDB_LCKQ","CSR_QDB_TTCrq_LLCK",]
|
149 |
list3_11=["DAT_VPC_TrackCount"]
|
150 |
list15_11=["DAT_VPC_VPCount"]
|
151 |
list3_11f=["DAT_VPC_TrackRate"]
|
152 |
list15_11f=["DAT_VPC_VPRate"]
|
153 |
list3_13f=["RateCounter"]
|
154 |
|
155 |
|
156 |
settimestamp()
|
157 |
tcurrent=time.strftime("%Y%m%d%H%M")
|
158 |
print tcurrent
|
159 |
dirname1 = "../public_html/MonitorableHistory/"+tcurrent+"/"
|
160 |
dirname1 = "./"+tcurrent+"/"
|
161 |
if not os.path.isdir(dirname1):
|
162 |
print "NOT DIR"
|
163 |
os.mkdir(dirname1)
|
164 |
os.chdir(dirname1)
|
165 |
|
166 |
|
167 |
for isp in xrange(7,13):
|
168 |
# dirname2="SP"+str(SPNum)
|
169 |
# os.mkdir(dirname2)
|
170 |
# os.chdir(dirname2)
|
171 |
width_data=6
|
172 |
cfunc=int
|
173 |
supprange=False
|
174 |
isSummary=False
|
175 |
isTotalrate=False
|
176 |
|
177 |
# for pat_ewc in list3_13f:
|
178 |
# os.mkdir(pat_ewc)
|
179 |
# os.chdir(pat_ewc)
|
180 |
width_data=13
|
181 |
cfunc=float
|
182 |
supprange=True
|
183 |
isSummary=True
|
184 |
# plot_linkhistory(3, "RateCounter", SPNum)
|
185 |
nlink=3
|
186 |
pat_ewc="RateCounter"
|
187 |
|
188 |
ind_ewc_old=0
|
189 |
c_ewc=0
|
190 |
ewc={}
|
191 |
|
192 |
for jj in lines:
|
193 |
if pat_ewc in jj:
|
194 |
ind_ewc=lines.index(jj, ind_ewc_old+1)
|
195 |
try:
|
196 |
if isSummary:
|
197 |
presentline=lines[isp+2+ind_ewc]
|
198 |
else:
|
199 |
presentline=lines[isp+1+ind_ewc]
|
200 |
except IndexError :
|
201 |
continue
|
202 |
|
203 |
rawlist=[]
|
204 |
for kk in xrange(nlink):
|
205 |
rawlist.append(cfunc(presentline[16+kk*width_data:16+(kk+1)*width_data]))
|
206 |
# print rawlist
|
207 |
ewc[c_ewc]=rawlist
|
208 |
ind_ewc_old=ind_ewc
|
209 |
c_ewc+=1
|
210 |
|
211 |
for jkey in xrange(index_startstamp):
|
212 |
del ewc[jkey]
|
213 |
|
214 |
ewc.keys().sort()
|
215 |
|
216 |
ewc_content={}
|
217 |
|
218 |
ewc_content[2]=[]
|
219 |
for nn in ewc.keys():
|
220 |
ewc_content[2].append(ewc[nn][2])
|
221 |
|
222 |
|
223 |
aa=subplot(3,2,isp-6)
|
224 |
# this equivalent to the best; but not so simple
|
225 |
# yscale('log')
|
226 |
# this doesn't scale well when using logscale
|
227 |
# myax=gca()
|
228 |
# myax.set_yscale('log')
|
229 |
|
230 |
text(180,20.0,"Sector %d" %(isp-6))
|
231 |
if isp<5+6:
|
232 |
subplots_adjust(hspace=0.0)
|
233 |
## this turn to be the best option for logscale
|
234 |
semilogy(ewc_content[2],linestyle='steps')
|
235 |
ind_tick=xrange(0,len(time_stamp),30)
|
236 |
# axvspan(50.0,100.0,facecolor='y',alpha=0.4)
|
237 |
axvspan(105.0,175.0,facecolor='y',alpha=0.3)
|
238 |
|
239 |
if isp>4+6:
|
240 |
xticks(ind_tick,time_stamp[::30],rotation=90)
|
241 |
else:
|
242 |
xticks([],[])
|
243 |
# xlabel('time stamp(/10s), from %s to %s' %(l_logtime[index_startstamp],l_logtime[-1]))
|
244 |
# due to logscale, remove the label from right subplots
|
245 |
if isp%2:
|
246 |
ylabel("halo rate(Hz)")
|
247 |
linklabel=''
|
248 |
linklabel="link_M%d" %(3)
|
249 |
|
250 |
# savefig(pat_ewc+'_'+linklabel+'.png')
|
251 |
|
252 |
# if isTotalrate:
|
253 |
# title("History of Total Rates for "+ratelabel[2])
|
254 |
# elif isSummary:
|
255 |
# title(pat_ewc+' history for SP#%s: %s' %(isp, ratelabel[2]))
|
256 |
# else:
|
257 |
# title(pat_ewc+' history for SP#%s %s' %(isp, linklabel))
|
258 |
if(supprange):
|
259 |
if isSummary:
|
260 |
axis(ymax=SUP_YMAX3)
|
261 |
else:
|
262 |
axis(ymax=SUP_YMAX)
|
263 |
|
264 |
suptitle('history of halo rate(/10s) in ME- trigger sectors, Sep 11')
|
265 |
savefig('HaloRateHistory_MEMinus.png')
|
266 |
savefig('HaloRateHistory_MEMinus.svg')
|
267 |
savefig('HaloRateHistory_MEMinus.eps')
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
# os.chdir("../")
|
279 |
|
280 |
# os.chdir("../")
|
281 |
# width_data=13
|
282 |
# cfunc=float
|
283 |
# supprange=False
|
284 |
# isSummary=True
|
285 |
# isTotalrate=True
|
286 |
# plot_linkhistory(3, "RateCounter", 0)
|