CMS 3D CMS Logo

Functions
ROOTData Namespace Reference

Functions

def literal2root (literal, rootType, debug=False)
 
def loadStreamerInfo (literal, debug)
 
def tfile_cd (dirname, tfile, debug=False)
 

Function Documentation

◆ literal2root()

def ROOTData.literal2root (   literal,
  rootType,
  debug = False 
)
Convert an hexadecimal string into a root-object. In case a
TStreamerInfo object is passed, this will be decoded by the
loadStreamerInfo function to handle it properly and a None object
will be returned. It is the responsibility of the user not the use
the returned object in this very case.

Definition at line 53 of file ROOTData.py.

References mps_check.array, and loadStreamerInfo().

Referenced by dqm_interfaces.DQMcommunicator.get_root_objects(), dqm_interfaces.DQMcommunicator.get_root_objects_list(), dqm_interfaces.DQMcommunicator.get_root_objects_list_recursive(), dqm_interfaces.DQMcommunicator.get_root_objects_recursive(), and dqm_interfaces.DirWalkerDB.run().

53 def literal2root (literal, rootType, debug=False):
54 
55  """Convert an hexadecimal string into a root-object. In case a
56  TStreamerInfo object is passed, this will be decoded by the
57  loadStreamerInfo function to handle it properly and a None object
58  will be returned. It is the responsibility of the user not the use
59  the returned object in this very case."""
60 
61  if rootType == "TStreamerInfo":
62  loadStreamerInfo(literal, debug)
63  return None
64 
65  bitsarray = array('B')
66  bitsarray.frombytes(bytes.fromhex(literal))
67 
68  tbuffer = TBufferFile(TBufferFile.kRead)
69  tbuffer.SetBuffer(bitsarray,len(bitsarray),False)
70 
71  # replace a couple of shortcuts with the real root class name
72  if rootType == 'TPROF':
73  rootType = 'TProfile'
74  if rootType == 'TPROF2D':
75  rootType = 'TProfile2D'
76 
77  root_class = eval(rootType+'.Class()')
78 
79  return tbuffer.ReadObject(root_class)
80 
81 
def literal2root(literal, rootType, debug=False)
Definition: ROOTData.py:53
def loadStreamerInfo(literal, debug)
Definition: ROOTData.py:25

◆ loadStreamerInfo()

def ROOTData.loadStreamerInfo (   literal,
  debug 
)
Decode a literal made of TStreamerInfo informations and load
streamers that are not part of the currently used version of
ROOT. The implementation is a back-to-bone and simplified version of
the one contained in the DQM GUI source code.

Definition at line 25 of file ROOTData.py.

References mps_check.array, and print().

Referenced by literal2root().

25 def loadStreamerInfo(literal, debug):
26 
27  """Decode a literal made of TStreamerInfo informations and load
28  streamers that are not part of the currently used version of
29  ROOT. The implementation is a back-to-bone and simplified version of
30  the one contained in the DQM GUI source code."""
31 
32  bitsarray = array('B')
33  bitsarray.frombytes(bytes.fromhex(literal))
34 
35  tbuffer = TBufferFile(TBufferFile.kRead)
36  tbuffer.Reset();
37  tbuffer.SetBuffer(bitsarray, len(bitsarray), False)
38  while tbuffer.Length() != tbuffer.BufferSize():
39  obj = tbuffer.ReadObject(eval("TStreamerInfo.Class()"))
40  v = obj.GetClassVersion()
41  c = TClass.GetClass(obj.GetName(), kTRUE)
42  if c:
43  c.GetStreamerInfo();
44  if c.GetStreamerInfos().At(v):
45  if debug:
46  print("skipping already present streamer info version %d for %s" % (v, obj.GetName()))
47  continue
48  if debug:
49  print("Importing streamer info version %d for %s" % (v, obj.GetName()))
50  obj.BuildCheck();
51 
52 #-------------------------------------------------------------------------------
def loadStreamerInfo(literal, debug)
Definition: ROOTData.py:25
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ tfile_cd()

def ROOTData.tfile_cd (   dirname,
  tfile,
  debug = False 
)
Safely re-build and navigate the directory structure. dirname is
considered to be an absolute path.

Definition at line 6 of file ROOTData.py.

References print().

6 def tfile_cd(dirname, tfile, debug=False):
7 
8  """ Safely re-build and navigate the directory structure. dirname is
9  considered to be an absolute path."""
10 
11  gDirectory.cd("/")
12  if tfile.GetDirectory(dirname):
13  gDirectory.cd(dirname)
14  else:
15  path=""
16  for component in dirname.split('/'):
17  path += "/%s" % component
18  if not tfile.GetDirectory(path):
19  gDirectory.mkdir(component)
20  gDirectory.cd(component)
21 
22  if debug:
23  print("Current dir %s" % gDirectory.pwd())
24 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def tfile_cd(dirname, tfile, debug=False)
Definition: ROOTData.py:6