|
def | __init__ (self, yamlPath=None, *addDefaultBlocks=True) |
|
def | setConfig (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) |
|
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 183 of file ConfigText.py.
183 def _addNewConfigBlocks(self, modulePath, functionName,
184 algName, defaults=None, pos=None, superBlocks=None):
186 Load <functionName> from <modulePath>
189 module = importlib.import_module(modulePath)
190 fxn = getattr(module, functionName)
191 except ModuleNotFoundError
as e:
192 raise ModuleNotFoundError(f
"{e}\nFailed to load {functionName} from {modulePath}")
194 sys.modules[functionName] = fxn
196 self.addAlgConfigBlock(algName=algName, alg=fxn,
198 superBlocks=superBlocks,
◆ _configureAlg()
def python.ConfigText.TextConfig._configureAlg |
( |
|
self, |
|
|
|
block, |
|
|
|
blockConfig, |
|
|
|
configSeq = None , |
|
|
|
containerName = None |
|
) |
| |
|
private |
Definition at line 203 of file ConfigText.py.
203 def _configureAlg(self, block, blockConfig, configSeq=None, containerName=None):
204 if not isinstance(blockConfig, list):
205 blockConfig = [blockConfig]
207 for options
in blockConfig:
209 if 'containerName' in options:
210 containerName = options[
'containerName']
211 elif containerName
is not None and 'containerName' not in options:
212 options[
'containerName'] = containerName
214 logCPAlgTextCfg.info(f
"Configuring {block.algName}")
215 seq, funcOpts = block.makeConfig(options)
218 algOpts = seq.setOptions(options)
219 if configSeq
is not None:
223 algOpts = [i[
'name']
for i
in algOpts]
224 expectedOptions =
set(funcOpts)
225 expectedOptions |=
set(algOpts)
226 expectedOptions |=
set(block.subAlgs)
228 difference =
set(options.keys()) - expectedOptions
230 difference =
"\n".
join(difference)
231 raise ValueError(f
"There are options set that are not used for "
232 f
"{block.algName}:\n{difference}\n"
233 "Please check your configuration.")
236 for alg
in self._order.
get(block.algName, []):
238 subAlg = block.subAlgs[alg]
239 self._configureAlg(subAlg, options[alg], configSeq, containerName)
◆ addBlock()
def python.ConfigText.TextConfig.addBlock |
( |
|
self, |
|
|
|
name, |
|
|
** |
kwargs |
|
) |
| |
Create entry into dictionary representing the text configuration
Definition at line 122 of file ConfigText.py.
122 def addBlock(self, name, **kwargs):
124 Create entry into dictionary representing the text configuration
126 def setEntry(name, config, opts):
128 if name
not in config:
130 elif isinstance(config[name], list):
133 config[name] = [config[name], opts]
137 name, rest = name[:name.index(
'.')], name[name.index(
'.') + 1:]
138 config = config[name]
139 if isinstance(config, list):
141 setEntry(rest, config, opts)
143 setEntry(name, self._config, dict(kwargs))
◆ configure()
def python.ConfigText.TextConfig.configure |
( |
|
self | ) |
|
Process YAML configuration file and confgure added algorithms.
Definition at line 158 of file ConfigText.py.
159 """Process YAML configuration file and confgure added algorithms."""
161 for blockName
in self._config:
162 if blockName
not in self._order[self.ROOTNAME]:
163 raise ValueError(f
"Unkown block {blockName} in yaml file")
166 configSeq = ConfigSequence()
167 for blockName
in self._order[self.ROOTNAME]:
168 if blockName ==
"AddConfigBlocks":
171 assert blockName
in self._algs
174 if blockName
in self._config:
175 blockConfig = self._config[blockName]
176 alg = self._algs[blockName]
177 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 61 of file ConfigText.py.
61 def loadConfig(self, yamlPath):
63 read a YAML file. Will combine with any config blocks added using python
65 if self.__loadedYaml
or isinstance(yamlPath, list):
66 raise NotImplementedError(
"Mering multiple yaml files is not implemented.")
67 self.__loadedYaml =
True
69 def merge(config, algs, path=''):
70 """Add to config block-by-block"""
71 if not isinstance(config, list):
76 if blocks == {}
and path:
81 for blockName
in algs:
82 if blockName
in blocks:
83 subBlocks[blockName] = blocks.pop(blockName)
86 self.addBlock(path, **blocks)
88 for subName, subBlock
in subBlocks.items():
89 newPath = f
'{path}.{subName}' if path
else subName
90 merge(subBlock, algs[subName].subAlgs, newPath)
93 logCPAlgTextCfg.info(f
'loading {yamlPath}')
96 if "AddConfigBlocks" in config:
97 self._configureAlg(self._algs[
"AddConfigBlocks"], config[
"AddConfigBlocks"])
98 merge(config, self._algs)
◆ printConfig()
def python.ConfigText.TextConfig.printConfig |
( |
|
self, |
|
|
|
sort = False , |
|
|
|
jsonFormat = False |
|
) |
| |
Print YAML configuration file.
Definition at line 102 of file ConfigText.py.
102 def printConfig(self, sort=False, jsonFormat=False):
103 """Print YAML configuration file."""
104 if self._config
is None:
105 raise ValueError(
"No configuration has been loaded.")
106 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 110 of file ConfigText.py.
110 def saveYaml(self, filePath='config.yaml', default_flow_style=False,
113 Convert dictionary representation to yaml and save
115 logCPAlgTextCfg.info(f
"Saving configuration to {filePath}")
116 config = self._config
117 with open(filePath,
'w')
as outfile:
118 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 147 of file ConfigText.py.
147 def setOptions(self, **kwargs):
149 Set option(s) for the lsat block that was added. If an option
150 was added previously, will update value
152 if self._last
is None:
153 raise TypeError(
"Cannot set options before adding a block")
155 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.