ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
MenuComponents.ChainStep Class Reference
Inheritance diagram for MenuComponents.ChainStep:
Collaboration diagram for MenuComponents.ChainStep:

Public Member Functions

def __init__ (self, name, SequenceGens=None, chainDicts=None, comboHypoCfg=ComboHypoCfg, comboToolConfs=None, isEmpty=False, createsGhostLegs=False)
 
def createSequences (self)
 
def relabelLegIdsForJets (self)
 
def setChainPartIndices (self)
 
def getLegIds (self)
 
def addComboHypoTools (self, tool)
 
def getComboHypoFncName (self)
 
def makeCombo (self)
 
def createComboHypoTools (self, flags, chainName)
 
def getChainLegs (self)
 
def getChainNames (self)
 
def __repr__ (self)
 

Public Attributes

 name
 
 sequences
 
 sequenceGens
 
 comboHypoCfg
 
 comboToolConfs
 
 stepDicts
 
 isEmpty
 
 multiplicity
 
 onlyJets
 
 legIds
 
 combo
 

Detailed Description

Class to describe one step of a chain; if multiplicity is greater than 1, the step is combo/combined.  Set one multiplicity value per sequence

Definition at line 624 of file MenuComponents.py.

Constructor & Destructor Documentation

◆ __init__()

def MenuComponents.ChainStep.__init__ (   self,
  name,
  SequenceGens = None,
  chainDicts = None,
  comboHypoCfg = ComboHypoCfg,
  comboToolConfs = None,
  isEmpty = False,
  createsGhostLegs = False 
)

Definition at line 627 of file MenuComponents.py.

627  def __init__(self, name, SequenceGens = None, chainDicts = None, comboHypoCfg = ComboHypoCfg , comboToolConfs = None, isEmpty = False, createsGhostLegs = False):
628 
629  # default mutable values must be initialized to None
630  if SequenceGens is None: SequenceGens = []
631  if comboToolConfs is None: comboToolConfs = []
632 
633  assert chainDicts is not None,"Error building a ChainStep without a chainDicts"
634 
635  self.name = name
636  self.sequences = []
637  self.sequenceGens = SequenceGens
638  self.comboHypoCfg = comboHypoCfg
639  self.comboToolConfs = list(comboToolConfs)
640  self.stepDicts = chainDicts # one dict per leg
641 
642  self.isEmpty = isEmpty
643  if self.isEmpty:
644  self.multiplicity = []
645  else:
646  self.multiplicity = [1 for seq in self.sequenceGens]
647  log.debug("Building step %s for chain %s: len=%d multiplicty=%s", name, chainDicts[0]['chainName'], len(chainDicts), ' '.join(map(str,[mult for mult in self.multiplicity])))
648  # sanity check on inputs, excluding empty steps
649  if len(chainDicts) != len(self.multiplicity) and 'Jet' not in chainDicts[0]['signatures']:
650  log.error("[ChainStep] SequenceGens: %s",self.sequenceGens)
651  log.error("[ChainStep] chainDicts: %s",chainDicts)
652  log.error("[ChainStep] multiplicity: %s",self.multiplicity)
653  raise RuntimeError("[ChainStep] Tried to configure a ChainStep %s with %i multiplicity and %i dictionaries. These lists must have the same size" % (name, len(self.multiplicity), len(chainDicts)) )
654 
655 
656  for iseq, seq in enumerate(self.sequenceGens):
657  if not isinstance(seq, functools.partial):
658  log.error("[ChainStep] %s SequenceGens verification failed, sequence %d is not partial function, likely ChainBase.getStep function was not used", self.name, iseq)
659  log.error("[ChainStep] It rather seems to be of type %s trying to print it", type(seq))
660  raise RuntimeError("Sequence is not packaged in a tuple, see error message above" )
661 
662  self.onlyJets = False
663  sig_set = None
664  if len(chainDicts) > 0 and 'signature' in chainDicts[0]:
665  leg_signatures = [step['signature'] for step in chainDicts if step['signature'] != 'Bjet']
666  if (len(self.multiplicity) > 0 and leg_signatures.count('Jet') == 1) and (len(set(leg_signatures)) > 1 and chainDicts[0]['signatures'].count('Jet') > 1) and (len(leg_signatures) != 2 or leg_signatures.count('MET') == 0):
667  index_jetLeg = leg_signatures.index('Jet')
668  self.multiplicity[index_jetLeg:index_jetLeg] = [1] * (len(chainDicts[0]['chainMultiplicities']) - len(self.multiplicity))
669  sig_set = set([step['signature'] for step in chainDicts])
670  if len(sig_set) == 1 and ('Jet' in sig_set or 'Bjet' in sig_set):
671  self.onlyJets = True
672  if len(sig_set) == 2 and ('Jet' in sig_set and 'Bjet' in sig_set):
673  self.onlyJets = True
674 
675 
676 
677  if not self.isEmpty:
678  #self.relabelLegIdsForJets()
679  self.setChainPartIndices()
680  self.legIds = self.getLegIds()
681  self.makeCombo()
682 

Member Function Documentation

◆ __repr__()

def MenuComponents.ChainStep.__repr__ (   self)

Definition at line 808 of file MenuComponents.py.

808  def __repr__(self):
809  if len(self.sequenceGens) == 0:
810  return "\n--- ChainStep %s ---\n is Empty, ChainDict = %s "%(self.name, ' '.join(map(str, [dic['chainName'] for dic in self.stepDicts])) )
811 
812  repr_string= "\n--- ChainStep %s ---\n , multiplicity = %s ChainDict = %s \n + MenuSequenceGens = %s "%\
813  (self.name, ' '.join(map(str,[mult for mult in self.multiplicity])),
814  ' '.join(map(str, [dic['chainName'] for dic in self.stepDicts])),
815  ' '.join(map(str, [seq.func.__name__ for seq in self.sequenceGens]) ))
816 
817  if self.combo is not None:
818  repr_string += "\n + ComboHypo = %s" % self.combo.Alg.name
819  if len(self.comboToolConfs)>0:
820  repr_string +=", ComboHypoTools = %s" %(' '.join(map(str, [tool.__name__ for tool in self.comboToolConfs])))
821  repr_string += "\n"
822  return repr_string
823 
824 

◆ addComboHypoTools()

def MenuComponents.ChainStep.addComboHypoTools (   self,
  tool 
)

Definition at line 763 of file MenuComponents.py.

763  def addComboHypoTools(self, tool):
764  #this function does not add tools, it just adds one tool. do not pass it a list!
765  self.comboToolConfs.append(tool)
766 

◆ createComboHypoTools()

def MenuComponents.ChainStep.createComboHypoTools (   self,
  flags,
  chainName 
)

Definition at line 794 of file MenuComponents.py.

794  def createComboHypoTools(self, flags, chainName):
795  chainDict = HLTMenuConfig.getChainDictFromChainName(chainName)
796  self.combo.createComboHypoTools(flags, chainDict, self.comboToolConfs)
797 

◆ createSequences()

def MenuComponents.ChainStep.createSequences (   self)
creation of this step sequences with instantiation of the CAs

Definition at line 683 of file MenuComponents.py.

683  def createSequences(self):
684  """ creation of this step sequences with instantiation of the CAs"""
685  log.debug("creating sequences for step %s", self.name)
686  for seq in self.sequenceGens:
687  self.sequences.append(seq()) # create the sequences
688 

◆ getChainLegs()

def MenuComponents.ChainStep.getChainLegs (   self)
This is extrapolating the chain legs from the step dictionaries

Definition at line 798 of file MenuComponents.py.

798  def getChainLegs(self):
799  """ This is extrapolating the chain legs from the step dictionaries"""
800  legs = [part['chainName'] for part in self.stepDicts]
801  return legs
802 

◆ getChainNames()

def MenuComponents.ChainStep.getChainNames (   self)

Definition at line 803 of file MenuComponents.py.

803  def getChainNames(self):
804  if self.combo is not None:
805  return list(self.combo.getChains())
806  return self.getChainLegs()
807 

◆ getComboHypoFncName()

def MenuComponents.ChainStep.getComboHypoFncName (   self)

Definition at line 767 of file MenuComponents.py.

767  def getComboHypoFncName(self):
768  return self.comboHypoCfg.func.__name__ if isinstance(self.comboHypoCfg, functools.partial) else self.comboHypoCfg
769 

◆ getLegIds()

def MenuComponents.ChainStep.getLegIds (   self)
get the gelId from the step dictionary for multi-leg chains

Definition at line 747 of file MenuComponents.py.

747  def getLegIds(self):
748  """ get the gelId from the step dictionary for multi-leg chains"""
749  if len(self.multiplicity) <= 1: # single leg step
750  return [0]
751  leg_ids = []
752  for istep,step_dict in enumerate(self.stepDicts):
753  if step_dict['chainName'][0:3] != 'leg':
754  if self.onlyJets:
755  leg_ids += [istep]
756  else:
757  log.error("[getLegIds] chain %s has multiplicities %s but no legs? ",step_dict['chainName'], self.multiplicity)
758  raise Exception("[getLegIds] cannot extract leg IDs, exiting.")
759  else:
760  leg_ids += [int(step_dict['chainName'][3:6])]
761  return leg_ids
762 

◆ makeCombo()

def MenuComponents.ChainStep.makeCombo (   self)
Configure the Combo Hypo Alg and generate the corresponding function, without instantiation which is done in createSequences() 

Definition at line 770 of file MenuComponents.py.

770  def makeCombo(self):
771  """ Configure the Combo Hypo Alg and generate the corresponding function, without instantiation which is done in createSequences() """
772  self.combo = None
773  if self.isEmpty or self.comboHypoCfg is None:
774  return
775  comboNameFromStep = CFNaming.comboHypoName(self.name) # name expected from the step name
776  funcName = self.getComboHypoFncName() # name of the function generator
777  key = hash((comboNameFromStep, funcName))
778  if key not in _ComboHypoPool:
779  tmpCombo = ComboHypoNode(comboNameFromStep, self.comboHypoCfg)
780  # exceptions for BLS chains that re-use the same custom CH in differnt steps
781  # this breaks the run one CH per step, but the BLS CH are able to handle decisions internally
782  if comboNameFromStep+"Node" != tmpCombo.name:
783  log.info("WARNING Created ComboHypo with name %s, expected from the step is instead %s. This is accepted only for allowed custom ComboHypos", tmpCombo.name, comboNameFromStep)
784  key = hash((tmpCombo.name, funcName))
785  _ComboHypoPool[key] = tmpCombo
786  self.combo = _ComboHypoPool[key]
787  log.debug("Created combo %s with name %s, step comboName %s, key %s", funcName, self.combo.name, comboNameFromStep,key)
788 
789 
790 
791 
792 
793 

◆ relabelLegIdsForJets()

def MenuComponents.ChainStep.relabelLegIdsForJets (   self)

Definition at line 689 of file MenuComponents.py.

689  def relabelLegIdsForJets(self):
690  has_jets = False
691  leg_counter = []
692 
693  for step_dict in self.stepDicts:
694  if 'Jet' in step_dict['signatures'] or 'Bjet' in step_dict['signatures']:
695  has_jets = True
696  leg_counter += [len(step_dict['chainParts'])]
697  elif len(step_dict['chainParts']) > 1:
698  log.error("[relabelLegIdsForJets] this should only happen for jet chains, but the signatures are %s",step_dict['signatures'])
699  raise Exception("[relabelLegIdsForJets] leg labelling is probably wrong...")
700  else:
701  leg_counter +=[1]
702 
703  self.onlyJets = False
704  if len(leg_counter) == len(self.multiplicity):
705  self.onlyJets = True
706 
707  log.debug("[relabelLegIdsForJets] leg_counter: %s , onlyjets: %s, multiplicity: %s...",leg_counter, self.onlyJets, self.multiplicity)
708 
709  if not has_jets or len(leg_counter) == len(self.multiplicity): #also don't relabel only jets since no offset needed
710  return
711 
712  if len(leg_counter) == 1 or (len(set(leg_counter)) == 1 and leg_counter[0] == 1):
713  #all legs are already length 1, or there's only one jet blocks nothing to do
714  return
715  elif len(set(leg_counter[:-1])) == 1 and leg_counter[0] == 1:
716  #it's the last leg that's not length one, so we don't need to relabel any end legs
717  return
718  else:
719  nLegs = 0
720  for i,nLegParts in enumerate(leg_counter):
721  oldLegName = self.stepDicts[i]['chainName']
722  if re.search('^leg[0-9]{3}_',oldLegName):
723  oldLegName = oldLegName[7:]
724  else:
725  log.error("[relabelLegIdsForJets] you told me to relabel the legs for %s",self.stepDicts)
726  raise Exception("[relabelLegIdsForJets] you told me to relabel the legs but this leg doesn't have a legXXX_ name!")
727  self.stepDicts[i]['chainName'] = legName(oldLegName,nLegs)
728  nLegs += nLegParts
729  return
730 

◆ setChainPartIndices()

def MenuComponents.ChainStep.setChainPartIndices (   self)

Definition at line 732 of file MenuComponents.py.

732  def setChainPartIndices(self):
733  leg_counter = 0
734  lists_of_chainPartNames = []
735  for step_dict in self.stepDicts:
736  if len(lists_of_chainPartNames) == 0:
737  lists_of_chainPartNames += [[cp['chainPartName'] for cp in step_dict['chainParts']]]
738  else:
739  new_list_of_chainPartNames = [cp['chainPartName'] for cp in step_dict['chainParts']]
740  if new_list_of_chainPartNames == lists_of_chainPartNames[-1]:
741  leg_counter -= len(new_list_of_chainPartNames)
742  for chainPart in step_dict['chainParts']:
743  chainPart['chainPartIndex'] = leg_counter
744  leg_counter += 1
745  return
746 

Member Data Documentation

◆ combo

MenuComponents.ChainStep.combo

Definition at line 772 of file MenuComponents.py.

◆ comboHypoCfg

MenuComponents.ChainStep.comboHypoCfg

Definition at line 638 of file MenuComponents.py.

◆ comboToolConfs

MenuComponents.ChainStep.comboToolConfs

Definition at line 639 of file MenuComponents.py.

◆ isEmpty

MenuComponents.ChainStep.isEmpty

Definition at line 642 of file MenuComponents.py.

◆ legIds

MenuComponents.ChainStep.legIds

Definition at line 680 of file MenuComponents.py.

◆ multiplicity

MenuComponents.ChainStep.multiplicity

Definition at line 644 of file MenuComponents.py.

◆ name

MenuComponents.ChainStep.name

Definition at line 635 of file MenuComponents.py.

◆ onlyJets

MenuComponents.ChainStep.onlyJets

Definition at line 662 of file MenuComponents.py.

◆ sequenceGens

MenuComponents.ChainStep.sequenceGens

Definition at line 637 of file MenuComponents.py.

◆ sequences

MenuComponents.ChainStep.sequences

Definition at line 636 of file MenuComponents.py.

◆ stepDicts

MenuComponents.ChainStep.stepDicts

Definition at line 640 of file MenuComponents.py.


The documentation for this class was generated from the following file:
test_athena_ntuple_filter.seq
seq
filter configuration ## -> we use the special sequence 'AthMasterSeq' which is run before any other a...
Definition: test_athena_ntuple_filter.py:18
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.TrigConfigSvcUtils.getChains
def getChains(connection, smk)
Definition: TrigConfigSvcUtils.py:592
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
python.TrigCompositeUtils.legName
def legName(chainName, legCounter)
Definition: DecisionHandling/python/TrigCompositeUtils.py:12
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78