Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
runHLT.py
Go to the documentation of this file.
1 #!/usr/bin/env athena.py
2 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 """
4 CA module to configure the (standalone) HLT for athena and athenaHLT.
5 There is a separate entry point for each application to tailor some
6 flags and services. All common code should go to runLTCfg(flags).
7 
8 Usage:
9  athena [options] TriggerJobOpts/runHLT.py [flags]
10  athenaHLT [options] TriggerJobOpts.runHLT [flags]
11 
12  python -m TriggerJobOpts.runHLT # not recommended (due to missing LD_PRELOADs)
13 """
14 
15 from AthenaConfiguration.ComponentFactory import CompFactory
16 
17 def lock_and_restrict(flags):
18  """Deny access to a few flags and lock"""
19 
20  def bomb(x):
21  raise RuntimeError("Concurrency flags cannot be used in the HLT to ensure "
22  "that the configuration is portable across different CPUs")
23 
24  flags.Concurrency.NumProcs = bomb
25  flags.Concurrency.NumThreads = bomb
26  flags.Concurrency.NumConcurrentEvents = bomb
27 
28  flags.lock()
29 
30 
31 def set_flags(flags):
32  """Set default flags for running HLT"""
33  from AthenaConfiguration.Enums import BeamType
34 
35  flags.Trigger.doHLT = True # needs to be set early as other flags depend on it
36  flags.Beam.Type = BeamType.Collisions
37  flags.InDet.useDCS = False # DCS is in general not available online
38  flags.Muon.MuonTrigger = True # Setup muon reconstruction for trigger
39 
40  # Disable some forward detetors
41  flags.Detector.GeometryALFA = False
42  flags.Detector.GeometryFwdRegion = False
43  flags.Detector.GeometryLucid = False
44 
45  # Increase scheduler checks and verbosity
46  flags.Scheduler.CheckDependencies = True
47  flags.Scheduler.EnableVerboseViews = True
48  flags.Input.FailOnUnknownCollections = True
49  flags.Scheduler.AutoLoadUnmetDependencies = False
50 
51 
52 def runHLTCfg(flags, checkMT=True):
53  """Main function to configure the HLT in athena and athenaHLT.
54 
55  checkMT: perform sanity check if we are running in MT mode
56  """
57 
58  from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
59  from AthenaCommon.Logging import logging
60 
61  log = logging.getLogger('runHLT')
62  cfg = ComponentAccumulator()
63 
64  # This needs to be conditional on checkMT because for the HLT use-case, we trapped the
65  # Concurrency flags and they cannot be accessed at this point anymore.
66  if checkMT and flags.Concurrency.NumThreads == 0:
67  raise RuntimeError("Trigger jobs must be run in multi-threaded mode. Use --threads=1 (or greater).")
68 
69  # Load these objects from StoreGate
70  loadFromSG = [('xAOD::EventInfo', 'StoreGateSvc+EventInfo'),
71  ('TrigConf::L1Menu','DetectorStore+L1TriggerMenu'),
72  ('TrigConf::HLTMenu','DetectorStore+HLTTriggerMenu')]
73 
74  from SGComps.SGInputLoaderConfig import SGInputLoaderCfg
75  cfg.merge(SGInputLoaderCfg(flags, loadFromSG))
76 
77  from TriggerJobOpts.TriggerHistSvcConfig import TriggerHistSvcConfig
78  cfg.merge(TriggerHistSvcConfig(flags))
79 
80  # Menu
81  from TriggerMenuMT.HLT.Config.GenerateMenuMT import generateMenuMT
82  from TriggerJobOpts.TriggerConfig import triggerRunCfg
83  menu = triggerRunCfg(flags, menu=generateMenuMT)
84  cfg.merge(menu)
85 
86  from LumiBlockComps.LumiBlockMuWriterConfig import LumiBlockMuWriterCfg
87  cfg.merge(LumiBlockMuWriterCfg(flags), sequenceName="HLTBeginSeq")
88 
89  if flags.Trigger.doTransientByteStream and flags.Trigger.doCalo:
90  from TriggerJobOpts.TriggerTransBSConfig import triggerTransBSCfg_Calo
91  cfg.merge(triggerTransBSCfg_Calo(flags), sequenceName="HLTBeginSeq")
92 
93  # L1 simulation
94  if flags.Trigger.doLVL1:
95  from TriggerJobOpts.Lvl1SimulationConfig import Lvl1SimulationCfg
96  cfg.merge(Lvl1SimulationCfg(flags), sequenceName="HLTBeginSeq")
97 
98  # Track overlay needs this to ensure that the collections are copied correctly
99  # (due to the hardcoding of the name in the converters)
100  if flags.Overlay.doTrackOverlay:
101  from TrkEventCnvTools.TrkEventCnvToolsConfig import TrkEventCnvSuperToolCfg
102  cfg.merge(TrkEventCnvSuperToolCfg(flags))
103 
104  if flags.Common.isOnline:
105  from TrigOnlineMonitor.TrigOnlineMonitorConfig import trigOpMonitorCfg
106  cfg.merge( trigOpMonitorCfg(flags) )
107 
108  # Print config and statistics
109  if log.getEffectiveLevel() <= logging.DEBUG:
110  cfg.printConfig(withDetails=False, summariseProps=True, printDefaults=True)
111 
112  # Disable spurious warnings from HepMcParticleLink (ATR-21838)
113  if flags.Input.isMC:
114  cfg.addService(CompFactory.MessageSvc(setError=["HepMcParticleLink"]))
115 
116  from AthenaConfiguration.AccumulatorCache import AccumulatorDecorator
117  AccumulatorDecorator.printStats()
118 
119  return cfg
120 
121 
122 def athenaHLTCfg(flags):
123  """Top-level cfg function when running in athenaHLT"""
124 
125  # Set default flags for running HLT
126  set_flags(flags)
127 
128  # Decoding the flags from the command line is already done in athenaHLT.
129  # But we have to do it again in case some of the flags from set_flags
130  # get overwritten by the user.
131  from TrigPSC import PscConfig
132  for flag_arg in PscConfig.unparsedArguments:
133  flags.fillFromString(flag_arg)
134 
135  # Lock flags
136  lock_and_restrict(flags)
137 
138  # Configure HLT (always runs in MT mode)
139  cfg = runHLTCfg(flags, checkMT=False)
140  return cfg
141 
142 
143 def athenaCfg(flags, parser=None):
144  """Top-level cfg function when running in athena"""
145  from AthenaConfiguration.Enums import Format
146 
147  # Set default flags for running HLT
148  set_flags(flags)
149 
150  # To allow running from MC
151  flags.Common.isOnline = lambda f: not f.Input.isMC
152 
153  # Add options to command line parser
154  if not parser:
155  parser = flags.getArgumentParser()
156  parser.add_argument('--postExec', metavar='CMD',
157  help='Commands executed after Python configuration')
158 
159  # Fill flags from command line
160  args = flags.fillFromArgs(parser=parser)
161 
162  if flags.Trigger.writeBS:
163  flags.Output.doWriteBS = True
164  else: # RDO writing is default in athena
165  flags.Output.doWriteRDO = True
166  if not flags.Output.RDOFileName:
167  flags.Output.RDOFileName = 'RDO_TRIG.pool.root'
168 
169  # Enable verbose control/data flow printouts if in a
170  # restricted menu, typical for debugging
171  if flags.Trigger.selectChains or len(flags.Trigger.enabledSignatures)==1:
172  flags.Scheduler.ShowControlFlow = True
173  flags.Scheduler.ShowDataDeps = True
174 
175  # Configure main services
176  _allflags = flags.clone() # copy including Concurrency flags
177  _allflags.lock()
178  if _allflags.Concurrency.NumThreads == 0:
179  raise RuntimeError("Trigger jobs must be run in multi-threaded mode. Use --threads=1 (or greater).")
180 
181  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
182  cfg = MainServicesCfg(_allflags)
183  del _allflags
184 
185  # Lock flags
186  lock_and_restrict(flags)
187 
188  if flags.Input.Format is Format.BS:
189  from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
190  cfg.merge(ByteStreamReadCfg(flags))
191  else:
192  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
193  cfg.merge(PoolReadCfg(flags))
194 
195  # Configure HLT
196  cfg.merge(runHLTCfg(flags, checkMT=False)) # MT check already done above
197 
198  if args.postExec:
199  exec(args.postExec)
200 
201  # Apply flags.Exec.XXXMessageComponents logic to configured job
202  from AthenaConfiguration.Utils import setupLoggingLevels
203  setupLoggingLevels(flags, cfg)
204 
205  return cfg
206 
207 
208 def main(flags):
209  """This method is called by athenaHLT (with pre-populated flags)"""
210  return athenaHLTCfg(flags)
211 
212 
213 # This entry point is only used when running in athena
214 if __name__ == "__main__":
215  from AthenaConfiguration.AllConfigFlags import initConfigFlags
216  flags = initConfigFlags()
217 
218  import sys
219  sys.exit(athenaCfg(flags).run().isFailure())
python.runHLT.lock_and_restrict
def lock_and_restrict(flags)
Definition: runHLT.py:17
python.runHLT.set_flags
def set_flags(flags)
Definition: runHLT.py:31
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.Lvl1SimulationConfig.Lvl1SimulationCfg
def Lvl1SimulationCfg(flags, seqName=None)
this function sets up the top L1 simulation sequence
Definition: Lvl1SimulationConfig.py:8
python.ByteStreamConfig.ByteStreamReadCfg
def ByteStreamReadCfg(flags, type_names=None)
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:25
python.LumiBlockMuWriterConfig.LumiBlockMuWriterCfg
def LumiBlockMuWriterCfg(flags, name='LumiBlockMuWriter', seqName="AthAlgSeq")
Definition: LumiBlockMuWriterConfig.py:14
python.Utils.setupLoggingLevels
def setupLoggingLevels(flags, ca)
Definition: Control/AthenaConfiguration/python/Utils.py:50
python.TrkEventCnvToolsConfig.TrkEventCnvSuperToolCfg
def TrkEventCnvSuperToolCfg(flags, name='EventCnvSuperTool', **kwargs)
Definition: TrkEventCnvToolsConfig.py:51
SGInputLoaderConfig.SGInputLoaderCfg
def SGInputLoaderCfg(flags, Load=None, **kwargs)
Definition: SGInputLoaderConfig.py:7
LArG4FSStartPointFilter.exec
exec
Definition: LArG4FSStartPointFilter.py:103
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
python.runHLT.athenaHLTCfg
def athenaHLTCfg(flags)
Definition: runHLT.py:122
python.TriggerHistSvcConfig.TriggerHistSvcConfig
def TriggerHistSvcConfig(flags)
Definition: TriggerHistSvcConfig.py:17
TrigOnlineMonitorConfig.trigOpMonitorCfg
def trigOpMonitorCfg(flags)
Definition: TrigOnlineMonitorConfig.py:8
run
Definition: run.py:1
python.runHLT.main
def main(flags)
Definition: runHLT.py:208
python.runHLT.athenaCfg
def athenaCfg(flags, parser=None)
Definition: runHLT.py:143
python.TriggerConfig.triggerRunCfg
def triggerRunCfg(flags, menu=None)
Definition: TriggerConfig.py:644
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.runHLT.runHLTCfg
def runHLTCfg(flags, checkMT=True)
Definition: runHLT.py:52
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69
python.TriggerTransBSConfig.triggerTransBSCfg_Calo
def triggerTransBSCfg_Calo(flags, seqName="AthAlgSeq")
Definition: TriggerTransBSConfig.py:83