#!/usr/bin/python # purpose: sum individual root files into one single root file # for all runs found in loc import os,sys # location of run directories #loc = '/cache/halld/home/gxproj3/calib/GlueX-CalibRun-2016-03-18' #loc = '/cache/halld/home/gxproj3/calib/GlueX-CalibRun-2016-04-04' #loc = '/cache/halld/home/gxproj3/calib/GlueX-CalibRun-2016-04-11' #loc = '/cache/halld/home/gxproj3/calib/GlueX-CalibRun-2016-04-27' loc = '/work/halld2/home/zihlmann/HallD/work/TOFmon/genroot/hists' RunDirs = [] RunNum = 10001 RUNS = [] for d in os.listdir(loc): run = d R = int(run) if R>RunNum: RunDirs.append(d) RUNS.append(R) RUNS.sort() RunDirs.sort() for k in range(0,len(RunDirs)): files = [] location = loc+'/'+RunDirs[k] runfiles = [] for f in os.listdir(location): if f.startswith('tofmon_'): runfiles.append(f) runfiles.sort() s = runfiles[0].split('_') RunFormat = s[1] of = location+'/tofmon_'+RunFormat+'.root' if os.path.isfile(of): print 'file ',of,' already exists!' continue if RUNS[k] > 10000: cmd = 'hadd '+of for n in range(0,len(runfiles)): cmd += ' '+location+'/'+runfiles[n] print cmd os.system(cmd)