Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 634 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 637 of file MenuComponents.py.

637  def __init__(self, name, SequenceGens = None, chainDicts = None, comboHypoCfg = ComboHypoCfg , comboToolConfs = None, isEmpty = False, createsGhostLegs = False):
638 
639  # default mutable values must be initialized to None
640  if SequenceGens is None: SequenceGens = []
641  if comboToolConfs is None: comboToolConfs = []
642 
643  assert chainDicts is not None,"Error building a ChainStep without a chainDicts"
644 
645  self.name = name
646  self.sequences = []
647  self.sequenceGens = SequenceGens
648  self.comboHypoCfg = comboHypoCfg
649  self.comboToolConfs = list(comboToolConfs)
650  self.stepDicts = chainDicts # one dict per leg
651 
652  self.isEmpty = isEmpty
653  if self.isEmpty:
654  self.multiplicity = []
655  else:
656  self.multiplicity = [1 for seq in self.sequenceGens]
657  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])))
658  # sanity check on inputs, excluding empty steps
659  if len(chainDicts) != len(self.multiplicity) and 'Jet' not in chainDicts[0]['signatures']:
660  log.error("[ChainStep] SequenceGens: %s",self.sequenceGens)
661  log.error("[ChainStep] chainDicts: %s",chainDicts)
662  log.error("[ChainStep] multiplicity: %s",self.multiplicity)
663  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)) )
664 
665 
666  for iseq, seq in enumerate(self.sequenceGens):
667  if not isinstance(seq, functools.partial):
668  log.error("[ChainStep] %s SequenceGens verification failed, sequence %d is not partial function, likely ChainBase.getStep function was not used", self.name, iseq)
669  log.error("[ChainStep] It rather seems to be of type %s trying to print it", type(seq))
670  raise RuntimeError("Sequence is not packaged in a tuple, see error message above" )
671 
672  self.onlyJets = False
673  sig_set = None
674  if len(chainDicts) > 0 and 'signature' in chainDicts[0]:
675  leg_signatures = [step['signature'] for step in chainDicts if step['signature'] != 'Bjet']
676  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):
677  index_jetLeg = leg_signatures.index('Jet')
678  self.multiplicity[index_jetLeg:index_jetLeg] = [1] * (len(chainDicts[0]['chainMultiplicities']) - len(self.multiplicity))
679  sig_set = set([step['signature'] for step in chainDicts])
680  if len(sig_set) == 1 and ('Jet' in sig_set or 'Bjet' in sig_set):
681  self.onlyJets = True
682  if len(sig_set) == 2 and ('Jet' in sig_set and 'Bjet' in sig_set):
683  self.onlyJets = True
684 
685 
686 
687  if not self.isEmpty:
688  #self.relabelLegIdsForJets()
689  self.setChainPartIndices()
690  self.legIds = self.getLegIds()
691  self.makeCombo()
692 

Member Function Documentation

◆ __repr__()

def MenuComponents.ChainStep.__repr__ (   self)

Definition at line 817 of file MenuComponents.py.

817  def __repr__(self):
818  if len(self.sequenceGens) == 0:
819  return "\n--- ChainStep %s ---\n is Empty, ChainDict = %s "%(self.name, ' '.join(map(str, [dic['chainName'] for dic in self.stepDicts])) )
820 
821  repr_string= "\n--- ChainStep %s ---\n , multiplicity = %s ChainDict = %s \n + MenuSequenceGens = %s "%\
822  (self.name, ' '.join(map(str,[mult for mult in self.multiplicity])),
823  ' '.join(map(str, [dic['chainName'] for dic in self.stepDicts])),
824  ' '.join(map(str, [seq.func.__name__ for seq in self.sequenceGens]) ))
825 
826  if self.combo is not None:
827  repr_string += "\n + ComboHypo = %s" % self.combo.Alg.name
828  if len(self.comboToolConfs)>0:
829  repr_string +=", ComboHypoTools = %s" %(' '.join(map(str, [tool.__name__ for tool in self.comboToolConfs])))
830  repr_string += "\n"
831  return repr_string
832 
833 

◆ addComboHypoTools()

def MenuComponents.ChainStep.addComboHypoTools (   self,
  tool 
)

Definition at line 773 of file MenuComponents.py.

773  def addComboHypoTools(self, tool):
774  #this function does not add tools, it just adds one tool. do not pass it a list!
775  self.comboToolConfs.append(tool)
776 

◆ createComboHypoTools()

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

Definition at line 803 of file MenuComponents.py.

803  def createComboHypoTools(self, flags, chainName):
804  chainDict = HLTMenuConfig.getChainDictFromChainName(chainName)
805  self.combo.createComboHypoTools(flags, chainDict, self.comboToolConfs)
806 

◆ createSequences()

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

Definition at line 693 of file MenuComponents.py.

693  def createSequences(self):
694  """ creation of this step sequences with instantiation of the CAs"""
695  log.debug("creating sequences for step %s", self.name)
696  for seq in self.sequenceGens:
697  self.sequences.append(seq()) # create the sequences
698 

◆ getChainLegs()

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

Definition at line 807 of file MenuComponents.py.

807  def getChainLegs(self):
808  """ This is extrapolating the chain legs from the step dictionaries"""
809  legs = [part['chainName'] for part in self.stepDicts]
810  return legs
811 

◆ getChainNames()

def MenuComponents.ChainStep.getChainNames (   self)

Definition at line 812 of file MenuComponents.py.

812  def getChainNames(self):
813  if self.combo is not None:
814  return list(self.combo.getChains())
815  return self.getChainLegs()
816 

◆ getComboHypoFncName()

def MenuComponents.ChainStep.getComboHypoFncName (   self)

Definition at line 777 of file MenuComponents.py.

777  def getComboHypoFncName(self):
778  return self.comboHypoCfg.__name__ if isinstance(self.comboHypoCfg, types.FunctionType) else self.comboHypoCfg
779 
780 

◆ getLegIds()

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

Definition at line 757 of file MenuComponents.py.

757  def getLegIds(self):
758  """ get the gelId from the step dictionary for multi-leg chains"""
759  if len(self.multiplicity) <= 1: # single leg step
760  return [0]
761  leg_ids = []
762  for istep,step_dict in enumerate(self.stepDicts):
763  if step_dict['chainName'][0:3] != 'leg':
764  if self.onlyJets:
765  leg_ids += [istep]
766  else:
767  log.error("[getLegIds] chain %s has multiplicities %s but no legs? ",step_dict['chainName'], self.multiplicity)
768  raise Exception("[getLegIds] cannot extract leg IDs, exiting.")
769  else:
770  leg_ids += [int(step_dict['chainName'][3:6])]
771  return leg_ids
772 

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

781  def makeCombo(self):
782  """ Configure the Combo Hypo Alg and generate the corresponding function, without instantiation which is done in createSequences() """
783  self.combo = None
784  if self.isEmpty or self.comboHypoCfg is None:
785  return
786  comboNameFromStep = CFNaming.comboHypoName(self.name) # name expected from the step name
787  funcName = self.getComboHypoFncName() # name of the function generator
788  key = hash((comboNameFromStep, funcName))
789  if key not in _ComboHypoPool:
790  tmpCombo = ComboHypoNode(comboNameFromStep, self.comboHypoCfg)
791  CHname = tmpCombo.name[:-4] # remove 'Node'
792  # exceptions for BLS chains that re-use the same custom CH in differnt steps
793  # this breaks the run-one-CH-per-step, but the BLS CH are able to handle decisions internally
794  if comboNameFromStep != CHname:
795  log.debug("Created ComboHypo with name %s, expected from the step is instead %s. This is accepted only for allowed custom ComboHypos", CHname, comboNameFromStep)
796  _CustomComboHypoAllowed.add(CHname)
797  key = hash((CHname, funcName))
798  _ComboHypoPool[key] = tmpCombo
799  self.combo = _ComboHypoPool[key]
800  log.debug("Created combo %s with name %s, step comboName %s, key %s", funcName, self.combo.name, comboNameFromStep,key)
801 
802 

◆ relabelLegIdsForJets()

def MenuComponents.ChainStep.relabelLegIdsForJets (   self)

Definition at line 699 of file MenuComponents.py.

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

◆ setChainPartIndices()

def MenuComponents.ChainStep.setChainPartIndices (   self)

Definition at line 742 of file MenuComponents.py.

742  def setChainPartIndices(self):
743  leg_counter = 0
744  lists_of_chainPartNames = []
745  for step_dict in self.stepDicts:
746  if len(lists_of_chainPartNames) == 0:
747  lists_of_chainPartNames += [[cp['chainPartName'] for cp in step_dict['chainParts']]]
748  else:
749  new_list_of_chainPartNames = [cp['chainPartName'] for cp in step_dict['chainParts']]
750  if new_list_of_chainPartNames == lists_of_chainPartNames[-1]:
751  leg_counter -= len(new_list_of_chainPartNames)
752  for chainPart in step_dict['chainParts']:
753  chainPart['chainPartIndex'] = leg_counter
754  leg_counter += 1
755  return
756 

Member Data Documentation

◆ combo

MenuComponents.ChainStep.combo

Definition at line 783 of file MenuComponents.py.

◆ comboHypoCfg

MenuComponents.ChainStep.comboHypoCfg

Definition at line 648 of file MenuComponents.py.

◆ comboToolConfs

MenuComponents.ChainStep.comboToolConfs

Definition at line 649 of file MenuComponents.py.

◆ isEmpty

MenuComponents.ChainStep.isEmpty

Definition at line 652 of file MenuComponents.py.

◆ legIds

MenuComponents.ChainStep.legIds

Definition at line 690 of file MenuComponents.py.

◆ multiplicity

MenuComponents.ChainStep.multiplicity

Definition at line 654 of file MenuComponents.py.

◆ name

MenuComponents.ChainStep.name

Definition at line 645 of file MenuComponents.py.

◆ onlyJets

MenuComponents.ChainStep.onlyJets

Definition at line 672 of file MenuComponents.py.

◆ sequenceGens

MenuComponents.ChainStep.sequenceGens

Definition at line 647 of file MenuComponents.py.

◆ sequences

MenuComponents.ChainStep.sequences

Definition at line 646 of file MenuComponents.py.

◆ stepDicts

MenuComponents.ChainStep.stepDicts

Definition at line 650 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
python.TrigConfigSvcUtils.getChains
def getChains(connection, smk)
Definition: TrigConfigSvcUtils.py:592
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
python.LArMinBiasAlgConfig.int
int
Definition: LArMinBiasAlgConfig.py:59
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