CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoLuminosity/LumiDB/scripts/lumiDBFiller.py

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