CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/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     rlist= eval(statusAndOutput[1])
00038     if rlist:
00039         lastAnalyzedRunNumber = rlist[-1]
00040         print 'Last run in DB: ', lastAnalyzedRunNumber
00041     else:
00042         print 'No qualified run found in DB'
00043         lastAnalyzedRunNumber=int(minrun)
00044     # check if there are new runs to be uploaded
00045     #command = 'ls -ltr '+dropbox
00046     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$')
00047     files=filter(os.path.isfile,[os.path.join(dropbox,x) for x in os.listdir(dropbox) if p.match(x)])
00048     files.sort(key=lambda x: os.path.getmtime(os.path.join(dropbox,x)))
00049     #print 'sorted files ',files
00050     #print files
00051     #print qualifiedfiles
00052     lastRaw=files[-1]
00053     lastRecordedRun = getRunnumberFromFileName(lastRaw)
00054     print 'Last lumi file produced by HF: ', lastRaw +', Run: ', lastRecordedRun 
00055         
00056     # if yes, fill a list with the runs yet to be uploaded
00057     runsToBeAnalyzed = {}
00058     if lastRecordedRun != lastAnalyzedRunNumber:
00059         for file in files:
00060             if len(file.split('_'))!=7: continue
00061             thisrun=getRunnumberFromFileName(file)
00062             #print 'this run ',thisrun,lastAnalyzedRunNumber
00063             #if  thisrun>lastAnalyzedRunNumber and isCollisionRun(str(thisrun),authpath):
00064             if thisrun>lastAnalyzedRunNumber :
00065                 runsToBeAnalyzed[str(thisrun)] = file
00066     return runsToBeAnalyzed
00067 
00068 import os, sys
00069 from RecoLuminosity.LumiDB import argparse
00070 def main():
00071     parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Lumi Data scan")
00072     parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
00073     parser.add_argument('-d',dest='dropbox',action='store',required=True,help='location of the lumi root files')
00074     parser.add_argument('-P',dest='authpath',action='store',required=False,help='auth path')
00075     parser.add_argument('-L',dest='logpath',action='store',required=False,help='log path')
00076     parser.add_argument('-f',dest='loaderconf',action='store',required=True,help='path to loder config file')
00077     parser.add_argument('--minrun',dest='minrun',action='store',required=False,help='minimum run to serch')
00078     args=parser.parse_args()
00079     if args.authpath:
00080         lumiauthpath=args.authpath
00081     if args.logpath:
00082         lumilogpath=args.logpath
00083     loaderconf=args.loaderconf
00084     runsToBeAnalyzed = getRunsToBeUploaded(args.connect,args.dropbox,lumiauthpath,minrun=args.minrun) 
00085     
00086     runCounter=0
00087     rs=runsToBeAnalyzed.keys()
00088     rs.sort()
00089     for run in rs:
00090         runCounter+=1
00091         if runCounter==1: print 'List of processed runs: '
00092         print 'Run: ', run, ' file: ', runsToBeAnalyzed[run]
00093         logFile=open(os.path.join(lumilogpath,'loadDB_run'+run+'.log'),'w',0)
00094 
00095         # filling the DB
00096         command = '$LOCALRT/test/$SCRAM_ARCH/cmmdLoadLumiDB -r '+run+' -L "file:'+runsToBeAnalyzed[run]+'"'+' -f '+loaderconf+' --debug'
00097         statusAndOutput = commands.getstatusoutput(command)
00098         logFile.write(command+'\n')
00099         logFile.write(statusAndOutput[1])
00100         if not statusAndOutput[0] == 0:
00101             print 'ERROR while loading info onto DB for run ' + run
00102             print statusAndOutput[1]
00103             
00104     #    selectstring='"{'+run+':[]}"'
00105     #    command = 'lumiValidate.py -c '+args.connect+' -P '+ lumiauthpath+' -runls '+selectstring+' update' 
00106     #    statusAndOutput = commands.getstatusoutput(command)
00107     #    logFile.write(command+'\n')
00108     #    logFile.write(statusAndOutput[1])
00109     #    logFile.close()
00110     #    if not statusAndOutput[0] == 0:
00111     #        print 'ERROR while applying validation flag to run '+ run
00112     #        print statusAndOutput[1]
00113     if runCounter == 0: print 'No runs to be analyzed'
00114 
00115 if __name__=='__main__':
00116     main()