ATLAS Offline Software
Treereader.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 
4 class Treereader (object):
5  leaftypes = (int, float, complex)
6  import builtins
7  if 'long' in builtins.__dict__:
8  leaftypes = leaftypes + (builtins.__dict__['long'],)
9  if 'buffer' in builtins.__dict__:
10  leaftypes = leaftypes + (builtins.__dict__['buffer'],)
11  def __init__ (*self):
12  raise Exception ("Use treereader() rather than creating Treereader directly.")
13 
14  def real_init (self, tree, parent = None, subpattern = None):
15  self.parent = parent
16  self._tree = tree
17  self._subpattern = subpattern
18  self._subreaders = []
19  if self._subpattern is None:
20  tree.SetNotify (self)
21  return
22 
23  def __getattr__ (self, attr):
24  if attr[0] == '_':
25  raise AttributeError
26  if self._subpattern:
27  lname = self._subpattern % attr
28  else:
29  lname = attr
30  ret = getattr (self._tree, lname)
31  if (isinstance (ret, Treereader.leaftypes) or
32  str(type(ret)) == "<type 'buffer'>"):
33  def getter (self, tree = self._tree, lname = lname):
34  return getattr (tree, lname)
35  setattr (self.__class__, attr, property (getter))
36  else:
37  setattr (self, attr, ret)
38  return ret
39 
40  def Notify (self):
41  newdict = { '_tree' : self._tree,
42  '_subpattern' : self._subpattern,
43  '_subreaders' : self._subreaders}
44  for (k, v) in self.__dict__.items():
45  if isinstance (v, Treereader):
46  newdict[k] = v
47  self.__dict__ = newdict
48  #print 'notify!', self.__dict__
49  for s in self._subreaders:
50  s.Notify()
51  return
52 
53 
54  def subreader (self, subpattern):
55  sub = treereader (self._tree, self, subpattern)
56  self._subreaders.append (sub)
57  return sub
58 
59 
60  def GetEntry (self, i):
61  return self._tree.GetEntry (i)
62 
63 
64 def treereader (tree, parent = None, subpattern = None):
65  class Treereader_Specific (Treereader):
66  def __init__ (self, tree, subpattern = None):
67  Treereader.real_init (self, tree, parent, subpattern)
68  return
69  return Treereader_Specific (tree, subpattern)
70 
71 
72 #tr=treereader(tt)
73 
74 #tr55=tr.subreader('cl_%s')
75 #tr35=tr.subreader('cl_%s_35')
python.Treereader.Treereader.parent
parent
Definition: Treereader.py:15
python.Treereader.Treereader.real_init
def real_init(self, tree, parent=None, subpattern=None)
Definition: Treereader.py:14
python.Treereader.Treereader.Notify
def Notify(self)
Definition: Treereader.py:40
python.Treereader.Treereader.__init__
def __init__(*self)
Definition: Treereader.py:11
python.Treereader.Treereader._subpattern
_subpattern
Definition: Treereader.py:17
python.Treereader.Treereader._subreaders
_subreaders
Definition: Treereader.py:18
python.Treereader.Treereader
Definition: Treereader.py:4
python.Treereader.Treereader.__dict__
__dict__
Definition: Treereader.py:47
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.Treereader.Treereader.__getattr__
def __getattr__(self, attr)
Definition: Treereader.py:23
python.Treereader.treereader
def treereader(tree, parent=None, subpattern=None)
Definition: Treereader.py:64
python.Utilities.__init__
__init__
Definition: Utilities.py:103
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.Treereader.Treereader.subreader
def subreader(self, subpattern)
Definition: Treereader.py:54
pickleTool.object
object
Definition: pickleTool.py:30
str
Definition: BTagTrackIpAccessor.cxx:11
python.Treereader.Treereader._tree
_tree
Definition: Treereader.py:16
python.Treereader.Treereader.GetEntry
def GetEntry(self, i)
Definition: Treereader.py:60