3 @file FPGATrackSimTagConfig.py
4 @author Riley Xu - riley.xu@cern.ch
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.
13 import FPGATrackSimConfTools.FPGATrackSimMapTags
as FPGATrackSimMapTags
14 import FPGATrackSimConfTools.FPGATrackSimBankTags
as FPGATrackSimBankTags
15 import FPGATrackSimConfTools.FPGATrackSimAlgorithmTags
as FPGATrackSimAlgorithmTags
25 def getTags(stage = 'algo', options = {}):
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
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.
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
43 @return [mapTag, bankTag, hitFilterTag, algoTag]
46 packages = [
'map',
'bank',
'algo']
49 for i
in range(packages.index(stage), -1, -1):
50 tags[packages[i]] =
_getTag(packages[i], options)
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]
58 elif requestedTag != tags[packages[i]][keyName]:
59 raise NameError(
"Inconsistent tags. Requested " + requestedTag +
" but expect " + tags[packages[i]][keyName])
67 Returns a tag from the specified package, with the given options applied.
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.
77 tagName = FPGATrackSimMapTags.defaultTag
78 tagList = FPGATrackSimMapTags.FPGATrackSimMapTags
80 elif package ==
'bank':
81 tagName = FPGATrackSimBankTags.defaultTag
82 tagList = FPGATrackSimBankTags.FPGATrackSimBankTags
84 elif package ==
'algo':
85 tagName = FPGATrackSimAlgorithmTags.defaultTag
86 tagList = FPGATrackSimAlgorithmTags.FPGATrackSimAlgorithmTags
89 raise NameError(
"Unknown package: " + package)
91 if keyName
in options:
92 tagName = options[keyName]
93 if tagName
not in tagList:
94 raise NameError(
"Invalid " + package +
" tag: " + tagName)
96 tag = tagList[tagName].
copy()
97 tag.update((k, options[k])
for k
in tag.keys() & options.keys())
103 Returns a description string with the tag name(s) and a complete summary of changes
104 from the original tag(s), if any.
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
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()
118 if 'filename' in kwargs
and kwargs[
'filename']:
119 skip_keys = [
'bankDir']
124 description += tag[
'name']
129 if tag[key] != original_tag[key]:
130 description +=
'.' + key +
'-' +
str(tag[key])
132 description += tag[
'package'] +
': ' + tag[
'name'] +
'\n'
134 if tag[key] != original_tag[key]:
135 description += key +
': ' +
str(tag[key]) +
' (default: ' +
str(original_tag[key]) +
')\n'