1 |
pjordi |
1.1 |
#!/usr/bin/python
|
2 |
|
|
|
3 |
|
|
import sys
|
4 |
|
|
import os
|
5 |
|
|
import os.path
|
6 |
|
|
import shutil
|
7 |
|
|
import hadd
|
8 |
|
|
|
9 |
|
|
if len(sys.argv) != 2:
|
10 |
|
|
print 'Usage: ', sys.argv[0], ' subfolder'
|
11 |
|
|
sys.exit()
|
12 |
|
|
|
13 |
|
|
subfolder = sys.argv[1]
|
14 |
|
|
|
15 |
|
|
if subfolder.endswith('/'):
|
16 |
|
|
subfolder = subfolder[:-1]
|
17 |
|
|
|
18 |
|
|
prefix = '/scratch/'+os.getenv('USER')+'/'
|
19 |
|
|
inpath = prefix+subfolder+'/'
|
20 |
|
|
assert os.path.exists(inpath)
|
21 |
|
|
|
22 |
|
|
print 'Found input path: ', inpath
|
23 |
|
|
|
24 |
|
|
outpath = 'output/' #+subfolder+'/'
|
25 |
|
|
#assert not os.path.exists(outpath)
|
26 |
|
|
outfile = outpath+subfolder+'.root'
|
27 |
|
|
assert not os.path.exists(outfile)
|
28 |
|
|
|
29 |
|
|
print 'Output path: ', outpath
|
30 |
|
|
print 'Output file: ', outfile
|
31 |
|
|
|
32 |
|
|
# merge all files
|
33 |
|
|
merged = inpath+subfolder+'_merged.root'
|
34 |
|
|
assert not os.path.exists(merged)
|
35 |
|
|
files = [inpath + s for s in os.listdir(inpath)]
|
36 |
|
|
|
37 |
|
|
print '---------------- start hadd ----------------'
|
38 |
|
|
hadd.hadd(merged, files)
|
39 |
|
|
print '---------------- hadd done ----------------'
|
40 |
|
|
|
41 |
|
|
print 'Created merged file: ', merged
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
# copy merged file
|
45 |
|
|
shutil.copy(merged, outfile)
|
46 |
|
|
print 'Copied merged file: ', outfile
|
47 |
|
|
print 'Done. The data hasn\'t been deleted on scratch...'
|
48 |
|
|
print ' To do that run: rm -r ', inpath
|