CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/RecoLuminosity/LumiDB/scripts/lumiDBFiller.py

Go to the documentation of this file.
00001 #! /usr/bin/python
00002 
00003 import string, os, time,re
00004 import commands
00005 lumiauthpath=''
00006 lumilogpath=''
00007 loaderconf=''
00008 
00009 #def isCollisionRun(run,authpath=''):
00010 #    itIs = False
00011 #    itIsAlso = False
00012 #    isInAfill = False
00013 #    command = 'dumpRunInfo.py -c oracle://cms_omds_lb/cms_runinfo -P '+authpath+' -r '+run+' --collision-only l1key | wc'
00014 #    statusAndOutput = commands.getstatusoutput(command)
00015 #    if statusAndOutput[1].split('   ')[2] == '2': itIs = True
00016 #    command = 'dumpRunInfo.py -c oracle://cms_omds_lb/cms_runinfo -P '+authpath+' -r '+run+' --collision-only hltkey | wc'
00017 #    statusAndOutput = commands.getstatusoutput(command)
00018 #    if statusAndOutput[1].split('   ')[2] == '2': itIsAlso = True
00019 #    command = 'dumpRunInfo.py -c oracle://cms_omds_lb/cms_runinfo -P '+authpath+' -r '+run+' fill'
00020 #    statusAndOutput = commands.getstatusoutput(command)
00021 #    fillnum=statusAndOutput[1].split('\n')[1].split(' ')[1]
00022 #    if fillnum and fillnum != '0':
00023 #        isInAfill=True
00024 #    return itIs and itIsAlso and isInAfill
00025 
00026 def getRunnumberFromFileName(lumifilename):
00027     runnumber=int(lumifilename.split('_')[4])
00028     return runnumber
00029 
00030 def getRunsToBeUploaded(connectionString, dropbox, authpath='',minrun=180250):
00031     #print 'authpath ',authpath
00032     # get the last analyzed run
00033     command = 'lumiData2.py -c ' +connectionString+' -P '+authpath+' listrun'
00034     if minrun:
00035         command+=' --minrun '+str(minrun)
00036     statusAndOutput = commands.getstatusoutput(command)
00037     print 'all runs in DB since ',minrun,' : ',statusAndOutput[1]
00038     rlist= eval(statusAndOutput[1])
00039     if rlist:
00040         lastAnalyzedRunNumber = rlist[-1]
00041         print 'Last run in DB: ', lastAnalyzedRunNumber
00042     else:
00043         print 'No qualified run found in DB'
00044         lastAnalyzedRunNumber=minrun
00045     # check if there are new runs to be uploaded
00046     #command = 'ls -ltr '+dropbox
00047     p=re.compile('^CMS_LUMI_RAW_\d\d\d\d\d\d\d\d_\d\d\d\d\d\d\d\d\d_\d\d\d\d_\d.root$')
00048     files=filter(os.path.isfile,[os.path.join(dropbox,x) for x in os.listdir(dropbox) if p.match(x)])
00049     files.sort(key=lambda x: os.path.getmtime(os.path.join(dropbox,x)))
00050     #print 'sorted files ',files
00051     #print files
00052     #print qualifiedfiles
00053     lastRaw=files[-1]
00054     lastRecordedRun = getRunnumberFromFileName(lastRaw)
00055     print 'Last lumi file produced by HF: ', lastRaw +', Run: ', lastRecordedRun 
00056         
00057     # if yes, fill a list with the runs yet to be uploaded
00058     runsToBeAnalyzed = {}
00059     if lastRecordedRun != lastAnalyzedRunNumber:
00060         for file in files:
00061             if len(file.split('_'))!=7: continue
00062             thisrun=getRunnumberFromFileName(file)
00063             #print 'this run ',thisrun
00064             #if  thisrun>lastAnalyzedRunNumber and isCollisionRun(str(thisrun),authpath):
00065             if thisrun>lastAnalyzedRunNumber :
00066                 runsToBeAnalyzed[str(thisrun)] = file
00067     return runsToBeAnalyzed
00068 
00069 import os, sys
00070 from RecoLuminosity.LumiDB import argparse
00071 def main():
00072     parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Lumi Data scan")
00073     parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
00074     parser.add_argument('-d',dest='dropbox',action='store',required=True,help='location of the lumi root files')
00075     parser.add_argument('-P',dest='authpath',action='store',required=False,help='auth path')
00076     parser.add_argument('-L',dest='logpath',action='store',required=False,help='log path')
00077     parser.add_argument('-f',dest='loaderconf',action='store',required=True,help='path to loder config file')
00078     parser.add_argument('--minrun',dest='minrun',action='store',required=False,help='minimum run to serch')
00079     args=parser.parse_args()
00080     if args.authpath:
00081         lumiauthpath=args.authpath
00082     if args.logpath:
00083         lumilogpath=args.logpath
00084     loaderconf=args.loaderconf
00085     runsToBeAnalyzed = getRunsToBeUploaded(args.connect,args.dropbox,lumiauthpath,minrun=args.minrun) 
00086     
00087     runCounter=0
00088     rs=runsToBeAnalyzed.keys()
00089     rs.sort()
00090     for run in rs:
00091         runCounter+=1
00092         if runCounter==1: print 'List of processed runs: '
00093         print 'Run: ', run, ' file: ', runsToBeAnalyzed[run]
00094         logFile=open(os.path.join(lumilogpath,'loadDB_run'+run+'.log'),'w',0)
00095 
00096         # filling the DB
00097         command = '$LOCALRT/test/$SCRAM_ARCH/cmmdLoadLumiDB -r '+run+' -L "file:'+runsToBeAnalyzed[run]+'"'+' -f '+loaderconf+' --debug'
00098         statusAndOutput = commands.getstatusoutput(command)
00099         logFile.write(command+'\n')
00100         logFile.write(statusAndOutput[1])
00101         if not statusAndOutput[0] == 0:
00102             print 'ERROR while loading info onto DB for run ' + run
00103             print statusAndOutput[1]
00104             
00105     #    selectstring='"{'+run+':[]}"'
00106     #    command = 'lumiValidate.py -c '+args.connect+' -P '+ lumiauthpath+' -runls '+selectstring+' update' 
00107     #    statusAndOutput = commands.getstatusoutput(command)
00108     #    logFile.write(command+'\n')
00109     #    logFile.write(statusAndOutput[1])
00110     #    logFile.close()
00111     #    if not statusAndOutput[0] == 0:
00112     #        print 'ERROR while applying validation flag to run '+ run
00113     #        print statusAndOutput[1]
00114     if runCounter == 0: print 'No runs to be analyzed'
00115 
00116 if __name__=='__main__':
00117     main()