ATLAS Offline Software
TestBeam_Skeleton.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 import sys
4 from PyJobTransforms.CommonRunArgsToFlags import commonRunArgsToFlags
5 from PyJobTransforms.TransformUtils import processPreExec, processPreInclude, processPostExec, processPostInclude
6 from SimuJobTransforms.CommonSimulationSteering import CommonSimulationCfg, specialConfigPreInclude, specialConfigPostInclude
7 
8 # force no legacy job properties
9 from AthenaCommon import JobProperties
10 JobProperties.jobPropertiesDisallowed = True
11 
12 
13 def fromRunArgs(runArgs):
14  from AthenaCommon.Logging import logging
15  log = logging.getLogger('TeamBeam')
16  log.info('****************** STARTING ATLASG4 Test Beam *****************')
17 
18  log.info('**** Transformation run arguments')
19  log.info(str(runArgs))
20 
21  log.info('**** Setting-up configuration flags')
22  from AthenaConfiguration.AllConfigFlags import initConfigFlags
23  from AthenaConfiguration.Enums import BeamType
24  from SimulationConfig.SimEnums import SimulationFlavour
25  flags = initConfigFlags()
26  commonRunArgsToFlags(runArgs, flags)
27 
28  if not hasattr(runArgs, 'geometryVersion'):
29  log.info('no geometryVersion specified, so assuming tb_Tile2000_2003_5B')
30  flags.GeoModel.AtlasVersion = "ATLAS-CTB-01" # 'tb_Tile2000_2003_5B' # "ctbh8"
31 
32  # Set ProductionStep
33  from AthenaConfiguration.Enums import ProductionStep
34  flags.Common.ProductionStep = ProductionStep.Simulation
35  # Set BeamType
36  flags.Beam.Type = BeamType.TestBeam
37  # Set Default ParticleGun configuration
38  flags.Sim.GenerationConfiguration="ParticleGun.ParticleGunConfig.ParticleGun_TestBeam_SingleParticleCfg"
39  flags.IOVDb.DatabaseInstance = "TMCP200"
40  # Set the simulator
41  flags.Sim.ISF.Simulator = SimulationFlavour.AtlasG4
42 
43  # This is not ISF
44  flags.Sim.ISFRun = False
45 
46  # Generate detector list
47  detectors = set()
48  detectors.add('Tile')
49 
50  # Setup input: Three possible cases:
51  # 1) inputEVNTFile (normal)
52  # 2) inputEVNT_TRFile (TrackRecords from pre-simulated events,
53  # used with TrackRecordGenerator)
54  # 3) no input file (on-the-fly generation - typically ParticleGun
55  # or CosmicGenerator)
56  if hasattr(runArgs, 'inputEVNTFile'):
57  flags.Input.Files = runArgs.inputEVNTFile
58  else:
59  # Common cases
60  # 3a) ParticleGun
61  flags.Input.Files = []
62  flags.Input.isMC = True
63  log.info('No inputEVNTFile provided. Assuming that you are running a generator on the fly.')
64  if hasattr(runArgs, 'outputHITSFile'):
65  if runArgs.outputHITSFile == 'None':
66  flags.Output.HITSFileName = ''
67  else:
68  flags.Output.HITSFileName = runArgs.outputHITSFile
69  else:
70  raise RuntimeError('No outputHITSFile defined')
71 
72  if hasattr(runArgs, 'conditionsTag'):
73  flags.IOVDb.GlobalTag = runArgs.conditionsTag
74 
75  # Setup detector flags
76  from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags
77  setupDetectorFlags(flags, detectors, toggle_geometry=True)
78 
79  # Setup perfmon flags from runargs
80  from PerfMonComps.PerfMonConfigHelpers import setPerfmonFlagsFromRunArgs
81  setPerfmonFlagsFromRunArgs(flags, runArgs)
82 
83  # Pre-include
84  processPreInclude(runArgs, flags)
85 
86  # Special Configuration preInclude
88 
89  # Pre-exec
90  processPreExec(runArgs, flags)
91 
92  # Common simulation runtime arguments
93  from SimulationConfig.SimConfigFlags import simulationRunArgsToFlags
94  simulationRunArgsToFlags(runArgs, flags)
95 
96  # Common simulation runtime arguments
97  from SimulationConfig.TestBeamConfigFlags import testBeamRunArgsToFlags
98  testBeamRunArgsToFlags(runArgs, flags)
99 
100  # To respect --athenaopts
101  flags.fillFromArgs()
102 
103  # Lock flags
104  flags.lock()
105 
106  cfg = CommonSimulationCfg(flags, log)
107 
108  # Special Configuration postInclude
109  specialConfigPostInclude(flags, cfg)
110 
111  # Post-include
112  processPostInclude(runArgs, flags, cfg)
113 
114  # Post-exec
115  processPostExec(runArgs, flags, cfg)
116 
117  # Write AMI tag into in-file metadata
118  from PyUtils.AMITagHelperConfig import AMITagCfg
119  cfg.merge(AMITagCfg(flags, runArgs))
120 
121  import time
122  tic = time.time()
123  # Run the final accumulator
124  sc = cfg.run()
125  log.info("Run G4AtlasAlg in " + str(time.time()-tic) + " seconds")
126 
127  sys.exit(not sc.isSuccess())
python.TransformUtils.processPreExec
def processPreExec(runArgs, flags)
Definition: Tools/PyJobTransforms/python/TransformUtils.py:41
python.TransformUtils.processPostExec
def processPostExec(runArgs, flags, cfg)
Definition: Tools/PyJobTransforms/python/TransformUtils.py:50
python.CommonSimulationSteering.CommonSimulationCfg
def CommonSimulationCfg(flags, log)
Definition: CommonSimulationSteering.py:35
python.TransformUtils.processPostInclude
def processPostInclude(runArgs, flags, cfg)
Definition: Tools/PyJobTransforms/python/TransformUtils.py:69
python.TransformUtils.processPreInclude
def processPreInclude(runArgs, flags)
Definition: Tools/PyJobTransforms/python/TransformUtils.py:62
python.CommonSimulationSteering.specialConfigPostInclude
def specialConfigPostInclude(flags, cfg)
Definition: CommonSimulationSteering.py:29
python.PerfMonConfigHelpers.setPerfmonFlagsFromRunArgs
def setPerfmonFlagsFromRunArgs(flags, runArgs)
Definition: PerfMonConfigHelpers.py:3
python.TestBeamConfigFlags.testBeamRunArgsToFlags
def testBeamRunArgsToFlags(runArgs, flags)
Definition: TestBeamConfigFlags.py:24
python.CommonRunArgsToFlags.commonRunArgsToFlags
def commonRunArgsToFlags(runArgs, configFlags)
Definition: CommonRunArgsToFlags.py:12
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.DetectorConfigFlags.setupDetectorFlags
def setupDetectorFlags(flags, custom_list=None, use_metadata=False, toggle_geometry=False, validate_only=False, keep_beampipe=False)
Definition: DetectorConfigFlags.py:289
python.SimConfigFlags.simulationRunArgsToFlags
def simulationRunArgsToFlags(runArgs, flags)
Definition: SimConfigFlags.py:267
python.CommonSimulationSteering.specialConfigPreInclude
def specialConfigPreInclude(flags)
Definition: CommonSimulationSteering.py:23
python.AMITagHelperConfig.AMITagCfg
def AMITagCfg(flags, runArgs=None, fixBroken=False)
Definition: AMITagHelperConfig.py:77
python.TestBeam_Skeleton.fromRunArgs
def fromRunArgs(runArgs)
Definition: TestBeam_Skeleton.py:13
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
str
Definition: BTagTrackIpAccessor.cxx:11