|
def | __init__ (self, yamlPath=None, *config=None, addDefaultBlocks=True) |
|
def | setConfig (self, config) |
|
def | preprocessConfig (self, config, algs) |
|
def | cleanupPlaceholders (self, config) |
|
def | loadConfig (self, yamlPath=None, *configDict=None) |
|
def | printConfig (self, sort=False, jsonFormat=False) |
|
def | saveYaml (self, filePath='config.yaml', default_flow_style=False, **kwargs) |
|
def | addBlock (self, name, **kwargs) |
|
def | setOptions (self, **kwargs) |
|
def | configure (self) |
|
|
def | _addNewConfigBlocks (self, modulePath, functionName, algName, defaults=None, pos=None, superBlocks=None) |
|
def | _configureAlg (self, block, blockConfig, configSeq=None, containerName=None, extraOptions=None) |
|
Definition at line 35 of file ConfigText.py.
◆ __init__()
def python.ConfigText.TextConfig.__init__ |
( |
|
self, |
|
|
|
yamlPath = None , |
|
|
* |
config = None , |
|
|
|
addDefaultBlocks = True |
|
) |
| |
Definition at line 36 of file ConfigText.py.
36 def __init__(self, yamlPath=None, *, config=None, addDefaultBlocks=True):
37 super().
__init__(addDefaultBlocks=
False)
39 if yamlPath
and config:
40 raise ValueError(
"Cannot specify both yamlPath and config. Use one or the other.")
43 self.addAlgConfigBlock(algName=
"AddConfigBlocks", alg=self._addNewConfigBlocks,
44 defaults={
'self': self})
51 self.__loadedYaml =
False
52 if yamlPath
is not None or config
is not None:
53 self.loadConfig(yamlPath, configDict=config)
◆ _addNewConfigBlocks()
def python.ConfigText.TextConfig._addNewConfigBlocks |
( |
|
self, |
|
|
|
modulePath, |
|
|
|
functionName, |
|
|
|
algName, |
|
|
|
defaults = None , |
|
|
|
pos = None , |
|
|
|
superBlocks = None |
|
) |
| |
|
private |
Load <functionName> from <modulePath>
Definition at line 237 of file ConfigText.py.
237 def _addNewConfigBlocks(self, modulePath, functionName,
238 algName, defaults=None, pos=None, superBlocks=None):
240 Load <functionName> from <modulePath>
243 module = importlib.import_module(modulePath)
244 fxn = getattr(module, functionName)
245 except ModuleNotFoundError
as e:
246 raise ModuleNotFoundError(f
"{e}\nFailed to load {functionName} from {modulePath}")
248 sys.modules[functionName] = fxn
250 self.addAlgConfigBlock(algName=algName, alg=fxn,
252 superBlocks=superBlocks,
◆ _configureAlg()
def python.ConfigText.TextConfig._configureAlg |
( |
|
self, |
|
|
|
block, |
|
|
|
blockConfig, |
|
|
|
configSeq = None , |
|
|
|
containerName = None , |
|
|
|
extraOptions = None |
|
) |
| |
|
private |
Definition at line 257 of file ConfigText.py.
257 def _configureAlg(self, block, blockConfig, configSeq=None, containerName=None,
259 if not isinstance(blockConfig, list):
260 blockConfig = [blockConfig]
262 for options
in blockConfig:
264 if 'containerName' in options:
265 containerName = options[
'containerName']
266 elif containerName
is not None and 'containerName' not in options:
267 options[
'containerName'] = containerName
269 logCPAlgTextCfg.info(f
"Configuring {block.algName}")
270 seq, funcOpts = block.makeConfig(options)
273 algOpts = seq.setOptions(options)
276 if containerName
is None:
278 if 'name' in opt
and opt[
'name'] ==
'containerName':
279 containerName = opt.get(
'value',
None)
282 if configSeq
is not None:
286 if extraOptions
is None:
287 extraOptionsList = [
"skipOnData",
"skipOnMC",
"onlyForDSIDs"]
289 if i[
'name']
in extraOptionsList
and i[
'defaultValue'] != i[
'value']:
290 if extraOptions
is None:
292 extraOptions[i[
'name']] = i[
'value']
294 algOpts = seq.setOptions(extraOptions.copy())
297 algOpts = [i[
'name']
for i
in algOpts]
298 expectedOptions =
set(funcOpts)
299 expectedOptions |=
set(algOpts)
300 expectedOptions |=
set(block.subAlgs)
302 difference =
set(options.keys()) - expectedOptions
303 difference.discard(
'__placeholder__')
305 difference =
"\n".
join(difference)
306 raise ValueError(f
"There are options set that are not used for "
307 f
"{block.algName}:\n{difference}\n"
308 "Please check your configuration.")
311 for alg
in self._order.
get(block.algName, []):
313 subAlg = block.subAlgs[alg]
314 self._configureAlg(subAlg, options[alg], configSeq, containerName, extraOptions)
◆ addBlock()
def python.ConfigText.TextConfig.addBlock |
( |
|
self, |
|
|
|
name, |
|
|
** |
kwargs |
|
) |
| |
Create entry into dictionary representing the text configuration
Definition at line 174 of file ConfigText.py.
174 def addBlock(self, name, **kwargs):
176 Create entry into dictionary representing the text configuration
178 def setEntry(name, config, opts):
180 if name
not in config:
182 elif isinstance(config[name], list):
185 config[name] = [config[name], opts]
189 name, rest = name[:name.index(
'.')], name[name.index(
'.') + 1:]
190 config = config[name]
191 if isinstance(config, list):
193 setEntry(rest, config, opts)
195 setEntry(name, self._config, dict(kwargs))
◆ cleanupPlaceholders()
def python.ConfigText.TextConfig.cleanupPlaceholders |
( |
|
self, |
|
|
|
config |
|
) |
| |
Remove placeholder markers after initialization.
Definition at line 90 of file ConfigText.py.
90 def cleanupPlaceholders(self, config):
92 Remove placeholder markers after initialization.
94 if not isinstance(config, dict):
96 if "__placeholder__" in config:
97 del config[
"__placeholder__"]
98 for key, value
in config.items():
99 self.cleanupPlaceholders(value)
◆ configure()
def python.ConfigText.TextConfig.configure |
( |
|
self | ) |
|
Process YAML configuration file and confgure added algorithms.
Definition at line 210 of file ConfigText.py.
211 """Process YAML configuration file and confgure added algorithms."""
213 for blockName
in self._config:
214 if blockName
not in self._order[self.ROOTNAME]:
216 blockName =
list(self._config[blockName].
keys())[0]
217 raise ValueError(f
"Unkown block {blockName} in yaml file")
220 configSeq = ConfigSequence()
221 for blockName
in self._order[self.ROOTNAME]:
222 if blockName ==
"AddConfigBlocks":
225 assert blockName
in self._algs
228 if blockName
in self._config:
229 blockConfig = self._config[blockName]
230 alg = self._algs[blockName]
231 self._configureAlg(alg, blockConfig, configSeq)
◆ loadConfig()
def python.ConfigText.TextConfig.loadConfig |
( |
|
self, |
|
|
|
yamlPath = None , |
|
|
* |
configDict = None |
|
) |
| |
read a YAML file. Will combine with any config blocks added using python
Definition at line 101 of file ConfigText.py.
101 def loadConfig(self, yamlPath=None, *, configDict=None):
103 read a YAML file. Will combine with any config blocks added using python
105 if self.__loadedYaml
or isinstance(yamlPath, list):
106 raise NotImplementedError(
"Mering multiple yaml files is not implemented.")
107 self.__loadedYaml =
True
109 def merge(config, algs, path=''):
110 """Add to config block-by-block"""
111 if not isinstance(config, list):
114 for blocks
in config:
116 if blocks == {}
and path:
121 for blockName
in algs:
122 if blockName
in blocks:
123 subBlocks[blockName] = blocks.pop(blockName)
126 self.addBlock(path, **blocks)
128 for subName, subBlock
in subBlocks.items():
129 newPath = f
'{path}.{subName}' if path
else subName
130 merge(subBlock, algs[subName].subAlgs, newPath)
133 logCPAlgTextCfg.info(f
'loading {yamlPath}')
134 if configDict
is not None:
140 if "AddConfigBlocks" in config:
141 self._configureAlg(self._algs[
"AddConfigBlocks"], config[
"AddConfigBlocks"])
144 self.preprocessConfig(config, self._algs)
146 merge(config, self._algs)
149 self.cleanupPlaceholders(config)
◆ preprocessConfig()
def python.ConfigText.TextConfig.preprocessConfig |
( |
|
self, |
|
|
|
config, |
|
|
|
algs |
|
) |
| |
Preprocess the configuration dictionary.
Ensure blocks with only sub-blocks are initialized with an empty dictionary.
Definition at line 66 of file ConfigText.py.
66 def preprocessConfig(self, config, algs):
68 Preprocess the configuration dictionary.
69 Ensure blocks with only sub-blocks are initialized with an empty dictionary.
71 def processNode(node, algs):
72 if not isinstance(node, dict):
74 for blockName, blockContent
in list(node.items()):
78 if isinstance(blockContent, dict)
and not any(
79 key
in algs[blockName].options
for key
in blockContent
82 node[blockName] = {
'__placeholder__':
True, **blockContent}
84 processNode(node[blockName], algs[blockName].subAlgs)
87 processNode(config, algs)
◆ printConfig()
def python.ConfigText.TextConfig.printConfig |
( |
|
self, |
|
|
|
sort = False , |
|
|
|
jsonFormat = False |
|
) |
| |
Print YAML configuration file.
Definition at line 154 of file ConfigText.py.
154 def printConfig(self, sort=False, jsonFormat=False):
155 """Print YAML configuration file."""
156 if self._config
is None:
157 raise ValueError(
"No configuration has been loaded.")
158 printYaml(self._config, sort, jsonFormat)
◆ saveYaml()
def python.ConfigText.TextConfig.saveYaml |
( |
|
self, |
|
|
|
filePath = 'config.yaml' , |
|
|
|
default_flow_style = False , |
|
|
** |
kwargs |
|
) |
| |
Convert dictionary representation to yaml and save
Definition at line 162 of file ConfigText.py.
162 def saveYaml(self, filePath='config.yaml', default_flow_style=False,
165 Convert dictionary representation to yaml and save
167 logCPAlgTextCfg.info(f
"Saving configuration to {filePath}")
168 config = self._config
169 with open(filePath,
'w')
as outfile:
170 yaml.dump(config, outfile, default_flow_style=
False, **kwargs)
◆ setConfig()
def python.ConfigText.TextConfig.setConfig |
( |
|
self, |
|
|
|
config |
|
) |
| |
Print YAML configuration file.
Definition at line 58 of file ConfigText.py.
58 def setConfig(self, config):
59 """Print YAML configuration file."""
61 raise ValueError(
"Configuration has already been loaded.")
◆ setOptions()
def python.ConfigText.TextConfig.setOptions |
( |
|
self, |
|
|
** |
kwargs |
|
) |
| |
Set option(s) for the lsat block that was added. If an option
was added previously, will update value
Definition at line 199 of file ConfigText.py.
199 def setOptions(self, **kwargs):
201 Set option(s) for the lsat block that was added. If an option
202 was added previously, will update value
204 if self._last
is None:
205 raise TypeError(
"Cannot set options before adding a block")
207 self._last.update(**kwargs)
◆ __loadedYaml
python.ConfigText.TextConfig.__loadedYaml |
|
private |
◆ _config
python.ConfigText.TextConfig._config |
|
private |
◆ _last
python.ConfigText.TextConfig._last |
|
private |
The documentation for this class was generated from the following file:
bool configure(asg::AnaToolHandle< ITrigGlobalEfficiencyCorrectionTool > &tool, ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > &electronEffToolsHandles, ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > &electronSFToolsHandles, ToolHandleArray< CP::IMuonTriggerScaleFactors > &muonToolsHandles, ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > &photonEffToolsHandles, ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > &photonSFToolsHandles, const std::string &triggers, const std::map< std::string, std::string > &legsPerTool, unsigned long nToys, bool debug)
def printYaml(d, sort=False, jsonFormat=False)
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.