ATLAS Offline Software
Classes | Functions | Variables
python.ConfigText Namespace Reference

Classes

class  TextConfig
 

Functions

def readYaml (yamlPath)
 
def printYaml (d, sort=False, jsonFormat=False)
 
def makeSequence (configPath, dataType, algSeq, geometry=None, autoconfigFromFlags=None, isPhyslite=False, noPhysliteBroken=False, noSystematics=None)
 
def combineConfigFiles (local, config_path, fragment_key="include")
 
def _find_fragment (fragment_path, config_path)
 
def _merge_dicts (local, fragment)
 

Variables

 logCPAlgTextCfg = logging.getLogger('CPAlgTextCfg')
 

Function Documentation

◆ _find_fragment()

def python.ConfigText._find_fragment (   fragment_path,
  config_path 
)
private

Definition at line 333 of file ConfigText.py.

333 def _find_fragment(fragment_path, config_path):
334  paths_to_check = [
335  fragment_path,
336  config_path / fragment_path,
337  *[x / fragment_path for x in os.environ["DATAPATH"].split(":")]
338  ]
339  for path in paths_to_check:
340  if path.exists():
341  return path
342 
343  raise FileNotFoundError(fragment_path)
344 
345 

◆ _merge_dicts()

def python.ConfigText._merge_dicts (   local,
  fragment 
)
private

Definition at line 346 of file ConfigText.py.

346 def _merge_dicts(local, fragment):
347  # in the list case append the fragment to the local list
348  if isinstance(local, list):
349  local += fragment
350  return
351  # In the dict case, append only missing values to local: the local
352  # values take precidence over the fragment ones.
353  if isinstance(local, dict):
354  for key, value in fragment.items():
355  if key in local:
356  _merge_dicts(local[key], value)
357  else:
358  local[key] = value
359  return

◆ combineConfigFiles()

def python.ConfigText.combineConfigFiles (   local,
  config_path,
  fragment_key = "include" 
)

Definition at line 286 of file ConfigText.py.

286 def combineConfigFiles(local, config_path, fragment_key="include"):
287 
288  # if this isn't an iterable there's nothing to combine
289  if isinstance(local, dict):
290  to_combine = local.values()
291  elif isinstance(local, list):
292  to_combine = local
293  else:
294  return
295 
296  # otherwise descend into all the entries here
297  for sub in to_combine:
298  combineConfigFiles(sub, config_path, fragment_key=fragment_key)
299 
300  # if there are no fragments to include we're done
301  if fragment_key not in local:
302  return
303 
304  fragment_path = _find_fragment(
305  pathlib.Path(local[fragment_key]),
306  config_path)
307 
308  with open(fragment_path) as fragment_file:
309  # once https://github.com/yaml/pyyaml/issues/173 is resolved
310  # pyyaml will support the yaml 1.2 spec, which is compatable
311  # with json. Until then yaml and json behave differently, so
312  # we have this override.
313  if fragment_path.suffix == '.json':
314  fragment = json.load(fragment_file)
315  else:
316  fragment = yaml.safe_load(fragment_file)
317 
318  # fill out any sub-fragments, looking in the parent path of the
319  # fragment for local sub-fragments.
321  fragment,
322  fragment_path.parent,
323  fragment_key=fragment_key
324  )
325 
326  # merge the fragment with this one
327  _merge_dicts(local, fragment)
328 
329  # delete the fragment so we don't stumble over it again
330  del local[fragment_key]
331 
332 

◆ makeSequence()

def python.ConfigText.makeSequence (   configPath,
  dataType,
  algSeq,
  geometry = None,
  autoconfigFromFlags = None,
  isPhyslite = False,
  noPhysliteBroken = False,
  noSystematics = None 
)
 

Definition at line 245 of file ConfigText.py.

245 def makeSequence(configPath, dataType, algSeq, geometry=None, autoconfigFromFlags=None,
246  isPhyslite=False, noPhysliteBroken=False, noSystematics=None):
247  """
248  """
249 
250  from AnalysisAlgorithmsConfig.ConfigAccumulator import ConfigAccumulator
251 
252  config = TextConfig(configPath)
253 
254  logCPAlgTextCfg.info("Configuration file read in:")
255  config.printConfig()
256 
257  logCPAlgTextCfg.info("Default algorithms:")
258  config.printAlgs(printOpts=True)
259 
260  logCPAlgTextCfg.info("Configuring algorithms based on YAML file:")
261  configSeq = config.configure()
262 
263  # defaults are added to config as algs are configured
264  logCPAlgTextCfg.info("Configuration used:")
265  config.printConfig()
266 
267  # compile
268  configAccumulator = ConfigAccumulator(algSeq, dataType, isPhyslite=isPhyslite, geometry=geometry, autoconfigFromFlags=autoconfigFromFlags, noSystematics=noSystematics)
269  configSeq.fullConfigure(configAccumulator)
270 
271  # blocks can be reordered during configSeq.fullConfigure
272  logCPAlgTextCfg.info("ConfigBlocks and their configuration:")
273  configSeq.printOptions()
274 
275  from AnaAlgorithm.DualUseConfig import isAthena, useComponentAccumulator
276  if isAthena and useComponentAccumulator:
277  return configAccumulator.CA
278  else:
279  return None
280 
281 
282 # Combine configuration files
283 #
284 # See the README for more info on how this works
285 #

◆ printYaml()

def python.ConfigText.printYaml (   d,
  sort = False,
  jsonFormat = False 
)
Prints a dictionary as YAML

Definition at line 28 of file ConfigText.py.

28 def printYaml(d, sort=False, jsonFormat=False):
29  """Prints a dictionary as YAML"""
30  print(yaml.dump(d, default_flow_style=jsonFormat, sort_keys=sort))
31 
32 

◆ readYaml()

def python.ConfigText.readYaml (   yamlPath)
Loads YAML file into a dictionary

Definition at line 19 of file ConfigText.py.

19 def readYaml(yamlPath):
20  """Loads YAML file into a dictionary"""
21  if not os.path.isfile(yamlPath):
22  raise ValueError(f"{yamlPath} is not a file.")
23  with open(yamlPath, 'r') as f:
24  textConfig = yaml.safe_load(f)
25  return textConfig
26 
27 

Variable Documentation

◆ logCPAlgTextCfg

python.ConfigText.logCPAlgTextCfg = logging.getLogger('CPAlgTextCfg')

Definition at line 16 of file ConfigText.py.

python.ConfigText.combineConfigFiles
def combineConfigFiles(local, config_path, fragment_key="include")
Definition: ConfigText.py:286
python.ConfigText.makeSequence
def makeSequence(configPath, dataType, algSeq, geometry=None, autoconfigFromFlags=None, isPhyslite=False, noPhysliteBroken=False, noSystematics=None)
Definition: ConfigText.py:245
python.ConfigText.readYaml
def readYaml(yamlPath)
Definition: ConfigText.py:19
python.ConfigText._find_fragment
def _find_fragment(fragment_path, config_path)
Definition: ConfigText.py:333
python.ConfigText.printYaml
def printYaml(d, sort=False, jsonFormat=False)
Definition: ConfigText.py:28
Trk::open
@ open
Definition: BinningType.h:40
python.ConfigText._merge_dicts
def _merge_dicts(local, fragment)
Definition: ConfigText.py:346
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
Trk::split
@ split
Definition: LayerMaterialProperties.h:38