import glob, sys, os, string, io, ROOT, math, commands pandapath=os.environ.get('PANDAPATH') sys.path.append(pandapath+'/macro/tpc/FOPI/python/argparse-1.2.1') sys.path.append(pandapath+'/macro/tpc/FOPI/python/xlrd-0.9.2') sys.path.append(pandapath+'/macro/tpc/FOPI/python/xlwt-0.7.5') from ROOT import std from parFile import create_parfile import argparse import xlrd def search(num): count=-1 for i in range(len(info)): if num in info[i]: count = i return count parser=argparse.ArgumentParser(description='runs the runReco_mb.C root script for a choosable range of files') parser.add_argument('--path',help='path to data files',type=str,default="") parser.add_argument('--outpath',help='outpath',type=str,default="outfiles/CosmicData/") parser.add_argument('--info',help='file with the information of the datas',default="macro/tpc/FOPI/vwalbre/FieldCorr/simfiles_vw.xls",type=str) parser.add_argument('--hlp',help='show this help',action='store_true') parser.add_argument('--low',help='Lowest run number',type=int,default=3701) parser.add_argument('--high',help='Highest run number',type=int,default=99999) parser.add_argument('--wallcl',help='wallclock',type=int,default=0) parser.add_argument('--clfile',help='Cluster Correction File (line-1) in tpc.files.par', type=int,default=57) parser.add_argument('--NumParts',help='split the job into junks of size NumParts',type=float,default=5000) parser.add_argument('--noreclust',help='no reclust',action='store_true') parser.add_argument('--noclcorr',help='no cluster correction',action='store_true') parser.add_argument('--nogain',help='disable gain correction',action='store_const',const=0,default=1) parser.add_argument('--fC',help='error parameter fC',type=float,default=14) parser.add_argument('--onlyone',help='only one part in comb. with part',action='store_true') parser.add_argument('--part',help='only one part',type=int,default=10000) parser.add_argument('--inter',help='use interactive session instead of batch farm',action='store_true') parser.add_argument('--file',help='create file with ids and jobname',action='store_true') parser.add_argument('--errorfile',help='calculates only the files in the errorfile from mergerecofiles.py',type=str,default="") args=parser.parse_args() if args.hlp: parser.print_help() exit(0) ROOT.gROOT.ProcessLine(".x rootlogon.C") ROOT.gROOT.ProcessLine('gStyle->SetPalette(1)') ROOT.gROOT.ProcessLine('gROOT->SetStyle("Plain")') nEvts=args.NumParts gaincorr=args.nogain joblist = [] #load datafiles #{ FileList = os.listdir(args.path) FileList.sort() #} #load the information of the DataFiles #{ infofile = xlrd.open_workbook(args.info) sheetinfo = infofile.sheet_by_name(u'DATA') erfilelist=[] info = [] for row_number in xrange(sheetinfo.nrows): if row_number == 0 or row_number == 1: continue info.append(sheetinfo.row_values(row_number)) for row in range(len(info)): if info[row][0] != '' : info[row][0]=int(info[row][0]) if info[row][4] != '' : info[row][4]=round(info[row][4],1) #} if args.file: batchfile=open("batchfile.txt", "w") if args.errorfile: erfiles=open(args.errorfile, "r") for i in erfiles: erfilelist.append(i[:-6]) #prepare file for batch #{ count=0 for files in FileList: if files[-5:] != ".root": print "No ROOT File given" continue fpath=args.path+files #search information #{ beg=files.find("_") runNumber=int(files[beg+1:beg+5]) if runNumber < args.low or runNumber > args.high: continue count = search(runNumber) if count==-1: print "No information found to:", args.path+files continue #} #reject not cosmic files and defect files #{ if info[count][1] != "cosmics": print fpath, ": ", "No Cosmic:", info[count][1] continue if str(info[count][2]) != '': print fpath, ": ", str(info[count][2]) continue #} field = int(info[count][4]) gas = str(info[count][7]) gain = int(info[count][6]*100) bfield= float(info[count][8]) print "runNumber:", runNumber #Check datafile and parfile #{ RFile=ROOT.TFile.Open(fpath) tree=RFile.Get("tpcEvent") if tree==None: print "no tree found in file ",fpath RFile.Close() continue nofEvts=tree.GetEntriesFast() RFile.Close() if os.path.isfile("tpc/FOPI/par/tpc.run"+str(runNumber)+".par"): print 'parfile ok' else: if gas == 'NeCO2': gasf = 34 elif gas == 'ArCO2': gasf = 35 else: print "No TpcGasFile for:", gas continue efie = float(info[count][5]) gain_par = float(info[count][9]) vd = float(info[count][3]/1000) if vd == 0: print "vdrift is not known... taking it from gasfile" wallc = args.wallcl print "Creating parfile..." create_parfile(runNumber, gasf, efie, gain_par, gain, args.clfile, vd, wallc) print "Checking if parfile creating was successful..." if os.path.isfile("tpc/FOPI/par/tpc.run"+str(runNumber)+".par"): print 'parfile ok' else: print "Not possible to creat a parfile" #} #Submit #{ start=0 print "total number of events in file:", nofEvts nparts = int(float(nofEvts)/float(nEvts)) print "there will be", nparts,"files" jobid='' for i in range(nparts+1): stop=start+nEvts if stop > nofEvts: stop=nofEvts if args.onlyone: if i != args.part: start=stop continue outFileName= "runC_"+str(runNumber)+"_"+str(field)+"_"+str(gas)+"_"+str(gain)+"_" num=runNumber os.environ['num']=str(num) os.environ['start']=str(start) os.environ['stop']=str(stop) os.environ['outpath']=str(args.outpath) os.environ['gaincorr']=str(gaincorr) os.environ['errorfC']=str(args.fC) if bfield==0.0: os.environ['bfield']="0" else: os.environ['bfield']="1" if args.noreclust: os.environ['reclust']="false" else: os.environ['reclust']="true" outFileName+="recl_" if args.noclcorr: os.environ['clcorr']="false" else: os.environ['clcorr']="true" outFileName+="clcorr_" outFileName+="part_{0:03d}".format(i) print "OutFile:", outFileName os.environ['outFileName']=str(outFileName) name ="runC"+str(num)+"_part"+str(i) if not args.noreclust: name+='_recl' if not args.noclcorr: name+='_clcorr' print "Name Batch Job:", name os.environ['name']=str(name) if args.inter: os.system('. macro/tpc/FOPI/vwalbre/Batch/submitCosmicData.sh') start=stop continue if args.errorfile!="": if outFileName in erfilelist: os.system('qsub -N '+name+' -v "num","start","stop","outpath","gaincorr","errorfC","bfield","reclust","clcorr","outFileName" -o ~/sgeout/'+name+' -j oe macro/tpc/FOPI/vwalbre/Batch/submitCosmicData.sh') if args.file: batchfile.write("jobid: "+ str(jobid) + " Name: " + str(name)+ "\n") start=stop continue qsub='qsub -N '+name+' -v "num","start","stop","outpath","gaincorr","errorfC","bfield","reclust","clcorr","outFileName" -o ~/sgeout/'+name #qsub+=' -W depend=afterok:'+jobid qsub+=' -j oe macro/tpc/FOPI/vwalbre/Batch/submitCosmicData.sh ' status, jobid = commands.getstatusoutput(qsub) if args.file: batchfile.write("jobid: "+ str(jobid) + " Name: " + str(name)+ "\n") os.system('sleep 0.1') start=stop print "*****" #} #}