371 def __generateChainConfig(self, flags, mainChainDict):
373 # Assembles the chain configuration and returns a chain object with (name, L1see and list of ChainSteps)
376 from TriggerMenuMT.HLT.Config.Utility.ChainDictTools
import splitInterSignatureChainDict
377 from TriggerMenuMT.HLT.Config.Utility.ComboHypoHandling
import addTopoInfo, comboConfigurator, topoLegIndices, anomdetWPIndices
378 from TriggerMenuMT.HLT.Config.Utility.ChainMerging
import mergeChainDefs
379 from TriggerMenuMT.HLT.CommonSequences
import EventBuildingSequences, TLABuildingSequences
384 if log.isEnabledFor(logging.DEBUG):
386 pp = pprint.PrettyPrinter(indent=4, depth=8)
387 log.debug(
'dictionary is: %s', pp.pformat(chainDicts))
390 listOfChainConfigs = []
391 perSig_lengthOfChainConfigs = []
393 for chainPartDict
in chainDicts:
394 chainPartConfig =
None
395 currentSig = chainPartDict[
'signature']
396 currentAlignGroup =
None
397 if len(chainPartDict[
'chainParts']) == 1:
398 currentAlignGroup = chainPartDict[
'chainParts'][0][
'alignmentGroup']
400 chainName = chainPartDict[
'chainName']
401 log.debug(
'Checking chainDict for chain %s in signature %s, alignment group %s' , chainName, currentSig, currentAlignGroup)
403 if currentSig
in self.availableSignatures:
405 log.debug(
"[__generateChainConfigs] Trying to get chain config for %s", currentSig)
406 if currentSig
in [
'Electron',
'Photon',
'Muon',
'Tau',
'Bphysics'] :
407 chainPartConfig, perSig_lengthOfChainConfigs = self.chainDefModule[currentSig].
generateChainConfigs(flags, chainPartDict, perSig_lengthOfChainConfigs)
410 if currentSig ==
'Test' and isinstance(chainPartConfig, tuple):
411 chainPartConfig = chainPartConfig[0]
413 log.error(
'[__generateChainConfigs] Problems creating ChainDef for chain %s ', chainName)
414 log.error(
'[__generateChainConfigs] I am in chain part\n %s ', chainPartDict)
415 log.exception(
'[__generateChainConfigs] Full chain dictionary is\n %s ', mainChainDict)
416 raise Exception(
'[__generateChainConfigs] Stopping menu generation. Please investigate the exception shown above.')
418 log.error(
'Chain %s cannot be generated - Signature "%s" not available', chainPartDict[
'chainName'], currentSig)
419 log.error(
'Available signature(s): %s', self.availableSignatures)
420 raise Exception(
'Stopping the execution. Please correct the configuration.')
422 log.debug(
"Chain %s \n chain config: %s",chainPartDict[
'chainName'],chainPartConfig)
424 listOfChainConfigs.append(chainPartConfig)
425 log.debug(
"[__generateChainConfigs] adding to the perSig_lengthOfChainConfigs list (%s, %s)",chainPartConfig.nSteps,chainPartConfig.alignmentGroups)
426 perSig_lengthOfChainConfigs.append((chainPartConfig.nSteps,chainPartConfig.alignmentGroups))
431 lengthOfChainConfigs = []
432 for nSteps, aGrps
in perSig_lengthOfChainConfigs:
433 if len(nSteps) != len(aGrps):
434 log.error(
"Chain part has %s steps and %s alignment groups - these don't match!",nSteps,aGrps)
436 for a,b
in zip(nSteps,aGrps):
437 lengthOfChainConfigs.append((a,b))
442 if len(listOfChainConfigs) == 0:
443 raise Exception(
'[__generateChainConfigs] No Chain Configuration found for {0}'.
format(mainChainDict[
'chainName']))
445 if len(listOfChainConfigs)>1:
446 log.debug(
"Merging strategy from dictionary: %s", mainChainDict[
"mergingStrategy"])
447 theChainConfig, perSig_lengthOfChainConfigs =
mergeChainDefs(listOfChainConfigs, mainChainDict, perSig_lengthOfChainConfigs)
448 lengthOfChainConfigs = []
449 for nSteps, aGrps
in perSig_lengthOfChainConfigs:
450 if len(nSteps) != len(aGrps):
451 log.error(
"Post-merged 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))
456 theChainConfig = listOfChainConfigs[0]
458 for topoID
in range(len(mainChainDict[
'extraComboHypos'])):
459 thetopo = mainChainDict[
'extraComboHypos'][topoID].strip(string.digits).rstrip(topoLegIndices)
462 if "anomdet" in thetopo:
463 thetopo = thetopo.rstrip(anomdetWPIndices)
465 theChainConfig.addTopo((comboConfigurator[thetopo],thetopo))
468 if len(theChainConfig.topoMap) > 0:
469 log.debug(
"Trying to add extra ComboHypoTool for %s",mainChainDict[
'extraComboHypos'])
470 addTopoInfo(theChainConfig,mainChainDict,listOfChainConfigs,lengthOfChainConfigs)
472 log.error(
'[__generateChainConfigs] Problems creating ChainDef for chain %s ', chainName)
473 log.error(
'[__generateChainConfigs] I am in the extraComboHypos section, for %s ', mainChainDict[
'extraComboHypos'])
474 log.exception(
'[__generateChainConfigs] Full chain dictionary is\n %s ', mainChainDict)
475 raise Exception(
'[__generateChainConfigs] Stopping menu generation. Please investigate the exception shown above.')
476 except AttributeError:
477 raise Exception(
'[__generateChainConfigs] Stopping menu generation. Please investigate the exception shown above.')
480 eventBuildType = mainChainDict[
'eventBuildType']
483 if 'PhysicsTLA' in eventBuildType:
484 log.debug(
"Adding TLA Step for chain %s", mainChainDict[
'chainName'])
485 TLABuildingSequences.addTLAStep(flags, theChainConfig, mainChainDict)
486 log.debug(
'Configuring event building sequence %s for chain %s', eventBuildType, mainChainDict[
'chainName'])
487 EventBuildingSequences.addEventBuildingSequence(flags, theChainConfig, eventBuildType, mainChainDict)
488 except TypeError
as ex:
490 raise Exception(
'[__generateChainConfigs] Stopping menu generation for EventBuilding/TLA sequences. Please investigate the exception shown above.')
492 log.debug(
'[__generateChainConfigs] lengthOfChainConfigs %s, ChainConfigs %s ', lengthOfChainConfigs, theChainConfig)
493 return theChainConfig,lengthOfChainConfigs