-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile_manager.py
47 lines (41 loc) · 1.65 KB
/
file_manager.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
39
40
41
42
43
44
45
46
47
import ROOT
from ROOT import TFile, TDirectory, TDirectoryFile, TList, THashList
class FileManager:
def __init__(self,list_hierarchies):
rootfile = TFile.Open(list_hierarchies[0],"READ");
self.list = [];
self.list.append(rootfile);
ROOT.SetOwnership(rootfile,False);
n = len(list_hierarchies);
for i in range(1,n):
#print(self.list[i-1].IsA());
if self.list[i-1].IsA() == TFile.Class() or self.list[i-1].IsA() == TDirectory.Class() or self.list[i-1].IsA() == TDirectoryFile.Class():
self.list.append(self.list[i-1].Get(list_hierarchies[i]));
else:
self.list.append(self.list[i-1].FindObject(list_hierarchies[i]));
print(self.list);
#print(self.list[-1].Print());
def get(self,objname):
if self.list[-1] is None:
print("self.list[-1] is None. return None.");
return None;
else:
if self.list[-1].IsA() == TFile.Class() or self.list[-1].IsA() == TDirectory.Class() or self.list[-1].IsA() == TDirectoryFile.Class():
return self.list[-1].Get(objname);
else:
return self.list[-1].FindObject(objname);
def close(self):
if self.list[0].IsOpen():
self.list[0].Close();
#_______________________________________________________________________
if __name__ == "__main__":
list_hierarchies = [
"AnalysisResults_table_maker.root"
,"table-maker"
,"output"
];
fm = FileManager(list_hierarchies);
list_ev_after = fm.get("Event_AfterCuts");
list_ev_after.ls();
fm.close();
#print(fm.get_list());