10 from .D3PDObject
import DeferArg
17 return eval (expr, globals(), dd)
21 """Helper for making LOD functions to evaluate flags.
23 Numerous parts of the D3PD configuration use arbitrary global flags
24 to control which blocks are included. This is bad because there
25 can be interference when multiple tuples are configured in the
28 Better is to use the level-of-detail mechanism to do this,
29 passing in flags as extra arguments to the D3PDObject.
31 This helper is to ease this conversion, while still allowing
32 backwards compatibility with flag-based configuration.
34 flagTestLOD will return a level-of-detail function that evaluates
35 the provided expression string EXP. This will be evaluated
36 in an environment that includes names for all flags in the flags
37 class(es) FLAGS, merged with the value of the hookargs.
38 The requested level of detail is also available as `reqlev'.
39 Thus, if you have something like:
41 myobj = make_SGDataVector_D3PDObject ('mycont', 'mykey', 'my_', 'myob',
42 allow_args = ['myLevel'])
43 myobj.defineBlock (flagTestLOD('myLevel>2', myFlags),
44 'myblock', filler_tool)
46 then myblock will be included in the tuple if the property
47 myFlags.myLevel() is greater than two. However, this can be overridden
48 by passing an argument to the D3PDObject:
50 alg += myobj (level, myLevel=4)
52 Explicit inclusion / exclusion also overrides this determination.
54 Flags are evaluated at the point where flagTestLOD is called.
56 If HOOK is supplied, then it is called if the LOD test passes.
57 It is passed as arguments two dictionaries: the block filler tool
58 arguments and the hook arguments.
61 >>> from AthenaConfiguration.AllConfigFlags import initConfigFlags
62 >>> flags = initConfigFlags()
63 >>> flags.addFlag ('D3PD.flag1', True)
64 >>> flags.addFlag ('D3PD.flag2', False)
66 >>> lod = flagTestLOD ('flag1', flags.D3PD)
69 >>> lod(2, {}, {'flag1': False})
73 >>> lod(999, {}, {'flag1': False})
75 >>> lod = flagTestLOD ('flag2 or reqlev>4', flags.D3PD)
82 >>> lod = flagTestLOD ('flag2 or reqlev>4', flags.D3PD, hook)
85 >>> lod(10, {'a':1}, {'b':2})
90 fdict = flags.asdict()
91 def flagTestLODFunc (reqlev, args, hookargs):
92 if reqlev < 0:
return False
96 ret = _eval_deferred (expr, fdict, hookargs, reqlev=reqlev)
100 return flagTestLODFunc
104 """Helper for making deferred arguments that evaluate flags.
106 Numerous parts of the D3PD configuration use arbitrary global flags
107 to control how tuples are configured. This is bad because there
108 can be interference when multiple tuples are configured in the
111 Better is to pass the flags in as arguments to the D3PDObject and pass
112 them to blocks using the DeferArg mechanism.
114 This helper is to ease this conversion, while still allowing
115 backwards compatibility with flag-based configuration.
117 deferFlag will return a DeferArg object that evaluates
118 the provided expression string EXP. This will be evaluated
119 in an environment that includes names for all flags in the flags
120 class(es) FLAGS, merged with the value of the hookargs.
122 So if you do something like
124 myobj = make_SGDataVector_D3PDObject ('mycont', 'mykey', 'my_', 'myob',
125 allow_args = ['doExtra'])
126 myobj.defineBlock (0, 'myblock', filler_tool,
127 DoExtra = deferFlag ('doExtra', myFlags))
129 then the DoExtra property will be set from the property myFlags.doExtra()
130 unless it's overridden by passing an argument to the D3PDObject:
132 alg += myobj (level, doExtra = True)
134 Flags are evaluated at the point where deferFlag is called.
136 GDICT gives extra names to be made available when evaluating EXPR.
140 >>> from AthenaConfiguration.AllConfigFlags import initConfigFlags
141 >>> flags = initConfigFlags()
142 >>> flags.addFlag ('D3PD.flag3', True)
144 >>> arg = deferFlag ('flag3', flags.D3PD)
147 >>> arg({'flag3':False})
149 >>> arg = deferFlag ('foo', flags.D3PD, {'foo' : 2})
153 fdict = flags.asdict()
154 return DeferArg (
'_eval_deferred(expr, fdict, locals(), **_gdict)',
158 _eval_deferred = _eval_deferred)