test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions
python.cmstools Namespace Reference

Classes

class  cmserror
 
class  Event
 
class  EventBranch
 
class  EventTree
 

Functions

def all
 workaround iterator generators for ROOT classes More...
 
def createBranchBuffer
 auto branch types (Chris Jones) More...
 
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 24 of file cmstools.py.

24 
25 def all(container):
26 
27  # loop over ROOT::TTree and similar
28  if hasattr(container,'GetEntries'):
29  try:
30  entries = container.GetEntries()
31  for entry in xrange(entries):
32  yield entry
33  except:
34  raise cmserror("Looping of %s failed" %container)
35 
36  # loop over std::vectors and similar
37  elif hasattr(container, 'size'):
38  try:
39  entries = container.size()
40  for entry in xrange(entries):
41  yield container[entry]
42  except:
43  pass
44 
# loop over containers with begin and end iterators
def all
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 
53 def createBranchBuffer(branch):
54  reColons = re.compile(r'::')
55  reCloseTemplate =re.compile(r'>')
56  reOpenTemplate =re.compile(r'<')
57  branchType = ROOT.branchToClass(branch)
58  #buffer = eval ('ROOT.'+reColons.sub(".",reOpenTemplate.sub("(ROOT.",reCloseTemplate.sub(")",branchType.GetName())))+'()')
59  buffer = ROOT.MakeRootClass(branchType.GetName()) ()
60  if( branch.GetName()[-1] != '.') and (branch.GetName()!="EventAuxiliary"):
61  branch.SetAddress(buffer)
62  else:
63  branch.SetAddress(ROOT.AddressOf(buffer))
64  return buffer
65 
def createBranchBuffer
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 
46 def loop(begin, end):
47  """Convert a pair of C++ iterators into a python generator"""
48  while (begin != end):
49  yield begin.__deref__() #*b
50  begin.__preinc__() #++b