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 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
00045
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
00050
00051
00052 lastRaw=files[-1]
00053 lastRecordedRun = getRunnumberFromFileName(lastRaw)
00054 print 'Last lumi file produced by HF: ', lastRaw +', Run: ', lastRecordedRun
00055
00056
00057 runsToBeAnalyzed = {}
00058 if lastRecordedRun != lastAnalyzedRunNumber:
00059 for file in files:
00060 if len(file.split('_'))!=7: continue
00061 thisrun=getRunnumberFromFileName(file)
00062
00063
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
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
00105
00106
00107
00108
00109
00110
00111
00112
00113 if runCounter == 0: print 'No runs to be analyzed'
00114
00115 if __name__=='__main__':
00116 main()