409 def __generateChainConfig(self, flags, mainChainDict):
410 """
411 # Assembles the chain configuration and returns a chain object with (name, L1see and list of ChainSteps)
412 """
413
414 from TriggerMenuMT.HLT.Config.Utility.ChainDictTools import splitInterSignatureChainDict
415 from TriggerMenuMT.HLT.Config.Utility.ComboHypoHandling import addTopoInfo, comboConfigurator, topoLegIndices, anomdetWPIndices, topo3VarLegIndices
416 from TriggerMenuMT.HLT.Config.Utility.ChainMerging import mergeChainDefs
417 from TriggerMenuMT.HLT.CommonSequences import EventBuildingSequences, TLABuildingSequences
418
419
420 chainDicts = splitInterSignatureChainDict(mainChainDict)
421
422 if log.isEnabledFor(logging.DEBUG):
423 import pprint
424 pp = pprint.PrettyPrinter(indent=4, depth=8)
425 log.debug('dictionary is: %s', pp.pformat(chainDicts))
426
427
428 listOfChainConfigs = []
429 perSig_lengthOfChainConfigs = []
430
431 for chainPartDict in chainDicts:
432 chainPartConfig = None
433 currentSig = chainPartDict['signature']
434 currentAlignGroup = None
435 if len(chainPartDict['chainParts']) == 1:
436 currentAlignGroup = chainPartDict['chainParts'][0]['alignmentGroup']
437
438 chainName = chainPartDict['chainName']
439 log.debug('Checking chainDict for chain %s in signature %s, alignment group %s' , chainName, currentSig, currentAlignGroup)
440
441 if currentSig in self.availableSignatures:
442 try:
443 log.debug("[__generateChainConfigs] Trying to get chain config for %s", currentSig)
444 if currentSig in self.defaultFlagsForSignature:
445 sigFlags = self.defaultFlagsForSignature[currentSig]
446 else:
447 try:
448 sigFlags = self.chainDefModule[currentSig].prepareDefaultSignatureFlags(flags)
449 except AttributeError:
450 log.debug("prepareDefaultSignatureFlags not present")
451 sigFlags = flags
452 except Exception as e:
453 log.error(f"Unexpected error invoking prepareDefaultSignatureFlags {e}")
454 sigFlags = flags
455
456 self.defaultFlagsForSignature[currentSig] = sigFlags
457
458 if currentSig in ['Electron', 'Photon', 'Muon', 'Tau', 'Bphysics'] :
459 chainPartConfig, perSig_lengthOfChainConfigs = self.chainDefModule[currentSig].generateChainConfigs(sigFlags, chainPartDict, perSig_lengthOfChainConfigs)
460 else:
461 chainPartConfig = self.chainDefModule[currentSig].generateChainConfigs(sigFlags, chainPartDict)
462 if currentSig == 'Test' and isinstance(chainPartConfig, tuple):
463 chainPartConfig = chainPartConfig[0]
464 except Exception:
465 log.error('[__generateChainConfigs] Problems creating ChainDef for chain %s ', chainName)
466 log.error('[__generateChainConfigs] I am in chain part\n %s ', chainPartDict)
467 log.exception('[__generateChainConfigs] Full chain dictionary is\n %s ', mainChainDict)
468 raise Exception('[__generateChainConfigs] Stopping menu generation. Please investigate the exception shown above.')
469 else:
470 log.error('Chain %s cannot be generated - Signature "%s" not available', chainPartDict['chainName'], currentSig)
471 log.error('Available signature(s): %s', self.availableSignatures)
472 raise Exception('Stopping the execution. Please correct the configuration.')
473
474 log.debug("Chain %s \n chain config: %s",chainPartDict['chainName'],chainPartConfig)
475
476 listOfChainConfigs.append(chainPartConfig)
477 log.debug("[__generateChainConfigs] adding to the perSig_lengthOfChainConfigs list (%s, %s)",chainPartConfig.nSteps,chainPartConfig.alignmentGroups)
478 perSig_lengthOfChainConfigs.append((chainPartConfig.nSteps,chainPartConfig.alignmentGroups))
479
480
481
482
483 lengthOfChainConfigs = []
484 for nSteps, aGrps in perSig_lengthOfChainConfigs:
485 if len(nSteps) != len(aGrps):
486 log.error("Chain part has %s steps and %s alignment groups - these don't match!",nSteps,aGrps)
487 else:
488 for a,b in zip(nSteps,aGrps):
489 lengthOfChainConfigs.append((a,b))
490
491
492
493 try:
494 if len(listOfChainConfigs) == 0:
495 raise Exception('[__generateChainConfigs] No Chain Configuration found for {0}'.format(mainChainDict['chainName']))
496 else:
497 if len(listOfChainConfigs)>1:
498 log.debug("Merging strategy from dictionary: %s", mainChainDict["mergingStrategy"])
499 theChainConfig, perSig_lengthOfChainConfigs = mergeChainDefs(listOfChainConfigs, mainChainDict, perSig_lengthOfChainConfigs)
500 lengthOfChainConfigs = []
501 for nSteps, aGrps in perSig_lengthOfChainConfigs:
502 if len(nSteps) != len(aGrps):
503 log.error("Post-merged chain part has %s steps and %s alignment groups - these don't match!",nSteps,aGrps)
504 else:
505 for a,b in zip(nSteps,aGrps):
506 lengthOfChainConfigs.append((a,b))
507 else:
508 theChainConfig = listOfChainConfigs[0]
509
510 for topoID in range(len(mainChainDict['extraComboHypos'])):
511 thetopo = mainChainDict[
'extraComboHypos'][topoID].
strip(string.digits).rstrip(topoLegIndices)
512
513
514 if "anomdet" in thetopo:
515 thetopo = thetopo.rstrip(anomdetWPIndices)
516
517 if "masswiso" in thetopo:
518 thetopo = thetopo.rstrip(topo3VarLegIndices)
519
520 theChainConfig.addTopo((comboConfigurator[thetopo],thetopo))
521
522
523 if len(theChainConfig.topoMap) > 0:
524 log.debug("Trying to add extra ComboHypoTool for %s",mainChainDict['extraComboHypos'])
525 addTopoInfo(theChainConfig,mainChainDict,listOfChainConfigs,lengthOfChainConfigs)
526 except RuntimeError:
527 log.error('[__generateChainConfigs] Problems creating ChainDef for chain %s ', chainName)
528 log.error('[__generateChainConfigs] I am in the extraComboHypos section, for %s ', mainChainDict['extraComboHypos'])
529 log.exception('[__generateChainConfigs] Full chain dictionary is\n %s ', mainChainDict)
530 raise Exception('[__generateChainConfigs] Stopping menu generation. Please investigate the exception shown above.')
531 except AttributeError:
532 raise Exception('[__generateChainConfigs] Stopping menu generation. Please investigate the exception shown above.')
533
534
535 eventBuildType = mainChainDict['eventBuildType']
536 TLAEventBuildTypes = ('PhysicsTLA', 'FTagPEBTLA', 'EgammaPEBTLA', 'DarkJetPEBTLA')
537 if eventBuildType:
538 try:
539 if any(ebtype in eventBuildType for ebtype in TLAEventBuildTypes):
540 log.debug("Adding TLA Step for chain %s", mainChainDict['chainName'])
541 TLABuildingSequences.addTLAStep(flags, theChainConfig, mainChainDict)
542 log.debug('Configuring event building sequence %s for chain %s', eventBuildType, mainChainDict['chainName'])
543 EventBuildingSequences.addEventBuildingSequence(flags, theChainConfig, eventBuildType, mainChainDict)
544 except TypeError as ex:
545 log.error(ex)
546 raise Exception('[__generateChainConfigs] Stopping menu generation for EventBuilding/TLA sequences. Please investigate the exception shown above.')
547
548 log.debug('[__generateChainConfigs] lengthOfChainConfigs %s, ChainConfigs %s ', lengthOfChainConfigs, theChainConfig)
549 return theChainConfig,lengthOfChainConfigs
550
551