run_hadd.py
Go to the documentation of this file.
1 import os, sys
2 import subprocess
3 import re
4 
5 isTrial = False;
6 
7 if len(sys.argv)>1:
8  if sys.argv[1]=="--trial":
9  isTrial = True
10 
11 dirFile = "dirsToHadd.txt"
12 l_Dirs = [line.rstrip('\n') for line in open(dirFile)]
13 s_Persistent= "/pnfs/nova/persistent/users/aboot"
14 
15 def checkFileCount(s_Dir):
16  s_ExampleFile = subprocess.check_output("ls " + d + " | grep root | tail -n1", shell=True);
17  nFiles = subprocess.check_output("ls " + s_Dir + " | grep root | wc -l", shell=True);
18  for sub in nFiles.split():
19  if sub.isdigit():
20  nFiles = sub;
21  break;
22 
23  if str(nFiles)=="0":
24  print(s_Dir + " IS EMPTY!");
25  return False;
26 
27  s_ExpectedFiles = re.search("_of_(.*).root", s_ExampleFile);
28  print("IN THIS DIR THERE ARE " + nFiles + " of " + s_ExpectedFiles.group(1) + " ROOT FILES");
29  return ("of_"+str(nFiles)) in s_ExampleFile;
30 
31 if len(l_Dirs) > 0:
32  s_FirstDir = l_Dirs[0]
33  s_Persistent += s_FirstDir.split("abooth",1)[1]
34  s_Persistent = s_Persistent.rsplit("/", 1)[0]
35  s_Persistent += "/"
36 
37 if not os.path.exists(s_Persistent):
38  print("MAKING PERSISTENT DIR!")
39  print(s_Persistent)
40  os.makedirs(s_Persistent)
41 
42 for d in l_Dirs:
43  print("\n\nLOOKING AT DIRECTORY: " + d)
44  s_ExampleFile = subprocess.check_output("ls " + d + " | grep root | tail -n1", shell=True);
45  s_FileStub = s_ExampleFile.split(".")[0]
46  s_DestFile = s_Persistent + s_FileStub + ".root"
47  if os.path.exists(s_DestFile):
48  print("*****HADDED FILE EXISTS IN OUTDIR, PLEASE DELETE AND RERUN IF YOU WANT REGENERATION***")
49  continue
50  s_DestFile += " "
51  #cmd = "hadd_cafana -f " + s_DestFile
52  cmd = "hadd_cafana " + s_DestFile
53  cmd += d + "/" + s_FileStub + ".*_of*.root"
54  if checkFileCount(d):
55  print("DIRECTORY COMPLETE, HADDING!!!\n")
56  if isTrial:
57  print("TRIAL RUN, JUST PRINTING THE COMMAND:")
58  print(cmd)
59  else:
60  os.system(cmd)
61  else:
62  print("ALL FILES NOT YET COMPLETE, MOVING ON\n")
63 
64 print("\n\nALL DONE!")
65 
def checkFileCount(s_Dir)
Definition: run_hadd.py:15
bool print
procfile open("FD_BRL_v0.txt")