00001
00002 import os,os.path,sys,commands,time,datetime,shutil
00003 import coral
00004 from RecoLuminosity.LumiDB import argparse,lumiQueryAPI,lumiTime,csvReporter
00005
00006
00007
00008 def findFileTrueName(filename):
00009 '''given a filename, find its true name
00010 '''
00011 truename=filename
00012 if os.path.islink(filename):
00013 truename=os.path.realpath(filename)
00014 else:
00015 print '[WARNING] ',filename,' is not a link'
00016 return truename
00017 def create2011RunList(c,p='.',o='.',dryrun=False):
00018 '''
00019 input:
00020 c connect string
00021 p authenticaion path
00022 '''
00023 msg=coral.MessageStream('')
00024 msg.setMsgVerbosity(coral.message_Level_Error)
00025 os.environ['CORAL_AUTH_PATH']='/build1/zx'
00026 svc = coral.ConnectionService()
00027 connectstr=c
00028 session=svc.connect(connectstr,accessMode=coral.access_ReadOnly)
00029 session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
00030 session.typeConverter().setCppTypeForSqlType("unsigned long long","NUMBER(20)")
00031 session.transaction().start(True)
00032 schema=session.nominalSchema()
00033 allruns=lumiQueryAPI.allruns(schema,requireLumisummary=True,requireTrg=True,requireHlt=True)
00034 session.transaction().commit()
00035 del session
00036 del svc
00037 allruns.sort()
00038 if not dryrun:
00039 report=csvReporter.csvReporter(os.path.join(o,'runlist.txt'))
00040 for run in allruns:
00041 if run>=160442:
00042 report.writeRow([run])
00043 else:
00044 for run in allruns:
00045 if run>=160442:
00046 print run
00047
00048 def createRunList(c,p='.',o='.',dryrun=False):
00049 '''
00050 input:
00051 c connect string
00052 p authenticaion path
00053 '''
00054 msg=coral.MessageStream('')
00055 msg.setMsgVerbosity(coral.message_Level_Error)
00056 os.environ['CORAL_AUTH_PATH']='/build1/zx'
00057 svc = coral.ConnectionService()
00058 connectstr=c
00059 session=svc.connect(connectstr,accessMode=coral.access_ReadOnly)
00060 session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
00061 session.typeConverter().setCppTypeForSqlType("unsigned long long","NUMBER(20)")
00062 session.transaction().start(True)
00063 schema=session.nominalSchema()
00064 allruns=lumiQueryAPI.allruns(schema,requireLumisummary=True,requireTrg=True,requireHlt=True)
00065 session.transaction().commit()
00066 del session
00067 del svc
00068 allruns.sort()
00069 if not dryrun:
00070 report=csvReporter.csvReporter(os.path.join(o,'runlist.txt'))
00071 for run in allruns:
00072 report.writeRow([run])
00073 else:
00074 print allruns
00075
00076 def totalLumi2011vstime(c,p='.',i='',o='.',begTime="03/14/11 09:00:00.00",endTime="",selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
00077 plotoutname='totallumivstime-2011.png'
00078 textoutname='totallumivstime-2011.csv'
00079 elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','time']
00080 if selectionfile:
00081 elements.append('-i')
00082 elements.append(selectionfile)
00083 if endTime:
00084 elements.append('-end')
00085 elements.append('"'+endTime+'"')
00086 if beamstatus:
00087 elements.append('-beamstatus')
00088 if beamstatus=='stable':
00089 elements.append('"STABLE BEAMS"')
00090 if beamenergy:
00091 elements.append('-beamenergy')
00092 elements.append(str(beamenergy))
00093 if beamfluctuation:
00094 elements.append('-beamfluctuation')
00095 elements.append(str(beamfluctuation))
00096 if withTextOutput:
00097 elements.append('-o')
00098 elements.append(os.path.join(o,textoutname))
00099 if annotateBoundaryRunnum:
00100 elements.append('--annotateboundary')
00101 command=' '.join(elements)
00102 print command
00103 if not dryrun:
00104 statusAndOutput=commands.getstatusoutput(command)
00105 print statusAndOutput[1]
00106
00107 def totalLumi2010vstime(c,p='.',i='',o='.',begTime="03/30/10 10:00:00.00",endTime="11/03/10 00:00:00.00",selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
00108 plotoutname='totallumivstime-2010.png'
00109 textoutname='totallumivstime-2010.csv'
00110 elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','time']
00111 if selectionfile:
00112 elements.append('-i')
00113 elements.append(selectionfile)
00114 if endTime:
00115 elements.append('-end')
00116 elements.append('"'+endTime+'"')
00117 if beamstatus:
00118 elements.append('-beamstatus')
00119 if beamstatus=='stable':
00120 elements.append('"STABLE BEAMS"')
00121 if beamenergy:
00122 elements.append('-beamenergy')
00123 elements.append(str(beamenergy))
00124 if beamfluctuation:
00125 elements.append('-beamfluctuation')
00126 elements.append(str(beamfluctuation))
00127 if withTextOutput:
00128 elements.append('-o')
00129 elements.append(os.path.join(o,textoutname))
00130 if annotateBoundaryRunnum:
00131 elements.append('--annotateboundary')
00132 command=' '.join(elements)
00133 print command
00134 if not dryrun:
00135 statusAndOutput=commands.getstatusoutput(command)
00136 print statusAndOutput[1]
00137
00138 def totalLumivstime(c,p='.',i='',o='.',begTime="03/30/10 10:00:00.00",endTime=None,selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
00139 '''
00140 input:
00141 c connect string
00142 p authenticaion path
00143 i input selection file name
00144 o output path
00145 '''
00146 plotoutname='totallumivstime.png'
00147 textoutname='totallumivstime.csv'
00148 elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','time']
00149 if selectionfile:
00150 elements.append('-i')
00151 elements.append(selectionfile)
00152 if endTime:
00153 elements.append('-end')
00154 elements.append('"'+endTime+'"')
00155 if beamstatus:
00156 elements.append('-beamstatus')
00157 if beamstatus=='stable':
00158 elements.append('"STABLE BEAMS"')
00159 if beamenergy:
00160 elements.append('-beamenergy')
00161 elements.append(str(beamenergy))
00162 if beamfluctuation:
00163 elements.append('-beamfluctuation')
00164 elements.append(str(beamfluctuation))
00165 if withTextOutput:
00166 elements.append('-o')
00167 elements.append(os.path.join(o,textoutname))
00168 if annotateBoundaryRunnum:
00169 elements.append('--annotateboundary')
00170 command=' '.join(elements)
00171 print command
00172 if not dryrun:
00173 statusAndOutput=commands.getstatusoutput(command)
00174 print statusAndOutput[1]
00175
00176 def totalLumivstimeLastweek(c,p='.',i='',o='.',selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False):
00177 '''
00178 input:
00179 c connect string
00180 p authenticaion path
00181 i input selection file name
00182 o output path
00183 ##fix me: year boundary is not considered!
00184 '''
00185 t=lumiTime.lumiTime()
00186 plotoutname='totallumivstime-weekly.png'
00187 textoutname='totallumivstime-weekly.csv'
00188 nowTime=datetime.datetime.now()
00189 lastMondayStr=' '.join([str(nowTime.isocalendar()[0]),str(nowTime.isocalendar()[1]-1),str(nowTime.isocalendar()[2])])
00190
00191 lastweekMonday=datetime.datetime(*time.strptime(lastMondayStr,'%Y %W %w')[0:5])
00192 lastweekEndSunday=lastweekMonday+datetime.timedelta(days=7,hours=24)
00193
00194 elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin','"'+t.DatetimeToStr(lastweekMonday)+'"','-end','"'+t.DatetimeToStr(lastweekEndSunday)+'"','-batch',os.path.join(o,plotoutname),'time']
00195 if withTextOutput:
00196 elements.append('-o')
00197 elements.append(os.path.join(o,textoutname))
00198 if beamstatus:
00199 elements.append('-beamstatus')
00200 if beamstatus=='stable':
00201 elements.append('"STABLE BEAMS"')
00202 if beamenergy:
00203 elements.append('-beamenergy')
00204 elements.append(str(beamenergy))
00205 if beamfluctuation:
00206 elements.append('-beamfluctuation')
00207 elements.append(str(beamfluctuation))
00208 command=' '.join(elements)
00209 print command
00210 if not dryrun:
00211 statusAndOutput=commands.getstatusoutput(command)
00212 print statusAndOutput[1]
00213
00214 def lumi2010PerDay(c,p='.',i='',o='',begTime="03/30/10 10:00:00.00",endTime="11/03/10 00:00:00.00",selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
00215 plotoutname='lumiperday-2010.png'
00216 textoutname='lumiperday-2010.csv'
00217 elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','perday']
00218 if selectionfile:
00219 elements.append('-i')
00220 elements.append(selectionfile)
00221 if endTime:
00222 elements.append('-end')
00223 elements.append('"'+endTime+'"')
00224 if beamstatus:
00225 elements.append('-beamstatus')
00226 if beamstatus=='stable':
00227 elements.append('"STABLE BEAMS"')
00228 if beamenergy:
00229 elements.append('-beamenergy')
00230 elements.append(str(beamenergy))
00231 if beamfluctuation:
00232 elements.append('-beamfluctuation')
00233 elements.append(str(beamfluctuation))
00234 if withTextOutput:
00235 elements.append('-o')
00236 elements.append(os.path.join(o,textoutname))
00237 if annotateBoundaryRunnum:
00238 elements.append('--annotateboundary')
00239 command=' '.join(elements)
00240 print command
00241 if not dryrun:
00242 statusAndOutput=commands.getstatusoutput(command)
00243 print statusAndOutput[1]
00244
00245 def lumi2011PerDay(c,p='.',i='',o='',begTime="03/14/11 09:00:00.00",endTime=None,selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
00246 plotoutname='lumiperday-2011.png'
00247 textoutname='lumiperday-2011.csv'
00248 elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','perday']
00249 if selectionfile:
00250 elements.append('-i')
00251 elements.append(selectionfile)
00252 if endTime:
00253 elements.append('-end')
00254 elements.append('"'+endTime+'"')
00255 if beamstatus:
00256 elements.append('-beamstatus')
00257 if beamstatus=='stable':
00258 elements.append('"STABLE BEAMS"')
00259 if beamenergy:
00260 elements.append('-beamenergy')
00261 elements.append(str(beamenergy))
00262 if beamfluctuation:
00263 elements.append('-beamfluctuation')
00264 elements.append(str(beamfluctuation))
00265 if withTextOutput:
00266 elements.append('-o')
00267 elements.append(os.path.join(o,textoutname))
00268 if annotateBoundaryRunnum:
00269 elements.append('--annotateboundary')
00270 command=' '.join(elements)
00271 print command
00272 if not dryrun:
00273 statusAndOutput=commands.getstatusoutput(command)
00274 print statusAndOutput[1]
00275
00276 def lumiPerDay(c,p='.',i='',o='',begTime="03/30/10 10:00:00.00",endTime="",selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
00277 '''
00278 input:
00279 c connect string
00280 p authenticaion path
00281 i input selection file
00282 o outputpath
00283 '''
00284 plotoutname='lumiperday.png'
00285 textoutname='lumiperday.csv'
00286 elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','perday']
00287 if selectionfile:
00288 elements.append('-i')
00289 elements.append(selectionfile)
00290 if endTime:
00291 elements.append('-end')
00292 elements.append('"'+endTime+'"')
00293 if beamstatus:
00294 elements.append('-beamstatus')
00295 if beamstatus=='stable':
00296 elements.append('"STABLE BEAMS"')
00297 if beamenergy:
00298 elements.append('-beamenergy')
00299 elements.append(str(beamenergy))
00300 if beamfluctuation:
00301 elements.append('-beamfluctuation')
00302 elements.append(str(beamfluctuation))
00303 if withTextOutput:
00304 elements.append('-o')
00305 elements.append(os.path.join(o,textoutname))
00306 if annotateBoundaryRunnum:
00307 elements.append('--annotateboundary')
00308 command=' '.join(elements)
00309 print command
00310 if not dryrun:
00311 statusAndOutput=commands.getstatusoutput(command)
00312 print statusAndOutput[1]
00313
00314 def totalLumi2010vsRun(c,p='.',i='',o='',begRun="132440",endRun="149509",selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False):
00315 plotoutname='totallumivsrun-2010.png'
00316 textoutname='totallumivsrun-2010.csv'
00317 elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin',begRun,'-batch',os.path.join(o,plotoutname),'-yscale both','run']
00318 if endRun:
00319 elements.append('-end')
00320 elements.append(endRun)
00321 if beamstatus:
00322 elements.append('-beamstatus')
00323 if beamstatus=='stable':
00324 elements.append('"STABLE BEAMS"')
00325 if beamenergy:
00326 elements.append('-beamenergy')
00327 elements.append(str(beamenergy))
00328 if beamfluctuation:
00329 elements.append('-beamfluctuation')
00330 elements.append(str(beamfluctuation))
00331 if withTextOutput:
00332 elements.append('-o')
00333 elements.append(os.path.join(o,textoutname))
00334 command=' '.join(elements)
00335 print command
00336 if not dryrun:
00337 statusAndOutput=commands.getstatusoutput(command)
00338 print statusAndOutput[1]
00339
00340 def totalLumi2011vsRun(c,p='.',i='',o='',begRun="160442",endRun=None,selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False):
00341 plotoutname='totallumivsrun-2011.png'
00342 textoutname='totallumivsrun-2011.csv'
00343 elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin',begRun,'-batch',os.path.join(o,plotoutname),'-yscale both','run']
00344 if endRun:
00345 elements.append('-end')
00346 elements.append(endRun)
00347 if beamstatus:
00348 elements.append('-beamstatus')
00349 if beamstatus=='stable':
00350 elements.append('"STABLE BEAMS"')
00351 if beamenergy:
00352 elements.append('-beamenergy')
00353 elements.append(str(beamenergy))
00354 if beamfluctuation:
00355 elements.append('-beamfluctuation')
00356 elements.append(str(beamfluctuation))
00357 if withTextOutput:
00358 elements.append('-o')
00359 elements.append(os.path.join(o,textoutname))
00360 command=' '.join(elements)
00361 print command
00362 if not dryrun:
00363 statusAndOutput=commands.getstatusoutput(command)
00364 print statusAndOutput[1]
00365
00366 def totalLumivsRun(c,p='.',i='',o='',begRun="132440",endRun="",selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False):
00367 '''
00368 input:
00369 c connect string
00370 p authenticaion path
00371 i input selection file
00372 o outputpath
00373 '''
00374 plotoutname='totallumivsrun.png'
00375 textoutname='totallumivsrun.csv'
00376 elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin',begRun,'-batch',os.path.join(o,plotoutname),'-yscale both','run']
00377 if endRun:
00378 elements.append('-end')
00379 elements.append(endRun)
00380 if beamstatus:
00381 elements.append('-beamstatus')
00382 if beamstatus=='stable':
00383 elements.append('"STABLE BEAMS"')
00384 if beamenergy:
00385 elements.append('-beamenergy')
00386 elements.append(str(beamenergy))
00387 if beamfluctuation:
00388 elements.append('-beamfluctuation')
00389 elements.append(str(beamfluctuation))
00390 if withTextOutput:
00391 elements.append('-o')
00392 elements.append(os.path.join(o,textoutname))
00393 command=' '.join(elements)
00394 print command
00395 if not dryrun:
00396 statusAndOutput=commands.getstatusoutput(command)
00397 print statusAndOutput[1]
00398
00399 def totalLumi2010vsFill(c,p='.',i='',o='',begFill="1005",endFill="1461",selectionfile=None,beamenergy=None,beamstatus=None,beamfluctuation=None,dryrun=False,withTextOutput=False):
00400 plotoutname='totallumivsfill-2010.png'
00401 textoutname='totallumivsfill-2010.csv'
00402 elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin',begFill,'-batch',os.path.join(o,plotoutname),'-yscale both','fill']
00403 if endFill:
00404 elements.append('-end')
00405 elements.append(endFill)
00406 if beamstatus:
00407 elements.append('-beamstatus')
00408 if beamstatus=='stable':
00409 elements.append('"STABLE BEAMS"')
00410 if beamenergy:
00411 elements.append('-beamenergy')
00412 elements.append(str(beamenergy))
00413 if beamfluctuation:
00414 elements.append('-beamfluctuation')
00415 elements.append(str(beamfluctuation))
00416 if withTextOutput:
00417 elements.append('-o')
00418 elements.append(os.path.join(o,textoutname))
00419 command=' '.join(elements)
00420 print command
00421 if not dryrun:
00422 statusAndOutput=commands.getstatusoutput(command)
00423 print statusAndOutput[1]
00424
00425 def totalLumi2011vsFill(c,p='.',i='',o='',begFill="1616",endFill=None,selectionfile=None,beamenergy=None,beamstatus=None,beamfluctuation=None,dryrun=False,withTextOutput=False):
00426 plotoutname='totallumivsfill-2011.png'
00427 textoutname='totallumivsfill-2011.csv'
00428 elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin',begFill,'-batch',os.path.join(o,plotoutname),'-yscale both','fill']
00429 if endFill:
00430 elements.append('-end')
00431 elements.append(endFill)
00432 if beamstatus:
00433 elements.append('-beamstatus')
00434 if beamstatus=='stable':
00435 elements.append('"STABLE BEAMS"')
00436 if beamenergy:
00437 elements.append('-beamenergy')
00438 elements.append(str(beamenergy))
00439 if beamfluctuation:
00440 elements.append('-beamfluctuation')
00441 elements.append(str(beamfluctuation))
00442 if withTextOutput:
00443 elements.append('-o')
00444 elements.append(os.path.join(o,textoutname))
00445 command=' '.join(elements)
00446 print command
00447 if not dryrun:
00448 statusAndOutput=commands.getstatusoutput(command)
00449 print statusAndOutput[1]
00450
00451 def totalLumivsFill(c,p='.',i='',o='',begFill="1005",endFill="",selectionfile=None,beamenergy=None,beamstatus=None,beamfluctuation=None,dryrun=False,withTextOutput=False):
00452 '''
00453 input:
00454 c connect string
00455 p authenticaion path
00456 i input selection file
00457 o output path
00458 '''
00459 plotoutname='totallumivsfill.png'
00460 textoutname='totallumivsfill.csv'
00461 elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin',begFill,'-batch',os.path.join(o,plotoutname),'-yscale both','fill']
00462 if endFill:
00463 elements.append('-end')
00464 elements.append(endFill)
00465 if beamstatus:
00466 elements.append('-beamstatus')
00467 if beamstatus=='stable':
00468 elements.append('"STABLE BEAMS"')
00469 if beamenergy:
00470 elements.append('-beamenergy')
00471 elements.append(str(beamenergy))
00472 if beamfluctuation:
00473 elements.append('-beamfluctuation')
00474 elements.append(str(beamfluctuation))
00475 if withTextOutput:
00476 elements.append('-o')
00477 elements.append(os.path.join(o,textoutname))
00478 command=' '.join(elements)
00479 print command
00480 if not dryrun:
00481 statusAndOutput=commands.getstatusoutput(command)
00482 print statusAndOutput[1]
00483 def instLumiForRuns(c,runnumbers,p='.',o='',dryrun=False):
00484 '''
00485 draw instlumperrun plot for the given runs
00486 input:
00487 c connect string
00488 runnumbers []
00489 p authenticaion path
00490 o output path
00491 '''
00492 plotoutname='rollinginstlumi_'
00493 textoutname='rollinginstlumi_'
00494 for idx,run in enumerate(runnumbers):
00495 batch=os.path.join(o,plotoutname+str(idx+1)+'.png')
00496 elements=['lumiInstPlot.py','-c',c,'-P',p,'-begin',str(run),'-batch',batch,'run']
00497 command=' '.join(elements)
00498 print command
00499 if not dryrun:
00500 statusAndOutput=commands.getstatusoutput(command)
00501 print statusAndOutput[1]
00502
00503 def instPeak2010Perday(c,p='.',o='.',begTime="03/30/10 10:00:00.00",endTime="11/03/10 00:00:00.00",dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
00504 plotoutname='lumipeak-2010.png'
00505 textoutname='lumipeak-2010.csv'
00506 elements=['lumiInstPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','peakperday']
00507 if endTime:
00508 elements.append('-end')
00509 elements.append('"'+endTime+'"')
00510 if withTextOutput:
00511 elements.append('-o')
00512 elements.append(os.path.join(o,textoutname))
00513 if annotateBoundaryRunnum:
00514 elements.append('--annotateboundary')
00515 command=' '.join(elements)
00516 print command
00517 if not dryrun:
00518 statusAndOutput=commands.getstatusoutput(command)
00519 print statusAndOutput[1]
00520
00521 def instPeak2011Perday(c,p='.',o='.',begTime="03/14/11 09:00:00.00",endTime="",dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
00522 plotoutname='lumipeak-2011.png'
00523 textoutname='lumipeak-2011.csv'
00524 elements=['lumiInstPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','peakperday']
00525 if endTime:
00526 elements.append('-end')
00527 elements.append('"'+endTime+'"')
00528 if withTextOutput:
00529 elements.append('-o')
00530 elements.append(os.path.join(o,textoutname))
00531 if annotateBoundaryRunnum:
00532 elements.append('--annotateboundary')
00533 command=' '.join(elements)
00534 print command
00535 if not dryrun:
00536 statusAndOutput=commands.getstatusoutput(command)
00537 print statusAndOutput[1]
00538
00539 def instPeakPerday(c,p='.',o='.',begTime="03/30/10 10:00:00.00",endTime="",dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
00540 '''
00541 input:
00542 c connect string
00543 p authenticaion path
00544 o outout text/csv file
00545 '''
00546 plotoutname='lumipeak.png'
00547 textoutname='lumipeak.csv'
00548 elements=['lumiInstPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','peakperday']
00549 if endTime:
00550 elements.append('-end')
00551 elements.append('"'+endTime+'"')
00552 if withTextOutput:
00553 elements.append('-o')
00554 elements.append(os.path.join(o,textoutname))
00555 if annotateBoundaryRunnum:
00556 elements.append('--annotateboundary')
00557 command=' '.join(elements)
00558 print command
00559 if not dryrun:
00560 statusAndOutput=commands.getstatusoutput(command)
00561 print statusAndOutput[1]
00562
00563 def main():
00564 actionlist=['instperrun','instpeakvstime','instpeak2011vstime','totalvstime','total2011vstime','totallumilastweek','totalvsfill','total2011vsfill','totalvsrun','total2011vsrun','perday','perday2011','createrunlist','create2011runlist','physicsperday','physicsvstime']
00565 parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Produce lumi plots")
00566 parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
00567 parser.add_argument('-P',dest='authpath',action='store',required=False,help='auth path. Optional. Default to .')
00568 parser.add_argument('-L',dest='logpath',action='store',required=False,help='log path. Optional. Default to .')
00569 parser.add_argument('-i',dest='ifile',action='store',required=False,help='input selection file. Optional.')
00570 parser.add_argument('-o',dest='opath',action='store',required=False,help='output file path. Optional')
00571 parser.add_argument('-beamenergy',dest='beamenergy',action='store',required=False,help='beamenergy (in GeV) selection criteria,e.g. 3.5e3')
00572 parser.add_argument('-beamfluctuation',dest='beamfluctuation',action='store',required=False,help='allowed beamenergy fluctuation (in GeV),e.g. 0.2e3')
00573 parser.add_argument('--annotateboundary',dest='annotateboundary',action='store_true',help='annotate boundary run numbers')
00574 parser.add_argument('-beamstatus',dest='beamstatus',action='store',required=False,help='selection criteria beam status,e.g. stable')
00575 parser.add_argument('--withTextOutput',dest='withtextoutput',action='store_true',help='write to text output file')
00576 parser.add_argument('--dryrun',dest='dryrun',action='store_true',help='dryrun mode')
00577 parser.add_argument('action',choices=actionlist,help='command actions')
00578 args=parser.parse_args()
00579
00580 authpath='.'
00581 logpath='.'
00582 opath='.'
00583 connectstr=args.connect
00584 isDryrun=False
00585 withTextOutput=False
00586 beamstatus=None
00587 beamenergy=None
00588 beamfluctuation=None
00589 if args.beamenergy:
00590 beamenergy=args.beamenergy
00591 if args.beamstatus:
00592 beamstatus=args.beamstatus
00593 if args.beamfluctuation:
00594 beamfluctuation=args.beamfluctuation
00595 if args.dryrun:
00596 isDryrun=True
00597 if args.withtextoutput:
00598 withTextOutput=True
00599 if args.authpath:
00600 authpath=args.authpath
00601 if args.logpath:
00602 lumilogpath=args.logpath
00603 if args.ifile:
00604 ifile=args.ifile
00605 if args.opath:
00606 opath=args.opath
00607 if args.action == 'create2011runlist':
00608 create2011RunList(connectstr,authpath,o=opath,dryrun=isDryrun)
00609 if args.action == 'createrunlist':
00610 createRunList(connectstr,authpath,o=opath,dryrun=isDryrun)
00611 if args.action == 'instperrun':
00612 if not args.ifile:
00613 print 'option -i is required for action instperrun'
00614 return 2
00615 f=open(args.ifile,'r')
00616 runs=[]
00617 for run in f:
00618 runs.append(int(run))
00619 last2runs=[runs[-2],runs[-1]]
00620 instLumiForRuns(connectstr,last2runs,p=authpath,o=opath,dryrun=isDryrun)
00621 if args.action == 'total2011vsrun':
00622 if args.ifile:
00623 f=open(args.ifile,'r')
00624 runs=[]
00625 for run in f:
00626 runs.append(int(run))
00627 else:
00628 runs=['160442','']
00629 totalLumi2011vsRun(connectstr,p=authpath,begRun=str(runs[0]),o=opath,endRun=str(runs[-1]),beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
00630
00631 if args.action == 'totalvsrun':
00632 if args.ifile:
00633 f=open(args.ifile,'r')
00634 runs=[]
00635 for run in f:
00636 runs.append(int(run))
00637 else:
00638 runs=['132440','']
00639 totalLumivsRun(connectstr,p=authpath,begRun=str(runs[0]),o=opath,endRun=str(runs[-1]),beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
00640
00641 if args.action == 'instpeakvstime':
00642 instPeakPerday(connectstr,p=authpath,o=opath,dryrun=isDryrun,withTextOutput=withTextOutput,annotateBoundaryRunnum=args.annotateboundary)
00643
00644 if args.action == 'instpeak2011vstime':
00645 instPeak2011Perday(connectstr,p=authpath,o=opath,dryrun=isDryrun,withTextOutput=withTextOutput,annotateBoundaryRunnum=args.annotateboundary)
00646 if args.action == 'total2011vstime':
00647 totalLumi2011vstime(connectstr,p=authpath,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput,annotateBoundaryRunnum=args.annotateboundary)
00648
00649 if args.action == 'totalvstime':
00650 totalLumivstime(connectstr,p=authpath,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput,annotateBoundaryRunnum=args.annotateboundary)
00651
00652 if args.action == 'totallumilastweek':
00653 totalLumivstimeLastweek(connectstr,p=authpath,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
00654
00655 if args.action == 'total2011vsfill':
00656 totalLumi2011vsFill(connectstr,p=authpath,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
00657
00658 if args.action == 'totalvsfill':
00659 totalLumivsFill(connectstr,p=authpath,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
00660
00661 if args.action == 'perday2011':
00662 lumi2011PerDay(connectstr,p=authpath,o=opath,dryrun=isDryrun,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,withTextOutput=withTextOutput,annotateBoundaryRunnum=args.annotateboundary)
00663
00664 if args.action == 'perday':
00665 lumiPerDay(connectstr,p=authpath,o=opath,dryrun=isDryrun,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,withTextOutput=withTextOutput,annotateBoundaryRunnum=args.annotateboundary)
00666
00667 if args.action == 'physicsperday' or args.action == 'physicsvstime':
00668 if not args.ifile:
00669 print 'input selection file is required'
00670 return 3
00671 if not os.path.isfile(args.ifile):
00672 print 'file: '+args.ifile+' does not exist'
00673 return 4
00674 truefilename=findFileTrueName(args.ifile)
00675
00676
00677
00678
00679 inputmodtime=os.path.getmtime(truefilename)
00680
00681 if not os.path.isfile(os.path.join(opath,'lumiperday.png')) or not os.path.isfile(os.path.join(opath,'totallumivstime.png')):
00682 if not isDryrun:
00683 shutil.copy2(truefilename,os.path.join(opath,os.path.basename(truefilename)))
00684 print 'cp '+truefilename+' '+os.path.join(opath,os.path.basename(truefilename))
00685 if args.action == 'physicsperday':
00686 lumiPerDay(connectstr,p=authpath,selectionfile=truefilename,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
00687 if args.action == 'physicsvstime':
00688 totalLumivstime(connectstr,p=authpath,selectionfile=truefilename,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
00689 else:
00690 outputmodtime=os.path.getmtime(os.path.join(opath,'lumiperday.png'))
00691
00692 if inputmodtime > outputmodtime :
00693 print 'physics selection file '+truefilename+' modified, updating physics plots: '
00694 if not isDryrun:
00695 shutil.copy2(truefilename,os.path.join(opath,os.path.basename(truefilename)))
00696 print 'cp '+truefilename+' '+os.path.join(opath,os.path.basename(truefilename))
00697 if args.action == 'physicsperday':
00698 lumiPerDay(connectstr,p=authpath,selectionfile=truefilename,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
00699 if args.action == 'physicsvstime':
00700 totalLumivstime(connectstr,p=authpath,selectionfile=truefilename,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
00701 else:
00702 print 'physics selection file older than plot, do nothing'
00703 return 0
00704
00705 if __name__=='__main__':
00706 main()