import os, argparse, sys, ROOT, math sys.path.append('/home/mberger/fopiroot/fopiroot_dev/macro/tpc/FOPI') sys.path.append('/home/mberger/fopiroot/fopiroot_dev/macro/tpc/FOPI/mberger') from parseFiles import PyFileParser from functions import parseRuns parser=argparse.ArgumentParser(description='start the root ana macro in junks and combine output afterwards') parser.add_argument('--path',help='path to store the parts',type=str,default='outfiles/ana_part') parser.add_argument('--outfname',help='name and path of the final file',default='./tmp_ana.root',type=str) parser.add_argument('--junk',help='size of the single file junks',default=100000,type=int) parser.add_argument('--rjunk',help='split in runs not junks',action='store_true') parser.add_argument('inpath',help='path to the files to analyze',type=str) parser.add_argument('runs',help='the runs to analyze',type=str) parser.add_argument('--pattern',help='a pattern to identfy special features of filenames',type=str,default='') parser.add_argument('--hlp',help='show help',action='store_true') args=parser.parse_args() if args.hlp: parser.print_help() exit() ROOT.gROOT.ProcessLine(".x rootlogon.C") ROOT.gROOT.ProcessLine('gStyle->SetPalette(1)') ROOT.gROOT.ProcessLine('gROOT->SetStyle("Plain")') fp=PyFileParser() fp.setPath(args.inpath) if not args.rjunk: chain=[] fp.setPath(args.inpath) fp.setPattern(args.pattern) run=fp.setRuns(args.runs) used=[] for i in range(fp.getNum()): chain.append(ROOT.TChain("cbmsim")) if used.count(i)==1: continue chain.AddFile(fp.getFile(i)) entries=chain.GetEntries() print "There are",entries,"Events available" donefiles="" for i in range(int(math.ceil(float(entries)/float(args.junk)))): start=i*args.junk stop=(i+1)*args.junk-1 if stop>entries: stop=entries print 'start=',start,'stop=',stop command='root -l macro/tpc/FOPI/runAna_mb.C\(\\"' command+=args.inpath+'\\",\\"' command+=args.runs+'\\"\,\\"' command+=args.path+'/anatmp_'+str(i)+'.root\\",' command+='\\"'+args.pattern+'\\\",' command+=str(stop)+','+str(start)+'\) -q' # print command os.system(command) donefiles+=args.path+'/anatmp_'+str(i)+'_ana.root ' #command='python macro/tpc/FOPI/BatchTools/mergerecofiles.py ' #command+='--files '+ donefiles #command+='--out '+args.outfname #command='hadd -f '+args.outfname+' ' #command+=donefiles #print command os.system(command) if args.rjunk: runList=parseRuns(args.runs) for run in runList: chain=ROOT.TChain("cbmsim") fp.resetFiles() fp.setPattern(args.pattern) fp.setRuns(str(run)) fp.printFiles() for i in range(fp.getNum()): chain.AddFile(fp.getFile(i)) entries=chain.GetEntries() command='root -l macro/tpc/FOPI/runAna_mb.C\(\\"' command+=args.inpath+'\\",\\"' command+=str(run)+'\\"\,\\"' command+=args.path+'/anatmp_'+str(run)+'.root\\",' command+='\\"'+args.pattern+'\\"' command+=','+str(entries) command+='\) -q' # print command os.system(command) # print runList