Helper for setting up an association to a contained object.
parent: The parent D3PDobject or block.
assoctool: The class for the (single) association tool.
prefix: Prefix to add to the contained variables, if any.
matched: If not null, a flag variable with this name will
be created, set to true when the association succeeds.
level: Level of detail for the block.
blockname: Name for the block.
suffix: Suffix to add to the contained variables, if any.
Extra arguments are passed to the association tool.
Here's an example. Suppose we have a generic tool that tuples
Perigee objects, producing variables z0, d0, etc. Suppose that
we also have an `electron' object that has a method to return
a Perigee. We want to use the Perigee filling tool to tuple
these variables as a new block.
We can do this by creating an associator tool that will go from
an electron object to its contained Perigee object. We then configure
things by creating a ContainedAssociationFillerTool using this
associator. We then add this as a block to the electron object,
and then add a Perigee block to the associator block. The helper
here reduces the amount of boilerplate configuration code
we need to do this.
Usage is something like this:
ElectronObject = ...
ElectronPerigee = SimpleAssocation (ElectronObject,
electronPerigeeAssociator)
ElectronPerigee.defineBlock (1, 'Perigee', PerigeeFillerTool)
If the electron prefix is `el_', this would create variables
`el_z0', etc. With `prefix="track"', the names would be
`el_trackz0', etc.
If we add `matched="hastrack"', then this will add a boolean
variable `el_hastrack', which is true if the association succeeded.
Definition at line 17 of file SimpleAssociation.py.
25 """Helper for setting up an association to a contained object.
27 parent: The parent D3PDobject or block.
28 assoctool: The class for the (single) association tool.
29 prefix: Prefix to add to the contained variables, if any.
30 matched: If not null, a flag variable with this name will
31 be created, set to true when the association succeeds.
32 level: Level of detail for the block.
33 blockname: Name for the block.
34 suffix: Suffix to add to the contained variables, if any.
36 Extra arguments are passed to the association tool.
38 Here's an example. Suppose we have a generic tool that tuples
39 Perigee objects, producing variables z0, d0, etc. Suppose that
40 we also have an `electron' object that has a method to return
41 a Perigee. We want to use the Perigee filling tool to tuple
42 these variables as a new block.
44 We can do this by creating an associator tool that will go from
45 an electron object to its contained Perigee object. We then configure
46 things by creating a ContainedAssociationFillerTool using this
47 associator. We then add this as a block to the electron object,
48 and then add a Perigee block to the associator block. The helper
49 here reduces the amount of boilerplate configuration code
52 Usage is something like this:
55 ElectronPerigee = SimpleAssocation (ElectronObject,
56 electronPerigeeAssociator)
57 ElectronPerigee.defineBlock (1, 'Perigee', PerigeeFillerTool)
59 If the electron prefix is `el_', this would create variables
60 `el_z0', etc. With `prefix="track"', the names would be
63 If we add `matched="hastrack"', then this will add a boolean
64 variable `el_hastrack', which is true if the association succeeded.
67 blockname = assoctool.__name__
69 def maker (name, prefix, object_name, **kw2):
70 assoc = assoctool (name +
'Assoc', **kw2)
72 (name, Prefix = prefix, Suffix = suffix,
73 Associator = assoc, Matched = matched)
75 obj = D3PDObject (maker, prefix)
76 parent.defineBlock (level, blockname, obj, **kw)