3 from fnmatch
import fnmatchcase
8 Wraps exported Go4 memory .root-files
11 def __init__(self, filename, rootfolder="Analysis"):
13 Open the TFile filename as file and
14 get the TDirectory rootfolder as root
15 For rootfolder, "Workspace" might be desired besides the default
16 An unset rootfolder, "*", and "/" all mean the actual root of the file
18 if not rootfolder
or rootfolder
in [
"*",
"/"]:
21 self.
file = f = ROOT.TFile(filename)
22 self.
root = f.GetDirectory(rootfolder)
30 Iterate over all objects in the opened .root-file
31 folder can be a string (relative to rootfolder) or a TDirectory
35 elif isinstance(folder, basestring):
36 folder = self.root.GetDirectory(folder)
41 diriter = folder.GetListOfKeys().MakeIterator()
46 if key.GetClassName().startswith(
"TDirectory"):
47 subfolder = key.ReadObj()
48 for obj
in self.
Objects(subfolder):
56 Iterate over Objects() that match expr
58 for obj
in self.
Objects(folder):
60 if fnmatchcase(name, expr):
64 def tree(self, folder=None, indent=1):
66 Recursively print the object/folder tree of the opened .root-file
70 print folder.GetName()
72 diriter = folder.GetListOfKeys().MakeIterator()
77 if key.GetClassName().startswith(
"TDirectory"):
78 subfolder = key.ReadObj()
79 sfname = subfolder.GetName()
80 print "-"*indent, sfname
81 self.
tree(subfolder, indent+1)
83 print "="*indent, key.ReadObj().GetName()