ATLAS Offline Software
runHLT.py
Go to the documentation of this file.
1 #!/usr/bin/env athena.py
2 # Copyright (C) 2002-2024 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.Trigger.EDMVersion = 3 # Run-3 EDM
37  flags.Beam.Type = BeamType.Collisions
38  flags.InDet.useDCS = False # DCS is in general not available online
39  flags.Muon.MuonTrigger = True # Setup muon reconstruction for trigger
40 
41  # Disable some forward detetors
42  flags.Detector.GeometryALFA = False
43  flags.Detector.GeometryFwdRegion = False
44  flags.Detector.GeometryLucid = False
45 
46  # Increase scheduler checks and verbosity
47  flags.Scheduler.CheckDependencies = True
48  flags.Scheduler.EnableVerboseViews = True
49  flags.Input.FailOnUnknownCollections = True
50  flags.Scheduler.AutoLoadUnmetDependencies = False
51 
52 
53 def runHLTCfg(flags):
54  """Main function to configure the HLT in athena and athenaHLT"""
55  from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
56  from AthenaCommon.Logging import logging
57 
58  log = logging.getLogger('runHLT')
59  cfg = ComponentAccumulator()
60 
61  # Load these objects from StoreGate
62  loadFromSG = [('xAOD::EventInfo', 'StoreGateSvc+EventInfo'),
63  ('TrigConf::L1Menu','DetectorStore+L1TriggerMenu'),
64  ('TrigConf::HLTMenu','DetectorStore+HLTTriggerMenu')]
65 
66  from SGComps.SGInputLoaderConfig import SGInputLoaderCfg
67  cfg.merge(SGInputLoaderCfg(flags, loadFromSG))
68 
69  from TriggerJobOpts.TriggerHistSvcConfig import TriggerHistSvcConfig
70  cfg.merge(TriggerHistSvcConfig(flags))
71 
72  # Menu
73  from TriggerMenuMT.HLT.Config.GenerateMenuMT import generateMenuMT
74  from TriggerJobOpts.TriggerConfig import triggerRunCfg
75  menu = triggerRunCfg(flags, menu=generateMenuMT)
76  cfg.merge(menu)
77 
78  from LumiBlockComps.LumiBlockMuWriterConfig import LumiBlockMuWriterCfg
79  cfg.merge(LumiBlockMuWriterCfg(flags), sequenceName="HLTBeginSeq")
80 
81  if flags.Trigger.doTransientByteStream and flags.Trigger.doCalo:
82  from TriggerJobOpts.TriggerTransBSConfig import triggerTransBSCfg_Calo
83  cfg.merge(triggerTransBSCfg_Calo(flags), sequenceName="HLTBeginSeq")
84 
85  # L1 simulation
86  if flags.Trigger.doLVL1:
87  from TriggerJobOpts.Lvl1SimulationConfig import Lvl1SimulationCfg
88  cfg.merge(Lvl1SimulationCfg(flags), sequenceName="HLTBeginSeq")
89 
90  # Track overlay needs this to ensure that the collections are copied correctly
91  # (due to the hardcoding of the name in the converters)
92  if flags.Overlay.doTrackOverlay:
93  from TrkEventCnvTools.TrkEventCnvToolsConfig import TrkEventCnvSuperToolCfg
94  cfg.merge(TrkEventCnvSuperToolCfg(flags))
95 
96  if flags.Common.isOnline:
97  from TrigOnlineMonitor.TrigOnlineMonitorConfig import trigOpMonitorCfg
98  cfg.merge( trigOpMonitorCfg(flags) )
99 
100  # Print config and statistics
101  if log.getEffectiveLevel() <= logging.DEBUG:
102  cfg.printConfig(withDetails=False, summariseProps=True, printDefaults=True)
103 
104  # Disable spurious warnings from HepMcParticleLink (ATR-21838)
105  if flags.Input.isMC:
106  cfg.addService(CompFactory.MessageSvc(setError=["HepMcParticleLink"]))
107 
108  from AthenaConfiguration.AccumulatorCache import AccumulatorDecorator
109  AccumulatorDecorator.printStats()
110 
111  return cfg
112 
113 
114 def athenaHLTCfg(flags):
115  """Top-level cfg function when running in athenaHLT"""
116 
117  # Set default flags for running HLT
118  set_flags(flags)
119 
120  # Decoding the flags from the command line is already done in athenaHLT.
121  # But we have to do it again in case some of the flags from set_flags
122  # get overwritten by the user.
123  from TrigPSC import PscConfig
124  for flag_arg in PscConfig.unparsedArguments:
125  flags.fillFromString(flag_arg)
126 
127  # Lock flags
128  lock_and_restrict(flags)
129 
130  # Configure HLT
131  cfg = runHLTCfg(flags)
132  return cfg
133 
134 
135 def athenaCfg(flags, parser=None):
136  """Top-level cfg function when running in athena"""
137  from AthenaConfiguration.Enums import Format
138 
139  # Set default flags for running HLT
140  set_flags(flags)
141 
142  # To allow running from MC
143  flags.Common.isOnline = lambda f: not f.Input.isMC
144 
145  # Add options to command line parser
146  if not parser:
147  parser = flags.getArgumentParser()
148  parser.add_argument('--postExec', metavar='CMD',
149  help='Commands executed after Python configuration')
150 
151  # Fill flags from command line
152  args = flags.fillFromArgs(parser=parser)
153 
154  if flags.Trigger.writeBS:
155  flags.Output.doWriteBS = True
156  else: # RDO writing is default in athena
157  flags.Output.doWriteRDO = True
158  if not flags.Output.RDOFileName:
159  flags.Output.RDOFileName = 'RDO_TRIG.pool.root'
160 
161  # Enable verbose control/data flow printouts if in a
162  # restricted menu, typical for debugging
163  if flags.Trigger.selectChains or len(flags.Trigger.enabledSignatures)==1:
164  flags.Scheduler.ShowControlFlow = True
165  flags.Scheduler.ShowDataDeps = True
166 
167  # Configure main services
168  _allflags = flags.clone() # copy including Concurrency flags
169  _allflags.lock()
170  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
171  cfg = MainServicesCfg(_allflags)
172  del _allflags
173 
174  # Lock flags
175  lock_and_restrict(flags)
176 
177  if flags.Input.Format is Format.BS:
178  from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
179  cfg.merge(ByteStreamReadCfg(flags))
180  else:
181  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
182  cfg.merge(PoolReadCfg(flags))
183 
184  # Configure HLT
185  cfg.merge(runHLTCfg(flags))
186 
187  if args.postExec:
188  exec(args.postExec)
189 
190  # Apply flags.Exec.XXXMessageComponents logic to configured job
191  from AthenaConfiguration.Utils import setupLoggingLevels
192  setupLoggingLevels(flags, cfg)
193 
194  return cfg
195 
196 
197 def main(flags):
198  """This method is called by athenaHLT (with pre-populated flags)"""
199  return athenaHLTCfg(flags)
200 
201 
202 # This entry point is only used when running in athena
203 if __name__ == "__main__":
204  from AthenaConfiguration.AllConfigFlags import initConfigFlags
205  flags = initConfigFlags()
206 
207  import sys
208  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:46
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:114
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:197
python.runHLT.athenaCfg
def athenaCfg(flags, parser=None)
Definition: runHLT.py:135
python.TriggerConfig.triggerRunCfg
def triggerRunCfg(flags, menu=None)
Definition: TriggerConfig.py:618
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.runHLT.runHLTCfg
def runHLTCfg(flags)
Definition: runHLT.py:53
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69
python.TriggerTransBSConfig.triggerTransBSCfg_Calo
def triggerTransBSCfg_Calo(flags, seqName="AthAlgSeq")
Definition: TriggerTransBSConfig.py:83