forked from elaird/hcalraw
-
Notifications
You must be signed in to change notification settings - Fork 2
/
datToRoot.py
executable file
·38 lines (27 loc) · 1.05 KB
/
datToRoot.py
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
#!/usr/bin/env python2
import os, sys
def main(directory):
roots = []
assert os.path.isdir(directory)
for dat in os.listdir(directory):
if not dat.endswith(".dat"):
continue
s = '"file://%s/%s"' % (directory, dat)
py = "%s/%s" % (directory, dat.replace(".dat", ".py"))
root = "%s/%s" % (directory, dat.replace(".dat", ".root"))
roots.append(root)
cmd = "cat template_datToRoot_cfg.py | sed s@FILEFLAG@'%s'@ | sed s@OUTFLAG@'%s'@ > %s" % (s, '"%s"' % root, py)
# print cmd
os.system(cmd)
os.system("cmsRun %s |& grep -v 'Initiating request to open file' |& grep -v 'Closed file'" % py)
hadd(directory, roots)
def hadd(directory, roots):
while directory.endswith("/"):
directory = directory[:-1]
cmd = "hadd -f %s.root %s" % (os.path.basename(directory), " ".join(roots))
# print cmd
os.system(cmd)
if __name__ == "__main__":
if len(sys.argv) != 2:
sys.exit("Please provide a directory as an argument.")
main(sys.argv[1])