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/mberger') import argparse from functions import parseRuns parser=argparse.ArgumentParser(description='submit make mtree for several files') parser.add_argument('path',help='path to where the runfolder are',type=str) parser.add_argument('runs',help='which runs to do') parser.add_argument('pattern',help='the pattern to select the infiles') parser.add_argument('--parts',help='use the part files',action='store_true') #parser.add_argument('--merge',help='merge the output files into one') args=parser.parse_args() runlist=parseRuns(args.runs) filelist=[] for run in runlist: if args.parts: filelist+=glob.glob('{0}/runC_{1}*{2}*.reco.root'.format(args.path,run,args.pattern)) else: filelist+=(glob.glob('{2}/run_{0}/run_{0}_*{1}*.reco.root'.format(run,args.pattern,args.path))) mergelist=open('mtree_files.txt','w') for f in filelist: if args.parts: run=int(f[f.find('runC_')+5:f.find('runC_')+9]) else: run=int(f[f.find('run_')+4:f.find('run_')+8]) outfilename=f.replace('.reco.','.mtree.') os.environ['infile']=f os.environ['outfile']=outfilename qsub='qsub -N mtree_run{0} -V -o ~/sgeout/mtree_run{0} -j oe -l walltime=02:00:00 -l mem=2000m FOPI/BatchTools/submitMakeMtree.sh'.format(run) mergelist.write('{0}\n'.format(outfilename)) # print qsub status, jobid = commands.getstatusoutput(qsub) print 'submitted: {0} ID={1}'.format(run,jobid) mergelist.close()