3 import itertools, importlib, re
5 from AthenaCommon.Logging
import logging
6 log = logging.getLogger( __name__ )
15 menu_name = flags.Trigger.triggerMenuSetup
17 log.info(
'Menu name: %s', menu_name)
20 base_menu_name = re.match(
r'\w*_v\d*',menu_name).
group(0)
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}"!')
26 chains = menu_module.setupMenu()
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'],
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')
64 L1Prescales = Prescales.L1Prescales
65 HLTPrescales = Prescales.HLTPrescales
67 return (L1Prescales, HLTPrescales, chains)
70 def filterChains(chains, type_prescales, type_groups, invert=False):
71 """Disable(enable if invert==True) chains with groups matching type_groups"""
73 def match(s1, s2):
return not s1.isdisjoint(s2)
76 chain_disable_list = [ch.name
for ch
in itertools.chain.from_iterable(chains.values())
77 if match(
set(type_groups), ch.groups) ^ invert ]
79 type_prescales.update(itertools.zip_longest(chain_disable_list, [], fillvalue=-1))
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)
89 log.error(
'Attempt to set prescales for nonexisting chain: %s', item)
91 hltchain = triggerPythonConfig.dicts()[item]
92 hltchain[
'prescale'] = prescale
93 log.info(
'Applied HLTPS to the item %s: PS %s', item, hltchain[
'prescale'])
99 L1Prescales = dict([(ctpid,1)
for ctpid
in L1Prescales])
106 L1Prescales_primary_prescale = {}
107 HLTPrescales_primary_prescale = {}
109 L1Prescales_trigvalid_prescale = {}
110 HLTPrescales_trigvalid_prescale = {}
112 L1Prescales_bulkmcprod_prescale = {}
113 HLTPrescales_bulkmcprod_prescale = {}
119 L1Prescales_HLTRepro_prescale = {}
120 HLTPrescales_HLTRepro_prescale = {
121 'HLT_cosmic_id_L1MU3V_EMPTY': 10,
122 'HLT_cosmic_id_L1MU8VF_EMPTY': 10,