-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathhaddsplit
executable file
·39 lines (30 loc) · 1.14 KB
/
haddsplit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
import sys, os
def haddsplit(destDir, inputFiles):
## estimate total size and merge not to exceed 1Gbytes
totalSize = sum([os.stat(f).st_size for f in inputFiles])
fSize = 4*1024.*1024*1024 # 4GB
nOutput = int(totalSize/fSize)+1
nTotalFiles = len(inputFiles)
nFiles = nTotalFiles/nOutput
for i in range(nOutput):
print i
cmd = 'hadd -f %s_%d.root ' % (destDir, i)
if i == nOutput-1: cmd += ' '.join(inputFiles[i*nFiles:])
else: cmd += ' '.join(inputFiles[i*nFiles:(i+1)*nFiles])
os.system(cmd)
for x in inputFiles: os.system("rm -f %s" % (x))
def usage():
print """usage: %s OUTPUT.root INPUT_0.root INPUT_1.root ...
OUTPUT root files will be split by 4GBytes,
OUTPUT_0.root OUTPUT_1.root ... will be created""" % (sys.argv[0])
if __name__ == '__main__':
if len(sys.argv) < 3:
usage()
sys.exit(1)
outFilePrefix = sys.argv[1].replace('.root', '')
inFileNames = sys.argv[2:]
if len(inFileNames) == 1:
os.system("mv %s %s_0.root" % (inFileNames[0], outFilePrefix))
else:
haddsplit(outFilePrefix, inFileNames)