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

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

auto branch types (Chris Jones)

Definition at line 55 of file cmstools.py.

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

Definition at line 48 of file cmstools.py.

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