20     from AthenaCommon.Logging 
import logging
 
   21     log = logging.getLogger(
'POOLtoHEPMC')
 
   22     log.info(
'*** Starting POOLtoHEPMC translation ***')
 
   25     log.info(
'*** Transformation run arguments ***')
 
   26     log.info(
str(runArgs))
 
   29     log.info(
'*** Setting-up configuration flags ***')
 
   30     from AthenaConfiguration.AllConfigFlags 
import initConfigFlags
 
   35     from AthenaConfiguration.Enums 
import ProductionStep
 
   36     flags.Common.ProductionStep = ProductionStep.Derivation
 
   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' 
   49         log.error(
'Input EVNT, HITS, or RDO file required for POOLtoHEPMC')
 
   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' 
   57                my_output_HepMCFile = runArgs.outputHEPMCFile[:index]+
'.hepmc' 
   59           log.error(
'Output should be a tar.gz file but it is '+runArgs.outputHEPMCFile)
 
   61         log.error(
'OutputHEPMCFile required for POOLtoHEPMC')
 
   63     hepMCFormat = 
'hepmc2' 
   64     if hasattr(runArgs, 
'hepmcFormat'):
 
   65        hepMCFormat = runArgs.hepmcFormat
 
   68     if hasattr(runArgs, 
'hepmcUnits'):
 
   69        hepMCUnits = runArgs.hepmcUnits
 
   72     from PerfMonComps.PerfMonConfigHelpers 
import setPerfmonFlagsFromRunArgs
 
   88     from AthenaConfiguration.MainServicesConfig 
import MainServicesCfg
 
   92     from AthenaPoolCnvSvc.PoolReadConfig 
import PoolReadCfg
 
   96     from AthenaConfiguration.ComponentFactory 
import CompFactory
 
  100     cfg.addEventAlgo(CompFactory.FixHepMC(
"FixHepMC"))
 
  103     cfg.addEventAlgo( CompFactory.WriteHepMC( 
'WriteHepMC',
 
  104                       OutputFile = my_output_HepMCFile,
 
  105                       Format = hepMCFormat,
 
  107                       McEventKey = McEventKey ) )
 
  122     log.info(
'Compressing HEPMC output (may take a moment)')
 
  124     with tarfile.open(runArgs.outputHEPMCFile,
'w:gz') 
as out_tar:
 
  125         out_tar.add( my_output_HepMCFile )
 
  128     log.debug(
'Deleting original (uncompressed) file')
 
  130     os.remove( my_output_HepMCFile )
 
  133     log.info(
"Ran POOLtoHEPMC in " + 
str(time.time()-tic) + 
" seconds")
 
  135     sys.exit(
not sc.isSuccess())