CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ROOTData.py
Go to the documentation of this file.
1 from ROOT import *
2 from array import array
3 
4 #-------------------------------------------------------------------------------
5 def tfile_cd(dirname,tfile,debug=False):
6  """
7  Safely re-build and navigate the directory structure.
8  """
9 
10  if not tfile.GetDirectory(dirname):
11  gDirectory.cd("/")
12  path=""
13  for component in dirname.split('/'):
14  path+="/%s" %component
15  if not tfile.GetDirectory(path):
16  gDirectory.mkdir(component)
17  gDirectory.cd(component)
18 
19  if debug:
20  print "Current dir"
21  gDirectory.pwd()
22 
23 #-------------------------------------------------------------------------------
24 def literal2root (literal,rootType,tstreamerinfo=None):
25  """
26  Convert an hexadecimal string into a root-object. The correct TStreamerInfo
27  is passed in order to avoid inconsistencies.
28  """
29  bitsarray = array('B')
30  bitsarray.fromstring(literal.decode('hex'))
31 
32  tbuffer = TBufferFile(TBufferFile.kRead)
33  if tstreamerinfo:
34  tbuffer.IncrementLevel(tstreamerinfo)
35  tbuffer.SetBuffer(bitsarray,len(bitsarray),False)
36 
37  # replace a couple of shortcuts with the real root class name
38  if rootType == 'TPROF':
39  rootType = 'TProfile'
40  if rootType == 'TPROF2D':
41  rootType = 'TProfile2D'
42 
43  root_class=eval(rootType+'.Class()')
44 
45  return tbuffer.ReadObject(root_class)
46 
def literal2root
Definition: ROOTData.py:24
def tfile_cd
Definition: ROOTData.py:5