CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
python.cmstools.EventTree Class Reference
Inheritance diagram for python.cmstools.EventTree:

Public Member Functions

def __getattr__
 
def __getitem__
 
def __init__
 
def __iter__
 
def branch
 
def cppCode
 
def getListOfAliases
 
def index
 
def SetAlias
 
def tree
 

Private Member Functions

def __setBranchIndicies
 

Private Attributes

 _aliases
 
 _index
 
 _tree
 
 _usedBranches
 

Detailed Description

Definition at line 65 of file cmstools.py.

Constructor & Destructor Documentation

def python.cmstools.EventTree.__init__ (   self,
  obj 
)

Definition at line 66 of file cmstools.py.

66 
67  def __init__(self,obj):
68  sys.stderr.write ("WARNING: This package has been deprecated and will be removed in the near future.\nPlease switch to using FWLite.Python (https://twiki.cern.ch/twiki/bin/viewauth/CMS/WorkBookFWLitePython)\n")
69  treeName = 'Events'
70  if isinstance(obj, ROOT.TTree):
71  self._tree = obj
72  elif isinstance(obj, ROOT.TFile):
73  self._tree = obj.Get(treeName)
74  elif isinstance(obj, str):
75  self._tree = ROOT.TFile.Open(obj).Get(treeName)
76  else:
77  raise cmserror("EventTree accepts only TTrees, TFiles and filenames")
79  self._index = -1
self._aliases = self._tree.GetListOfAliases()

Member Function Documentation

def python.cmstools.EventTree.__getattr__ (   self,
  name 
)

Definition at line 117 of file cmstools.py.

References python.cmstools.EventTree.branch().

118  def __getattr__(self, name):
return self.branch(name)
def python.cmstools.EventTree.__getitem__ (   self,
  key 
)

Definition at line 119 of file cmstools.py.

References python.cmstools.EventTree.__setBranchIndicies(), Vispa.Share.FindAlgorithm.FindAlgorithm._index, RPCMuonExtraStruct._index, and python.cmstools.EventTree._index.

120  def __getitem__(self,key):
121  if key <0 or key > self._tree.GetEntries():
122  raise IndexError
123  self._index = key
124  self.__setBranchIndicies()
125  self._tree.GetEntry(self._index,0)
return Event(self)
def python.cmstools.EventTree.__iter__ (   self)

Definition at line 126 of file cmstools.py.

References python.cmstools.EventTree.__setBranchIndicies(), Vispa.Share.FindAlgorithm.FindAlgorithm._index, RPCMuonExtraStruct._index, and python.cmstools.EventTree._index.

127  def __iter__(self):
128  # flushing/initializing the root buffers
129  entry = 0
130  self._index = entry
131  self.__setBranchIndicies()
132  self._tree.GetEntry(self._index,0)
133  # the real loop
134  for entry in xrange(self._tree.GetEntries()):
135  self._index = entry
136  self.__setBranchIndicies()
137  self._tree.GetEntry(self._index,0)
138  yield Event(self) # TODO: don't return a new object but update the old one
139 
def python.cmstools.EventTree.__setBranchIndicies (   self)
private

Definition at line 114 of file cmstools.py.

References Vispa.Share.FindAlgorithm.FindAlgorithm._index, RPCMuonExtraStruct._index, and python.cmstools.EventTree._index.

Referenced by python.cmstools.EventTree.__getitem__(), and python.cmstools.EventTree.__iter__().

115  def __setBranchIndicies(self):
116  for branch in self._usedBranches.itervalues():
branch.setIndex(self._index)
def python.cmstools.EventTree.branch (   self,
  name 
)

Definition at line 80 of file cmstools.py.

References python.cmstools.EventTree._usedBranches.

Referenced by python.cmstools.EventTree.__getattr__().

80 
81  def branch(self,name):
82  # support for aliases
83  alias = self._tree.GetAlias(name)
84  if alias != '': name = alias
85  # access the branch in ttree
86  if name in self._usedBranches:
87  return self._usedBranches[name]
88  self._usedBranches[name]=EventBranch(self,name)
return self._usedBranches[name]
def python.cmstools.EventTree.cppCode (   self,
  name 
)
C++ code for accessing the product inside the full framework

Definition at line 89 of file cmstools.py.

89 
90  def cppCode(self, name):
91  """C++ code for accessing the product inside the full framework"""
92  alias = self._tree.GetAlias(name)
93  if alias != '': name = alias
94  tmpBranch = self._tree.GetBranch(name)
95  typeString = ROOT.branchToClass(tmpBranch).GetName()
96  if "edm::Wrapper" in typeString:
97  typeString = typeString.replace("<edm::Wrapper","")
98  typeString = typeString.rstrip(">")
99  nameParts = name.split("_")
100  if nameParts[2] == "":
101  cppCode = 'edm::Handle<%s > dummy;\nevent.getByLabel("%s", dummy);'\
102  %(typeString, nameParts[1])
103  else:
104  cppCode = 'edm::Handle<%s > dummy;\nevent.getByLabel("%s", "%s", dummy);'\
105  %(typeString, nameParts[1], nameParts[2])
return cppCode
def python.cmstools.EventTree.getListOfAliases (   self)

Definition at line 106 of file cmstools.py.

References python.cmstools.EventTree._aliases.

107  def getListOfAliases(self):
return self._aliases
def python.cmstools.EventTree.index (   self)

Definition at line 110 of file cmstools.py.

References Vispa.Share.FindAlgorithm.FindAlgorithm._index, RPCMuonExtraStruct._index, and python.cmstools.EventTree._index.

Referenced by BeautifulSoup.PageElement._invert().

111  def index(self):
return self._index
def python.cmstools.EventTree.SetAlias (   self,
  alias,
  fullName 
)

Definition at line 108 of file cmstools.py.

References CSCTFAnalyzer.tree, CSCTFanalyzer.tree, HcalTestHistoManager.tree, NtupleROOTFile.tree, TkOfflineVariables.tree, AlignmentIORootBase.tree, IsolatedParticlesGeneratedJets.tree, EcalPerEvtMatacqAnalyzer.tree, CheckSecondary.tree, KVFTest.tree, ShallowTree.tree, PhysicsTools::TreeReader.tree, FWFileEntry.tree(), cms::DiJetAnalyzer.tree, TreeSaver.tree, edm::RootOutputTree.tree(), EcalMatacqAnalyzer.tree, edm::FileBlock.tree(), edm::RootTree.tree(), python.cmstools.EventTree.tree(), KinematicVertex.tree, HcalIsoTrkAnalyzer.tree, KinematicParticle.tree, IsolatedGenParticles.tree, IsolatedTracksHcalScale.tree, IsolatedTracksNxN.tree, and svgfig.SVG.tree().

109  def SetAlias (self, alias, fullName):
self.tree().SetAlias(alias, fullName)
def python.cmstools.EventTree.tree (   self)

Definition at line 112 of file cmstools.py.

References python.cmstools.EventTree._tree.

Referenced by python.cmstools.EventTree.SetAlias().

113  def tree(self):
return self._tree

Member Data Documentation

python.cmstools.EventTree._aliases
private

Definition at line 79 of file cmstools.py.

Referenced by python.cmstools.EventTree.getListOfAliases().

python.cmstools.EventTree._index
private

Definition at line 78 of file cmstools.py.

Referenced by python.cmstools.EventTree.__getitem__(), python.cmstools.EventTree.__iter__(), python.cmstools.EventBranch.__readData(), python.cmstools.EventTree.__setBranchIndicies(), python.cmstools.EventTree.index(), and python.cmstools.EventBranch.setIndex().

python.cmstools.EventTree._tree
private

Definition at line 70 of file cmstools.py.

Referenced by python.cmstools.EventTree.tree().

python.cmstools.EventTree._usedBranches
private

Definition at line 77 of file cmstools.py.

Referenced by python.cmstools.EventTree.branch().