Go to the documentation of this file.00001 from ROOT import *
00002 from array import array
00003
00004
00005 def tfile_cd(dirname,tfile,debug=False):
00006 """
00007 Safely re-build and navigate the directory structure.
00008 """
00009
00010 if not tfile.GetDirectory(dirname):
00011 gDirectory.cd("/")
00012 path=""
00013 for component in dirname.split('/'):
00014 path+="/%s" %component
00015 if not tfile.GetDirectory(path):
00016 gDirectory.mkdir(component)
00017 gDirectory.cd(component)
00018
00019 if debug:
00020 print "Current dir"
00021 gDirectory.pwd()
00022
00023
00024 def literal2root (literal,rootType,tstreamerinfo=None):
00025 """
00026 Convert an hexadecimal string into a root-object. The correct TStreamerInfo
00027 is passed in order to avoid inconsistencies.
00028 """
00029 bitsarray = array('B')
00030 bitsarray.fromstring(literal.decode('hex'))
00031
00032 tbuffer = TBufferFile(TBufferFile.kRead)
00033 if tstreamerinfo:
00034 tbuffer.IncrementLevel(tstreamerinfo)
00035 tbuffer.SetBuffer(bitsarray,len(bitsarray),False)
00036
00037
00038 if rootType == 'TPROF':
00039 rootType = 'TProfile'
00040 if rootType == 'TPROF2D':
00041 rootType = 'TProfile2D'
00042
00043 root_class=eval(rootType+'.Class()')
00044
00045 return tbuffer.ReadObject(root_class)
00046