diff --git a/macros/CCEScan/batch/hadd.py b/macros/CCEScan/batch/hadd.py index 82fdc61..0b6047a 100644 --- a/macros/CCEScan/batch/hadd.py +++ b/macros/CCEScan/batch/hadd.py @@ -1,82 +1,17 @@ +import sys import os -import time -from datetime import datetime -import calendar +import glob -temp_dir = "/disk/data1/hep/elena/data/ST/Aging" -pwd = os.getcwd() +fills = sys.argv[1:] -os.chdir(temp_dir) -files = filter(os.path.isfile, os.listdir(temp_dir)) -files = [os.path.join(temp_dir, f) for f in files] -files.sort(key=lambda x: os.path.getmtime(x)) +disk = os.path.expandvars('$DISK') + '/data/ST/Aging' -#dec15 = time.mktime(datetime.strptime('15/12/2015', '%d/%m/%Y').timetuple()) -# UTC time (ignore time zone) -dec15 = float(calendar.timegm(datetime.strptime('15/12/2015', '%d/%m/%Y').timetuple())) - -haddcmd = os.path.expandvars('$ROOTSYS') + '/bin/hadd' - -def modtime(f): - return os.path.getmtime(f) - -files_to_hadd = {} - -sectors = [] -#with open('%s/TTsectors.dat' % os.path.dirname(pwd), 'rb') as sectsfile: -# for line in sectsfile: -# sectors.append(str(line).strip()) - -with open('%s/ITsectors.dat' % os.path.dirname(pwd), 'rb') as sectsfile: - for line in sectsfile: - sectors.append(str(line).strip()) - -print sectors - -for sector in sectors: - files_to_hadd[sector] = {} - files_to_hadd[sector]['list'] = [] - files_to_hadd[sector]['target'] = temp_dir + '/landauFit_%s.root' % sector - for f in files: - if modtime(f) > dec15 and 'temp_' in f and sector in f and '.root' in f: - files_to_hadd[sector]['list'].append(f) - -sector_files = [] - -def hadd(): - - for sector in sectors: - haddstring = "%s -f %s %s\n" % (haddcmd, files_to_hadd[sector]['target'], " ".join(files_to_hadd[sector]['list'])) - - with open('hadd-%s.sh' % sector, 'wb') as exefile: - exefile.write(haddstring) - os.system('bash hadd-%s.sh' % sector) - os.system('rm hadd-%s.sh' % sector) - - sector_files.append(files_to_hadd[sector]['target']) - #sector_files.extend([files_to_hadd[sector]['target'] for sector in sectors]) - - target = temp_dir + '/CCEScan_temp.root' - with open('haddAll.sh', 'wb') as exefile: - exefile.write('%s -f %s %s\n' % (haddcmd, target, ' '.join(sector_files))) - exefile.write('%s -f %s %s %s\n' % (haddcmd, temp_dir + '/CCEScan_temp_all.root', target, temp_dir + '/CCEScan.root')) - exefile.write('cp %s %s\n' % (temp_dir + '/CCEScan.root', temp_dir + 'CCEScan_BK.root')) - - os.system('bash haddAll.sh') - os.system('rm haddAll.sh') - - -def cleanup(): - with open('cleanup.sh', 'wb') as cleanfile: - for sector in sectors: - for f in files_to_hadd[sector]['list']: - cleanfile.write('rm %s\n' % f) - for f in sector_files: - cleanfile.write('rm %s\n' % f) - - cleanfile.write('rm %s\n' % (temp_dir + '/CCEScan.root')) - cleanfile.write('mv %s %s\n' % (temp_dir + '/CCEScan_temp_all.root', temp_dir + '/CCEScan.root')) - - os.system('bash cleanup.sh') - os.system('rm cleanup.sh') - +ll = {} +for fill in fills: + ll[fill] = glob.glob('%s/temp*_%s_*.root' % (disk,fill)) +targets = [] +for fill in fills: + targets += ll[fill] +with open('haddfile.sh', 'wb') as f: + f.write('hadd -f %s/CCEScan_temp.root %s\n' % (disk, ' '.join(targets))) + f.write('hadd -f %s/CCEScan.root %s/CCEScan.root /disk/data1/hep/elena/data/ST/Aging/CCEScan_temp.root\n' % (disk, disk))