10 import os,os.path,sys,math,array,datetime,time,re
12 from RecoLuminosity.LumiDB
import argparse,lumiTime,lumiCalcAPI,sessionManager,lumiParameters
15 allfillname=
'allfills.txt' 16 runtofilldqmfile=
'runtofill_dqm.txt' 19 fillnamepat=
r'^[0-9]{4}$' 20 p=re.compile(fillnamepat)
22 dirList=os.listdir(indir)
24 if p.match(fname)
and os.path.isdir(os.path.join(indir,fname)):
25 allfs=os.listdir(os.path.join(indir,fname))
27 sumfilenamepat=
r'^[0-9]{4}_bxsum_CMS.txt$' 28 s=re.compile(sumfilenamepat)
31 processedfills.append(
int(fname))
36 hlinepat=
r'(LASTCOMPLETEFILL )([0-9]{4})' 37 h=re.compile(hlinepat)
38 dqmfile=open(infile,
'r') 42 lastfill=result.group(2)
54 if __name__ ==
'__main__':
57 parser.add_argument(
'-c',
61 help=
'connect string to lumiDB,optional',
62 default=
'oracle://cms_orcon_adg/cms_lumi_prod')
63 parser.add_argument(
'-P',
67 help=
'authentication.xml dir')
68 parser.add_argument(
'-i',
72 help=
'input dir to runtofill_dqm.txt',
74 parser.add_argument(
'-o',
80 parser.add_argument(
'-f',
'--fill',
86 parser.add_argument(
'--datatag',
92 parser.add_argument(
'--normtag',
98 parser.add_argument(
'--minfill',
102 help=
'minimal fillnumber',
104 parser.add_argument(
'--maxfill',
108 help=
'maximum fillnumber ',
110 parser.add_argument(
'--amodetag',
114 help=
'specific accelerator mode choices [PROTOPHYS,IONPHYS,PAPHYS] (optional)')
115 parser.add_argument(
'--beamenergy',
120 help=
'nominal beam energy in GeV')
121 parser.add_argument(
'--beamfluctuation',
122 dest=
'beamfluctuation',
123 type=float,action=
'store',
126 help=
'fluctuation in fraction allowed to nominal beam energy, default 0.2, to be used together with -beamenergy (optional)')
127 parser.add_argument(
'--debug',
131 parser.add_argument(
'--without-stablebeam',
132 dest=
'withoutStablebeam',
135 help=
'without requirement on stable beams')
136 parser.add_argument(
'--without-correction',
137 dest=
'withoutFineCorrection',
140 help=
'without fine correction')
141 options=parser.parse_args()
143 MINFILL=
int(options.minfill)
145 maxfillnum=options.maxfill
146 summaryfilenameTMP=
'_summary_CMS.txt' 147 dbname=options.connect
148 authdir=options.authpath
149 if options.fillnum
is not None:
150 fillstoprocess.append(
int(options.fillnum))
153 session=svc.openSession(isReadOnly=
True,cpp2sqltype=[(
'unsigned int',
'NUMBER(10)'),(
'unsigned long long',
'NUMBER(20)')])
154 session.transaction().
start(
True)
155 schema=session.nominalSchema()
157 session.transaction().commit()
160 for pf
in processedfills:
161 if pf>lastcompletedFill:
162 print '\tremove unfinished fill from processed list ',pf
163 processedfills.remove(pf)
164 for fill
in allfillsFromDB:
165 if fill
not in processedfills :
166 if int(fill)<=lastcompletedFill:
167 if int(fill)>MINFILL:
168 fillstoprocess.append(fill)
170 print 'ongoing fill...',fill
171 print 'fills to process : ',fillstoprocess
172 if len(fillstoprocess)==0:
173 print 'no fill to process, exit ' 176 lslength=lumip.lslengthsec()
177 import commands,os,RecoLuminosity.LumiDB.lumiTime,datetime,time
178 for fillnum
in fillstoprocess:
179 clineElements=[
'lumiCalc2.py',
'lumibyls',
'-c',dbname,
'-P',authdir,
'-f',
str(fillnum),
'-o',
'tmp.out',
'--without-checkforupdate',
'--nowarning']
180 if not options.withoutStablebeam:
181 clineElements.append(
'-b stable')
182 if options.withoutFineCorrection:
183 clineElements.append(
'--without-correction')
185 clineElements.append(
'--datatag '+options.datatag)
187 clineElements.append(
'--normtag '+options.normtag)
188 if options.beamenergy:
189 clineElements.append(
'--beamenergy '+
str(options.beamenergy))
190 if options.beamfluctuation:
191 clineElements.append(
'--beamfluctuation '+
str(options.beamfluctuation))
193 finalcmmd=
' '.
join(clineElements)
194 print 'cmmd executed:',finalcmmd
195 (exestat,resultStr)=commands.getstatusoutput(finalcmmd)
197 print 'lumiCalc2.py execution error ',resultStr
199 f=open(
'tmp.out',
'r') 209 lineList=line.split(
',')
211 if runnum
not in stablefillmap:
212 stablefillmap[runnum]=([],[])
213 timestamp=lineList[2]
216 pydate=t.StrToDatetime(timestamp,
'%m/%d/%y %H:%M:%S')
218 os.environ[
'TZ']=
'UTC' 220 unixts=
int(time.mktime(pydate.timetuple()))
222 if bstatus==
'STABLE BEAMS':
223 stablefillmap[runnum][0].
append(unixts)
224 stablefillmap[runnum][1].
append(deliveredintl)
225 filloutdir=os.path.join(options.outputdir,
str(fillnum))
226 if not os.path.exists(filloutdir):
231 summaryfilename=os.path.join(options.outputdir,
str(fillnum),
str(fillnum)+summaryfilenameTMP)
233 ofile=open(summaryfilename,
'w')
234 if len(stablefillmap)==0:
235 print >>ofile,
'%s'%(
'#no stable beams')
237 for r
in sorted(stablefillmap):
238 rundata=stablefillmap[r]
239 print >>ofile,
'%d\t%d\t%.6e\t%.6e'%(
min(rundata[0]),
max(rundata[0]),
max(rundata[1])/lslength,sum(rundata[1]))
def lastcompleteFill(infile)
def fillInRange(schema, fillmin=1000, fillmax=9999, amodetag='PROTPHYS', startT=None, stopT=None)
static std::string join(char **cmd)