10 from __future__
import print_function
11 import os,os.path,sys,math,array,datetime,time,re
13 from RecoLuminosity.LumiDB
import argparse,lumiTime,lumiCalcAPI,sessionManager,lumiParameters
16 allfillname=
'allfills.txt' 17 runtofilldqmfile=
'runtofill_dqm.txt' 20 fillnamepat=
r'^[0-9]{4}$' 21 p=re.compile(fillnamepat)
23 dirList=os.listdir(indir)
25 if p.match(fname)
and os.path.isdir(os.path.join(indir,fname)):
26 allfs=os.listdir(os.path.join(indir,fname))
28 sumfilenamepat=
r'^[0-9]{4}_bxsum_CMS.txt$' 29 s=re.compile(sumfilenamepat)
32 processedfills.append(
int(fname))
37 hlinepat=
r'(LASTCOMPLETEFILL )([0-9]{4})' 38 h=re.compile(hlinepat)
39 dqmfile=open(infile,
'r') 43 lastfill=result.group(2)
55 if __name__ ==
'__main__':
56 parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description =
"Dump Fill",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
58 parser.add_argument(
'-c',
62 help=
'connect string to lumiDB,optional',
63 default=
'oracle://cms_orcon_adg/cms_lumi_prod')
64 parser.add_argument(
'-P',
68 help=
'authentication.xml dir')
69 parser.add_argument(
'-i',
73 help=
'input dir to runtofill_dqm.txt',
75 parser.add_argument(
'-o',
81 parser.add_argument(
'-f',
'--fill',
87 parser.add_argument(
'--datatag',
93 parser.add_argument(
'--normtag',
99 parser.add_argument(
'--minfill',
103 help=
'minimal fillnumber',
105 parser.add_argument(
'--maxfill',
109 help=
'maximum fillnumber ',
111 parser.add_argument(
'--amodetag',
115 help=
'specific accelerator mode choices [PROTOPHYS,IONPHYS,PAPHYS] (optional)')
116 parser.add_argument(
'--beamenergy',
121 help=
'nominal beam energy in GeV')
122 parser.add_argument(
'--beamfluctuation',
123 dest=
'beamfluctuation',
124 type=float,action=
'store',
127 help=
'fluctuation in fraction allowed to nominal beam energy, default 0.2, to be used together with -beamenergy (optional)')
128 parser.add_argument(
'--debug',
132 parser.add_argument(
'--without-stablebeam',
133 dest=
'withoutStablebeam',
136 help=
'without requirement on stable beams')
137 parser.add_argument(
'--without-correction',
138 dest=
'withoutFineCorrection',
141 help=
'without fine correction')
142 options=parser.parse_args()
144 MINFILL=
int(options.minfill)
146 maxfillnum=options.maxfill
147 summaryfilenameTMP=
'_summary_CMS.txt' 148 dbname=options.connect
149 authdir=options.authpath
150 if options.fillnum
is not None:
151 fillstoprocess.append(
int(options.fillnum))
154 session=svc.openSession(isReadOnly=
True,cpp2sqltype=[(
'unsigned int',
'NUMBER(10)'),(
'unsigned long long',
'NUMBER(20)')])
155 session.transaction().
start(
True)
156 schema=session.nominalSchema()
158 session.transaction().commit()
161 for pf
in processedfills:
162 if pf>lastcompletedFill:
163 print(
'\tremove unfinished fill from processed list ',pf)
164 processedfills.remove(pf)
165 for fill
in allfillsFromDB:
166 if fill
not in processedfills :
167 if int(fill)<=lastcompletedFill:
168 if int(fill)>MINFILL:
169 fillstoprocess.append(fill)
171 print(
'ongoing fill...',fill)
172 print(
'fills to process : ',fillstoprocess)
173 if len(fillstoprocess)==0:
174 print(
'no fill to process, exit ')
177 lslength=lumip.lslengthsec()
178 import commands,os,RecoLuminosity.LumiDB.lumiTime,datetime,time
179 for fillnum
in fillstoprocess:
180 clineElements=[
'lumiCalc2.py',
'lumibyls',
'-c',dbname,
'-P',authdir,
'-f',
str(fillnum),
'-o',
'tmp.out',
'--without-checkforupdate',
'--nowarning']
181 if not options.withoutStablebeam:
182 clineElements.append(
'-b stable')
183 if options.withoutFineCorrection:
184 clineElements.append(
'--without-correction')
186 clineElements.append(
'--datatag '+options.datatag)
188 clineElements.append(
'--normtag '+options.normtag)
189 if options.beamenergy:
190 clineElements.append(
'--beamenergy '+
str(options.beamenergy))
191 if options.beamfluctuation:
192 clineElements.append(
'--beamfluctuation '+
str(options.beamfluctuation))
194 finalcmmd=
' '.
join(clineElements)
195 print(
'cmmd executed:',finalcmmd)
196 (exestat,resultStr)=commands.getstatusoutput(finalcmmd)
198 print(
'lumiCalc2.py execution error ',resultStr)
200 f=open(
'tmp.out',
'r') 210 lineList=line.split(
',')
212 if runnum
not in stablefillmap:
213 stablefillmap[runnum]=([],[])
214 timestamp=lineList[2]
217 pydate=t.StrToDatetime(timestamp,
'%m/%d/%y %H:%M:%S')
219 os.environ[
'TZ']=
'UTC' 221 unixts=
int(time.mktime(pydate.timetuple()))
223 if bstatus==
'STABLE BEAMS':
224 stablefillmap[runnum][0].
append(unixts)
225 stablefillmap[runnum][1].
append(deliveredintl)
226 filloutdir=os.path.join(options.outputdir,
str(fillnum))
227 if not os.path.exists(filloutdir):
232 summaryfilename=os.path.join(options.outputdir,
str(fillnum),
str(fillnum)+summaryfilenameTMP)
234 ofile=open(summaryfilename,
'w')
235 if len(stablefillmap)==0:
236 print(
'%s'%(
'#no stable beams'), file=ofile)
238 for r
in sorted(stablefillmap):
239 rundata=stablefillmap[r]
240 print(
'%d\t%d\t%.6e\t%.6e'%(
min(rundata[0]),
max(rundata[0]),
max(rundata[1])/lslength,sum(rundata[1])), file=ofile)
S & print(S &os, JobReport::InputFile const &f)
def lastcompleteFill(infile)
def fillInRange(schema, fillmin=1000, fillmax=9999, amodetag='PROTPHYS', startT=None, stopT=None)
static std::string join(char **cmd)