a sequence of ConfigBlock objects
This could in principle just be a simple python list, and maybe we
change it to that at some point (10 Mar 22). Having it as its own
class allows to implement some helper functions.
This implements an interface similar to ConfigBlock, but it
doesn't derive from it, as ConfigBlock will likely gain
functionality in the future that wouldn't work for a sequence (or
wouldn't work in the same way).
Definition at line 28 of file ConfigSequence.py.
| def python.ConfigSequence.ConfigSequence.reorderAlgs |
( |
|
self | ) |
|
Check for blocks with dependencies.
If a block required another block that is not present, will
throw an error; Otherwise, will move block immediately after
required block. If dependency is not required, will move
after other block, if it is present.
Note: this implementation can only move blocks forward.
Definition at line 78 of file ConfigSequence.py.
78 def reorderAlgs(self):
80 Check for blocks with dependencies.
82 If a block required another block that is not present, will
83 throw an error; Otherwise, will move block immediately after
84 required block. If dependency is not required, will move
85 after other block, if it is present.
87 Note: this implementation can only move blocks forward.
89 def moveBlock(blocks):
90 for i, block
in enumerate(blocks):
92 ignore = block.getOptionValue(
'ignoreDependencies')
93 if block.hasDependencies():
95 for dep
in block.getDependencies():
100 lastIdx =
max(index
for index,value
in enumerate(blocks)
if value == dep.blockName)
104 raise ValueError(f
"{dep} block is required"
105 f
" for {block} but was not found.")
108 logCPAlgCfgSeq.info(f
"Moving {block} after {blocks[depIdx]}")
110 blocks.insert(depIdx, blocks.pop(i))
115 for _
in range(MAXTRIES):
116 if moveBlock(self._blocks):
120 raise Exception(
"Could not order blocks based on dependencies"
121 f
" in {MAXTRIES} moves.")
| def python.ConfigSequence.ConfigSequence.setOptionValue |
( |
|
self, |
|
|
|
name, |
|
|
|
value, |
|
|
** |
kwargs |
|
) |
| |
set the given option on the sequence
The name should generally be of the form
"groupName.optionName" to identify what group the option
belongs to.
For simplicity I also allow a ".optionName" here, which will
then set the property in the last group added. That makes it
fairly straightforward to add new blocks, set options on them,
and then move on to the next blocks. Please note that this
mechanism ought to be viewed as strictly as a temporary
convenience, and this short cut may go away once better
alternatives are available.
WARNING: The backend to option handling is slated to be
replaced at some point. This particular function may change
behavior, interface or be removed/replaced entirely.
Definition at line 142 of file ConfigSequence.py.
142 def setOptionValue (self, name, value, **kwargs) :
143 """set the given option on the sequence
145 The name should generally be of the form
146 "groupName.optionName" to identify what group the option
149 For simplicity I also allow a ".optionName" here, which will
150 then set the property in the last group added. That makes it
151 fairly straightforward to add new blocks, set options on them,
152 and then move on to the next blocks. Please note that this
153 mechanism ought to be viewed as strictly as a temporary
154 convenience, and this short cut may go away once better
155 alternatives are available.
157 WARNING: The backend to option handling is slated to be
158 replaced at some point. This particular function may change
159 behavior, interface or be removed/replaced entirely.
161 names = name.split(
'.')
163 optionName = names.pop(-1)
166 groupName = names.pop(0)
if names
else ''
168 raise ValueError(f
'Option name can be either <groupName>.<optionName>'
169 f
' or <optionName> not {name}')
170 blocks = self._blocks
173 groupName = blocks[-1].getOptionValue(
'groupName')
178 if ( block.getOptionValue(
'groupName') == groupName
179 and block.hasOption(optionName) ):
180 block.setOptionValue (optionName, value, **kwargs)
183 raise ValueError(f
'{optionName} not found in blocks with '
184 f
'group name {groupName}')
187 blocks[-1].setOptionValue (optionName, value, **kwargs)