|
def | __init__ (self, maker, default_prefix='', default_object_name='', default_name=None, allow_args=[], **kw) |
|
def | defineBlock (self, lod, name, func, prefix=None, **kw) |
|
def | removeBlock (self, name, allowMissing=False) |
|
def | defineHook (self, hook) |
|
def | allBlocknames (self) |
|
def | __call__ (self, level, name=None, prefix=None, name_prefix='', parent_prefix='', object_name=None, include=[], exclude=[], blockargs={}, parent_hookargs=None, *args, **kw) |
|
def | blockFillers (self, level, parent_name, parent_prefix='', include=[], exclude=[], blockargs={}, hookargs={}) |
|
def | copy (self, default_prefix=None, default_object_name=None, default_name=None, **kw_in) |
|
D3PD object creator class.
For each type of object written to the D3PD, create
an instance of this class. The arguments to the constructor
are a function to create the Configurable for the object filler
tool and a default value for the variable name prefix
for this block.
After creating the instance, one calls defineBlock to define
the blocks of variables that can be written for this object.
Finally, one calls the object in order to create the
configurable.
So, a typical usage might look like this.
def makeElectronD3PDObject (name, prefix,
getter = None,
sgkey = 'ElectronAODCollection')
if not getter:
getter = CompFactory.D3PD.SGDataVectorGetterTool \
(name + '_Getter',
TypeName = 'ElectronContainer',
SGKey = sgkey)
return CompFactory.D3PD.VectorFillerTool (name,
Prefix = prefix,
Getter = getter)
ElectronD3PDObject = D3PDObject (makeElectronD3PDObject, 'el_')
ElectronD3PDObject.defineBlock (0, 'Kinematics',
EventCommonD3PDMaker.FourMomFillerTool)
alg = ...
alg += ElectronD3PDObject (level)
Definition at line 99 of file D3PDObject.py.
def python.D3PDObject.D3PDObject.__init__ |
( |
|
self, |
|
|
|
maker, |
|
|
|
default_prefix = '' , |
|
|
|
default_object_name = '' , |
|
|
|
default_name = None , |
|
|
|
allow_args = [] , |
|
|
** |
kw |
|
) |
| |
Constructor.
Arguments:
maker: A function to create the IObjFillerTool Configurable
for this object. It is called with two fixed arguments,
the tool name and the variable name prefix. Any other
arguments provided to the call will be passed through.
default_prefix: Default variable name prefix for objects
of this type.
default_object_name: Default D3PDObject name, something like
'EventInfoD3PDObject'
default_name: If specified, the default tool name to use
for these objects.
allow_args: Additional arguments that may be passed in when
instantiating the D3PDObject, but which are not
to be passed to the maker function. This can be
used to allow for additional arguments to hook
or level-of-detail functions.
Any additional arguments are passed into any hook functions.
Definition at line 141 of file D3PDObject.py.
141 def __init__ (self, maker, default_prefix = '', default_object_name = '',
142 default_name = None, allow_args = [], **kw):
146 maker: A function to create the IObjFillerTool Configurable
147 for this object. It is called with two fixed arguments,
148 the tool name and the variable name prefix. Any other
149 arguments provided to the call will be passed through.
150 default_prefix: Default variable name prefix for objects
152 default_object_name: Default D3PDObject name, something like
153 'EventInfoD3PDObject'
154 default_name: If specified, the default tool name to use
156 allow_args: Additional arguments that may be passed in when
157 instantiating the D3PDObject, but which are not
158 to be passed to the maker function. This can be
159 used to allow for additional arguments to hook
160 or level-of-detail functions.
162 Any additional arguments are passed into any hook functions.
166 self._default_object_name = default_object_name
169 self._all_blocknames = {}
170 self._default_prefix = default_prefix
171 self._default_name = default_name
174 self._allow_args = allow_args
def python.D3PDObject.D3PDObject.__call__ |
( |
|
self, |
|
|
|
level, |
|
|
|
name = None , |
|
|
|
prefix = None , |
|
|
|
name_prefix = '' , |
|
|
|
parent_prefix = '' , |
|
|
|
object_name = None , |
|
|
|
include = [] , |
|
|
|
exclude = [] , |
|
|
|
blockargs = {} , |
|
|
|
parent_hookargs = None , |
|
|
* |
args, |
|
|
** |
kw |
|
) |
| |
Create a Configurable to fill an object of this type.
Arguments:
level: Requested level of detail for this object. An integer.
name: Tool name. If omitted, one will be constructed.
prefix: Variable name prefix for this object.
name_prefix: If name wasn't specified, this is a prefix
to add to the tool name.
parent_prefix: Variable name prefix for any parent tool.
object_name: Name of the D3PDObject, like 'EventInfoD3PDObject'
include: List of block names to include, regardless
of level of detail.
exclude: List of block names to exclude, regardless
of level of detail.
blockargs: Extra arguments to pass to block filler tools.
The keys are block names.
Values are dictionaries of keyword arguments.
These override anything specified in defineBlock.
parent_hookargs: [Not to be used by user code.]
Dictionary of hook args from the parent,
to be merged into our hook arg dictionary.
args, kw: Additional arguments to pass to the maker function.
However, any entries in KW that have the form
BLOCK_parm, where BLOCK is a known block name,
will instead be interpreted as arguments to pass
to a block filler tool. These override entries
in BLOCKARGS.
Definition at line 316 of file D3PDObject.py.
326 parent_hookargs = None,
328 """Create a Configurable to fill an object of this type.
331 level: Requested level of detail for this object. An integer.
332 name: Tool name. If omitted, one will be constructed.
333 prefix: Variable name prefix for this object.
334 name_prefix: If name wasn't specified, this is a prefix
335 to add to the tool name.
336 parent_prefix: Variable name prefix for any parent tool.
337 object_name: Name of the D3PDObject, like 'EventInfoD3PDObject'
338 include: List of block names to include, regardless
340 exclude: List of block names to exclude, regardless
342 blockargs: Extra arguments to pass to block filler tools.
343 The keys are block names.
344 Values are dictionaries of keyword arguments.
345 These override anything specified in defineBlock.
346 parent_hookargs: [Not to be used by user code.]
347 Dictionary of hook args from the parent,
348 to be merged into our hook arg dictionary.
349 args, kw: Additional arguments to pass to the maker function.
350 However, any entries in KW that have the form
351 BLOCK_parm, where BLOCK is a known block name,
352 will instead be interpreted as arguments to pass
353 to a block filler tool. These override entries
359 prefix = self._default_prefix
362 if object_name
is None:
363 object_name = self._default_object_name
367 name = self._default_name
368 name = _make_name (name, prefix, name_prefix, parent_prefix,
369 self._default_prefix)
372 blockargs = dict ([(k, v.copy())
for (k, v)
in blockargs.items()])
376 for k
in list (kw.keys()):
382 for i
in range(1, len(kk)):
383 this_key =
'_'.join (kk[:i])
384 if this_key
in self._all_blocknames:
385 this_var =
'_'.join (kk[i:])
386 blockargs.setdefault(this_key,{})[this_var] = kw[k]
392 for k
in self._allow_args:
393 if k
in kw2: del kw2[k]
397 c = self._maker (name=name, prefix=prefix, object_name=object_name,
400 except TypeError
as exc:
401 if (len(exc.args) > 0
and
402 exc.args[0].find (
"unexpected keyword argument 'object_name'") >= 0):
403 log = logging.getLogger (
'D3PDObject')
404 log.warn (
"Maker function missing `object_name' formal arg: %s", self._maker)
405 c = self._maker (name=name, prefix=prefix, *args, **kw2)
412 if parent_hookargs
is None:
415 hookargs = StackedDict (local_hookargs, kw,
416 self._hookArgs, parent_hookargs)
417 local_hookargs[
'level'] = level
418 local_hookargs[
'name'] = name
419 local_hookargs[
'prefix'] = prefix
420 local_hookargs[
'name_prefix'] = name_prefix
421 local_hookargs[
'parent_prefix'] = parent_prefix
422 local_hookargs[
'include'] = include
423 local_hookargs[
'exclude'] = exclude
424 local_hookargs[
'blockargs'] = blockargs
425 local_hookargs[
'd3pdo'] = self
428 self._makeBlockFillers (c, level, parent_prefix + prefix,
429 include, exclude, blockargs, hookargs)
441 D3PDObject._hookArgsStore[c.getName()] = (self._hooks, args, hookargs)
def python.D3PDObject.D3PDObject._makeBlockFillers |
( |
|
self, |
|
|
|
c, |
|
|
|
level, |
|
|
|
parent_prefix, |
|
|
|
include, |
|
|
|
exclude, |
|
|
|
blockargs, |
|
|
|
hookargs |
|
) |
| |
|
private |
Create block filler tools for object C, for the specified
level of detail.
Arguments:
c: Object for which to create the block fillers.
level: Requested level of detail for this object. An integer.
parent_prefix: Variable name prefix for any parent tool.
include: List of block names to include, regardless
of level of detail.
exclude: List of block names to exclude, regardless
of level of detail.
blockargs: Extra arguments to pass to block filler tools.
The keys are block names.
Values are dictionaries of keyword arguments.
These override anything specified in defineBlock.
hookargs: Arguments passed to the D3PD object, to be passed
on to LOD functions.
Definition at line 540 of file D3PDObject.py.
540 def _makeBlockFillers (self,
548 """Create block filler tools for object C, for the specified
552 c: Object for which to create the block fillers.
553 level: Requested level of detail for this object. An integer.
554 parent_prefix: Variable name prefix for any parent tool.
555 include: List of block names to include, regardless
557 exclude: List of block names to exclude, regardless
559 blockargs: Extra arguments to pass to block filler tools.
560 The keys are block names.
561 Values are dictionaries of keyword arguments.
562 These override anything specified in defineBlock.
563 hookargs: Arguments passed to the D3PD object, to be passed
566 for bf
in self.blockFillers (level, c.getName(), parent_prefix,
567 include, exclude, blockargs,
569 c.BlockFillers += [bf]
def python.D3PDObject.D3PDObject.blockFillers |
( |
|
self, |
|
|
|
level, |
|
|
|
parent_name, |
|
|
|
parent_prefix = '' , |
|
|
|
include = [] , |
|
|
|
exclude = [] , |
|
|
|
blockargs = {} , |
|
|
|
hookargs = {} |
|
) |
| |
Return a list of block filler tool configurables.
Arguments:
level: Requested level of detail for this object. An integer.
parent_name: Name of the parent component.
parent_prefix: Variable name prefix for any parent tool.
include: List of block names to include, regardless
of level of detail.
exclude: List of block names to exclude, regardless
of level of detail.
blockargs: Extra arguments to pass to block filler tools.
The keys are block names.
Values are dictionaries of keyword arguments.
These override anything specified in defineBlock.
hookargs: Arguments passed to the D3PD object, to be passed
on to LOD functions.
Definition at line 464 of file D3PDObject.py.
464 def blockFillers (self,
472 """Return a list of block filler tool configurables.
475 level: Requested level of detail for this object. An integer.
476 parent_name: Name of the parent component.
477 parent_prefix: Variable name prefix for any parent tool.
478 include: List of block names to include, regardless
480 exclude: List of block names to exclude, regardless
482 blockargs: Extra arguments to pass to block filler tools.
483 The keys are block names.
484 Values are dictionaries of keyword arguments.
485 These override anything specified in defineBlock.
486 hookargs: Arguments passed to the D3PD object, to be passed
490 for b
in self._blocks:
492 if b.name
in include:
495 elif b.name
in exclude:
504 args.update (blockargs.get (b.name, {}))
511 for k, v
in args.items():
512 if isinstance(v, list):
514 if isinstance(v, DeferArg):
515 args[k] =
v(hookargs)
517 if _testLOD (b.lod, reqlev, args, hookargs):
518 fillername = parent_name +
'_' + b.name
519 if isinstance (b.func, D3PDObject):
520 for k
in self._allow_args:
522 args[k] = hookargs[k]
523 bf = b.func (level, fillername,
524 parent_prefix = parent_prefix,
527 blockargs = blockargs,
528 parent_hookargs = hookargs,
531 bf = b.func (fillername, **args)
535 D3PDObject._hookArgsStore[bf.getName()] = (b._hooks, args, hookargs)
def python.D3PDObject.D3PDObject.defineBlock |
( |
|
self, |
|
|
|
lod, |
|
|
|
name, |
|
|
|
func, |
|
|
|
prefix = None , |
|
|
** |
kw |
|
) |
| |
Define a new block of variables for this object type.
Arguments:
lod: Level of detail of this block. See below.
name: Name of this block.
func: Function to create the block Configurable.
prefix: Variable name prefix for this block.
kw: Arguments to pass to the creation function.
The creation function will be called like this:
b.func (name, BlockName = blockname, **b.kw)
where name is the name for the tool.
However, if b.func is a class deriving from D3PDObject, then the creation
function will instead be called like this:
b.func (level, name, parent_prefix, **b.kw)
LOD is used to control whether this block should be included.
In the simple case, this is an integer, and the block is included
if the block's level of detail is less than or equal to the
requested level of detail (unless the block was explicitly
included or excluded).
In the general case, LOD may be a function. The first two arguments
passed to the function will be the requested level of detail
and the block filler
arguments. The requested level of detail will be an integer;
it will be 999 if the block was explicitly included, and -999
if the block was explicitly excluded. The block filler arguments
is a dictionary of keyword arguments. The LOD function should
return a boolean value saying whether or not the block should
be included. It may also alter the dictionary of arguments
(this overrides all other argument settings).
The LOD function may optionally take a third argument; if present,
this is a dictionary of the arguments passed to the D3PDObject
(the same arguments that are passed to hook functions).
Definition at line 178 of file D3PDObject.py.
178 def defineBlock (self, lod, name, func, prefix = None, **kw):
179 """Define a new block of variables for this object type.
182 lod: Level of detail of this block. See below.
183 name: Name of this block.
184 func: Function to create the block Configurable.
185 prefix: Variable name prefix for this block.
186 kw: Arguments to pass to the creation function.
188 The creation function will be called like this:
190 b.func (name, BlockName = blockname, **b.kw)
192 where name is the name for the tool.
194 However, if b.func is a class deriving from D3PDObject, then the creation
195 function will instead be called like this:
197 b.func (level, name, parent_prefix, **b.kw)
199 LOD is used to control whether this block should be included.
201 In the simple case, this is an integer, and the block is included
202 if the block's level of detail is less than or equal to the
203 requested level of detail (unless the block was explicitly
204 included or excluded).
206 In the general case, LOD may be a function. The first two arguments
207 passed to the function will be the requested level of detail
209 arguments. The requested level of detail will be an integer;
210 it will be 999 if the block was explicitly included, and -999
211 if the block was explicitly excluded. The block filler arguments
212 is a dictionary of keyword arguments. The LOD function should
213 return a boolean value saying whether or not the block should
214 be included. It may also alter the dictionary of arguments
215 (this overrides all other argument settings).
216 The LOD function may optionally take a third argument; if present,
217 this is a dictionary of the arguments passed to the D3PDObject
218 (the same arguments that are passed to hook functions).
220 if prefix
is not None:
222 kw[
'Prefix'] = prefix
227 self._add_blockname (name)
228 if isinstance (func, D3PDObject):
229 for n
in func.allBlocknames():
230 self._add_blockname (n)
232 func._allow_args = self._allow_args
234 self._blocks.append (Block (name, lod, func, kw))
235 return self._blocks[-1]