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

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

auto branch types (Chris Jones)

Definition at line 52 of file cmstools.py.

References reco.if().

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

Definition at line 45 of file cmstools.py.

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