import glob, sys, os, ROOT from ROOT import std nokeep=0 runs="bla" check=0 merge=0 for iarg in range(len(sys.argv)): arg=sys.argv[iarg] if arg == "-nokeep": nokeep=1 if arg=="-runs": runs=sys.argv[iarg+1] if arg=="-check": check=1 if arg=="-merge": merge=1 runList=[] colindex = runs.find(",") if colindex > 0: runs = runs.split(",") for i in range(len(runs)) : dashIndex = runs[i].find("-") if dashIndex > 0 : runs[i] = runs[i].split("-") for j in range(int(runs[i][0]), int(runs[i][1])+1) : runList.append(j) # runList = range(int(runs[0]), int(runs[1])+1) if dashIndex < 0 and len(runs) > 1 : runList.append(int(runs[i])) else : dashIndex = runs.find("-") if dashIndex > 0 : runs = runs.split("-") runList = range(int(runs[0]), int(runs[1])+1) if dashIndex < 0 and len(runs) > 1 : runList = [runs] print runList files=glob.glob("./*.root") filelist = [] filenumber = [] filecount=0 for file in files : if len(runList) >= 1 : found = 0 for i in runList : if file.find(str(i)) >= 0 : found = 1 filecount += 1 filelist.append(file) filenumber.append(i) else: filelist.append(file) filelist.append("runC_9999.reco90.root") filelist.sort() counter=0 eventsum=0 todo="" start=filelist[0].find("runC_") oldfnum=int(filelist[0][start+5:start+9]) print filelist ROOT.gROOT.ProcessLine(".x /nfs/hicran/project/panda/SIM/bergerm/fopiroot/rootlogon.C") for f in filelist: counter+=1 start=f.find("runC_") fnum=int(f[start+5:start+9]) start=f.find("reco") end=f.find(".root") # print "start:",start," end:",end if start+4==end: pnum=0 else: pnum=int(f[start+4:end]) #print "pnum:",pnum if oldfnum==fnum: todo+=f todo+=" " else: todo2="" if nokeep ==1: todo2 +=" -f " todo2 += " ../runC_"+str(oldfnum)+".smoothed_reco.root " + todo if merge==1: print "todo2:",todo2 os.system("hadd "+todo2) todo="" todo+=f todo += " " # eventsum=0 if check==1: if f!="runC_9999.reco90.root": RFile=ROOT.TFile.Open(f) tree=RFile.Get("cbmsim") if tree==None: print "no tree found in file ",f RFile.Close() continue nofEvts=tree.GetEntriesFast() eventsum+=nofEvts print "Events in run",fnum, "part",pnum," : ",nofEvts if oldfnum!=fnum: print "Total events in run ",oldfnum," : ",eventsum eventsum=0 oldfnum=fnum