From c08d8fff65eb00ff6e3369ccc8bff97001df82bd Mon Sep 17 00:00:00 2001
From: Francesca Pastore <francesca.pastore@cern.ch>
Date: Wed, 25 Mar 2020 15:19:24 +0100
Subject: [PATCH] fix  definition of ComboHypoTools in both sym and asym case

---
 .../TriggerJobOpts/python/TriggerConfig.py    |  2 +
 .../Menu/ChainConfigurationBase.py            |  4 +-
 .../python/HLTMenuConfig/Menu/LS2_v1.py       |  2 +-
 .../HLTMenuConfig/Menu/MenuComponents.py      | 43 ++++++-------------
 .../python/HLTMenuConfig/Muon/MuonDef.py      | 10 ++---
 5 files changed, 23 insertions(+), 38 deletions(-)

diff --git a/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfig.py b/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfig.py
index cd241f6d90b..793ca70c42a 100644
--- a/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfig.py
+++ b/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfig.py
@@ -35,6 +35,8 @@ def collectHypos( steps ):
                 # will replace by function once dependencies are sorted
                 if 'HypoInputDecisions'  in alg.getProperties():
                     __log.info( "found hypo " + alg.name() + " in " +stepSeq.name() )
+                    if alg.getType() == 'ComboHypo':
+                        __log.info( "    with %d comboHypoTools: %s", len(alg.ComboHypoTools), ' '.join(map(str, [tool.name() for  tool in alg.ComboHypoTools])))
                     hypos[stepSeq.name()].append( alg )
                 else:
                     __log.verbose("Not a hypo" + alg.name())
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/ChainConfigurationBase.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/ChainConfigurationBase.py
index 68a1c24e67c..7094f7ef2ad 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/ChainConfigurationBase.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/ChainConfigurationBase.py
@@ -50,10 +50,12 @@ class ChainConfigurationBase(object):
         for sequenceCfg in sequenceCfgArray:
             seqArray.append( RecoFragmentsPool.retrieve( sequenceCfg, None))
         return ChainStep(stepName, seqArray, [self.mult], [self.dict], comboToolConfs=comboTools)
-
+    
     def buildChain(self, chainSteps):
         myChain = Chain(name = self.chainName,
                         ChainSteps = chainSteps,
                         L1Thresholds = [self.L1Threshold] )
 
         return myChain
+
+
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py
index ff6c380904e..1ecc8244cf4 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py
@@ -53,7 +53,7 @@ def setupMenu():
 
         # this is for test only
         ChainProp(name='HLT_2mu6_Dr_L12MU4',  groups=MultiMuonGroup),
-       # ChainProp(name='HLT_mu6_Dr_mu4_Dr_L12MU4', l1SeedThresholds=['MU4']*2, groups=MultiMuonGroup),
+      #  ChainProp(name='HLT_mu6_Dr_mu4_Dr_L12MU4', l1SeedThresholds=['MU4']*2, groups=MultiMuonGroup),
         # ATR-20049
         ChainProp(name='HLT_mu6_mu4_L12MU4',  l1SeedThresholds=['MU4']*2, groups=MultiMuonGroup),
 
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py
index 3840d458e8e..00185f16fa7 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py
@@ -3,6 +3,7 @@
 
 from AthenaCommon.Logging import logging
 log = logging.getLogger( __name__ )
+#log.setLevel(logging.DEBUG)
 
 from DecisionHandling.DecisionHandlingConf import RoRSeqFilter
 from TriggerMenuMT.HLTMenuConfig.Menu.MenuComponentsNaming import CFNaming
@@ -248,7 +249,6 @@ class ComboMaker(AlgNode):
         AlgNode.__init__(self,  Alg, 'HypoInputDecisions', 'HypoOutputDecisions')
         self.prop="MultiplicitiesMap"
         self.mult=list(multiplicity)
-        self._hypoToolConf = []
 
     def create (self, name):
         log.debug("ComboMaker.create %s",name)
@@ -270,24 +270,20 @@ class ComboMaker(AlgNode):
             cval=newdict
 
         setattr(self.Alg, self.prop, cval)
-        log.debug("ComboAlg %s has now these chains chain %s", self.Alg.name(), self.getPar(self.prop))
 
 
     def getChains(self):
         cval = self.Alg.getProperties()[self.prop]
         return cval
 
-    def addComboHypoToolConfs(self, comboToolConfs):
-        self._hypoToolConf = [ HypoToolConf( tool ) for tool in comboToolConfs ]
-        for conf in self._hypoToolConf:
-            log.debug("ComboMaker.addComboHypoToolConfs %s %s", self.Alg.name(), conf.name)
 
-    def createComboHypoTools(self, chainDict):
-        """Ccreated the ComboHypoTools"""
-        if not len(self._hypoToolConf):
+    def createComboHypoTools(self, chainDict, comboToolConfs):
+        """Created the ComboHypoTools"""
+        if not len(comboToolConfs):
             return
-        log.debug("ComboMaker.createComboHypoTools for %s with %d tools", self.Alg.name(), len(self._hypoToolConf))        
-        self.Alg.ComboHypoTools = [conf.confAndCreate( chainDict ) for conf in self._hypoToolConf]
+        confs = [ HypoToolConf( tool ) for tool in comboToolConfs ]
+        log.debug("ComboMaker.createComboHypoTools for chain %s, Alg %s with %d tools", chainDict["chainName"],self.Alg.name(), len(comboToolConfs))        
+        self.Alg.ComboHypoTools = [conf.confAndCreate( chainDict ) for conf in confs]
         
 
 
@@ -387,7 +383,6 @@ class MenuSequence(object):
     def maker(self):
         return self._maker
 
-
     @property
     def hypo(self):
         return self._hypo
@@ -396,12 +391,10 @@ class MenuSequence(object):
     def getOutputList(self):
         outputlist = []
         if type(self._hypo) is list:
-
             for hypo in self._hypo:
                 outputlist.append(hypo.readOutputList()[0])
         else:
             outputlist.append(self._hypo.readOutputList()[0])
-
         return outputlist
 
 
@@ -564,10 +557,6 @@ class CAMenuSequence(MenuSequence):
         return self._hypo
 
 
-#################################################
-
-#from TriggerMenuMT.HLTMenuConfig.Menu.DictFromChainName import getAllThresholdsFromItem, getUniqueThresholdsFromItem
-
 
 class Chain(object):
     """Basic class to define the trigger menu """
@@ -637,23 +626,25 @@ class Chain(object):
 
     def createHypoTools(self):
         """ This is extrapolating the hypotool configuration from the chain name"""
-        log.debug("decodeHypoToolConfs for chain %s", self.name)
+        log.debug("createHypoTools for chain %s", self.name)
         from TriggerMenuMT.HLTMenuConfig.Menu.ChainDictTools import splitChainInDict
 
         # this spliting is only needed for chains which don't yet attach
         # the dictionaries to the chain steps. It should be removed
         # later once that migration is done.
         listOfChainDictsLegs = splitChainInDict(self.name)
-        
         for step in self.steps:
+            log.debug("createHypoTools for Step %s", step.name)
             if len(step.sequences) == 0:
                 continue
 
             step_mult = [str(m) for m in step.multiplicity]
+            if step_mult >1 and not step.isCombo:
+                log.error("Step mult > 1 (%d), but step is not combo", step_mult)
 
             if len(step.chainDicts) > 0:
                 # new way to configure hypo tools, works if the chain dictionaries have been attached to the steps
-                log.info('%s in new hypo tool creation method', self.name)
+                log.info('%s in new hypo tool creation method, step mult= %d, isCombo=%d', self.name, step_mult, step.isCombo)
                 for seq, onePartChainDict in zip(step.sequences, step.chainDicts):
                     log.info('    onePartChainDict:')
                     log.info('    ' + str(onePartChainDict))
@@ -663,7 +654,6 @@ class Chain(object):
                 # legacy way, to be removed once all signatures pass the chainDicts to the steps
                 log.info('%s in old hypo tool creation method', self.name)
                 menu_mult = [ part['chainParts'][0]['multiplicity'] for part in listOfChainDictsLegs ]
-                #print 'step, step_mult, menu_mult: ' + step.name + ' ' + str(step_mult) + ' ' + str(menu_mult)
                 if step_mult != menu_mult:
                     # Probably this shouldn't happen, but it currently does
                     log.warning("Got multiplicty %s from chain parts, but have %s legs. This is expected only for jet chains, but it has happened for %s, using the first chain dict", menu_mult, step_mult, self.name)
@@ -671,13 +661,11 @@ class Chain(object):
                     firstChainDict['chainName']= self.name # rename the chaindict to remove the leg name
                     for seq in step.sequences:
                         seq.createHypoTools( firstChainDict )
-
                 else:
                     # add one hypotool per sequence and chain part
                     for seq, onePartChainDict in zip(step.sequences, listOfChainDictsLegs):
                         seq.createHypoTools( onePartChainDict )
 
-           
             step.createComboHypoTools(self.name) 
 
 
@@ -742,7 +730,6 @@ class CFSequence(object):
           log.debug("This CFSequence has no sequences: outputs are the Filter outputs")
 
 
-
     def connectCombo(self):
         """ connect Combo to Hypos"""
         for seq in self.step.sequences:
@@ -758,7 +745,6 @@ class CFSequence(object):
             log.debug("CFSequence.connectCombo: adding output to  %s: %s",  self.step.combo.Alg.name(), combo_output)
 
 
-
     def __repr__(self):
         return "--- CFSequence ---\n + Filter: %s \n + decisions: %s\n +  %s \n"%(\
                     self.filter.Alg.name(), self.decisions, self.step)
@@ -800,19 +786,18 @@ class ChainStep(object):
             return
         hashableMult = tuple(self.multiplicity)
         self.combo =  RecoFragmentsPool.retrieve(createComboAlg, None, name=CFNaming.comboHypoName(self.name), multiplicity=hashableMult)
-        self.combo.addComboHypoToolConfs(self.comboToolConfs)
 
     def createComboHypoTools(self, chainName):
         if self.isCombo:
             from TriggerMenuMT.HLTMenuConfig.Menu.TriggerConfigHLT import TriggerConfigHLT
             chainDict = TriggerConfigHLT.getChainDictFromChainName(chainName)
-            self.combo.createComboHypoTools(chainDict)
+            self.combo.createComboHypoTools(chainDict, self.comboToolConfs)
         
         
 
 
     def __repr__(self):
-        return "--- ChainStep %s ---\n + isCombo = %d, multiplicity = %d \n + MenuSequences = %s  \n + ComboHypoTools = %s"%(self.name, self.isCombo,sum(self.multiplicity), ' '.join(map(str, [seq.name for seq in self.sequences]) ),  ' '.join(map(str, [tool for tool in self.comboToolConfs]) ))
+        return "--- ChainStep %s ---\n + isCombo = %d, multiplicity = %d  ChainDict = %s \n + MenuSequences = %s  \n + ComboHypoTools = %s"%(self.name, self.isCombo,  sum(self.multiplicity), ' '.join(map(str, [dic['chainName'] for dic in self.chainDicts])), ' '.join(map(str, [seq.name for seq in self.sequences]) ),  ' '.join(map(str, [tool.__name__ for tool in self.comboToolConfs]))) 
 
 
 def createComboAlg(dummyFlags, name, multiplicity):
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Muon/MuonDef.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Muon/MuonDef.py
index 5659ab0d457..03bba0544bd 100755
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Muon/MuonDef.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Muon/MuonDef.py
@@ -82,7 +82,6 @@ class MuonChainConfiguration(ChainConfigurationBase):
     # ----------------------
     def assembleChain(self):                            
         chainSteps = []
-        #log.debug("Assembling leg for chain " + self.chainName)
 
         stepDictionary = self.getStepDictionary()
 
@@ -236,13 +235,10 @@ class MuonChainConfiguration(ChainConfigurationBase):
         return self.getStep(2,'muEFLate',[muEFLateSequenceCfg])
 
     #--------------------
-
     def getmuCombDr(self):     
-        step=self.getStep(2, 'muComb', sequenceCfgArray=[muCombSequenceCfg])
-        step.addComboHypoTools([dimuDrComboHypoToolFromDict] )
+        step=self.getStep(2, 'muComb', sequenceCfgArray=[muCombSequenceCfg], comboTools=[dimuDrComboHypoToolFromDict])
         return step
 
-    def getmuFastDr(self):     
-        step=self.getStep(1,"mufast", [muFastSequenceCfg] )
-        step.addComboHypoTools([dimuDrComboHypoToolFromDict] )
+    def getmuFastDr(self):
+        step=self.getStep(1,"mufast", [muFastSequenceCfg], comboTools=[dimuDrComboHypoToolFromDict]  )
         return step
-- 
GitLab