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 613 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 616 of file MenuComponents.py.

616  def __init__(self, name, SequenceGens = None, chainDicts = None, comboHypoCfg = ComboHypoCfg , comboToolConfs = None, isEmpty = False, createsGhostLegs = False):
617 
618  # default mutable values must be initialized to None
619  if SequenceGens is None: SequenceGens = []
620  if comboToolConfs is None: comboToolConfs = []
621 
622  assert chainDicts is not None,"Error building a ChainStep without a chainDicts"
623 
624  self.name = name
625  self.sequences = []
626  self.sequenceGens = SequenceGens
627  self.comboHypoCfg = comboHypoCfg
628  self.comboToolConfs = list(comboToolConfs)
629  self.stepDicts = chainDicts # one dict per leg
630 
631  self.isEmpty = isEmpty
632  if self.isEmpty:
633  self.multiplicity = []
634  else:
635  self.multiplicity = [1 for seq in self.sequenceGens]
636  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])))
637  # sanity check on inputs, excluding empty steps
638  if len(chainDicts) != len(self.multiplicity) and 'Jet' not in chainDicts[0]['signatures']:
639  log.error("[ChainStep] SequenceGens: %s",self.sequenceGens)
640  log.error("[ChainStep] chainDicts: %s",chainDicts)
641  log.error("[ChainStep] multiplicity: %s",self.multiplicity)
642  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)) )
643 
644 
645  for iseq, seq in enumerate(self.sequenceGens):
646  if not isinstance(seq, functools.partial):
647  log.error("[ChainStep] %s SequenceGens verification failed, sequence %d is not partial function, likely ChainBase.getStep function was not used", self.name, iseq)
648  log.error("[ChainStep] It rather seems to be of type %s trying to print it", type(seq))
649  raise RuntimeError("Sequence is not packaged in a tuple, see error message above" )
650 
651  self.onlyJets = False
652  sig_set = None
653  if len(chainDicts) > 0 and 'signature' in chainDicts[0]:
654  leg_signatures = [step['signature'] for step in chainDicts if step['signature'] != 'Bjet']
655  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):
656  index_jetLeg = leg_signatures.index('Jet')
657  self.multiplicity[index_jetLeg:index_jetLeg] = [1] * (len(chainDicts[0]['chainMultiplicities']) - len(self.multiplicity))
658  sig_set = set([step['signature'] for step in chainDicts])
659  if len(sig_set) == 1 and ('Jet' in sig_set or 'Bjet' in sig_set):
660  self.onlyJets = True
661  if len(sig_set) == 2 and ('Jet' in sig_set and 'Bjet' in sig_set):
662  self.onlyJets = True
663 
664 
665 
666  if not self.isEmpty:
667  #self.relabelLegIdsForJets()
668  self.setChainPartIndices()
669  self.legIds = self.getLegIds()
670  self.makeCombo()
671 

Member Function Documentation

◆ __repr__()

def MenuComponents.ChainStep.__repr__ (   self)

Definition at line 797 of file MenuComponents.py.

797  def __repr__(self):
798  if len(self.sequenceGens) == 0:
799  return "\n--- ChainStep %s ---\n is Empty, ChainDict = %s "%(self.name, ' '.join(map(str, [dic['chainName'] for dic in self.stepDicts])) )
800 
801  repr_string= "\n--- ChainStep %s ---\n , multiplicity = %s ChainDict = %s \n + MenuSequenceGens = %s "%\
802  (self.name, ' '.join(map(str,[mult for mult in self.multiplicity])),
803  ' '.join(map(str, [dic['chainName'] for dic in self.stepDicts])),
804  ' '.join(map(str, [seq.func.__name__ for seq in self.sequenceGens]) ))
805 
806  if self.combo is not None:
807  repr_string += "\n + ComboHypo = %s" % self.combo.Alg.name
808  if len(self.comboToolConfs)>0:
809  repr_string +=", ComboHypoTools = %s" %(' '.join(map(str, [tool.__name__ for tool in self.comboToolConfs])))
810  repr_string += "\n"
811  return repr_string
812 
813 

◆ addComboHypoTools()

def MenuComponents.ChainStep.addComboHypoTools (   self,
  tool 
)

Definition at line 752 of file MenuComponents.py.

752  def addComboHypoTools(self, tool):
753  #this function does not add tools, it just adds one tool. do not pass it a list!
754  self.comboToolConfs.append(tool)
755 

◆ createComboHypoTools()

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

Definition at line 783 of file MenuComponents.py.

783  def createComboHypoTools(self, flags, chainName):
784  chainDict = HLTMenuConfig.getChainDictFromChainName(chainName)
785  self.combo.createComboHypoTools(flags, chainDict, self.comboToolConfs)
786 

◆ createSequences()

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

Definition at line 672 of file MenuComponents.py.

672  def createSequences(self):
673  """ creation of this step sequences with instantiation of the CAs"""
674  log.debug("creating sequences for step %s", self.name)
675  for seq in self.sequenceGens:
676  self.sequences.append(seq()) # create the sequences
677 

◆ getChainLegs()

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

Definition at line 787 of file MenuComponents.py.

787  def getChainLegs(self):
788  """ This is extrapolating the chain legs from the step dictionaries"""
789  legs = [part['chainName'] for part in self.stepDicts]
790  return legs
791 

◆ getChainNames()

def MenuComponents.ChainStep.getChainNames (   self)

Definition at line 792 of file MenuComponents.py.

792  def getChainNames(self):
793  if self.combo is not None:
794  return list(self.combo.getChains())
795  return self.getChainLegs()
796 

◆ getComboHypoFncName()

def MenuComponents.ChainStep.getComboHypoFncName (   self)

Definition at line 756 of file MenuComponents.py.

756  def getComboHypoFncName(self):
757  return self.comboHypoCfg.func.__name__ if isinstance(self.comboHypoCfg, functools.partial) else self.comboHypoCfg
758 

◆ getLegIds()

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

Definition at line 736 of file MenuComponents.py.

736  def getLegIds(self):
737  """ get the gelId from the step dictionary for multi-leg chains"""
738  if len(self.multiplicity) <= 1: # single leg step
739  return [0]
740  leg_ids = []
741  for istep,step_dict in enumerate(self.stepDicts):
742  if step_dict['chainName'][0:3] != 'leg':
743  if self.onlyJets:
744  leg_ids += [istep]
745  else:
746  log.error("[getLegIds] chain %s has multiplicities %s but no legs? ",step_dict['chainName'], self.multiplicity)
747  raise Exception("[getLegIds] cannot extract leg IDs, exiting.")
748  else:
749  leg_ids += [int(step_dict['chainName'][3:6])]
750  return leg_ids
751 

◆ 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 759 of file MenuComponents.py.

759  def makeCombo(self):
760  """ Configure the Combo Hypo Alg and generate the corresponding function, without instantiation which is done in createSequences() """
761  self.combo = None
762  if self.isEmpty or self.comboHypoCfg is None:
763  return
764  comboNameFromStep = CFNaming.comboHypoName(self.name) # name expected from the step name
765  funcName = self.getComboHypoFncName() # name of the function generator
766  key = hash((comboNameFromStep, funcName))
767  if key not in _ComboHypoPool:
768  tmpCombo = ComboHypoNode(comboNameFromStep, self.comboHypoCfg)
769  # exceptions for BLS chains that re-use the same custom CH in differnt steps
770  # this breaks the run one CH per step, but the BLS CH are able to handle decisions internally
771  if comboNameFromStep+"Node" != tmpCombo.name:
772  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)
773  key = hash((tmpCombo.name, funcName))
774  _ComboHypoPool[key] = tmpCombo
775  self.combo = _ComboHypoPool[key]
776  log.debug("Created combo %s with name %s, step comboName %s, key %s", funcName, self.combo.name, comboNameFromStep,key)
777 
778 
779 
780 
781 
782 

◆ relabelLegIdsForJets()

def MenuComponents.ChainStep.relabelLegIdsForJets (   self)

Definition at line 678 of file MenuComponents.py.

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

◆ setChainPartIndices()

def MenuComponents.ChainStep.setChainPartIndices (   self)

Definition at line 721 of file MenuComponents.py.

721  def setChainPartIndices(self):
722  leg_counter = 0
723  lists_of_chainPartNames = []
724  for step_dict in self.stepDicts:
725  if len(lists_of_chainPartNames) == 0:
726  lists_of_chainPartNames += [[cp['chainPartName'] for cp in step_dict['chainParts']]]
727  else:
728  new_list_of_chainPartNames = [cp['chainPartName'] for cp in step_dict['chainParts']]
729  if new_list_of_chainPartNames == lists_of_chainPartNames[-1]:
730  leg_counter -= len(new_list_of_chainPartNames)
731  for chainPart in step_dict['chainParts']:
732  chainPart['chainPartIndex'] = leg_counter
733  leg_counter += 1
734  return
735 

Member Data Documentation

◆ combo

MenuComponents.ChainStep.combo

Definition at line 761 of file MenuComponents.py.

◆ comboHypoCfg

MenuComponents.ChainStep.comboHypoCfg

Definition at line 627 of file MenuComponents.py.

◆ comboToolConfs

MenuComponents.ChainStep.comboToolConfs

Definition at line 628 of file MenuComponents.py.

◆ isEmpty

MenuComponents.ChainStep.isEmpty

Definition at line 631 of file MenuComponents.py.

◆ legIds

MenuComponents.ChainStep.legIds

Definition at line 669 of file MenuComponents.py.

◆ multiplicity

MenuComponents.ChainStep.multiplicity

Definition at line 633 of file MenuComponents.py.

◆ name

MenuComponents.ChainStep.name

Definition at line 624 of file MenuComponents.py.

◆ onlyJets

MenuComponents.ChainStep.onlyJets

Definition at line 651 of file MenuComponents.py.

◆ sequenceGens

MenuComponents.ChainStep.sequenceGens

Definition at line 626 of file MenuComponents.py.

◆ sequences

MenuComponents.ChainStep.sequences

Definition at line 625 of file MenuComponents.py.

◆ stepDicts

MenuComponents.ChainStep.stepDicts

Definition at line 629 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