ATLAS Offline Software
EVNTtoHEPMC.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 # Simple script for converting an EVNT file into a HEPMC file
5 
6 # Options: input and output file, and compression (tgz)
7 from AthenaConfiguration.AllConfigFlags import initConfigFlags
8 flags = initConfigFlags()
9 flags.addFlag('Output.HepMCFileName','events.hepmc',help='Name of the output HepMC file')
10 flags.addFlag('Output.CompressHepMC',False,help='Compress the output after Athena finishes')
11 flags.fillFromArgs()
12 flags.lock()
13 
14 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
15 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
16 cfg = MainServicesCfg(flags)
17 cfg.merge(PoolReadCfg(flags))
18 
19 # Use the WriteHepMC AlgTool from TruthIO to do the conversion
20 from AthenaConfiguration.ComponentFactory import CompFactory
21 cfg.addEventAlgo( CompFactory.WriteHepMC( 'WriteHepMC',
22  OutputFile = flags.Output.HepMCFileName.replace('.tgz','') ) )
23 
24 cfg.run(flags.Exec.MaxEvents)
25 
26 # In case we were asked to, compress the output
27 if flags.Output.CompressHepMC:
28  print('Compressing output (this may take a moment)')
29  import tarfile
30  final_name = flags.Output.HepMCFileName if '.tgz' in flags.Output.HepMCFileName else flags.Output.HepMCFileName+'.tgz'
31  tar = tarfile.open(final_name,'w:gz')
32  tar.add(flags.Output.HepMCFileName.replace('.tgz',''))
33  tar.close()
34  # Remove the original uncompressed file
35  import os
36  os.remove(flags.Output.HepMCFileName.replace('.tgz',''))
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69