ATLAS Offline Software
ChainDictTools.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 
3 from copy import deepcopy
4 
5 from AthenaCommon.Logging import logging
6 log = logging.getLogger( __name__ )
7 
8 
10  listOfSplitChainDicts = []
11 
12  move_jets = 'Bjet' in chainDict['signatures']
13 
14  #Bjet and jet always go together, and the overall dict needs to have signature 'Bjet'
15 
16  for chainPart in chainDict['chainParts']:
17  thisSignature = chainPart['signature']
18  chainPartAdded = False
19 
20  for splitChainDict in listOfSplitChainDicts:
21  splitSignature = splitChainDict['chainParts'][0]['signature']
22  if thisSignature == splitSignature or \
23  (move_jets and thisSignature == 'Jet' and splitSignature == 'Bjet') or \
24  (move_jets and thisSignature == 'Bjet' and splitSignature == 'Jet'):
25  splitChainDict['chainParts'] += [chainPart]
26  chainPartAdded = True
27  break
28  if not chainPartAdded:
29  newSplitChainDict = deepcopy(chainDict)
30  newSplitChainDict['chainParts'] = [chainPart]
31  newSplitChainDict['signature'] = chainPart['signature']
32  listOfSplitChainDicts += [newSplitChainDict]
33 
34  if move_jets:
35  for newDict in listOfSplitChainDicts:
36  if newDict['signature'] == 'Jet':
37  newDict['signature'] = 'Bjet'
38 
39  #special code to handle chains with "AND" in the name
40  #jet,ht and bjet jet chains belong to the same signature
41  #so an extra key is needed to make sure the part are treated separately
42  for splitChainDict in listOfSplitChainDicts:
43  if 'AND' in [part['extra'] for part in splitChainDict['chainParts']]:
44  log.info("Implement extra splitting, triggered by AND key (%s.)", chainDict['chainName'])
45 
46  listOfSplitChainDicts=[]
47  addNewSplit= False
48  for chainPart in chainDict['chainParts']:
49  thisSignature = chainPart['signature']
50  chainPartAdded = False
51 
52  #chainPart coming after the AND, change temporaly the Signature name,
53  #so it does not get added to existing dictionary
54  if addNewSplit:
55  thisSignature = 'extraSplit'
56  addNewSplit = False
57 
58  #chainPart containing at AND,
59  # make sure next chainPart is added as a new elemented to the listOfSplitChainDicts
60  if 'AND' in chainPart['extra']:
61  addNewSplit = True
62  #log.info("AND key found, next chainPart will be added as a new element of listOfSplitChainDicts")
63 
64  for splitChainDict in listOfSplitChainDicts:
65  #if AND present in an elemenent of listOfSplitChainDicts, don't add anything to it
66  if 'AND' in [part['extra'] for part in splitChainDict['chainParts']]:
67  continue
68  if thisSignature == splitChainDict['chainParts'][0]['signature']:
69  #log.info("Adding %s to existing element %s.", chainPart['chainPartName'], splitChainDict)
70  splitChainDict['chainParts'] += [chainPart]
71  chainPartAdded = True
72  break
73  if not chainPartAdded:
74  newSplitChainDict = deepcopy(chainDict)
75  newSplitChainDict['chainParts'] = [chainPart]
76  newSplitChainDict['signature'] = chainPart['signature']
77  listOfSplitChainDicts += [newSplitChainDict]
78  #log.info("Adding %s as a new element of listOfSplitChainDicts", chainPart['chainPartName'])
79 
80  #log.info("ListOfSplitChainDicts", chainPart['chainPartName'])
81 
82  #order the splitted dicts
83  orderedListOfSplitChainDicts = []
84  if "mergingOrder" not in chainDict:
85  log.debug("No merging order given for chain %s.", chainDict['chainName'])
86  elif chainDict["mergingOrder"] == []:
87  log.debug("No merging order given for chain %s.", chainDict['chainName'])
88  else:
89  for chainPartName in chainDict["mergingOrder"]:
90  for splitChainDict in listOfSplitChainDicts:
91  if splitChainDict['chainParts'][0]['chainPartName'] == chainPartName:
92  orderedListOfSplitChainDicts += [splitChainDict]
93 
94  if not len(orderedListOfSplitChainDicts) == len(listOfSplitChainDicts):
95  for chainPartName in chainDict["mergingOrder"]:
96  log.error("Ordering of split chain dicts failed. Please check that orderedListOfSplitChainDicts and listOfSplitChainDicts contain the same elements!!")
97  log.info(chainDict)
98 
99  return orderedListOfSplitChainDicts
100 
101  return listOfSplitChainDicts
102 
103 
104 def splitChainDict(chainDict):
105  listOfChainDicts = []
106  for chainPart in chainDict['chainParts']:
107  newChainDict = deepcopy(chainDict)
108  newChainDict['chainParts'] = [chainPart]
109  listOfChainDicts += [newChainDict]
110  return listOfChainDicts
111 
112 def splitChainDictInLegs(chainDict):
113  from TrigCompositeUtils.TrigCompositeUtils import legName
114  if len(chainDict['chainParts']) ==1:
115  return [chainDict]
116 
117  chainName= chainDict['chainName']
118  listOfChainDicts = []
119  for count, chainDictPart in enumerate(chainDict['chainParts']):
120  onePartChainDict = deepcopy( chainDict )
121  onePartChainDict['chainParts'] = [ chainDictPart ]
122  onePartChainDict['chainName'] = legName(chainName, count)
123  listOfChainDicts += [onePartChainDict]
124  return listOfChainDicts
125 
126 
127 def splitChainInLegs(chainName):
128  from TriggerMenuMT.HLT.Config.Utility.HLTMenuConfig import HLTMenuConfig
129  from TrigCompositeUtils.TrigCompositeUtils import legName
130  chainDict = HLTMenuConfig.getChainDictFromChainName(chainName)
131  if len(chainDict['chainParts']) ==1:
132  return [deepcopy(chainDict)]
133 
134  listOfChainDicts = []
135  for count, chainDictPart in enumerate(chainDict['chainParts']):
136  onePartChainDict = deepcopy( chainDict )
137  onePartChainDict['chainParts'] = [ chainDictPart ]
138  onePartChainDict['chainName'] = legName(chainName, count)
139  listOfChainDicts += [onePartChainDict]
140  return listOfChainDicts
ChainDictTools.splitChainDictInLegs
def splitChainDictInLegs(chainDict)
Definition: ChainDictTools.py:112
ChainDictTools.splitChainInLegs
def splitChainInLegs(chainName)
Definition: ChainDictTools.py:127
python.TrigCompositeUtils.legName
def legName(chainName, legCounter)
Definition: DecisionHandling/python/TrigCompositeUtils.py:12
ChainDictTools.splitChainDict
def splitChainDict(chainDict)
Definition: ChainDictTools.py:104
ChainDictTools.splitInterSignatureChainDict
def splitInterSignatureChainDict(chainDict)
Definition: ChainDictTools.py:9