374 def __generateChainConfig(self, flags, mainChainDict):
376 # Assembles the chain configuration and returns a chain object with (name, L1see and list of ChainSteps)
379 from TriggerMenuMT.HLT.Config.Utility.ChainDictTools
import splitInterSignatureChainDict
380 from TriggerMenuMT.HLT.Config.Utility.ComboHypoHandling
import addTopoInfo, comboConfigurator, topoLegIndices, anomdetWPIndices
381 from TriggerMenuMT.HLT.Config.Utility.ChainMerging
import mergeChainDefs
382 from TriggerMenuMT.HLT.CommonSequences
import EventBuildingSequences, TLABuildingSequences
387 if log.isEnabledFor(logging.DEBUG):
389 pp = pprint.PrettyPrinter(indent=4, depth=8)
390 log.debug(
'dictionary is: %s', pp.pformat(chainDicts))
393 listOfChainConfigs = []
394 perSig_lengthOfChainConfigs = []
396 for chainPartDict
in chainDicts:
397 chainPartConfig =
None
398 currentSig = chainPartDict[
'signature']
399 currentAlignGroup =
None
400 if len(chainPartDict[
'chainParts']) == 1:
401 currentAlignGroup = chainPartDict[
'chainParts'][0][
'alignmentGroup']
403 chainName = chainPartDict[
'chainName']
404 log.debug(
'Checking chainDict for chain %s in signature %s, alignment group %s' , chainName, currentSig, currentAlignGroup)
406 if currentSig
in self.availableSignatures:
408 log.debug(
"[__generateChainConfigs] Trying to get chain config for %s", currentSig)
409 if currentSig
in self.defaultFlagsForSignature:
410 sigFlags = self.defaultFlagsForSignature[currentSig]
414 except AttributeError:
415 log.debug(
"prepareDefaultSignatureFlags not present")
417 except Exception
as e:
418 log.error(f
"Unexpected error invoking prepareDefaultSignatureFlags {e}")
421 self.defaultFlagsForSignature[currentSig] = sigFlags
423 if currentSig
in [
'Electron',
'Photon',
'Muon',
'Tau',
'Bphysics'] :
424 chainPartConfig, perSig_lengthOfChainConfigs = self.chainDefModule[currentSig].
generateChainConfigs(sigFlags, chainPartDict, perSig_lengthOfChainConfigs)
427 if currentSig ==
'Test' and isinstance(chainPartConfig, tuple):
428 chainPartConfig = chainPartConfig[0]
430 log.error(
'[__generateChainConfigs] Problems creating ChainDef for chain %s ', chainName)
431 log.error(
'[__generateChainConfigs] I am in chain part\n %s ', chainPartDict)
432 log.exception(
'[__generateChainConfigs] Full chain dictionary is\n %s ', mainChainDict)
433 raise Exception(
'[__generateChainConfigs] Stopping menu generation. Please investigate the exception shown above.')
435 log.error(
'Chain %s cannot be generated - Signature "%s" not available', chainPartDict[
'chainName'], currentSig)
436 log.error(
'Available signature(s): %s', self.availableSignatures)
437 raise Exception(
'Stopping the execution. Please correct the configuration.')
439 log.debug(
"Chain %s \n chain config: %s",chainPartDict[
'chainName'],chainPartConfig)
441 listOfChainConfigs.append(chainPartConfig)
442 log.debug(
"[__generateChainConfigs] adding to the perSig_lengthOfChainConfigs list (%s, %s)",chainPartConfig.nSteps,chainPartConfig.alignmentGroups)
443 perSig_lengthOfChainConfigs.append((chainPartConfig.nSteps,chainPartConfig.alignmentGroups))
448 lengthOfChainConfigs = []
449 for nSteps, aGrps
in perSig_lengthOfChainConfigs:
450 if len(nSteps) != len(aGrps):
451 log.error(
"Chain part has %s steps and %s alignment groups - these don't match!",nSteps,aGrps)
453 for a,b
in zip(nSteps,aGrps):
454 lengthOfChainConfigs.append((a,b))
459 if len(listOfChainConfigs) == 0:
460 raise Exception(
'[__generateChainConfigs] No Chain Configuration found for {0}'.
format(mainChainDict[
'chainName']))
462 if len(listOfChainConfigs)>1:
463 log.debug(
"Merging strategy from dictionary: %s", mainChainDict[
"mergingStrategy"])
464 theChainConfig, perSig_lengthOfChainConfigs =
mergeChainDefs(listOfChainConfigs, mainChainDict, perSig_lengthOfChainConfigs)
465 lengthOfChainConfigs = []
466 for nSteps, aGrps
in perSig_lengthOfChainConfigs:
467 if len(nSteps) != len(aGrps):
468 log.error(
"Post-merged chain part has %s steps and %s alignment groups - these don't match!",nSteps,aGrps)
470 for a,b
in zip(nSteps,aGrps):
471 lengthOfChainConfigs.append((a,b))
473 theChainConfig = listOfChainConfigs[0]
475 for topoID
in range(len(mainChainDict[
'extraComboHypos'])):
476 thetopo = mainChainDict[
'extraComboHypos'][topoID].strip(string.digits).rstrip(topoLegIndices)
479 if "anomdet" in thetopo:
480 thetopo = thetopo.rstrip(anomdetWPIndices)
482 theChainConfig.addTopo((comboConfigurator[thetopo],thetopo))
485 if len(theChainConfig.topoMap) > 0:
486 log.debug(
"Trying to add extra ComboHypoTool for %s",mainChainDict[
'extraComboHypos'])
487 addTopoInfo(theChainConfig,mainChainDict,listOfChainConfigs,lengthOfChainConfigs)
489 log.error(
'[__generateChainConfigs] Problems creating ChainDef for chain %s ', chainName)
490 log.error(
'[__generateChainConfigs] I am in the extraComboHypos section, for %s ', mainChainDict[
'extraComboHypos'])
491 log.exception(
'[__generateChainConfigs] Full chain dictionary is\n %s ', mainChainDict)
492 raise Exception(
'[__generateChainConfigs] Stopping menu generation. Please investigate the exception shown above.')
493 except AttributeError:
494 raise Exception(
'[__generateChainConfigs] Stopping menu generation. Please investigate the exception shown above.')
497 eventBuildType = mainChainDict[
'eventBuildType']
498 TLAEventBuildTypes = (
'PhysicsTLA',
'FTagPEBTLA',
'EgammaPEBTLA',
'DarkJetPEBTLA')
501 if any(ebtype
in eventBuildType
for ebtype
in TLAEventBuildTypes):
502 log.debug(
"Adding TLA Step for chain %s", mainChainDict[
'chainName'])
503 TLABuildingSequences.addTLAStep(flags, theChainConfig, mainChainDict)
504 log.debug(
'Configuring event building sequence %s for chain %s', eventBuildType, mainChainDict[
'chainName'])
505 EventBuildingSequences.addEventBuildingSequence(flags, theChainConfig, eventBuildType, mainChainDict)
506 except TypeError
as ex:
508 raise Exception(
'[__generateChainConfigs] Stopping menu generation for EventBuilding/TLA sequences. Please investigate the exception shown above.')
510 log.debug(
'[__generateChainConfigs] lengthOfChainConfigs %s, ChainConfigs %s ', lengthOfChainConfigs, theChainConfig)
511 return theChainConfig,lengthOfChainConfigs