356 def __generateChainConfig(self, flags, mainChainDict):
358 # Assembles the chain configuration and returns a chain object with (name, L1see and list of ChainSteps)
361 from TriggerMenuMT.HLT.Config.Utility.ChainDictTools
import splitInterSignatureChainDict
362 from TriggerMenuMT.HLT.Config.Utility.ComboHypoHandling
import addTopoInfo, comboConfigurator, topoLegIndices
363 from TriggerMenuMT.HLT.Config.Utility.ChainMerging
import mergeChainDefs
364 from TriggerMenuMT.HLT.CommonSequences
import EventBuildingSequences, TLABuildingSequences
369 if log.isEnabledFor(logging.DEBUG):
371 pp = pprint.PrettyPrinter(indent=4, depth=8)
372 log.debug(
'dictionary is: %s', pp.pformat(chainDicts))
375 listOfChainConfigs = []
376 perSig_lengthOfChainConfigs = []
378 for chainPartDict
in chainDicts:
379 chainPartConfig =
None
380 currentSig = chainPartDict[
'signature']
381 currentAlignGroup =
None
382 if len(chainPartDict[
'chainParts']) == 1:
383 currentAlignGroup = chainPartDict[
'chainParts'][0][
'alignmentGroup']
385 chainName = chainPartDict[
'chainName']
386 log.debug(
'Checking chainDict for chain %s in signature %s, alignment group %s' , chainName, currentSig, currentAlignGroup)
388 if currentSig
in self.availableSignatures:
390 log.debug(
"[__generateChainConfigs] Trying to get chain config for %s", currentSig)
391 if currentSig
in [
'Electron',
'Photon',
'Muon',
'Tau',
'Bphysics'] :
392 chainPartConfig, perSig_lengthOfChainConfigs = self.chainDefModule[currentSig].
generateChainConfigs(flags, chainPartDict, perSig_lengthOfChainConfigs)
395 if currentSig ==
'Test' and isinstance(chainPartConfig, tuple):
396 chainPartConfig = chainPartConfig[0]
398 log.error(
'[__generateChainConfigs] Problems creating ChainDef for chain %s ', chainName)
399 log.error(
'[__generateChainConfigs] I am in chain part\n %s ', chainPartDict)
400 log.exception(
'[__generateChainConfigs] Full chain dictionary is\n %s ', mainChainDict)
401 raise Exception(
'[__generateChainConfigs] Stopping menu generation. Please investigate the exception shown above.')
403 log.error(
'Chain %s cannot be generated - Signature "%s" not available', chainPartDict[
'chainName'], currentSig)
404 log.error(
'Available signature(s): %s', self.availableSignatures)
405 raise Exception(
'Stopping the execution. Please correct the configuration.')
407 log.debug(
"Chain %s \n chain config: %s",chainPartDict[
'chainName'],chainPartConfig)
409 listOfChainConfigs.append(chainPartConfig)
410 log.debug(
"[__generateChainConfigs] adding to the perSig_lengthOfChainConfigs list (%s, %s)",chainPartConfig.nSteps,chainPartConfig.alignmentGroups)
411 perSig_lengthOfChainConfigs.append((chainPartConfig.nSteps,chainPartConfig.alignmentGroups))
416 lengthOfChainConfigs = []
417 for nSteps, aGrps
in perSig_lengthOfChainConfigs:
418 if len(nSteps) != len(aGrps):
419 log.error(
"Chain part has %s steps and %s alignment groups - these don't match!",nSteps,aGrps)
421 for a,b
in zip(nSteps,aGrps):
422 lengthOfChainConfigs.append((a,b))
427 if len(listOfChainConfigs) == 0:
428 raise Exception(
'[__generateChainConfigs] No Chain Configuration found for {0}'.
format(mainChainDict[
'chainName']))
430 if len(listOfChainConfigs)>1:
431 log.debug(
"Merging strategy from dictionary: %s", mainChainDict[
"mergingStrategy"])
432 theChainConfig, perSig_lengthOfChainConfigs =
mergeChainDefs(listOfChainConfigs, mainChainDict, perSig_lengthOfChainConfigs)
433 lengthOfChainConfigs = []
434 for nSteps, aGrps
in perSig_lengthOfChainConfigs:
435 if len(nSteps) != len(aGrps):
436 log.error(
"Post-merged chain part has %s steps and %s alignment groups - these don't match!",nSteps,aGrps)
438 for a,b
in zip(nSteps,aGrps):
439 lengthOfChainConfigs.append((a,b))
441 theChainConfig = listOfChainConfigs[0]
443 for topoID
in range(len(mainChainDict[
'extraComboHypos'])):
444 thetopo = mainChainDict[
'extraComboHypos'][topoID].strip(string.digits).rstrip(topoLegIndices)
445 theChainConfig.addTopo((comboConfigurator[thetopo],thetopo))
448 if len(theChainConfig.topoMap) > 0:
449 log.debug(
"Trying to add extra ComboHypoTool for %s",mainChainDict[
'extraComboHypos'])
450 addTopoInfo(theChainConfig,mainChainDict,listOfChainConfigs,lengthOfChainConfigs)
452 log.error(
'[__generateChainConfigs] Problems creating ChainDef for chain %s ', chainName)
453 log.error(
'[__generateChainConfigs] I am in the extraComboHypos section, for %s ', mainChainDict[
'extraComboHypos'])
454 log.exception(
'[__generateChainConfigs] Full chain dictionary is\n %s ', mainChainDict)
455 raise Exception(
'[__generateChainConfigs] Stopping menu generation. Please investigate the exception shown above.')
456 except AttributeError:
457 raise Exception(
'[__generateChainConfigs] Stopping menu generation. Please investigate the exception shown above.')
460 eventBuildType = mainChainDict[
'eventBuildType']
463 if 'PhysicsTLA' in eventBuildType:
464 log.debug(
"Adding TLA Step for chain %s", mainChainDict[
'chainName'])
465 TLABuildingSequences.addTLAStep(flags, theChainConfig, mainChainDict)
466 log.debug(
'Configuring event building sequence %s for chain %s', eventBuildType, mainChainDict[
'chainName'])
467 EventBuildingSequences.addEventBuildingSequence(flags, theChainConfig, eventBuildType, mainChainDict)
468 except TypeError
as ex:
470 raise Exception(
'[__generateChainConfigs] Stopping menu generation for EventBuilding/TLA sequences. Please investigate the exception shown above.')
472 log.debug(
'[__generateChainConfigs] lengthOfChainConfigs %s, ChainConfigs %s ', lengthOfChainConfigs, theChainConfig)
473 return theChainConfig,lengthOfChainConfigs