CMS 3D CMS Logo

checklumidiff.py
Go to the documentation of this file.
1 import sys,os,os.path,glob,csv,math,datetime
2 def parseplotcache(filelist,fillmin,fillmax):
3  result={}#{fill:{run:delivered}}
4  for f in filelist:
5  fileobj=open(f,'rb')
6  plotreader=csv.reader(fileobj,delimiter=',')
7  idx=0
8  for row in plotreader:
9  if idx!=0:
10  [run,fill]=row[0].split(':')
11  [lumils,cmsls]=row[1].split(':')
12  if int(fill) not in range(fillmin,fillmax+1):
13  continue
14  delivered=float(row[5])
15  if int(fill) not in result:
16  result[int(fill)]={}
17  if int(run) in result[int(fill)]:
18  result[int(fill)][int(run)]+=delivered
19  else:
20  result[int(fill)][int(run)]=delivered
21  idx+=1
22  fileobj.close()
23  return result
24 def findlpcdir(lpcdir,fillmin):
25  result=[]
26  cachedir=lpcdir
27  lpcfilldir=[f for f in glob.glob(cachedir+'/????') if os.path.isdir(f) ]
28  lpcfills=[os.path.split(f)[1] for f in lpcfilldir]
29  #print lpcfills
30  result=[int(f) for f in lpcfills if int(f)>=fillmin]
31  return result
32 
33 if __name__ == "__main__" :
34  ofile=open('checklumi.log','w')
35  lpcdir='/afs/cern.ch/cms/CAF/CMSCOMM/COMM_GLOBAL/LHCFILES/'
36  plotcachedir='/afs/cern.ch/cms/lumi/www/publicplots/public_lumi_plots_cache/pp_all'
37  plotfiles=[f for f in glob.glob(os.path.join(plotcachedir,'lumicalc_cache_2012-??-??.csv')) if os.path.getsize(f)>0]
38  fillmin=2450
39  lpcfill2012=sorted(findlpcdir(lpcdir,fillmin))
40  lpcresult={}#{fill:[delivered]}
41 
42  plotfilldata={}#{fill:{run:delivered}}
43  plotfilldata=parseplotcache(plotfiles,min(lpcfill2012),max(lpcfill2012))
44 
45  ofile.write('checking fills %s\n'%str(lpcfill2012))
46  ofile.write("-----------------------------------------------------------------------------------\n")
47  ofile.write('on %s\n'%str(datetime.datetime.now()) )
48  ofile.write("-----------------------------------------------------------------------------------\n")
49  tot_lumipplot=0.
50  tot_nrunpplot=0
51  tot_lumilpc=0.
52  tot_nrunlpc=0
53 
54  for fill in lpcfill2012:
55  nruns_pplot=0
56  nrun_lpc=0
57  lumi_pplot=0.
58  lumi_lpc=0.
59  dellumi=0.
60  delta=0.
61  lpcfile=os.path.join(lpcdir,str(fill),str(fill)+'_summary_CMS.txt')
62  if not os.path.exists(lpcfile):
63  continue
64  l=open(lpcfile,'rb')
65  for line in l.readlines():
66  line=line.strip()
67  rundataline=line.split()
68  if len(rundataline)!=4: continue
69  lpcdelperrun=float(rundataline[3])
70  lpcresult.setdefault(fill,[]).append(lpcdelperrun)
71  nrun_lpc+=1
72  lumi_lpc+=lpcdelperrun
73  tot_nrunlpc+=1
74  l.close()
75  if fill in plotfilldata:
76  runs=plotfilldata[fill].keys()
77  if not runs: continue
78  nruns_pplot=len(runs)
79  tot_nrunpplot+=nruns_pplot
80  runs.sort()
81  for run in runs:
82  lumi_pplot+=plotfilldata[fill][run]
83  tot_lumipplot+=lumi_pplot
84  tot_lumilpc+=lumi_lpc
85  delta=lumi_pplot-lumi_lpc
86  if lumi_lpc:
87  dellumi=1.-math.fabs(lumi_pplot/lumi_lpc)
88  if nruns_pplot!=nrun_lpc:
89  ofile.write('fill: %d plot=%.2f plotrun=%d lpc=%.2f lpcrun=%d diff=%.2f rel=%.3f *\n'%(fill,lumi_pplot,nruns_pplot,lumi_lpc,nrun_lpc,delta,dellumi))
90  else:
91  ofile.write('fill: %d plot=%.2f plotrun=%d lpc=%.2f lpcrun=%d diff=%.2f rel=%.3f \n'%(fill,lumi_pplot,nruns_pplot,lumi_lpc,nrun_lpc,delta,dellumi))
92  tot_diff=tot_lumipplot-tot_lumilpc
93  tot_rel=0.
94  if tot_lumilpc!=0:
95  tot_rel=1.-tot_lumipplot/tot_lumilpc
96 
97  ofile.write("-----------------------------------------------------------------------------------\n")
98  ofile.write("tot : plot=%.2f lpc=%.2f diff=%.2f rel=%.3f\n" % (tot_lumipplot,tot_lumilpc,tot_diff,tot_rel))
99  ofile.write("tot : plotnrun=%d lpcnrun=%d\n"%(tot_nrunpplot,tot_nrunlpc))
T min(T a, T b)
Definition: MathUtil.h:58
def parseplotcache(filelist, fillmin, fillmax)
Definition: checklumidiff.py:2
def findlpcdir(lpcdir, fillmin)
#define str(s)
double split
Definition: MVATrainer.cc:139