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):
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  parser = flags.getArgumentParser()
147  parser.add_argument('--postExec', metavar='CMD',
148  help='Commands executed after Python configuration')
149 
150  # Fill flags from command line
151  args = flags.fillFromArgs(parser=parser)
152 
153  if flags.Trigger.writeBS:
154  flags.Output.doWriteBS = True
155  else: # RDO writing is default in athena
156  flags.Output.doWriteRDO = True
157  if not flags.Output.RDOFileName:
158  flags.Output.RDOFileName = 'RDO_TRIG.pool.root'
159 
160  # Enable verbose control/data flow printouts if in a
161  # restricted menu, typical for debugging
162  if flags.Trigger.selectChains or len(flags.Trigger.enabledSignatures)==1:
163  flags.Scheduler.ShowControlFlow = True
164  flags.Scheduler.ShowDataDeps = True
165 
166  # Configure main services
167  _allflags = flags.clone() # copy including Concurrency flags
168  _allflags.lock()
169  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
170  cfg = MainServicesCfg(_allflags)
171  del _allflags
172 
173  # Lock flags
174  lock_and_restrict(flags)
175 
176  if flags.Input.Format is Format.BS:
177  from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
178  cfg.merge(ByteStreamReadCfg(flags))
179  else:
180  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
181  cfg.merge(PoolReadCfg(flags))
182 
183  # Configure HLT
184  cfg.merge(runHLTCfg(flags))
185 
186  if args.postExec:
187  exec(args.postExec)
188 
189  # Apply flags.Exec.XXXMessageComponents logic to configured job
190  from AthenaConfiguration.Utils import setupLoggingLevels
191  setupLoggingLevels(flags, cfg)
192 
193  return cfg
194 
195 
196 def main(flags):
197  """This method is called by athenaHLT (with pre-populated flags)"""
198  return athenaHLTCfg(flags)
199 
200 
201 # This entry point is only used when running in athena
202 if __name__ == "__main__":
203  from AthenaConfiguration.AllConfigFlags import initConfigFlags
204  flags = initConfigFlags()
205 
206  import sys
207  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.runHLT.athenaCfg
def athenaCfg(flags)
Definition: runHLT.py:135
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:256
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:196
python.TriggerConfig.triggerRunCfg
def triggerRunCfg(flags, menu=None)
Definition: TriggerConfig.py:611
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