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') import argparse parser=argparse.ArgumentParser(description='submit all reco files in folder for cluster distribution cal;c to batch') parser.add_argument('path',help='path to the reco files',type=str) parser.add_argument('ppath',help='path to where to save the pdf and root files',type=str) parser.add_argument('prefix',help='prefix for the pdf and root files',type=str) parser.add_argument('--list',help='path is not a folder but a file with an list of files and titles (file;title)',action='store_true') args=parser.parse_args() import ROOT ROOT.gROOT.ProcessLine(".x rootlogon.C") titles=[] if args.list: files=[] for f in open(args.path): f=f.replace(' ','') f=f.replace('\n','') words=f.split(';') files.append(words[0]) if len(words)>1: titles.append(words[1]) else: files=glob.glob("{0}/*.reco.root".format(args.path)) fcounter=-1 for f in files: #construct resulting pictuire files name fcounter+=1 fname=f.split('/')[-1] fnamep=fname.split('_') fnamep_end=fnamep.pop().split('.') fnamep=fnamep+fnamep_end endindex=fnamep.index('reco') startindex=fnamep.index('1') pname='' for i in range(startindex+1,endindex): pname+='_{0}'.format(fnamep[i]) if len(titles)>0: pname+='_{0}'.format(titles[fcounter]) pname='{0}/{1}{2}.pdf'.format(args.ppath,args.prefix,pname) if os.path.isfile(pname): print 'pdf is existing, skipping this one',pname continue os.environ['cldistpath']=args.path os.environ['cldistfile']=f os.environ['cldistpname']=pname qsub='qsub -N {0} -V -o ~/sgeout/{0} -j oe -l walltime=01:15:00 -l mem=500m macro/tpc/FOPI/BatchTools/submitClusterDist.sh '.format(pname.split('/')[-1].replace('.pdf','.txt')) print 'submitting',pname status, jobid = commands.getstatusoutput(qsub) print status,jobid