203 Function to obtain the chain configuration dictionary from the short name by parsing its
204 components and finding the corresponding properties which are defined in SignatureDicts.
205 The naming convention is defined in https://twiki.cern.ch/twiki/bin/view/Atlas/TriggerNamingRun2
206 and https://twiki.cern.ch/twiki/bin/view/Atlas/TriggerNamingRun3
210 from TriggerMenuMT.HLT.Menu.SignatureDicts
import ChainDictTemplate
211 from TriggerMenuMT.HLT.Menu.SignatureDicts
import getSignatureInformation
212 from TriggerMenuMT.HLT.Jet.JetRecoCommon
import etaRangeAbbrev
213 genchainDict = deepcopy(ChainDictTemplate)
214 genchainDict[
'chainName'] = chainName
217 hltChainName = chainName.rsplit(
"_L1",1)[0]
220 if 'HLT_HLT' in hltChainName:
221 log.error(
"%s is incorrect, please fix the HLT_HLT part", hltChainName)
222 raise RuntimeError(
"[analyseChainName] chain name contains HLT_HLT, please fix in corresponding menu where this chain is included")
225 allChainProperties=[]
226 cparts = hltChainName.split(
"_")
227 if 'HLT' in hltChainName:
232 if genchainDict[
'eventBuildType']:
233 cparts.remove( genchainDict[
'eventBuildType'] )
235 hltChainNameShort =
'_'.
join(cparts)
238 from TriggerMenuMT.HLT.Menu.SignatureDicts
import AllowedTopos, AllowedTopos_comb, AllowedTopos_Bphysics_topoVariant, AllowedTopos_Bphysics_topoExtra
247 for cindex, cpart
in enumerate(cparts):
249 if cpart
in AllowedTopos:
250 log.debug(
'" %s" is in this part of the name %s -> topo alg', AllowedTopos, cpart)
253 toposIndexed.update({topo : topoindex})
254 hltChainNameShort=hltChainNameShort.replace(
'_'+cpart,
'')
256 elif cpart
in AllowedTopos_Bphysics_topoVariant:
257 log.debug(
'[analyseChainName] chain part %s is a BLS topo variant, adding to bphys_topoVariant', cpart)
258 bphys_topoVariant.append(cpart)
259 toposIndexed.update({cpart : cindex})
261 elif cpart
in AllowedTopos_Bphysics_topoExtra:
262 log.debug(
'[analyseChainName] chain part %s is a BLS extra topo hypo, adding to bphys_topoExtra', cpart)
263 bphys_topoExtra.append(cpart)
264 toposIndexed.update({cpart : cindex})
267 log.debug(
'[analyseChainName] chain part %s is not a general topo, BLS extra or variant topo hypo, checking comb topos next', cpart)
268 if cpart
in AllowedTopos_comb:
269 log.debug(
'[analyseChainName] chain part %s is a combined topo hypo, adding to extraComboHypo', cpart)
270 toposIndexed.update({cpart : cindex})
271 extraComboHypos.append(cpart)
273 genchainDict[
'topo'] = topos
274 genchainDict[
'extraComboHypos'] = extraComboHypos
276 if bphysTopos
is True:
277 genchainDict[
'topoVariant'] = bphys_topoVariant
278 genchainDict[
'topoExtra'] = bphys_topoExtra
281 for t, i
in enumerate(toposIndexed):
283 log.debug(
'topo %s with index %s is going to be deleted from chain parts', t, i)
292 from TriggerMenuMT.HLT.Menu.SignatureDicts
import getBasePattern
299 from TriggerMenuMT.HLT.Menu.SignatureDicts
import getSignatureNameFromToken, AllowedCosmicChainIdentifiers, \
300 AllowedCalibChainIdentifiers, AllowedMonitorChainIdentifiers, AllowedBeamspotChainIdentifiers
302 from TriggerMenuMT.HLT.Config.Utility.MenuAlignmentTools
import get_alignment_group_from_pattern
as getAlignmentGroupFromPattern
304 def buildDict(signature, sigToken ):
305 groupdict = {
'signature': signature,
'threshold':
'',
'multiplicity':
'',
306 'trigType': sigToken,
'extra':
''}
307 mdicts.append( groupdict )
311 log.debug(
"Looping over chain part: %s", cpart)
312 m = pattern.match(cpart)
315 log.debug(
"Pattern found in this string: %s", cpart)
316 groupdict = m.groupdict()
318 multiChainIndices = [i
for i
in range(len(hltChainNameShort))
if ( hltChainNameShort.startswith(cpart, i) ) ]
319 log.debug(
"MultiChainIndices: %s", multiChainIndices)
320 for theMultiChainIndex
in multiChainIndices:
324 if (theMultiChainIndex != 0) & (hltChainNameShort[theMultiChainIndex-1] !=
'_'):
327 if theMultiChainIndex
not in multichainindex:
328 multichainindex.append(theMultiChainIndex)
330 log.debug(
"HLTChainName: %s", hltChainName)
331 log.debug(
"HLTChainNameShort: %s", hltChainNameShort)
332 log.debug(
"cpart: %s", cpart)
333 log.debug(
"groupdict: %s", groupdict)
334 log.debug(
"multichainindex: %s", multichainindex)
338 groupdict[
'signature'] = sName
339 log.debug(
"groupdict['signature']: %s",groupdict[
'signature'])
341 mdicts.append(groupdict)
343 elif cpart ==
'noalg':
344 multichainindex.append(hltChainNameShort.index(cpart))
345 buildDict(
'Streaming',
'streamer')
347 elif cpart ==
'acceptedevts':
348 multichainindex.append(hltChainNameShort.index(cpart))
349 buildDict(
'Calib',
'calib')
352 for chainCategory
in [([
'mb'],
'MinBias',
'mb'),
353 ([
'hi'],
'HeavyIon',
'mb'),
354 (AllowedCosmicChainIdentifiers,
'Cosmic',
'cosmic'),
355 (AllowedCalibChainIdentifiers,
'Calib',
'calib'),
356 (AllowedMonitorChainIdentifiers,
'Monitor',
'calib'),
357 (AllowedBeamspotChainIdentifiers,
'Beamspot',
'beamspot'),
358 ([
'eb'],
'EnhancedBias',
'eb')]:
359 if cpart
in chainCategory[0]:
360 log.debug(
'Doing chain type %s', chainCategory[1])
361 multichainindex.append(hltChainNameShort.index(cpart))
362 buildDict(chainCategory[1], chainCategory[2])
368 multichainindex =
sorted(multichainindex, key=int)
369 cN = deepcopy(hltChainNameShort)
370 for i
in reversed(multichainindex):
372 log.debug(
'Appending to multichainparts (i!=0): %s', hltChainNameShort[i:len(cN)])
374 multichainparts.append(hltChainNameShort[i:len(cN)])
377 log.debug(
'Appending to multichainparts: %s', hltChainNameShort[i:len(cN)])
378 multichainparts.append(cN)
379 log.debug(
"multichainparts: %s",multichainparts)
383 multichainparts.reverse()
384 log.debug(
'multichainparts after reverse: %s', multichainparts)
388 if len(L1thresholds) != 0:
389 assert len(L1thresholds) == len(multichainparts),
'ERROR IN CHAIN {} definition, l1 thresholds specified {} have different length than chain parts {}'\
390 .
format(chainName,
str(L1thresholds),
str(multichainparts) )
399 if chainName.count(
"_L1") > 1:
402 for chainindex, chainparts
in enumerate(multichainparts):
404 chainpartsNoL1 = chainparts.rsplit(
'_L1',1)[0]
if 'L1' in chainparts
else chainparts
406 if len(L1thresholds) != 0:
407 chainProperties[
'L1threshold'] = L1thresholds[chainindex]
409 __th = getAllThresholdsFromItem ( L1item )
410 assert chainindex < len(__th),
"In defintion of the chain {chainName} there is not enough thresholds to be used, index: {chainindex} >= number of thresholds, thresholds are: {__th}"
411 chainProperties[
'L1threshold'] = __th[chainindex]
413 parts=chainpartsNoL1.split(
'_')
414 log.debug(
"[analyseChainName] chain parts w/o L1 are %s", parts)
416 log.error(
"[analyseChainName] chainpartsNoL1 -> parts: %s -> %s", chainpartsNoL1, parts)
417 raise Exception(
"[analyseChainName] parts contains None, please identify how this is happening")
419 log.debug(
"[analyseChainName] chainpartsNoL1 %s, parts %s", chainpartsNoL1, parts)
422 duplicateParts = ([item
for item, count
in collections.Counter(parts).
items()
if count > 1])
423 log.debug(
"[analyseChainName] chainpartsNoL1 %s contains duplicate strings %s", chainpartsNoL1, duplicateParts)
425 log.error(
"[analyseChainName] chain %s has duplicate strings %s, please fix!!", chainName, duplicateParts)
426 raise RuntimeError(
"[analyseChainName] Check the chain name, there are duplicate configurations: %s", duplicateParts)
428 chainProperties[
'trigType']=mdicts[chainindex][
'trigType']
429 if 'extra' in chainProperties:
430 raise RuntimeError(
"[analyseChainName] Overwrote 'extra' value, only one supported!")
432 chainProperties[
'extra']=mdicts[chainindex][
'extra']
433 multiplicity = mdicts[chainindex][
'multiplicity']
if not mdicts[chainindex][
'multiplicity'] ==
'' else '1'
434 chainProperties[
'multiplicity'] = multiplicity
435 chainProperties[
'threshold']=mdicts[chainindex][
'threshold']
436 chainProperties[
'signature']=mdicts[chainindex][
'signature']
441 chainProperties[
'chainPartName'] = chainparts
442 if (
'-' in L1item)
and (len(multichainparts) > 1):
443 chainProperties[
'chainPartName'] = chainpartsNoL1
445 if len(multichainparts) > 1
and L1item.count(
"_") > 1 :
446 chainProperties[
'chainPartName'] = chainpartsNoL1
448 log.debug(
'[analyseChainname] Chainparts: %s', chainparts)
449 if (chainProperties[
'signature'] !=
'Cosmic') \
450 & (chainProperties[
'signature'] !=
'Calib')\
451 & (chainProperties[
'signature'] !=
'Streaming') \
452 & (chainProperties[
'signature'] !=
'Beamspot') \
453 & (chainProperties[
'signature'] !=
'Monitor') :
458 from TriggerMenuMT.HLT.Menu.SignatureDicts
import AllAllowedTopos_Bphysics
459 for t
in genchainDict[
'topo']:
460 if (t
in AllAllowedTopos_Bphysics):
461 chainProperties[
'signature'] =
'Bphysics'
462 if "tnpInfo" in chainProperties.keys()
and chainProperties[
'tnpInfo'] !=
"":
463 chainProperties[
'alignmentGroup'] = getAlignmentGroupFromPattern(
'Bphysics',chainProperties[
'tnpInfo'])
465 chainProperties[
'alignmentGroup'] = getAlignmentGroupFromPattern(
'Bphysics',chainProperties[
'extra'])
468 SignatureDefaultValues, allowedSignaturePropertiesAndValues =
getSignatureInformation(chainProperties[
'signature'])
469 log.debug(
'SignatureDefaultValues: %s', SignatureDefaultValues)
470 allDefaults =
list(SignatureDefaultValues.values())
471 log.debug(
'All default values in a list')
474 result = deepcopy(SignatureDefaultValues)
475 result.update(chainProperties)
476 chainProperties = result
479 overlaps = [x
for x
in parts
if x
in allDefaults]
480 log.debug(
"parts that are also in defaults: %s ", overlaps)
484 log.warning(
"[analyseChainName] The following chainpart %s contains the string(s) %s which is/are already defined as defaults, please remove!", chainparts, overlaps)
489 log.debug(
"[analyseChainname] parts to match are %s", parts)
490 for pindex, part
in enumerate(parts):
491 for prop, allowedValues
in allowedSignaturePropertiesAndValues.items():
492 if part
in allowedValues:
493 if type(chainProperties[prop])
is list:
494 chainProperties[prop] += [part]
496 chainProperties[prop] = part
497 matchedparts.append(part)
500 if chainProperties[
'signature']==
'Jet':
503 if chainProperties[
'bTag'] !=
'':
504 log.debug(
'Setting b-jet chain defaults')
507 for prop, value
in bJetDefaultValues.items():
509 for value
in allowedbJetPropertiesAndValues[prop]:
510 if value
in matchedparts:
516 log.debug(
'Changing %s from %s to %s', prop,
str(chainProperties[prop]),
str(bJetDefaultValues[prop]))
517 chainProperties[prop] = bJetDefaultValues[prop]
520 if chainProperties[
'signature'] ==
'Jet' and chainProperties[
'beamspotChain'] !=
'':
521 log.debug(
'Setting beamspot chain defaults')
524 for prop, value
in BeamspotDefaultValues.items():
526 for value
in allowedBeamspotPropertiesAndValues[prop]:
527 if value
in matchedparts:
533 log.debug(
'Changing %s from %s to %s', prop,
str(chainProperties[prop]),
str(BeamspotDefaultValues[prop]))
534 chainProperties[prop] = BeamspotDefaultValues[prop]
538 if chainProperties[
'extra']:
541 etarange = etaRangeAbbrev[chainProperties[
'extra']]
542 chainProperties[
'etaRange'] = etarange
544 raise RuntimeError(f
"Invalid jet 'extra' value {chainProperties['extra']} in {chainProperties['chainPartName']}. Only [a,c,f] allowed")
547 log.debug(
"matched parts %s", matchedparts)
548 leftoverparts =
set(parts)-
set(matchedparts)
549 log.debug(
'leftoverparts %s', leftoverparts)
550 for pindex, part
in enumerate(leftoverparts):
551 for prop, allowedValues
in allowedSignaturePropertiesAndValues.items():
552 if prop
in chainProperties.keys():
554 for aV
in allowedValues:
556 if (chainProperties[
'signature']
in [
'Egamma',
'Muon'] )& (prop
in [
'trkInfo',
'hypoInfo']):
557 chainProperties[prop] = part
558 part = part.replace(part,
'')
560 chainProperties[prop] = aV
561 part = part.replace(aV,
'')
564 assert len(part.split()) == 0,
"These parts of the chain name {} are not understood: {}".
format(chainpartsNoL1,part)
568 forbiddenProperties =
set(chainProperties.keys()) -
set(allowedSignaturePropertiesAndValues.keys())
569 log.debug(
'chainProperties: %s',
sorted(
set(chainProperties.keys())))
570 log.debug(
'allowedSignaturePropertiesAndValues: %s',
sorted(
set(allowedSignaturePropertiesAndValues.keys())))
571 for fb
in forbiddenProperties:
572 forbiddenValue = chainProperties.pop(fb)
573 assert forbiddenValue ==
'',
"Property {} not allowed for signature '{}', but specified '{}'".format (fb, chainProperties[
'signature'], forbiddenValue)
578 if any(x
in chainName
for x
in (
'larnoiseburst',
'idcalib',
'metcalo',
'mettrk')):
579 chainProperties[
'alignmentGroup'] =
'JetMET'
581 if 'tnpInfo' in chainProperties.keys()
and chainProperties[
'tnpInfo'] !=
"":
582 chainProperties[
'alignmentGroup'] = getAlignmentGroupFromPattern(mdicts[chainindex][
'signature'],chainProperties[
'tnpInfo'])
584 chainProperties[
'alignmentGroup'] = getAlignmentGroupFromPattern(mdicts[chainindex][
'signature'],chainProperties[
'extra'])
587 allChainProperties.append(chainProperties)
591 genchainDict[
'chainParts'] = allChainProperties
592 for cPart
in allChainProperties:
593 if cPart[
'signature'] ==
'Jet' and cPart[
'bTag'] !=
'':
594 cPart[
'signature'] =
'Bjet'
595 if 'tnpInfo' in cPart.keys()
and cPart[
'tnpInfo'] !=
"":
596 cPart[
'alignmentGroup'] = getAlignmentGroupFromPattern(
'Bjet', cPart[
'tnpInfo'])
598 cPart[
'alignmentGroup'] = getAlignmentGroupFromPattern(
'Bjet', cPart[
'extra'])
599 genchainDict[
'signatures'] += [cPart[
'signature']]
600 genchainDict[
'alignmentGroups'] += [cPart[
'alignmentGroup']]
604 if len(genchainDict[
'chainParts'])>1:
605 if 'Jet' in genchainDict[
'signatures']
or 'Bjet' in genchainDict[
'signatures']: