|
| 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 38 of file ConfigText.py.
◆ __init__()
| def python.ConfigText.TextConfig.__init__ |
( |
|
self, |
|
|
|
yamlPath = None, |
|
|
* |
config = None, |
|
|
|
addDefaultBlocks = True |
|
) |
| |
Definition at line 39 of file ConfigText.py.
39 def __init__(self, yamlPath=None, *, config=None, addDefaultBlocks=True):
40 super().
__init__(addDefaultBlocks=
False)
42 if yamlPath
and config:
43 raise ValueError(
"Cannot specify both yamlPath and config. Use one or the other.")
46 self.addAlgConfigBlock(algName=
"AddConfigBlocks", alg=self._addNewConfigBlocks,
47 defaults={
'self': self})
54 self.__loadedYaml =
False
55 if yamlPath
is not None or config
is not None:
56 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 240 of file ConfigText.py.
240 def _addNewConfigBlocks(self, modulePath, functionName,
241 algName, defaults=None, pos=None, superBlocks=None):
243 Load <functionName> from <modulePath>
246 module = importlib.import_module(modulePath)
247 fxn = getattr(module, functionName)
248 except ModuleNotFoundError
as e:
249 raise ModuleNotFoundError(f
"{e}\nFailed to load {functionName} from {modulePath}")
251 sys.modules[functionName] = fxn
253 self.addAlgConfigBlock(algName=algName, alg=fxn,
255 superBlocks=superBlocks,
◆ _configureAlg()
| def python.ConfigText.TextConfig._configureAlg |
( |
|
self, |
|
|
|
block, |
|
|
|
blockConfig, |
|
|
|
configSeq = None, |
|
|
|
containerName = None, |
|
|
|
extraOptions = None |
|
) |
| |
|
private |
Definition at line 260 of file ConfigText.py.
260 def _configureAlg(self, block, blockConfig, configSeq=None, containerName=None,
262 if not isinstance(blockConfig, list):
263 blockConfig = [blockConfig]
265 for options
in blockConfig:
267 if 'containerName' in options:
268 containerName = options[
'containerName']
269 elif containerName
is not None and 'containerName' not in options:
270 options[
'containerName'] = containerName
272 logCPAlgTextCfg.info(f
"Configuring {block.algName}")
273 seq, funcOpts = block.makeConfig(options)
276 algOpts = seq.setOptions(options)
279 if containerName
is None:
281 if 'name' in opt
and opt[
'name'] ==
'containerName':
282 containerName = opt.get(
'value',
None)
285 if configSeq
is not None:
289 if extraOptions
is None:
290 extraOptionsList = [
"skipOnData",
"skipOnMC",
"onlyForDSIDs"]
292 if i[
'name']
in extraOptionsList
and i[
'defaultValue'] != i[
'value']:
293 if extraOptions
is None:
295 extraOptions[i[
'name']] = i[
'value']
297 algOpts = seq.setOptions(extraOptions.copy())
300 algOpts = [i[
'name']
for i
in algOpts]
301 expectedOptions =
set(funcOpts)
302 expectedOptions |=
set(algOpts)
303 expectedOptions |=
set(block.subAlgs)
305 difference =
set(options.keys()) - expectedOptions
306 difference.discard(
'__placeholder__')
308 difference =
"\n".
join(difference)
309 raise ValueError(f
"There are options set that are not used for "
310 f
"{block.algName}:\n{difference}\n"
311 "Please check your configuration.")
314 for alg
in self._order.
get(block.algName, []):
316 subAlg = block.subAlgs[alg]
317 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 177 of file ConfigText.py.
177 def addBlock(self, name, **kwargs):
179 Create entry into dictionary representing the text configuration
181 def setEntry(name, config, opts):
183 if name
not in config:
185 elif isinstance(config[name], list):
188 config[name] = [config[name], opts]
192 name, rest = name[:name.index(
'.')], name[name.index(
'.') + 1:]
193 config = config[name]
194 if isinstance(config, list):
196 setEntry(rest, config, opts)
198 setEntry(name, self._config, dict(kwargs))
◆ cleanupPlaceholders()
| def python.ConfigText.TextConfig.cleanupPlaceholders |
( |
|
self, |
|
|
|
config |
|
) |
| |
Remove placeholder markers after initialization.
Definition at line 93 of file ConfigText.py.
93 def cleanupPlaceholders(self, config):
95 Remove placeholder markers after initialization.
97 if not isinstance(config, dict):
99 if "__placeholder__" in config:
100 del config[
"__placeholder__"]
101 for key, value
in config.items():
102 self.cleanupPlaceholders(value)
◆ configure()
| def python.ConfigText.TextConfig.configure |
( |
|
self | ) |
|
Process YAML configuration file and confgure added algorithms.
Definition at line 213 of file ConfigText.py.
214 """Process YAML configuration file and confgure added algorithms."""
216 for blockName
in self._config:
217 if blockName
not in self._order[self.ROOTNAME]:
219 blockName =
list(self._config[blockName].
keys())[0]
220 raise ValueError(f
"Unkown block {blockName} in yaml file")
223 configSeq = ConfigSequence()
224 for blockName
in self._order[self.ROOTNAME]:
225 if blockName ==
"AddConfigBlocks":
228 assert blockName
in self._algs
231 if blockName
in self._config:
232 blockConfig = self._config[blockName]
233 alg = self._algs[blockName]
234 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 104 of file ConfigText.py.
104 def loadConfig(self, yamlPath=None, *, configDict=None):
106 read a YAML file. Will combine with any config blocks added using python
108 if self.__loadedYaml
or isinstance(yamlPath, list):
109 raise NotImplementedError(
"Mering multiple yaml files is not implemented.")
110 self.__loadedYaml =
True
112 def merge(config, algs, path=''):
113 """Add to config block-by-block"""
114 if not isinstance(config, list):
117 for blocks
in config:
119 if blocks == {}
and path:
124 for blockName
in algs:
125 if blockName
in blocks:
126 subBlocks[blockName] = blocks.pop(blockName)
129 self.addBlock(path, **blocks)
131 for subName, subBlock
in subBlocks.items():
132 newPath = f
'{path}.{subName}' if path
else subName
133 merge(subBlock, algs[subName].subAlgs, newPath)
136 logCPAlgTextCfg.info(f
'loading {yamlPath}')
137 if configDict
is not None:
143 if "AddConfigBlocks" in config:
144 self._configureAlg(self._algs[
"AddConfigBlocks"], config[
"AddConfigBlocks"])
147 self.preprocessConfig(config, self._algs)
149 merge(config, self._algs)
152 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 69 of file ConfigText.py.
69 def preprocessConfig(self, config, algs):
71 Preprocess the configuration dictionary.
72 Ensure blocks with only sub-blocks are initialized with an empty dictionary.
74 def processNode(node, algs):
75 if not isinstance(node, dict):
77 for blockName, blockContent
in list(node.items()):
81 if isinstance(blockContent, dict)
and not any(
82 key
in algs[blockName].options
for key
in blockContent
85 node[blockName] = {
'__placeholder__':
True, **blockContent}
87 processNode(node[blockName], algs[blockName].subAlgs)
90 processNode(config, algs)
◆ printConfig()
| def python.ConfigText.TextConfig.printConfig |
( |
|
self, |
|
|
|
sort = False, |
|
|
|
jsonFormat = False |
|
) |
| |
Print YAML configuration file.
Definition at line 157 of file ConfigText.py.
157 def printConfig(self, sort=False, jsonFormat=False):
158 """Print YAML configuration file."""
159 if self._config
is None:
160 raise ValueError(
"No configuration has been loaded.")
161 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 165 of file ConfigText.py.
165 def saveYaml(self, filePath='config.yaml', default_flow_style=False,
168 Convert dictionary representation to yaml and save
170 logCPAlgTextCfg.info(f
"Saving configuration to {filePath}")
171 config = self._config
172 with open(filePath,
'w')
as outfile:
173 yaml.dump(config, outfile, default_flow_style=
False, **kwargs)
◆ setConfig()
| def python.ConfigText.TextConfig.setConfig |
( |
|
self, |
|
|
|
config |
|
) |
| |
Print YAML configuration file.
Definition at line 61 of file ConfigText.py.
61 def setConfig(self, config):
62 """Print YAML configuration file."""
64 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 202 of file ConfigText.py.
202 def setOptions(self, **kwargs):
204 Set option(s) for the lsat block that was added. If an option
205 was added previously, will update value
207 if self._last
is None:
208 raise TypeError(
"Cannot set options before adding a block")
210 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.