ATLAS Offline Software
MenuPrescaleConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 
3 import itertools, importlib, re
4 
5 from AthenaCommon.Logging import logging
6 log = logging.getLogger( __name__ )
7 
8 
9 def MenuPrescaleConfig(hltMenuConfig, flags):
10  L1Prescales = {}
11  HLTPrescales = {}
12  chains = {}
13  Prescales = PrescaleClass()
14 
15  menu_name = flags.Trigger.triggerMenuSetup
16 
17  log.info('Menu name: %s', menu_name)
18 
19  # Generate the list of chains from the basic menu (terminates in a version number)
20  base_menu_name = re.match(r'\w*_v\d*',menu_name).group(0)
21  try:
22  menu_module = importlib.import_module(f'TriggerMenuMT.HLT.Menu.{base_menu_name}')
23  except Exception as e:
24  log.fatal(f'Failed to import menu module "{base_menu_name}" inferred from menu "{menu_name}"!')
25  raise e
26  chains = menu_module.setupMenu()
27 
28  # Determine prescale sets from the remainder of the menu name
29  # These filters become progressively less inclusive:
30  # - Primary: primary (always unprescaled) triggers only
31  # - BulkMCProd: triggers for generic CP and physics analysis work (veto label PS:NoBulkMCProd)
32  # - TriggerValidation: adds more specialised triggers for trigger performance
33  # and/or CP studies, possibly run heavily prescaled in data (veto label PS:NoTrigVal)
34  # - HLTReprocessing: excludes a handful of triggers not to be
35  # used in reprocessing jobs, mostly due to CPU cost (veto label PS:NoHLTRepro)
36  #
37  # Besides the filter, explicit prescale values may also be set for specific triggers
38  # -- see the end of the file for these mappings, which should not overlap with the
39  # disabled triggers (else they will be overwritten)
40  if 'Primary_prescale' in menu_name:
41  filterChains(chains, Prescales.HLTPrescales_primary_prescale,
42  ['Primary:L1Muon','Primary:Legacy','Primary:PhaseI','Primary:CostAndRate',
43  'Support:TagAndProbe','Support:LegacyTagAndProbe','Support:PhaseITagAndProbe'],
44  invert = True) # enable these groups
45  L1Prescales = Prescales.L1Prescales_primary_prescale
46  HLTPrescales = Prescales.HLTPrescales_primary_prescale
47  elif 'BulkMCProd_prescale' in menu_name:
48  assert(menu_name.startswith('Dev') or menu_name.startswith('MC'))
49  filterChains(chains, Prescales.HLTPrescales_bulkmcprod_prescale, ["PS:NoHLTRepro","PS:NoTrigVal","PS:NoBulkMCProd"])
50  L1Prescales = Prescales.L1Prescales_bulkmcprod_prescale
51  HLTPrescales = Prescales.HLTPrescales_bulkmcprod_prescale
52  elif 'TriggerValidation_prescale' in menu_name:
53  filterChains(chains, Prescales.HLTPrescales_trigvalid_prescale, ["PS:NoHLTRepro","PS:NoTrigVal"])
54  L1Prescales = Prescales.L1Prescales_trigvalid_prescale
55  HLTPrescales = Prescales.HLTPrescales_trigvalid_prescale
56  elif 'HLTReprocessing_prescale' in menu_name:
57  filterChains(chains, Prescales.HLTPrescales_HLTRepro_prescale, ["PS:NoHLTRepro"])
58  L1Prescales = Prescales.L1Prescales_HLTRepro_prescale
59  HLTPrescales = Prescales.HLTPrescales_HLTRepro_prescale
60  elif 'prescale' in menu_name:
61  log.error(f'Unknown menu prescale set for menu {menu_name}!')
62  raise RuntimeError('Unknown menu prescale set')
63  else:
64  L1Prescales = Prescales.L1Prescales
65  HLTPrescales = Prescales.HLTPrescales
66 
67  return (L1Prescales, HLTPrescales, chains)
68 
69 
70 def filterChains(chains, type_prescales, type_groups, invert=False):
71  """Disable(enable if invert==True) chains with groups matching type_groups"""
72 
73  def match(s1, s2): return not s1.isdisjoint(s2)
74 
75  # Loop over all chains in all signatures and find chains to enable/disable
76  chain_disable_list = [ch.name for ch in itertools.chain.from_iterable(chains.values())
77  if match(set(type_groups), ch.groups) ^ invert ]
78 
79  type_prescales.update(itertools.zip_longest(chain_disable_list, [], fillvalue=-1))
80 
81 
82 def applyHLTPrescale(triggerPythonConfig, HLTPrescale, ignoreUnknownChains=False):
83  for item, prescale in HLTPrescale.items():
84  if item not in triggerPythonConfig.dicts().keys():
85  if ignoreUnknownChains:
86  log.warning('Attempt to set prescales for nonexisting chain: %s', item)
87  continue
88  else:
89  log.error('Attempt to set prescales for nonexisting chain: %s', item)
90  continue
91  hltchain = triggerPythonConfig.dicts()[item]
92  hltchain['prescale'] = prescale
93  log.info('Applied HLTPS to the item %s: PS %s', item, hltchain['prescale'])
94 
96  # Item name | Prescale
97  #----------------------------------------------------------
98  L1Prescales = {}
99  L1Prescales = dict([(ctpid,1) for ctpid in L1Prescales]) # setting all L1 prescales to 1 # NOT DOING ANYTHING ATM
100 
101  # Item name | HLTprescale
102  # - Chains only need adding if have a Prescale value different from 1 (default)
103  #----------------------------------------------------------
104  HLTPrescales = {}
105 
106  L1Prescales_primary_prescale = {}
107  HLTPrescales_primary_prescale = {}
108 
109  L1Prescales_trigvalid_prescale = {}
110  HLTPrescales_trigvalid_prescale = {}
111 
112  L1Prescales_bulkmcprod_prescale = {}
113  HLTPrescales_bulkmcprod_prescale = {}
114 
115  # PS for reprocessing and related ART tests
116  # Avoid high CPU usage for low-mu triggers
117  # mainly to be used for 900 GeV, or other triggers
118  # that should normally run with prescales in standard pp
119  L1Prescales_HLTRepro_prescale = {}
120  HLTPrescales_HLTRepro_prescale = {
121  'HLT_cosmic_id_L1MU3V_EMPTY': 10,
122  'HLT_cosmic_id_L1MU8VF_EMPTY': 10,
123  }
124 
125  chain_list=[]
python.HLT.Menu.MenuPrescaleConfig.PrescaleClass
Definition: MenuPrescaleConfig.py:95
python.HLT.Menu.MenuPrescaleConfig.filterChains
def filterChains(chains, type_prescales, type_groups, invert=False)
Definition: MenuPrescaleConfig.py:70
python.HLT.Menu.MenuPrescaleConfig.applyHLTPrescale
def applyHLTPrescale(triggerPythonConfig, HLTPrescale, ignoreUnknownChains=False)
Definition: MenuPrescaleConfig.py:82
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
python.HLT.Menu.MenuPrescaleConfig.MenuPrescaleConfig
def MenuPrescaleConfig(hltMenuConfig, flags)
Definition: MenuPrescaleConfig.py:9
CaloLCW_tf.group
group
Definition: CaloLCW_tf.py:28
pickleTool.object
object
Definition: pickleTool.py:30
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356