O2-DQ User Interface 1.0.0
Loading...
Searching...
No Matches
getTTrees Namespace Reference

Functions

def ExpandDeepTDirs (tf, to_map)
 
def getTTrees (str aod)
 
def Map (tf, browsable_to, tpath=None)
 
def MappingTFile (filename)
 

Function Documentation

◆ ExpandDeepTDirs()

def ExpandDeepTDirs (   tf,
  to_map 
)
A deep-mapping function for one TDirectory

Definition at line 37 of file getTTrees.py.

37def ExpandDeepTDirs(tf, to_map):
38 """
39 A deep-mapping function for one TDirectory
40 """
41
42 tpath = None # dummy param
43 names = sorted(to_map.keys())
44 # print("names = ",names)
45 for n in names:
46 # print("n =", n)
47 if len(to_map[n]) != 1:
48 continue
49 if tpath == None:
50 tpath_ = n
51 else:
52 tpath_ = tpath + "/" + n
53
54 tobject = to_map[n][0]
55 if type(tobject) is ROOT.TDirectoryFile:
56 m = Map(tf, tobject, tpath_)
57 #print(m)
58 to_map[n].append(m)
59 # print("TO MAP = ", to_map[n])
60 return to_map[n] #
61
62

◆ getTTrees()

def getTTrees ( str  aod)
 Get TTrees from one DF

Args:
    aod (CLI Argument): CLI Argument for AO2D.root File 

Returns:
    list: list of all ttres names in provided AO2D.root File

Definition at line 83 of file getTTrees.py.

83def getTTrees(aod: str):
84 """ Get TTrees from one DF
85
86 Args:
87 aod (CLI Argument): CLI Argument for AO2D.root File
88
89 Returns:
90 list: list of all ttres names in provided AO2D.root File
91 """
92 textAodList = aod.startswith("@")
93 endsWithTxt = aod.endswith("txt") or aod.endswith("text")
94 ttreeList = []
95
96 # Management for text aod list files
97 if textAodList and endsWithTxt:
98 aod = aod.replace("@", "")
99 with open(aod) as f:
100 for line in f:
101 if line.endswith(".root"):
102 # print(line)
103 aod = line # get one AO2D.root file from text
104 break
105
106 tFile = (MappingTFile(aod)) # Input as aod
107 for i in tFile:
108 if isinstance(i, dict):
109 for key in i.keys():
110 ttreeList.append(key)
111 return ttreeList

◆ Map()

def Map (   tf,
  browsable_to,
  tpath = None 
)
Maps objets as dict[obj_name][0] using a TFile (tf) and TObject to browse.

Definition at line 23 of file getTTrees.py.

23def Map(tf, browsable_to, tpath = None):
24 """
25 Maps objets as dict[obj_name][0] using a TFile (tf) and TObject to browse.
26 """
27 m = {}
28 for k in browsable_to.GetListOfKeys():
29 n = k.GetName()
30 if tpath == None:
31 m[n] = [tf.Get(n)]
32 else:
33 m[n] = [tf.Get(tpath + "/" + n)]
34 return m
35
36

◆ MappingTFile()

def MappingTFile (   filename)
Get TTree names from one Data Frame

Definition at line 63 of file getTTrees.py.

63def MappingTFile(filename):
64 """
65 Get TTree names from one Data Frame
66 """
67 if filename.endswith("txt") or filename.endswith("text"):
68 with open(filename) as f:
69 for line in f:
70 line = line.strip()
71 if line.endswith(".root"):
72 logging.info("Converter manager will use this file from text list : %s", line)
73 filename = line
74 break
75
76 f = ROOT.TFile(filename)
77 m = Map(f, f)
78 # print("MAP = ",m)
79 # print("FİLE = ",f)
80 return ExpandDeepTDirs(f, m)
81
82