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