CMS 3D CMS Logo

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__ (self, name)
 
def __getitem__ (self, key)
 
def __init__ (self, obj)
 
def __iter__ (self)
 
def branch (self, name)
 
def cppCode (self, name)
 
def getListOfAliases (self)
 
def index (self)
 
def SetAlias (self, alias, fullName)
 
def tree (self)
 

Private Member Functions

def __setBranchIndicies (self)
 

Private Attributes

 _aliases
 
 _index
 
 _tree
 
 _usedBranches
 

Detailed Description

Definition at line 66 of file cmstools.py.

Constructor & Destructor Documentation

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

Definition at line 67 of file cmstools.py.

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
80  self._aliases = self._tree.GetListOfAliases()
def __init__(self, obj)
Definition: cmstools.py:67

Member Function Documentation

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

Definition at line 118 of file cmstools.py.

References edm::BranchToCount.branch, and python.cmstools.EventTree.branch().

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

Definition at line 120 of file cmstools.py.

References python.cmstools.EventTree.__setBranchIndicies(), SeedingNode< DATA >._index, 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)
126  return Event(self)
def __setBranchIndicies(self)
Definition: cmstools.py:115
def __getitem__(self, key)
Definition: cmstools.py:120
def python.cmstools.EventTree.__iter__ (   self)

Definition at line 127 of file cmstools.py.

References python.cmstools.EventTree.__setBranchIndicies(), SeedingNode< DATA >._index, 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 
140 
def __setBranchIndicies(self)
Definition: cmstools.py:115
def python.cmstools.EventTree.__setBranchIndicies (   self)
private
def python.cmstools.EventTree.branch (   self,
  name 
)

Definition at line 81 of file cmstools.py.

References python.cmstools.EventTree._usedBranches.

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

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)
89  return self._usedBranches[name]
def branch(self, name)
Definition: cmstools.py:81
def python.cmstools.EventTree.cppCode (   self,
  name 
)
C++ code for accessing the product inside the full framework

Definition at line 90 of file cmstools.py.

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])
106  return cppCode
def cppCode(self, name)
Definition: cmstools.py:90
def python.cmstools.EventTree.getListOfAliases (   self)

Definition at line 107 of file cmstools.py.

References python.cmstools.EventTree._aliases.

107  def getListOfAliases(self):
108  return self._aliases
def getListOfAliases(self)
Definition: cmstools.py:107
def python.cmstools.EventTree.index (   self)
def python.cmstools.EventTree.SetAlias (   self,
  alias,
  fullName 
)
def python.cmstools.EventTree.tree (   self)

Member Data Documentation

python.cmstools.EventTree._aliases
private

Definition at line 80 of file cmstools.py.

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

python.cmstools.EventTree._index
private
python.cmstools.EventTree._tree
private

Definition at line 71 of file cmstools.py.

Referenced by ntuple._Object.__getattr__(), ntuple.BeamSpot.__getattr__(), ntuple._Collection.__getitem__(), ntuple._Collection.__iter__(), ntuple.TrackingNtuple.__iter__(), ntuple._TrackingParticleMatchAdaptor._nMatchedTrackingParticles(), ntuple.Event.beamspot(), ntuple.TrackingVertex.daughterTrackingParticles(), ntuple.TrackingParticle.decayVertices(), ntuple._RecoHitAdaptor.gluedHits(), ntuple.Event.gluedHits(), ntuple.TrackingNtuple.hasHits(), ntuple.TrackingNtuple.hasSeeds(), ntuple._RecoHitAdaptor.hits(), ntuple.Seed.indexWithinAlgo(), ntuple._RecoHitAdaptor.invalidHits(), ntuple._LayerStrAdaptor.layerStr(), ntuple.TrackingParticle.matchedTrackInfos(), ntuple._TrackingParticleMatchAdaptor.matchedTrackingParticleInfos(), ntuple.GluedHit.monoHit(), ntuple._HitObject.nseeds(), ntuple.Seeds.nSeedsForAlgo(), ntuple._HitObject.ntracks(), ntuple.TrackingParticle.parentVertex(), ntuple._RecoHitAdaptor.phase2OTHits(), ntuple.Event.phase2OTHits(), ntuple._RecoHitAdaptor.pixelHits(), ntuple.Event.pixelHits(), ntuple.Track.seed(), ntuple._HitObject.seeds(), ntuple.Event.seeds(), ntuple.GluedHit.seeds(), ntuple.Seeds.seedsForAlgo(), ntuple._SimHitAdaptor.simHits(), ntuple._Collection.size(), ntuple.TrackingVertex.sourceTrackingParticles(), ntuple.GluedHit.stereoHit(), ntuple._RecoHitAdaptor.stripHits(), ntuple.Event.stripHits(), ntuple.TrackMatchInfo.track(), ntuple.Seed.track(), ntuple.TrackingParticleMatchInfo.trackingParticle(), ntuple.SimHit.trackingParticle(), ntuple.Event.trackingParticles(), ntuple.Event.trackingVertices(), ntuple._HitObject.tracks(), ntuple.Event.tracks(), ntuple.Vertex.tracks(), python.cmstools.EventTree.tree(), ntuple.TrackingNtuple.tree(), ntuple.Track.vertex(), and ntuple.Event.vertices().

python.cmstools.EventTree._usedBranches
private

Definition at line 78 of file cmstools.py.

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