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='hadd file from filelist') parser.add_argument('filelist',help='the list withe the files',type=str) parser.add_argument('outfile',help='the name of the output file',type=str) parser.add_argument('--subst',help='substitde string with other string',type=str,nargs=2,default=['','']) args=parser.parse_args() haddstring='' counter=-1 for l in open(args.filelist,'r'): counter+=1 fname=l.replace('\n','') fname=fname.replace(args.subst[0],args.subst[1]) haddstring+=' '+fname if counter==0 and args.outfile=='Auto': paths=fname.split('/') paths.pop() paths.pop() #print paths basename=fname.split('/')[-1] args.outfile="/".join(paths) + '/' + basename[0:basename.rfind("_")] + basename[basename.rfind("_")+5:len(basename)] if counter==20: if os.path.isfile("{0}".format(args.outfile)): print 'outfile is existent, moving and adding' os.system('mv {0} {0}_tmp'.format(args.outfile)) os.system('hadd -f {0} {1} {0}_tmp'.format(args.outfile,haddstring)) os.system('rm {0}_tmp'.format(args.outfile)) else: os.system('hadd -f {0} {1}'.format(args.outfile,haddstring)) haddstring='' counter=-1 #print haddstring #print 'hadd -f {0} {1}'.format(args.outfile,haddstring) if os.path.isfile("{0}".format(args.outfile)): print 'outfile is existent, moving and adding' os.system('mv {0} {0}_tmp'.format(args.outfile)) os.system('hadd -f {0} {1} {0}_tmp'.format(args.outfile,haddstring)) os.system('rm {0}_tmp'.format(args.outfile)) else: os.system('hadd -f {0} {1}'.format(args.outfile,haddstring)) #print commands.getstatusoutput('hadd -f {0} {1}'.format(args.outfile,haddstring))