ATLAS Offline Software
FPGATrackSimTagConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 '''
3 @file FPGATrackSimTagConfig.py
4 @author Riley Xu - riley.xu@cern.ch
5 @date August 27, 2020
6 
7 This file declares functions to interface with the tag system. Tags should be
8 retrieved and modified using these functions, and not accessing them directly
9 from their respective files.
10 '''
11 
12 
13 import FPGATrackSimConfTools.FPGATrackSimMapTags as FPGATrackSimMapTags
14 import FPGATrackSimConfTools.FPGATrackSimBankTags as FPGATrackSimBankTags
15 import FPGATrackSimConfTools.FPGATrackSimAlgorithmTags as FPGATrackSimAlgorithmTags
16 
17 
18 _tagDependency = {
19  'map': [],
20  'bank': ['map'],
21  'algo': [],
22 }
23 
24 
25 def getTags(stage = 'algo', options = {}):
26  '''
27  Returns a set of tags used to configure various FPGATrackSim components, configured
28  with additional user options. This function will do consistency checks on
29  tag dependencies.
30 
31  @param options - This should be a dictionary with keys that match those
32  in the packages' tags, and optionally entries to switch to a
33  different tag from the default (see below). Extra/missing keys are ok.
34 
35  To swith to a different tag, use the following keys:
36  FPGATrackSimMaps - mapTag
37  FPGATrackSimBanks - bankTag
38  FPGATrackSimAlgorithms - algoTag
39  @param stage - Which stage this function is being called from: map/bank/algo.
40  This is limits the returned tags and the dependency checking to the
41  given stage.
42 
43  @return [mapTag, bankTag, hitFilterTag, algoTag]
44  '''
45 
46  packages = ['map', 'bank', 'algo'] # In order of stage
47  tags = {}
48 
49  for i in range(packages.index(stage), -1, -1):
50  tags[packages[i]] = _getTag(packages[i], options)
51 
52  # Consistency check with dependent tags
53  for dependentPackage in _tagDependency[packages[i]]:
54  keyName = dependentPackage + 'Tag'
55  requestedTag = options.get(keyName)
56  if requestedTag is None:
57  options[keyName] = tags[packages[i]][keyName] # Force the use of the dependent tag
58  elif requestedTag != tags[packages[i]][keyName]:
59  raise NameError("Inconsistent tags. Requested " + requestedTag + " but expect " + tags[packages[i]][keyName])
60 
61  return tags
62 
63 
64 def _getTag(package, options):
65  '''
66  Helper function.
67  Returns a tag from the specified package, with the given options applied.
68 
69  @param package - Can be: map, bank, algo
70  @param options - This should be a dictionary with keys that match those
71  in the package's tag, and optionally an entry to switch to a
72  different tag from the default, using the key (package + 'Tag').
73  Extra/missing keys are ok.
74  '''
75 
76  if package == 'map':
77  tagName = FPGATrackSimMapTags.defaultTag
78  tagList = FPGATrackSimMapTags.FPGATrackSimMapTags
79  keyName = 'mapTag'
80  elif package == 'bank':
81  tagName = FPGATrackSimBankTags.defaultTag
82  tagList = FPGATrackSimBankTags.FPGATrackSimBankTags
83  keyName = 'bankTag'
84  elif package == 'algo':
85  tagName = FPGATrackSimAlgorithmTags.defaultTag
86  tagList = FPGATrackSimAlgorithmTags.FPGATrackSimAlgorithmTags
87  keyName = 'algoTag'
88  else:
89  raise NameError("Unknown package: " + package)
90 
91  if keyName in options:
92  tagName = options[keyName]
93  if tagName not in tagList:
94  raise NameError("Invalid " + package + " tag: " + tagName)
95 
96  tag = tagList[tagName].copy()
97  tag.update((k, options[k]) for k in tag.keys() & options.keys())
98  return tag
99 
100 
101 def getDescription(*args, **kwargs):
102  '''
103  Returns a description string with the tag name(s) and a complete summary of changes
104  from the original tag(s), if any.
105 
106  @param args - Any number of tags (the actual dictionary, not just the name) in any order.
107  @param filename - Omit all whitespace, and use '-' and '_' as seperator
108  '''
109  description = ''
110  for tag in args:
111  if tag['package'] == 'map':
112  original_tag = FPGATrackSimMapTags.FPGATrackSimMapTags[tag['name']].copy()
113  elif tag['package'] == 'bank':
114  original_tag = FPGATrackSimBankTags.FPGATrackSimBankTags[tag['name']].copy()
115  elif tag['package'] == 'algo':
116  original_tag = FPGATrackSimAlgorithmTags.FPGATrackSimAlgorithmTags[tag['name']].copy()
117 
118  if 'filename' in kwargs and kwargs['filename']:
119  skip_keys = ['bankDir']
120  # keys to skip when generating filename / short description
121 
122  if description:
123  description += '__'
124  description += tag['name']
125 
126  for key in tag:
127  if key in skip_keys:
128  continue
129  if tag[key] != original_tag[key]:
130  description += '.' + key + '-' + str(tag[key])
131  else:
132  description += tag['package'] + ': ' + tag['name'] + '\n'
133  for key in tag:
134  if tag[key] != original_tag[key]:
135  description += key + ': ' + str(tag[key]) + ' (default: ' + str(original_tag[key]) + ')\n'
136 
137  return description
138 
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.FPGATrackSimTagConfig.getDescription
def getDescription(*args, **kwargs)
Definition: FPGATrackSimTagConfig.py:101
python.FPGATrackSimTagConfig._getTag
def _getTag(package, options)
Definition: FPGATrackSimTagConfig.py:64
python.FPGATrackSimTagConfig.getTags
def getTags(stage='algo', options={})
Definition: FPGATrackSimTagConfig.py:25
str
Definition: BTagTrackIpAccessor.cxx:11
calibdata.copy
bool copy
Definition: calibdata.py:27