CMS 3D CMS Logo

Functions | Variables
treeReaderArrayTools Namespace Reference

Functions

def _currentTreeEntry (tree)
 
def _gotoEntry (tree, entry, forceCall=False)
 
def _makeArrayReader (tree, typ, nam)
 PRIVATE IMPLEMENTATION PART #######. More...
 
def _makeValueReader (tree, typ, nam)
 
def _readAllBranches (tree)
 
def _remakeAllReaders (tree)
 
def clearExtraBranches (tree)
 
def getArrayReader (tree, branchName)
 
def getValueReader (tree, branchName)
 
def InputTree (tree, entrylist=ROOT.MakeNullPointer(ROOT.TEntryList))
 
def readBranch (tree, branchName)
 
def setExtraBranch (tree, name, val)
 

Variables

 IgnoreCommandLineOptions
 

Function Documentation

◆ _currentTreeEntry()

def treeReaderArrayTools._currentTreeEntry (   tree)
private

Definition at line 137 of file treeReaderArrayTools.py.

Referenced by _readAllBranches().

137 def _currentTreeEntry(tree):
138  if tree._entrylist:
139  return tree._entrylist.GetEntry(tree.entry)
140  else:
141  return tree.entry
142 
143 

◆ _gotoEntry()

def treeReaderArrayTools._gotoEntry (   tree,
  entry,
  forceCall = False 
)
private

Definition at line 144 of file treeReaderArrayTools.py.

144 def _gotoEntry(tree, entry, forceCall=False):
145  tree._ttreereader._isClean = False
146  if tree.entry != entry or forceCall:
147  if (tree.entry == entry - 1 and entry != 0):
148  tree._ttreereader.Next()
149  else:
150  tree._ttreereader.SetEntry(entry)
151  tree.entry = entry
152 
def _gotoEntry(tree, entry, forceCall=False)

◆ _makeArrayReader()

def treeReaderArrayTools._makeArrayReader (   tree,
  typ,
  nam 
)
private

PRIVATE IMPLEMENTATION PART #######.

Definition at line 100 of file treeReaderArrayTools.py.

References _remakeAllReaders().

Referenced by getArrayReader(), and readBranch().

100 def _makeArrayReader(tree, typ, nam):
101  if not tree._ttreereader._isClean:
102  _remakeAllReaders(tree)
103  ttra = ROOT.TTreeReaderArray(typ)(tree._ttreereader, nam)
104  tree._leafTypes[nam] = typ
105  tree._ttras[nam] = ttra
106  return tree._ttras[nam]
107 
108 
def _makeArrayReader(tree, typ, nam)
PRIVATE IMPLEMENTATION PART #######.

◆ _makeValueReader()

def treeReaderArrayTools._makeValueReader (   tree,
  typ,
  nam 
)
private

Definition at line 109 of file treeReaderArrayTools.py.

References _remakeAllReaders().

Referenced by getValueReader(), and readBranch().

109 def _makeValueReader(tree, typ, nam):
110  if not tree._ttreereader._isClean:
111  _remakeAllReaders(tree)
112  ttrv = ROOT.TTreeReaderValue(typ)(tree._ttreereader, nam)
113  tree._leafTypes[nam] = typ
114  tree._ttrvs[nam] = ttrv
115  return tree._ttrvs[nam]
116 
117 
def _makeValueReader(tree, typ, nam)

◆ _readAllBranches()

def treeReaderArrayTools._readAllBranches (   tree)
private

Definition at line 133 of file treeReaderArrayTools.py.

References _currentTreeEntry().

133 def _readAllBranches(tree):
134  tree.GetEntry(_currentTreeEntry(tree))
135 
136 

◆ _remakeAllReaders()

def treeReaderArrayTools._remakeAllReaders (   tree)
private

Definition at line 118 of file treeReaderArrayTools.py.

Referenced by _makeArrayReader(), and _makeValueReader().

118 def _remakeAllReaders(tree):
119  _ttreereader = ROOT.TTreeReader(tree, getattr(tree, '_entrylist', ROOT.MakeNullPointer(ROOT.TEntryList)))
120  _ttreereader._isClean = True
121  _ttrvs = {}
122  for k in tree._ttrvs.keys():
123  _ttrvs[k] = ROOT.TTreeReaderValue(tree._leafTypes[k])(_ttreereader, k)
124  _ttras = {}
125  for k in tree._ttras.keys():
126  _ttras[k] = ROOT.TTreeReaderArray(tree._leafTypes[k])(_ttreereader, k)
127  tree._ttrvs = _ttrvs
128  tree._ttras = _ttras
129  tree._ttreereader = _ttreereader
130  tree._ttreereaderversion += 1
131 
132 

◆ clearExtraBranches()

def treeReaderArrayTools.clearExtraBranches (   tree)

Definition at line 58 of file treeReaderArrayTools.py.

Referenced by eventloop.eventLoop().

58 def clearExtraBranches(tree):
59  tree._extrabranches = {}
60 
61 

◆ getArrayReader()

def treeReaderArrayTools.getArrayReader (   tree,
  branchName 
)
Make a reader for branch branchName containing a variable-length value array.

Definition at line 28 of file treeReaderArrayTools.py.

References _makeArrayReader(), and nano_mu_local_reco_cff.bool.

28 def getArrayReader(tree, branchName):
29  """Make a reader for branch branchName containing a variable-length value array."""
30  if branchName not in tree._ttras:
31  if not tree.GetBranch(branchName):
32  raise RuntimeError("Can't find branch '%s'" % branchName)
33  if not tree.GetBranchStatus(branchName):
34  raise RuntimeError("Branch %s has status=0" % branchName)
35  leaf = tree.GetBranch(branchName).GetLeaf(branchName)
36  if not bool(leaf.GetLeafCount()):
37  raise RuntimeError("Branch %s is not a variable-length value array" % branchName)
38  typ = leaf.GetTypeName()
39  tree._ttras[branchName] = _makeArrayReader(tree, typ, branchName)
40  return tree._ttras[branchName]
41 
42 
def getArrayReader(tree, branchName)
def _makeArrayReader(tree, typ, nam)
PRIVATE IMPLEMENTATION PART #######.

◆ getValueReader()

def treeReaderArrayTools.getValueReader (   tree,
  branchName 
)
Make a reader for branch branchName containing a single value.

Definition at line 43 of file treeReaderArrayTools.py.

References _makeValueReader(), and nano_mu_local_reco_cff.bool.

43 def getValueReader(tree, branchName):
44  """Make a reader for branch branchName containing a single value."""
45  if branchName not in tree._ttrvs:
46  if not tree.GetBranch(branchName):
47  raise RuntimeError("Can't find branch '%s'" % branchName)
48  if not tree.GetBranchStatus(branchName):
49  raise RuntimeError("Branch %s has status=0" % branchName)
50  leaf = tree.GetBranch(branchName).GetLeaf(branchName)
51  if bool(leaf.GetLeafCount()) or leaf.GetLen() != 1:
52  raise RuntimeError("Branch %s is not a value" % branchName)
53  typ = leaf.GetTypeName()
54  tree._ttrvs[branchName] = _makeValueReader(tree, typ, branchName)
55  return tree._ttrvs[branchName]
56 
57 
def getValueReader(tree, branchName)
def _makeValueReader(tree, typ, nam)

◆ InputTree()

def treeReaderArrayTools.InputTree (   tree,
  entrylist = ROOT.MakeNullPointer(ROOT.TEntryList) 
)
add to the PyROOT wrapper of a TTree a TTreeReader and methods readBranch, arrayReader, valueReader

Definition at line 6 of file treeReaderArrayTools.py.

Referenced by postprocessor.PostProcessor.run().

6 def InputTree(tree, entrylist=ROOT.MakeNullPointer(ROOT.TEntryList)):
7  """add to the PyROOT wrapper of a TTree a TTreeReader and methods readBranch, arrayReader, valueReader"""
8  if hasattr(tree, '_ttreereader'):
9  return tree # don't initialize twice
10  tree.entry = -1
11  tree._entrylist = entrylist
12  tree._ttreereader = ROOT.TTreeReader(tree, tree._entrylist)
13  tree._ttreereader._isClean = True
14  tree._ttrvs = {}
15  tree._ttras = {}
16  tree._leafTypes = {}
17  tree._ttreereaderversion = 1
18  tree.arrayReader = types.MethodType(getArrayReader, tree)
19  tree.valueReader = types.MethodType(getValueReader, tree)
20  tree.readBranch = types.MethodType(readBranch, tree)
21  tree.gotoEntry = types.MethodType(_gotoEntry, tree)
22  tree.readAllBranches = types.MethodType(_readAllBranches, tree)
23  tree.entries = tree._ttreereader.GetEntries(False)
24  tree._extrabranches = {}
25  return tree
26 
27 
def InputTree(tree, entrylist=ROOT.MakeNullPointer(ROOT.TEntryList))

◆ readBranch()

def treeReaderArrayTools.readBranch (   tree,
  branchName 
)
Return the branch value if the branch is a value, and a TreeReaderArray if the branch is an array

Definition at line 66 of file treeReaderArrayTools.py.

References _makeArrayReader(), _makeValueReader(), nano_mu_local_reco_cff.bool, and Get().

Referenced by datamodel.Event.__getattr__(), and edm::RootOutputTree.checkEntriesInReadBranches().

66 def readBranch(tree, branchName):
67  """Return the branch value if the branch is a value, and a TreeReaderArray if the branch is an array"""
68  if tree._ttreereader._isClean:
69  raise RuntimeError("readBranch must not be called before calling gotoEntry")
70  if branchName in tree._extrabranches:
71  return tree._extrabranches[branchName]
72  elif branchName in tree._ttras:
73  return tree._ttras[branchName]
74  elif branchName in tree._ttrvs:
75  ret = tree._ttrvs[branchName].Get()[0]
76  return ord(ret) if type(ret) == str else ret
77  else:
78  branch = tree.GetBranch(branchName)
79  if not branch:
80  raise RuntimeError("Unknown branch %s" % branchName)
81  if not tree.GetBranchStatus(branchName):
82  raise RuntimeError("Branch %s has status=0" % branchName)
83  leaf = branch.GetLeaf(branchName)
84  typ = leaf.GetTypeName()
85  if leaf.GetLen() == 1 and not bool(leaf.GetLeafCount()):
86  _vr = _makeValueReader(tree, typ, branchName)
87  # force calling SetEntry as a new ValueReader was created
88  tree.gotoEntry(tree.entry, forceCall=True)
89  ret = _vr.Get()[0]
90  return ord(ret) if type(ret) == str else ret
91  else:
92  _ar = _makeArrayReader(tree, typ, branchName)
93  # force calling SetEntry as a new ArrayReader was created
94  tree.gotoEntry(tree.entry, forceCall=True)
95  return _ar
96 
97 
def _makeArrayReader(tree, typ, nam)
PRIVATE IMPLEMENTATION PART #######.
def readBranch(tree, branchName)
def _makeValueReader(tree, typ, nam)
T * Get(Args... args)
Definition: Trend.h:122

◆ setExtraBranch()

def treeReaderArrayTools.setExtraBranch (   tree,
  name,
  val 
)

Definition at line 62 of file treeReaderArrayTools.py.

Referenced by output.OutputTree.fillBranch().

62 def setExtraBranch(tree, name, val):
63  tree._extrabranches[name] = val
64 
65 
def setExtraBranch(tree, name, val)

Variable Documentation

◆ IgnoreCommandLineOptions

treeReaderArrayTools.IgnoreCommandLineOptions

Definition at line 3 of file treeReaderArrayTools.py.