00001
00002
00003 import string, os, time,re
00004 import commands
00005 lumiauthpath=''
00006 lumilogpath=''
00007 loaderconf=''
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 def getRunnumberFromFileName(lumifilename):
00027 runnumber=int(lumifilename.split('_')[4])
00028 return runnumber
00029
00030 def getRunsToBeUploaded(connectionString, dropbox, authpath='',minrun=180250):
00031
00032
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
00046
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
00051
00052
00053 lastRaw=files[-1]
00054 lastRecordedRun = getRunnumberFromFileName(lastRaw)
00055 print 'Last lumi file produced by HF: ', lastRaw +', Run: ', lastRecordedRun
00056
00057
00058 runsToBeAnalyzed = {}
00059 if lastRecordedRun != lastAnalyzedRunNumber:
00060 for file in files:
00061 if len(file.split('_'))!=7: continue
00062 thisrun=getRunnumberFromFileName(file)
00063
00064
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
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
00106
00107
00108
00109
00110
00111
00112
00113
00114 if runCounter == 0: print 'No runs to be analyzed'
00115
00116 if __name__=='__main__':
00117 main()