All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions | Variables
python.subruns Namespace Reference

Functions

def get_subruns
 

Variables

 myargv = sys.argv
 
tuple run_subruns = get_subruns(str(sys.argv[1]))
 

Function Documentation

def python.subruns.get_subruns (   inputfile)

Definition at line 46 of file subruns.py.

46 
47 def get_subruns(inputfile):
48 
49  # Initialize return value to empty list.
50 
51  result = []
52 
53  # Check whether this file exists.
54  if not os.path.exists(inputfile) or not inputfile.endswith('.root'):
55  return result
56 
57  # Root checks.
58 
59  file = ROOT.TFile.Open(larbatch_posix.root_stream(inputfile))
60  if file and file.IsOpen() and not file.IsZombie():
61 
62  # Root file opened successfully.
63  # Get runs and subruns fro SubRuns tree.
64 
65  subrun_tree = file.Get('SubRuns')
66  if subrun_tree and subrun_tree.InheritsFrom('TTree'):
67  nsubruns = subrun_tree.GetEntriesFast()
68  tfr = ROOT.TTreeFormula('runs',
69  'SubRunAuxiliary.id_.run_.run_',
70  subrun_tree)
71  tfs = ROOT.TTreeFormula('subruns',
72  'SubRunAuxiliary.id_.subRun_',
73  subrun_tree)
74  for entry in range(nsubruns):
75  subrun_tree.GetEntry(entry)
76  run = tfr.EvalInstance64()
77  subrun = tfs.EvalInstance64()
78  run_subrun = (run, subrun)
79  result.append(run_subrun)
80 
81  # If previous section didn't find anything, try extracting
82  # from beam data trees.
83 
84  if len(result) == 0:
85  tdir = file.Get('beamdata')
86  if tdir and tdir.InheritsFrom('TDirectory'):
87 
88  # Look for bnb tree.
89 
90  bnb_tree = tdir.Get('bnb')
91  if bnb_tree and bnb_tree.InheritsFrom('TTree'):
92  nsubruns = bnb_tree.GetEntriesFast()
93  tfr = ROOT.TTreeFormula('runs', 'run', bnb_tree)
94  tfs = ROOT.TTreeFormula('subruns', 'subrun', bnb_tree)
95  for entry in range(nsubruns):
96  bnb_tree.GetEntry(entry)
97  run = tfr.EvalInstance64()
98  subrun = tfs.EvalInstance64()
99  run_subrun = (run, subrun)
100  if run_subrun not in result:
101  result.append(run_subrun)
102 
103  # Look for numi tree.
104 
105  numi_tree = tdir.Get('numi')
106  if numi_tree and numi_tree.InheritsFrom('TTree'):
107  nsubruns = numi_tree.GetEntriesFast()
108  tfr = ROOT.TTreeFormula('runs', 'run', numi_tree)
109  tfs = ROOT.TTreeFormula('subruns', 'subrun', numi_tree)
110  for entry in range(nsubruns):
111  numi_tree.GetEntry(entry)
112  run = tfr.EvalInstance64()
113  subrun = tfs.EvalInstance64()
114  run_subrun = (run, subrun)
115  if run_subrun not in result:
116  result.append(run_subrun)
117 
118  else:
119 
120  # Root file could not be opened.
121 
122  result = []
123 
124  # Sort in order of increasing run, then increasing subrun.
125 
126  result.sort()
127 
128  # Done.
129 
130  return result
def get_subruns
Definition: subruns.py:46

Variable Documentation

python.subruns.myargv = sys.argv

Definition at line 27 of file subruns.py.

tuple python.subruns.run_subruns = get_subruns(str(sys.argv[1]))

Definition at line 132 of file subruns.py.