ATLAS Offline Software
EVNTtoHEPMC_Skeleton.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 # Job transform version of converting an EVNT file into a HEPMC file
3 
4 # For the exit code at the end
5 import sys
6 
7 # For translating the run arguments into flags
8 from PyJobTransforms.CommonRunArgsToFlags import commonRunArgsToFlags
9 
10 # For using pre include, pre-exec, etc; should only rarely be needed
11 from PyJobTransforms.TransformUtils import processPreExec, processPreInclude, processPostExec, processPostInclude
12 
13 # Force no legacy job properties
14 from AthenaCommon import JobProperties
15 JobProperties.jobPropertiesDisallowed = True
16 
17 def fromRunArgs(runArgs):
18  # Start the logger and identify ourselves
19  from AthenaCommon.Logging import logging
20  log = logging.getLogger('EVNTtoHEPMC')
21  log.info('*** Starting EVNTtoHEPMC translation ***')
22 
23  # Print some job information
24  log.info('*** Transformation run arguments ***')
25  log.info(str(runArgs))
26 
27  # Set up the flags we need
28  log.info('*** Setting-up configuration flags ***')
29  from AthenaConfiguration.AllConfigFlags import initConfigFlags
30  flags = initConfigFlags()
31  commonRunArgsToFlags(runArgs, flags)
32 
33  # Set ProductionStep
34  from AthenaConfiguration.Enums import ProductionStep
35  flags.Common.ProductionStep = ProductionStep.Derivation
36 
37  # Set the input file
38  if hasattr(runArgs, 'inputEVNTFile'):
39  flags.Input.Files = runArgs.inputEVNTFile
40  else:
41  log.error('Input EVNT file required for EVNTtoHEPMC')
42 
43  # Set the output file
44  if hasattr(runArgs, 'outputEvtFile'):
45  my_output_HepMCFile = runArgs.outputEvtFile
46  else:
47  log.error('Output Evt file (HepMC) required for EVNTtoHEPMC')
48 
49  # Setup perfmon flags from runargs
50  from PerfMonComps.PerfMonConfigHelpers import setPerfmonFlagsFromRunArgs
51  setPerfmonFlagsFromRunArgs(flags, runArgs)
52 
53  # Pre-include
54  processPreInclude(runArgs, flags)
55 
56  # Pre-exec
57  processPreExec(runArgs, flags)
58 
59  # To respect --athenaopts
60  flags.fillFromArgs()
61 
62  # Lock flags
63  flags.lock()
64 
65  # Do the configuration of the main services
66  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
67  cfg = MainServicesCfg(flags)
68 
69  # Set us up for reading a POOL file
70  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
71  cfg.merge(PoolReadCfg(flags))
72 
73  # Use the WriteHepMC AlgTool from TruthIO to do the conversion
74  from AthenaConfiguration.ComponentFactory import CompFactory
75  cfg.addEventAlgo( CompFactory.WriteHepMC( 'WriteHepMC',
76  OutputFile = my_output_HepMCFile ) )
77 
78  # Post-include
79  processPostInclude(runArgs, flags, cfg)
80 
81  # Post-exec
82  processPostExec(runArgs, flags, cfg)
83 
84  import time
85  tic = time.time()
86 
87  # Run the final accumulator
88  sc = cfg.run()
89  log.info("Ran EVNTtoHEPMC in " + str(time.time()-tic) + " seconds")
90 
91  sys.exit(not sc.isSuccess())
92 
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.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.PerfMonConfigHelpers.setPerfmonFlagsFromRunArgs
def setPerfmonFlagsFromRunArgs(flags, runArgs)
Definition: PerfMonConfigHelpers.py:3
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
python.CommonRunArgsToFlags.commonRunArgsToFlags
def commonRunArgsToFlags(runArgs, configFlags)
Definition: CommonRunArgsToFlags.py:12
python.EVNTtoHEPMC_Skeleton.fromRunArgs
def fromRunArgs(runArgs)
Definition: EVNTtoHEPMC_Skeleton.py:17
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
str
Definition: BTagTrackIpAccessor.cxx:11
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69