|
def | __init__ (self, yamlPath=None, *addDefaultBlocks=True) |
|
def | setConfig (self, config) |
|
def | preprocessConfig (self, config, algs) |
|
def | cleanupPlaceholders (self, config) |
|
def | loadConfig (self, yamlPath) |
|
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 33 of file ConfigText.py.
◆ __init__()
def python.ConfigText.TextConfig.__init__ |
( |
|
self, |
|
|
|
yamlPath = None , |
|
|
* |
addDefaultBlocks = True |
|
) |
| |
Definition at line 34 of file ConfigText.py.
34 def __init__(self, yamlPath=None, *, addDefaultBlocks=True):
35 super().
__init__(addDefaultBlocks=
False)
38 self.addAlgConfigBlock(algName=
"AddConfigBlocks", alg=self._addNewConfigBlocks,
39 defaults={
'self': self})
46 self.__loadedYaml =
False
47 if yamlPath
is not None:
48 self.loadConfig(yamlPath)
◆ _addNewConfigBlocks()
def python.ConfigText.TextConfig._addNewConfigBlocks |
( |
|
self, |
|
|
|
modulePath, |
|
|
|
functionName, |
|
|
|
algName, |
|
|
|
defaults = None , |
|
|
|
pos = None , |
|
|
|
superBlocks = None |
|
) |
| |
|
private |
Load <functionName> from <modulePath>
Definition at line 228 of file ConfigText.py.
228 def _addNewConfigBlocks(self, modulePath, functionName,
229 algName, defaults=None, pos=None, superBlocks=None):
231 Load <functionName> from <modulePath>
234 module = importlib.import_module(modulePath)
235 fxn = getattr(module, functionName)
236 except ModuleNotFoundError
as e:
237 raise ModuleNotFoundError(f
"{e}\nFailed to load {functionName} from {modulePath}")
239 sys.modules[functionName] = fxn
241 self.addAlgConfigBlock(algName=algName, alg=fxn,
243 superBlocks=superBlocks,
◆ _configureAlg()
def python.ConfigText.TextConfig._configureAlg |
( |
|
self, |
|
|
|
block, |
|
|
|
blockConfig, |
|
|
|
configSeq = None , |
|
|
|
containerName = None , |
|
|
|
extraOptions = None |
|
) |
| |
|
private |
Definition at line 248 of file ConfigText.py.
248 def _configureAlg(self, block, blockConfig, configSeq=None, containerName=None,
250 if not isinstance(blockConfig, list):
251 blockConfig = [blockConfig]
253 for options
in blockConfig:
255 if 'containerName' in options:
256 containerName = options[
'containerName']
257 elif containerName
is not None and 'containerName' not in options:
258 options[
'containerName'] = containerName
260 logCPAlgTextCfg.info(f
"Configuring {block.algName}")
261 seq, funcOpts = block.makeConfig(options)
264 algOpts = seq.setOptions(options)
267 if containerName
is None:
269 if 'name' in opt
and opt[
'name'] ==
'containerName':
270 containerName = opt.get(
'value',
None)
273 if configSeq
is not None:
277 if extraOptions
is None:
278 extraOptionsList = [
"skipOnData",
"skipOnMC",
"onlyForDSIDs"]
280 if i[
'name']
in extraOptionsList
and i[
'defaultValue'] != i[
'value']:
281 if extraOptions
is None:
283 extraOptions[i[
'name']] = i[
'value']
285 algOpts = seq.setOptions(extraOptions)
288 algOpts = [i[
'name']
for i
in algOpts]
289 expectedOptions =
set(funcOpts)
290 expectedOptions |=
set(algOpts)
291 expectedOptions |=
set(block.subAlgs)
293 difference =
set(options.keys()) - expectedOptions
294 difference.discard(
'__placeholder__')
296 difference =
"\n".
join(difference)
297 raise ValueError(f
"There are options set that are not used for "
298 f
"{block.algName}:\n{difference}\n"
299 "Please check your configuration.")
302 for alg
in self._order.
get(block.algName, []):
304 subAlg = block.subAlgs[alg]
305 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 165 of file ConfigText.py.
165 def addBlock(self, name, **kwargs):
167 Create entry into dictionary representing the text configuration
169 def setEntry(name, config, opts):
171 if name
not in config:
173 elif isinstance(config[name], list):
176 config[name] = [config[name], opts]
180 name, rest = name[:name.index(
'.')], name[name.index(
'.') + 1:]
181 config = config[name]
182 if isinstance(config, list):
184 setEntry(rest, config, opts)
186 setEntry(name, self._config, dict(kwargs))
◆ cleanupPlaceholders()
def python.ConfigText.TextConfig.cleanupPlaceholders |
( |
|
self, |
|
|
|
config |
|
) |
| |
Remove placeholder markers after initialization.
Definition at line 85 of file ConfigText.py.
85 def cleanupPlaceholders(self, config):
87 Remove placeholder markers after initialization.
89 if not isinstance(config, dict):
91 if "__placeholder__" in config:
92 del config[
"__placeholder__"]
93 for key, value
in config.items():
94 self.cleanupPlaceholders(value)
◆ configure()
def python.ConfigText.TextConfig.configure |
( |
|
self | ) |
|
Process YAML configuration file and confgure added algorithms.
Definition at line 201 of file ConfigText.py.
202 """Process YAML configuration file and confgure added algorithms."""
204 for blockName
in self._config:
205 if blockName
not in self._order[self.ROOTNAME]:
207 blockName =
list(self._config[blockName].
keys())[0]
208 raise ValueError(f
"Unkown block {blockName} in yaml file")
211 configSeq = ConfigSequence()
212 for blockName
in self._order[self.ROOTNAME]:
213 if blockName ==
"AddConfigBlocks":
216 assert blockName
in self._algs
219 if blockName
in self._config:
220 blockConfig = self._config[blockName]
221 alg = self._algs[blockName]
222 self._configureAlg(alg, blockConfig, configSeq)
◆ loadConfig()
def python.ConfigText.TextConfig.loadConfig |
( |
|
self, |
|
|
|
yamlPath |
|
) |
| |
read a YAML file. Will combine with any config blocks added using python
Definition at line 96 of file ConfigText.py.
96 def loadConfig(self, yamlPath):
98 read a YAML file. Will combine with any config blocks added using python
100 if self.__loadedYaml
or isinstance(yamlPath, list):
101 raise NotImplementedError(
"Mering multiple yaml files is not implemented.")
102 self.__loadedYaml =
True
104 def merge(config, algs, path=''):
105 """Add to config block-by-block"""
106 if not isinstance(config, list):
109 for blocks
in config:
111 if blocks == {}
and path:
116 for blockName
in algs:
117 if blockName
in blocks:
118 subBlocks[blockName] = blocks.pop(blockName)
121 self.addBlock(path, **blocks)
123 for subName, subBlock
in subBlocks.items():
124 newPath = f
'{path}.{subName}' if path
else subName
125 merge(subBlock, algs[subName].subAlgs, newPath)
128 logCPAlgTextCfg.info(f
'loading {yamlPath}')
131 if "AddConfigBlocks" in config:
132 self._configureAlg(self._algs[
"AddConfigBlocks"], config[
"AddConfigBlocks"])
135 self.preprocessConfig(config, self._algs)
137 merge(config, self._algs)
140 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 61 of file ConfigText.py.
61 def preprocessConfig(self, config, algs):
63 Preprocess the configuration dictionary.
64 Ensure blocks with only sub-blocks are initialized with an empty dictionary.
66 def processNode(node, algs):
67 if not isinstance(node, dict):
69 for blockName, blockContent
in list(node.items()):
73 if isinstance(blockContent, dict)
and not any(
74 key
in algs[blockName].options
for key
in blockContent
77 node[blockName] = {
'__placeholder__':
True, **blockContent}
79 processNode(node[blockName], algs[blockName].subAlgs)
82 processNode(config, algs)
◆ printConfig()
def python.ConfigText.TextConfig.printConfig |
( |
|
self, |
|
|
|
sort = False , |
|
|
|
jsonFormat = False |
|
) |
| |
Print YAML configuration file.
Definition at line 145 of file ConfigText.py.
145 def printConfig(self, sort=False, jsonFormat=False):
146 """Print YAML configuration file."""
147 if self._config
is None:
148 raise ValueError(
"No configuration has been loaded.")
149 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 153 of file ConfigText.py.
153 def saveYaml(self, filePath='config.yaml', default_flow_style=False,
156 Convert dictionary representation to yaml and save
158 logCPAlgTextCfg.info(f
"Saving configuration to {filePath}")
159 config = self._config
160 with open(filePath,
'w')
as outfile:
161 yaml.dump(config, outfile, default_flow_style=
False, **kwargs)
◆ setConfig()
def python.ConfigText.TextConfig.setConfig |
( |
|
self, |
|
|
|
config |
|
) |
| |
Print YAML configuration file.
Definition at line 53 of file ConfigText.py.
53 def setConfig(self, config):
54 """Print YAML configuration file."""
56 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 190 of file ConfigText.py.
190 def setOptions(self, **kwargs):
192 Set option(s) for the lsat block that was added. If an option
193 was added previously, will update value
195 if self._last
is None:
196 raise TypeError(
"Cannot set options before adding a block")
198 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.