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, *flags=None, algSeq=None, noSystematics=None, dataType=None, geometry=None, autoconfigFromFlags=None, isPhyslite=None, noPhysliteBroken=False)
 
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 422 of file ConfigText.py.

422 def _find_fragment(fragment_path, config_path):
423  paths_to_check = [
424  fragment_path,
425  config_path / fragment_path,
426  *[x / fragment_path for x in os.environ["DATAPATH"].split(":")]
427  ]
428  for path in paths_to_check:
429  if path.exists():
430  return path
431 
432  raise FileNotFoundError(fragment_path)
433 
434 

◆ _merge_dicts()

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

Definition at line 435 of file ConfigText.py.

435 def _merge_dicts(local, fragment):
436  # in the list case append the fragment to the local list
437  if isinstance(local, list):
438  local += fragment
439  return
440  # In the dict case, append only missing values to local: the local
441  # values take precidence over the fragment ones.
442  if isinstance(local, dict):
443  for key, value in fragment.items():
444  if key in local:
445  _merge_dicts(local[key], value)
446  else:
447  local[key] = value
448  return

◆ combineConfigFiles()

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

Definition at line 370 of file ConfigText.py.

370 def combineConfigFiles(local, config_path, fragment_key="include"):
371  combined = False
372 
373  # if this isn't an iterable there's nothing to combine
374  if isinstance(local, dict):
375  to_combine = local.values()
376  elif isinstance(local, list):
377  to_combine = local
378  else:
379  return combined
380 
381  # otherwise descend into all the entries here
382  for sub in to_combine:
383  combined = combineConfigFiles(sub, config_path, fragment_key=fragment_key) or combined
384 
385  # if there are no fragments to include we're done
386  if fragment_key not in local:
387  return combined
388 
389  fragment_path = _find_fragment(
390  pathlib.Path(local[fragment_key]),
391  config_path)
392 
393  with open(fragment_path) as fragment_file:
394  # once https://github.com/yaml/pyyaml/issues/173 is resolved
395  # pyyaml will support the yaml 1.2 spec, which is compatable
396  # with json. Until then yaml and json behave differently, so
397  # we have this override.
398  if fragment_path.suffix == '.json':
399  fragment = json.load(fragment_file)
400  else:
401  fragment = yaml.safe_load(fragment_file)
402 
403  # fill out any sub-fragments, looking in the parent path of the
404  # fragment for local sub-fragments.
406  fragment,
407  fragment_path.parent,
408  fragment_key=fragment_key
409  )
410 
411  # merge the fragment with this one
412  _merge_dicts(local, fragment)
413 
414  # delete the fragment so we don't stumble over it again
415  del local[fragment_key]
416 
417 
418  # if we came to here we merged a fragment, so return True
419  return True
420 
421 

◆ makeSequence()

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

Definition at line 318 of file ConfigText.py.

318 def makeSequence(configPath, *, flags=None, algSeq=None, noSystematics=None, dataType=None, geometry=None, autoconfigFromFlags=None, isPhyslite=None, noPhysliteBroken=False):
319  """
320  """
321 
322  # Historically we have used the identifier
323  # `autoconfigFromFlags`, but in the rest of the code base
324  # `flags` is used. So for now we allow either, and can hopefully
325  # at some point remove the former (21 Aug 25).
326  if autoconfigFromFlags is not None:
327  if flags is not None:
328  raise ValueError("Cannot pass both flags and autoconfigFromFlags arguments")
329  flags = autoconfigFromFlags
330  warnings.warn ('Using autoconfigFromFlags parameter is deprecated, use flags instead', category=deprecationWarningCategory, stacklevel=2)
331  elif flags is None:
332  warnings.warn ('it is deprecated to configure meta-data for analysis configuration manually, please read the configuration flags via the meta-data reader', category=deprecationWarningCategory, stacklevel=2)
333 
334  from AnalysisAlgorithmsConfig.ConfigAccumulator import ConfigAccumulator
335 
336  config = TextConfig(configPath)
337 
338  logCPAlgTextCfg.info("Configuration file read in:")
339  config.printConfig()
340 
341  logCPAlgTextCfg.info("Default algorithms:")
342  config.printAlgs(printOpts=True)
343 
344  logCPAlgTextCfg.info("Configuring algorithms based on YAML file:")
345  configSeq = config.configure()
346 
347  # defaults are added to config as algs are configured
348  logCPAlgTextCfg.info("Configuration used:")
349  config.printConfig()
350 
351  # compile
352  configAccumulator = ConfigAccumulator(algSeq=algSeq, dataType=dataType, isPhyslite=isPhyslite, geometry=geometry, autoconfigFromFlags=autoconfigFromFlags, flags=flags, noSystematics=noSystematics)
353  configSeq.fullConfigure(configAccumulator)
354 
355  # blocks can be reordered during configSeq.fullConfigure
356  logCPAlgTextCfg.info("ConfigBlocks and their configuration:")
357  configSeq.printOptions()
358 
359  from AnaAlgorithm.DualUseConfig import isAthena, useComponentAccumulator
360  if isAthena and useComponentAccumulator:
361  return configAccumulator.CA
362  else:
363  return None
364 
365 
366 # Combine configuration files
367 #
368 # See the README for more info on how this works
369 #

◆ printYaml()

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

Definition at line 30 of file ConfigText.py.

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

◆ readYaml()

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

Definition at line 21 of file ConfigText.py.

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

Variable Documentation

◆ logCPAlgTextCfg

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

Definition at line 18 of file ConfigText.py.

python.ConfigText.combineConfigFiles
def combineConfigFiles(local, config_path, fragment_key="include")
Definition: ConfigText.py:370
python.ConfigText.readYaml
def readYaml(yamlPath)
Definition: ConfigText.py:21
python.ConfigText._find_fragment
def _find_fragment(fragment_path, config_path)
Definition: ConfigText.py:422
python.ConfigText.printYaml
def printYaml(d, sort=False, jsonFormat=False)
Definition: ConfigText.py:30
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:26
Trk::open
@ open
Definition: BinningType.h:40
python.ConfigText.makeSequence
def makeSequence(configPath, *flags=None, algSeq=None, noSystematics=None, dataType=None, geometry=None, autoconfigFromFlags=None, isPhyslite=None, noPhysliteBroken=False)
Definition: ConfigText.py:318
python.ConfigText._merge_dicts
def _merge_dicts(local, fragment)
Definition: ConfigText.py:435
Trk::split
@ split
Definition: LayerMaterialProperties.h:38