ATLAS Offline Software
TriggerLeg_DictHelpers.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 
3 # Helper functions to convert cfg file into python dictionaries
4 
5 from AthenaCommon.Utils.unixtools import find_datafile
6 
7 
8 def TriggerDict():
9 
10  # Dictionary from TrigGlobalEfficiencyCorrection/Triggers.cfg
11  # Key is trigger chain (w/o HLT prefix)
12  # Value is empty for single leg trigger or list of legs
13 
14  with open(find_datafile('TrigGlobalEfficiencyCorrection/Triggers.cfg'), 'r') as file:
15  file_content = file.read()
16 
17  # Split the content by lines
18  lines = file_content.strip().split('\n')
19  # Initialize an empty dictionary to hold the results
20  trigger_dict = {}
21  # Loop through each line in the file content
22  for line in lines:
23  # Split the line by whitespace
24  parts = line.split()
25  if not parts:
26  continue
27  # The first element is the key, the rest are the values
28  key = parts[0]
29  if key.startswith('#'):
30  continue
31  values = parts[1:]
32  # Add to dictionary
33  trigger_dict[key] = values
34  return trigger_dict
35 
36 
37 def MapKeysDict(target_version):
38 
39  # Dictionary from TrigGlobalEfficiencyCorrection/MapKeys.cfg
40  # Key is year_leg
41  # Value is list of configs available
42 
43  with open(find_datafile('TrigGlobalEfficiencyCorrection/MapKeys.cfg'), 'r') as file:
44  file_content = file.read()
45 
46  # Split the content by lines
47  lines = file_content.strip().split('\n')
48 
49  # Initialize an empty dictionary to hold the results
50  trigger_dict = {}
51 
52  # Variables to keep track of the current version and if we are in the right version section
53  current_version = None
54  in_target_version = False
55 
56  for line in lines:
57  # Remove leading and trailing whitespaces
58  line = line.strip()
59 
60  # Skip empty lines and comment lines
61  if not line or line.startswith('#'):
62  continue
63 
64  # Check for version lines
65  if line.startswith("[VERSION]"):
66  current_version = line.replace("[VERSION]", "").strip()
67  in_target_version = target_version in current_version
68  continue
69 
70  # If we are in the target version section, parse the entries
71  if in_target_version:
72  parts = line.split()
73  if len(parts) < 3:
74  continue
75  key = f"{parts[0]}_{parts[1]}"
76  values = parts[2:]
77  trigger_dict[key] = values
78 
79  return trigger_dict
TriggerLeg_DictHelpers.MapKeysDict
def MapKeysDict(target_version)
Definition: TriggerLeg_DictHelpers.py:37
TriggerLeg_DictHelpers.TriggerDict
def TriggerDict()
Definition: TriggerLeg_DictHelpers.py:8
Trk::open
@ open
Definition: BinningType.h:40
python.Utils.unixtools.find_datafile
def find_datafile(fname, pathlist=None, access=os.R_OK)
pathresolver-like helper function --------------------------------------—
Definition: unixtools.py:67
Trk::split
@ split
Definition: LayerMaterialProperties.h:38