10 def __init__(self, name, function, type=float, help="", default=-99, mcOnly=False, filler=None):
22 if self.
mcOnly and not isMC:
return
25 if self.
mcOnly and not isMC:
return
26 treeNumpy.fill(self.
name, self(object))
29 def __init__(self,name,baseObjectTypes=[],mcOnly=[],variables=[]):
35 """Return only my vars, not including the ones from the bases"""
36 return [ v
for v
in self.
variables if (isMC
or not v.mcOnly) ]
38 """Return all vars, including the base ones. Duplicate bases are not added twice"""
40 if not isMC
and self.
mcOnly:
return []
42 if not isMC
and base.mcOnly:
continue
43 for var
in base.ownVars(isMC):
44 if var.name
in names:
raise RuntimeError,
"Duplicate definition of variable %s from %s and %s" % (var.name, base.name, names[var.name])
45 names[var.name] = base.name
48 if var.name
in names:
raise RuntimeError,
"Duplicate definition of variable %s from %s and %s" % (var.name, self.
name, names[var.name])
49 names[var.name] = self.
name
57 for b2
in b.allBases():
65 def __init__(self, name, objectType, help="", mcOnly=False):
71 if not isMC
and self.
mcOnly:
return
72 allvars = self.objectType.allVars(isMC)
75 if self.
help: h =
"%s for %s" % ( h
if h
else v.name, self.
help )
76 treeNumpy.var(
"%s_%s" % (self.
name, v.name), type=v.type, default=v.default, title=h, filler=v.filler)
78 if self.
mcOnly and not isMC:
return
79 allvars = self.objectType.allVars(isMC)
81 treeNumpy.fill(
"%s_%s" % (self.
name, v.name),
v(object))
85 def __init__(self, name, objectType, maxlen, help="", mcOnly=False, sortAscendingBy=None, sortDescendingBy=None, filter=None):
90 if objectType.mcOnly
and mcOnly ==
False:
91 print "collection %s is set to mcOnly since the type %s is mcOnly" % (name, objectType.name)
94 if sortAscendingBy !=
None and sortDescendingBy !=
None:
95 raise RuntimeError,
"Cannot specify two sort conditions"
100 if not isMC
and self.objectType.mcOnly:
return
101 treeNumpy.var(
"n"+self.
name, int)
102 allvars = self.objectType.allVars(isMC)
104 for i
in xrange(1,self.
maxlen+1):
106 if self.
help: h =
"%s for %s [%d]" % ( h
if h
else v.name, self.
help, i-1 )
107 treeNumpy.var(
"%s%d_%s" % (self.
name, i, v.name), type=v.type, default=v.default, title=h, filler=v.filler)
109 if not isMC
and self.objectType.mcOnly:
return
110 treeNumpy.var(
"n"+self.
name, int)
111 allvars = self.objectType.allVars(isMC)
114 if self.
help: h =
"%s for %s" % ( h
if h
else v.name, self.
help )
115 name=
"%s_%s" % (self.
name, v.name)
if v.name !=
"" else self.
name
116 treeNumpy.vector(name,
"n"+self.
name, self.
maxlen, type=v.type, default=v.default, title=h, filler=v.filler)
118 if not isMC
and self.objectType.mcOnly:
return
119 if self.
filter !=
None: collection = [ o
for o
in collection
if self.
filter(o) ]
123 treeNumpy.fill(
"n"+self.
name, num)
124 allvars = self.objectType.allVars(isMC)
125 for i
in xrange(num):
128 treeNumpy.fill(
"%s%d_%s" % (self.
name, i+1, v.name),
v(o))
130 if not isMC
and self.objectType.mcOnly:
return
131 if self.
filter !=
None: collection = [ o
for o
in collection
if self.
filter(o) ]
135 treeNumpy.fill(
"n"+self.
name, num)
136 allvars = self.objectType.allVars(isMC)
138 name=
"%s_%s" % (self.
name, v.name)
if v.name !=
"" else self.
name
139 treeNumpy.vfill(name, [
v(collection[i])
for i
in xrange(num) ])