ATLAS Offline Software
Functions | Variables
python.POOLtoHEPMC_Skeleton Namespace Reference

Functions

def fromRunArgs (runArgs)
 

Variables

 jobPropertiesDisallowed
 

Function Documentation

◆ fromRunArgs()

def python.POOLtoHEPMC_Skeleton.fromRunArgs (   runArgs)

Definition at line 18 of file POOLtoHEPMC_Skeleton.py.

18 def fromRunArgs(runArgs):
19  # Start the logger and identify ourselves
20  from AthenaCommon.Logging import logging
21  log = logging.getLogger('POOLtoHEPMC')
22  log.info('*** Starting POOLtoHEPMC translation ***')
23 
24  # Print some job information
25  log.info('*** Transformation run arguments ***')
26  log.info(str(runArgs))
27 
28  # Set up the flags we need
29  log.info('*** Setting-up configuration flags ***')
30  from AthenaConfiguration.AllConfigFlags import initConfigFlags
31  flags = initConfigFlags()
32  commonRunArgsToFlags(runArgs, flags)
33 
34  # Set ProductionStep
35  from AthenaConfiguration.Enums import ProductionStep
36  flags.Common.ProductionStep = ProductionStep.Derivation
37 
38  # Set the input file and configure the input collection key
39  if hasattr(runArgs, 'inputEVNTFile'):
40  flags.Input.Files = runArgs.inputEVNTFile
41  McEventKey = 'GEN_EVENT'
42  elif hasattr(runArgs, 'inputHITSFile'):
43  flags.Input.Files = runArgs.inputHITSFile
44  McEventKey = 'TruthEvent'
45  elif hasattr(runArgs, 'inputRDOFile'):
46  flags.Input.Files = runArgs.inputRDOFile
47  McEventKey = 'TruthEvent'
48  else:
49  log.error('Input EVNT, HITS, or RDO file required for POOLtoHEPMC')
50  # Set the output file
51  if hasattr(runArgs, 'outputHEPMCFile'):
52  if ('.tar' in runArgs.outputHEPMCFile):
53  index = re.search(".tar",runArgs.outputHEPMCFile).span()[0]
54  if hasattr(runArgs, 'extension') and ('events' in runArgs.extension):
55  my_output_HepMCFile = runArgs.outputHEPMCFile[:index]+'.events'
56  else:
57  my_output_HepMCFile = runArgs.outputHEPMCFile[:index]+'.hepmc'
58  else:
59  log.error('Output should be a tar.gz file but it is '+runArgs.outputHEPMCFile)
60  else:
61  log.error('OutputHEPMCFile required for POOLtoHEPMC')
62 
63  hepMCFormat = 'hepmc2'
64  if hasattr(runArgs, 'hepmcFormat'):
65  hepMCFormat = runArgs.hepmcFormat
66 
67  hepMCUnits = 'GEVMM'
68  if hasattr(runArgs, 'hepmcUnits'):
69  hepMCUnits = runArgs.hepmcUnits
70 
71  # Setup perfmon flags from runargs
72  from PerfMonComps.PerfMonConfigHelpers import setPerfmonFlagsFromRunArgs
73  setPerfmonFlagsFromRunArgs(flags, runArgs)
74 
75  # Pre-include
76  processPreInclude(runArgs, flags)
77 
78  # Pre-exec
79  processPreExec(runArgs, flags)
80 
81  # To respect --athenaopts
82  flags.fillFromArgs()
83 
84  # Lock flags
85  flags.lock()
86 
87  # Do the configuration of the main services
88  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
89  cfg = MainServicesCfg(flags)
90 
91  # Set us up for reading a POOL file
92  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
93  cfg.merge(PoolReadCfg(flags))
94 
95  # We need the component factory to build the job up
96  from AthenaConfiguration.ComponentFactory import CompFactory
97 
98  # Add FixHepMC to remove loops here
99  # This is a work-around for AGENE-2342, which needs a HepMC patch to fix
100  cfg.addEventAlgo(CompFactory.FixHepMC("FixHepMC"))
101 
102  # Use the WriteHepMC AlgTool from TruthIO to do the conversion
103  cfg.addEventAlgo( CompFactory.WriteHepMC( 'WriteHepMC',
104  OutputFile = my_output_HepMCFile,
105  Format = hepMCFormat,
106  Units = hepMCUnits,
107  McEventKey = McEventKey ) )
108  # Here one should set the output format
109  # Post-include
110  processPostInclude(runArgs, flags, cfg)
111 
112  # Post-exec
113  processPostExec(runArgs, flags, cfg)
114 
115  import time
116  tic = time.time()
117 
118  # Run the final accumulator
119  sc = cfg.run()
120 
121  # Compress the output file
122  log.info('Compressing HEPMC output (may take a moment)')
123  import tarfile
124  with tarfile.open(runArgs.outputHEPMCFile,'w:gz') as out_tar:
125  out_tar.add( my_output_HepMCFile )
126 
127  # And remove the uncompressed version
128  log.debug('Deleting original (uncompressed) file')
129  import os
130  os.remove( my_output_HepMCFile )
131 
132  # All done, now just report back
133  log.info("Ran POOLtoHEPMC in " + str(time.time()-tic) + " seconds")
134 
135  sys.exit(not sc.isSuccess())
136 

Variable Documentation

◆ jobPropertiesDisallowed

python.POOLtoHEPMC_Skeleton.jobPropertiesDisallowed

Definition at line 16 of file POOLtoHEPMC_Skeleton.py.

CxxUtils::span
span(T *ptr, std::size_t sz) -> span< T >
A couple needed deduction guides.
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.POOLtoHEPMC_Skeleton.fromRunArgs
def fromRunArgs(runArgs)
Definition: POOLtoHEPMC_Skeleton.py:18
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:312
python.CommonRunArgsToFlags.commonRunArgsToFlags
def commonRunArgsToFlags(runArgs, configFlags)
Definition: CommonRunArgsToFlags.py:12
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
str
Definition: BTagTrackIpAccessor.cxx:11
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:71