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