CMS 3D CMS Logo

Classes | Functions
python.cmstools Namespace Reference

Classes

class  cmserror
 
class  Event
 
class  EventBranch
 
class  EventTree
 

Functions

def all (container)
 workaround iterator generators for ROOT classes More...
 
def createBranchBuffer (branch)
 auto branch types (Chris Jones) More...
 
def loop (begin, end)
 

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 26 of file cmstools.py.

26 def all(container):
27 
28  # loop over ROOT::TTree and similar
29  if hasattr(container,'GetEntries'):
30  try:
31  entries = container.GetEntries()
32  for entry in xrange(entries):
33  yield entry
34  except:
35  raise cmserror("Looping of %s failed" %container)
36 
37  # loop over std::vectors and similar
38  elif hasattr(container, 'size'):
39  try:
40  entries = container.size()
41  for entry in xrange(entries):
42  yield container[entry]
43  except:
44  pass
45 
46  # loop over containers with begin and end iterators
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:26
def python.cmstools.createBranchBuffer (   branch)

auto branch types (Chris Jones)

Definition at line 54 of file cmstools.py.

54 def createBranchBuffer(branch):
55  reColons = re.compile(r'::')
56  reCloseTemplate =re.compile(r'>')
57  reOpenTemplate =re.compile(r'<')
58  branchType = ROOT.branchToClass(branch)
59  #buffer = eval ('ROOT.'+reColons.sub(".",reOpenTemplate.sub("(ROOT.",reCloseTemplate.sub(")",branchType.GetName())))+'()')
60  buffer = ROOT.MakeRootClass(branchType.GetName()) ()
61  if( branch.GetName()[-1] != '.') and (branch.GetName()!="EventAuxiliary"):
62  branch.SetAddress(buffer)
63  else:
64  branch.SetAddress(ROOT.AddressOf(buffer))
65  return buffer
66 
67 
def createBranchBuffer(branch)
auto branch types (Chris Jones)
Definition: cmstools.py:54
def python.cmstools.loop (   begin,
  end 
)
Convert a pair of C++ iterators into a python generator

Definition at line 47 of file cmstools.py.

47 def loop(begin, end):
48  """Convert a pair of C++ iterators into a python generator"""
49  while (begin != end):
50  yield begin.__deref__() #*b
51  begin.__preinc__() #++b
52 
def loop(begin, end)
Definition: cmstools.py:47