CMS 3D CMS Logo

Classes | Functions

python::cmstools Namespace Reference

Classes

class  cmserror
class  Event
class  EventBranch
class  EventTree

Functions

def all
 workaround iterator generators for ROOT classes
def createBranchBuffer
 auto branch types (Chris Jones)
def loop

Detailed Description

Python helper tools for CMS FWLite

benedikt.hegner@cern.ch


Function Documentation

def python::cmstools::all (   container)

workaround iterator generators for ROOT classes

Definition at line 23 of file cmstools.py.

00024                   :
00025 
00026   # loop over ROOT::TTree and similar
00027   if hasattr(container,'GetEntries'):
00028     try:
00029       entries = container.GetEntries()
00030       for entry in xrange(entries):
00031         yield entry
00032     except:
00033         raise cmserror("Looping of %s failed" %container) 
00034 
00035   # loop over std::vectors and similar
00036   elif hasattr(container, 'size'):
00037     try:
00038       entries = container.size()
00039       for entry in xrange(entries):
00040         yield container[entry]
00041     except:
00042       pass
00043 
 # loop over containers with begin and end iterators
def python::cmstools::createBranchBuffer (   branch)

auto branch types (Chris Jones)

Definition at line 51 of file cmstools.py.

00052                               :
00053     reColons = re.compile(r'::')
00054     reCloseTemplate =re.compile(r'>')
00055     reOpenTemplate =re.compile(r'<')
00056     branchType = ROOT.branchToClass(branch)
00057     #buffer = eval ('ROOT.'+reColons.sub(".",reOpenTemplate.sub("(ROOT.",reCloseTemplate.sub(")",branchType.GetName())))+'()')
00058     buffer = ROOT.MakeRootClass(branchType.GetName()) ()
00059     if( branch.GetName()[-1] != '.') and (branch.GetName()!="EventAuxiliary"):
00060         branch.SetAddress(buffer)
00061     else:
00062         branch.SetAddress(ROOT.AddressOf(buffer))
00063     return buffer
00064 

def python::cmstools::loop (   begin,
  end 
)