10 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
12 flags.addFlag(
'Output.HepMCFileName',
'events.hepmc',help=
'Name of the output HepMC file; files with .tgz, .gz, or .tar.gz extensions will be compressed')
16 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
17 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
21 McEventKey =
'GEN_EVENT'
22 if 'McEventCollection#GEN_EVENT' not in flags.Input.TypedCollections:
23 if 'McEventCollection#TruthEvent' in flags.Input.TypedCollections:
24 McEventKey =
'TruthEvent'
26 print(
'Truth collection not found in input file. Might be a problem.')
29 from AthenaConfiguration.ComponentFactory
import CompFactory
33 cfg.addEventAlgo(CompFactory.FixHepMC(
"FixHepMC"))
36 events_filename = flags.Output.HepMCFileName.replace(
'.tgz',
'').
replace(
'.tar',
'').
replace(
'.gz',
'')
39 cfg.addEventAlgo( CompFactory.WriteHepMC(
'WriteHepMC',
40 OutputFile = events_filename,
41 McEventKey = McEventKey ) )
42 cfg.run(flags.Exec.MaxEvents)
45 if '.tgz' in flags.Output.HepMCFileName
or '.tar.gz' in flags.Output.HepMCFileName:
46 print(
'Compressing output into tar+gz format (this may take a moment)')
48 tar = tarfile.open(flags.Output.HepMCFileName,
'w:gz')
49 tar.add(events_filename)
53 os.remove(events_filename)
54 elif '.gz' in flags.Output.HepMCFileName:
55 print(
'Compressing output into gz format (this may take a moment)')
58 with open(events_filename,
'rb')
as in_file, gzip.open(flags.Output.HepMCFileName,
'wb')
as out_file:
59 shutil.copyfileobj(in_file,out_file)
62 os.remove(events_filename)