Helper for making LOD functions to evaluate flags.
Numerous parts of the D3PD configuration use arbitrary global flags
to control which blocks are included. This is bad because there
can be interference when multiple tuples are configured in the
same job.
Better is to use the level-of-detail mechanism to do this,
passing in flags as extra arguments to the D3PDObject.
This helper is to ease this conversion, while still allowing
backwards compatibility with flag-based configuration.
flagTestLOD will return a level-of-detail function that evaluates
the provided expression string EXP. This will be evaluated
in an environment that includes names for all flags in the flags
class(es) FLAGS, merged with the value of the hookargs.
The requested level of detail is also available as `reqlev'.
Thus, if you have something like:
myobj = make_SGDataVector_D3PDObject ('mycont', 'mykey', 'my_', 'myob',
allow_args = ['myLevel'])
myobj.defineBlock (flagTestLOD('myLevel>2', myFlags),
'myblock', filler_tool)
then myblock will be included in the tuple if the property
myFlags.myLevel() is greater than two. However, this can be overridden
by passing an argument to the D3PDObject:
alg += myobj (level, myLevel=4)
Explicit inclusion / exclusion also overrides this determination.
Flags are evaluated at the point where flagTestLOD is called.
If HOOK is supplied, then it is called if the LOD test passes.
It is passed as arguments two dictionaries: the block filler tool
arguments and the hook arguments.
Examples:
>>> from AthenaConfiguration.AllConfigFlags import initConfigFlags
>>> flags = initConfigFlags()
>>> flags.addFlag ('D3PD.flag1', True)
>>> flags.addFlag ('D3PD.flag2', False)
>>> lod = flagTestLOD ('flag1', flags.D3PD)
>>> lod(2, {}, {})
True
>>> lod(2, {}, {'flag1': False})
False
>>> lod(-999, {}, {})
False
>>> lod(999, {}, {'flag1': False})
True
>>> lod = flagTestLOD ('flag2 or reqlev>4', flags.D3PD)
>>> lod(2, {}, {})
False
>>> lod(10, {}, {})
True
>>> def hook(*args):
... print(args)
>>> lod = flagTestLOD ('flag2 or reqlev>4', flags.D3PD, hook)
>>> lod(2, {}, {})
False
>>> lod(10, {'a':1}, {'b':2})
({'a': 1}, {'b': 2})
True
Definition at line 20 of file flagTestLOD.py.
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