diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/HLTCFConfig.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/HLTCFConfig.py index eaf19edf8caf5083b6f2ae8977267ab9838c34e7..575e1dc5447243ee3d5f4d32b3613fd86295b3a4 100644 --- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/HLTCFConfig.py +++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/HLTCFConfig.py @@ -99,19 +99,10 @@ def createCFTree(CFseq): already_connected = [] for menuseq in CFseq.step.sequences: - ath_sequence = menuseq.sequence.Alg - name = ath_sequence.name() - if name in already_connected: - log.debug("AthSequencer %s already in the Tree, not added again",name) - continue - else: - already_connected.append(name) - stepReco += ath_sequence - if type(menuseq.hypo) is list: - for hp in menuseq.hypo: - seqAndView += hp.Alg - else: - seqAndView += menuseq.hypo.Alg + stepReco, seqAndView, already_connected = menuseq.addToSequencer( + stepReco, + seqAndView, + already_connected) if CFseq.step.isCombo: seqAndView += CFseq.step.combo.Alg @@ -119,7 +110,6 @@ def createCFTree(CFseq): return seqAndWithFilter - ####################################### ## CORE of Decision Handling ####################################### @@ -246,18 +236,14 @@ def matrixDisplayOld( allCFSeq ): def matrixDisplay( allCFSeq ): - + def __getHyposOfStep( step ): if len(step.sequences): if len(step.sequences)==1: - if type(step.sequences[0].hypo) is list: - return step.sequences[0].hypo[0].tools - else: - return step.sequences[0].hypo.tools + return step.sequences[0].getTools() else: return list(step.combo.getChains().keys()) return [] - # fill dictionary to cumulate chains on same sequences, in steps (dict with composite keys) from collections import defaultdict diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/HLTCFDot.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/HLTCFDot.py index a3e071a15f32e4a1d1698bbad5d88a022532e2df..55578c7346f77794ae0bc280ba6d50e3fa74c877 100644 --- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/HLTCFDot.py +++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/HLTCFDot.py @@ -129,34 +129,18 @@ def all_DataFlow_to_dot(name, step_list): cfseq_algs = [] cfseq_algs.append(cfseq.filter) - alreadydrawn = set() - if len(cfseq.step.sequences)==0: last_step_hypoNodes.append(cfseq.filter) for menuseq in cfseq.step.sequences: - cfseq_algs.append(menuseq.maker) - cfseq_algs.append(menuseq.sequence ) - if menuseq not in alreadydrawn: - alreadydrawn.add(menuseq) - file.write(" %s[fillcolor=%s]\n"%(menuseq.maker.Alg.name(), algColor(menuseq.maker.Alg))) - file.write(" %s[fillcolor=%s]\n"%(menuseq.sequence.Alg.name(), algColor(menuseq.sequence.Alg))) - if type(menuseq.hypo) is list: - for hp in menuseq.hypo: - cfseq_algs.append(hp) - file.write(" %s[color=%s]\n"%(hp.Alg.name(), algColor(hp.Alg))) - all_hypos.append(hp) - else: - cfseq_algs.append(menuseq.hypo) - file.write(" %s[color=%s]\n"%(menuseq.hypo.Alg.name(), algColor(menuseq.hypo.Alg))) - all_hypos.append(menuseq.hypo) - if not cfseq.step.isCombo: - if type(menuseq.hypo) is list: - last_step_hypoNodes.append(menuseq.hypo[-1]) - else: - last_step_hypoNodes.append(menuseq.hypo) - - #combo + cfseq_algs, all_hypos, last_step_hypoNodes = menuseq.buildCFDot(cfseq_algs, + all_hypos, + cfseq.step.isCombo, + last_step_hypoNodes, + file) + + + #combo if cfseq.step.isCombo: if cfseq.step.combo is not None: file.write(" %s[color=%s]\n"%(cfseq.step.combo.Alg.name(), algColor(cfseq.step.combo.Alg))) @@ -201,26 +185,13 @@ def stepCF_DataFlow_to_dot(name, cfseq_list): cfseq_algs = [] cfseq_algs.append(cfseq.filter) - alreadydrawn = set() - for menuseq in cfseq.step.sequences: - cfseq_algs.append(menuseq.maker) - cfseq_algs.append(menuseq.sequence ) - if menuseq not in alreadydrawn: - alreadydrawn.add(menuseq) - file.write(" %s[fillcolor=%s]\n"%(menuseq.maker.Alg.name(), algColor(menuseq.maker.Alg))) - file.write(" %s[fillcolor=%s]\n"%(menuseq.sequence.Alg.name(), algColor(menuseq.sequence.Alg))) - if type(menuseq.hypo) is list: - for hp in menuseq.hypo: - cfseq_algs.append(hp) - file.write(" %s[color=%s]\n"%(hp.Alg.name(), algColor(hp.Alg))) - all_hypos.append(hp) - else: - cfseq_algs.append(menuseq.hypo) - file.write(" %s[color=%s]\n"%(menuseq.hypo.Alg.name(), algColor(menuseq.hypo.Alg))) - all_hypos.append(menuseq.hypo) - - #combo + cfseq_algs, all_hypos, _ = menuseq.buildCFDot(cfseq_algs, + all_hypos, + True, + None, + file) + #combo if cfseq.step.isCombo: if cfseq.step.combo is not None: file.write(" %s[color=%s]\n"%(cfseq.step.combo.Alg.name(), algColor(cfseq.step.combo.Alg))) diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py index 2f66cc4621dfdec5764fae2a7bd686196a4a5c8a..416219a681cef3256f1621a87213e41ca22fdb21 100644 --- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py +++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py @@ -123,6 +123,17 @@ class AlgNode(Node): return "Alg::%s [%s] -> [%s]"%(self.Alg.name(), ' '.join(map(str, self.getInputList())), ' '.join(map(str, self.getOutputList()))) +def algColor(alg): + """ Set given color to Alg type""" + if isHypoBase(alg): + return "darkorchid1" + if isInputMakerBase(alg): + return "cyan3" + if isFilterAlg(alg): + return "chartreuse3" + return "cadetblue1" + + class HypoToolConf(object): """ Class to group info on hypotools for ChainDict""" def __init__(self, hypoToolGen): @@ -354,23 +365,137 @@ class MenuSequence(object): def maker(self): return self._maker + @property def hypo(self): return self._hypo + + 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 + + def connectToFilter(self, outfilter): """ Connect filter to the InputMaker""" - self.maker.addInput(outfilter) + self._maker.addInput(outfilter) + + + def connect(self, Hypo, HypoToolGen): + """ Sets the input and output of the hypo, and links to the input maker """ + input_maker_output= self._maker.readOutputList()[0] # only one since it's merged + + #### Add input/output Decision to Hypo + if type(Hypo) is list: + self.name=[] + self.hypoToolConf=[] + self._hypo=[] + hypo_input_total=[] + hypo_output_total=[] + hypo_input = input_maker_output + for hypo_alg, hptool in zip(Hypo, HypoToolGen): + self.name.append( CFNaming.menuSequenceName(hypo_alg.name()) ) + self.hypoToolConf.append( HypoToolConf( hptool ) ) + + hypo_input_total.append(hypo_input) + hypo_output = CFNaming.hypoAlgOutName(hypo_alg.name()) + hypo_output_total.append(hypo_output) + + hypo_node = HypoAlgNode( Alg = hypo_alg ) + hypo_node.addOutput(hypo_output) + hypo_node.setPreviousDecision(hypo_input) + + self._hypo.append( hypo_node ) + hypo_input = hypo_output + log.warning("Sequence %s has more than one Hypo; correct your sequence for next develpments", self.name) + else: + self.name = CFNaming.menuSequenceName(Hypo.name()) + self.hypoToolConf = HypoToolConf( HypoToolGen ) + self._hypo = HypoAlgNode( Alg = Hypo ) + hypo_output = CFNaming.hypoAlgOutName(Hypo.name()) + self._hypo.addOutput(hypo_output) + self._hypo.setPreviousDecision( input_maker_output) + + + log.debug("MenuSequence.connect: connecting InputMaker and HypoAlg and OverlapRemoverAlg, adding: \n\ + InputMaker::%s.output=%s",\ + self._maker.Alg.name(), input_maker_output) + if type(self._hypo) is list: + for hp, hp_in, hp_out in zip( self._hypo, hypo_input_total, hypo_output_total): + log.debug("HypoAlg::%s.previousDecision=%s, \n\ + HypoAlg::%s.output=%s",\ + hp.Alg.name(), hp_in, hp.Alg.name(), hp_out) + else: + log.debug("HypoAlg::%s.previousDecision=%s, \n\ + HypoAlg::%s.output=%s",\ + self._hypo.Alg.name(), input_maker_output, self._hypo.Alg.name(), self._hypo.readOutputList()[0]) def createHypoTools(self, chainDict): - if isinstance(self._hypoToolConf, list): - for hypoAlg, hypoToolConf in zip( self._hypo, self._hypoToolConf ): + if type(self._hypoToolConf) is list: + log.warning ("This sequence %s has %d multiple HypoTools ",self.sequence.name, len(self.hypoToolConf)) + for hypo, hypoToolConf in zip(self._hypo, self._hypoToolConf): hypoToolConf.setConf( chainDict ) - hypoAlg.addHypoTool(hypoToolConf) #this creates the HypoTools + hypo.addHypoTool(self._hypoToolConf) else: self._hypoToolConf.setConf( chainDict ) - self._hypo.addHypoTool( self._hypoToolConf ) #this creates the HypoTools + self._hypo.addHypoTool(self._hypoToolConf) #this creates the HypoTools + + + def addToSequencer(self, stepReco, seqAndView, already_connected): + ath_sequence = self.sequence.Alg + name = ath_sequence.name() + if name in already_connected: + log.debug("AthSequencer %s already in the Tree, not added again",name) + return stepReco, seqAndView, already_connected + else: + already_connected.append(name) + stepReco += ath_sequence + if type(self._hypo) is list: + for hp in self._hypo: + seqAndView += hp.Alg + else: + seqAndView += self._hypo.Alg + return stepReco, seqAndView, already_connected + + + def buildCFDot(self, cfseq_algs, all_hypos, isCombo, last_step_hypo_nodes, file): + cfseq_algs.append(self._maker) + cfseq_algs.append(self.sequence ) + + file.write(" %s[fillcolor=%s]\n"%(self._maker.Alg.name(), algColor(self._maker.Alg))) + file.write(" %s[fillcolor=%s]\n"%(self.sequence.Alg.name(), algColor(self.sequence.Alg))) + + if type(self._hypo) is list: + for hp in self._hypo: + cfseq_algs.append(hp) + file.write(" %s[color=%s]\n"%(hp.Alg.name(), algColor(hp.Alg))) + all_hypos.append(hp) + else: + cfseq_algs.append(self._hypo) + file.write(" %s[color=%s]\n"%(self._hypo.Alg.name(), algColor(self._hypo.Alg))) + all_hypos.append(self._hypo) + if not isCombo: + if type(self._hypo) is list: + last_step_hypo_nodes.append(self._hypo[-1]) + else: + last_step_hypo_nodes.append(self._hypo) + + return cfseq_algs, all_hypos, last_step_hypo_nodes + + + def getTools(self): + if type(self._hypo) is list: + return self._hypo[0].tools + else: + return self._hypo.tools def setSeed( self, seed ): self._seed = seed @@ -383,12 +508,12 @@ class MenuSequence(object): hyponame.append( hp.Alg.name() ) hypotool.append( hptool.name ) return "MenuSequence::%s \n Hypo::%s \n Maker::%s \n Sequence::%s \n HypoTool::%s"\ - %(self.name, hyponame, self.maker.Alg.name(), self.sequence.Alg.name(), hypotool) + %(self.name, hyponame, self._maker.Alg.name(), self.sequence.Alg.name(), hypotool) else: hyponame = self._hypo.Alg.name() hypotool = self.hypoToolConf.name return "MenuSequence::%s \n Hypo::%s \n Maker::%s \n Sequence::%s \n HypoTool::%s\n"\ - %(self.name, hyponame, self.maker.Alg.name(), self.sequence.Alg.name(), hypotool) + %(self.name, hyponame, self._maker.Alg.name(), self.sequence.Alg.name(), hypotool) class CAMenuSequence(MenuSequence): @@ -505,12 +630,12 @@ class Chain(object): chainDict = listOfChainDictsLegs[0] chainDict['chainName']= self.name # rename the chaindict to remove the leg name for seq in step.sequences: - seq.createHypoTools( chainDict ) + seq.createHypoTools( chainDict ) #this creates the HypoTools + continue # add one hypotool per sequence and chain part - else: - for seq, onePartChainDict in zip(step.sequences, listOfChainDictsLegs): - seq.createHypoTools( onePartChainDict ) + for seq, onePartChainDict in zip(step.sequences, listOfChainDictsLegs): + seq.createHypoTools( onePartChainDict )#this creates the HypoTools def __repr__(self): @@ -542,12 +667,9 @@ class CFSequence(object): self.decisions.extend(self.step.combo.getOutputList()) else: for sequence in self.step.sequences: - hp=sequence.hypo - if type(hp) is list: - for hypo in hp: - self.decisions.append(hypo.readOutputList()[0]) - else: - self.decisions.append(hp.readOutputList()[0]) + sequence_outputs=sequence.getOutputList() + for output in sequence_outputs: + self.decisions.append(output) log.debug("CFSequence: set out decisions: %s", self.decisions) @@ -581,10 +703,10 @@ class CFSequence(object): def connectCombo(self): """ connect Combo to Hypos""" for seq in self.step.sequences: - if type(seq.hypo) is list: - combo_input=seq.hypo[-1].readOutputList()[0] # last one? + if type(seq.getOutputList()) is list: + combo_input=seq.getOutputList()[-1] # last one? else: - combo_input=seq.hypo.readOutputList()[0] + combo_input=seq.getOutputList()[0] self.step.combo.addInput(combo_input) log.debug("CFSequence.connectCombo: adding input to %s: %s", self.step.combo.Alg.name(), combo_input) # inputs are the output decisions of the hypos of the sequences