6 Run event simulation and produce an EVNT file.
9 import os, sys, time, shutil
13 from PyJobTransforms.trfArgs
import addAthenaArguments
14 from PyJobTransforms.trfDecorators
import stdTrfExceptionHandler, sigUsrStackTrace
15 from EvgenJobTransforms.evgenTrfArgs
import addStdEvgenArgs
21 ListOfDefaultPositionalKeys=[
'--AMI',
'--AMITag',
'--DBRelease',
'--asetup',
'--athena',
'--athenaopts',
'--autoConfiguration',
'--beamType',
'--checkEventCount',
'--command',
'--conditionsTag',
'--ecmEnergy',
'--eventAcceptanceEfficiency',
'--evgenJobOpts',
'--execOnly',
'--firstEvent',
'--geometryVersion',
'--ignoreErrors',
'--ignoreFilters',
'--ignorePatterns',
'--inputGenConfFile',
'--inputGeneratorFile',
'--jobConfig',
'--maxEvents',
'--omitFileValidation',
'--outputEVNTFile',
'--postExec',
'--postInclude',
'--preExec',
'--preInclude',
'--randomSeed',
'--reportName',
'--runNumber',
'--showGraph',
'--showPath',
'--showSteps',
'--skipEvents',
'--uploadtoami',
'--validation',
'--outputTXTFile']
25 "Specialised trf executor class for event generation jobs"
28 athenaExecutor.__init__(self, name=
"generate", skeletonFile=skeleton, substep=
"gen2evnt", tryDropAndReload=
False, inData=[
"EVNT_Pre"], outData=[
"EVNT"])
31 "Get input tarball, unpack and set up env if an evgenJobOpts arg was provided."
34 super(EvgenExecutor, self).
preExecute(input, output)
36 def expand_if_archive(filename):
37 "Function to expand a file if it is a zip archive or tarball"
38 if ".tar" in filename:
40 tf = tarfile.open(filename)
43 elif filename.endswith(
".zip"):
45 zf = zipfile.ZipFile(filename)
50 return [name
for name
in os.listdir(a_dir)
51 if os.path.isdir(os.path.join(a_dir, name))]
53 def mk_jo_proxy(targetbasepath, pkgname, proxypath, addtosearch=True):
54 "Make a JO proxy dir such that the MCxxJobOptions/dddd dirs contents are found via include(MCxxJobOptions/yyyy)"
56 if os.path.exists(proxypath):
57 shutil.rmtree(proxypath)
59 os.environ[
'LOCAL_INSTALL_DIR'] = (os.environ[
'JOBOPTSEARCHPATH']).
split(
":")[0]
60 comdir = os.path.join(targetbasepath,
"common")
62 subdirlist1 = [
'common/%s' % item
for item
in subdirlist]
63 dirlist = [
'common',
'share',
'gencontrol',
'susycontrol']
64 for d
in (dirlist+subdirlist1):
66 if (d !=
'common/.svn'):
67 dpath = os.path.join(proxypath, d)
71 os.symlink(os.path.join(targetbasepath, d), os.path.join(dpath, pkgname))
73 os.environ[
"JOBOPTSEARCHPATH"] = dpath+
":"+os.environ[
"JOBOPTSEARCHPATH"]
74 os.environ[
"DATAPATH"] =os.path.join(targetbasepath, d)+
":"+os.environ[
"DATAPATH"]
76 os.environ[
"JOBOPTSEARCHPATH"] = os.environ[
'LOCAL_INSTALL_DIR']+
":"+os.environ[
"JOBOPTSEARCHPATH"]
80 if "evgenJobOpts" in self._trf.argdict:
81 tarball = self._trf.argdict[
"evgenJobOpts"].value
84 if tarball.startswith(
"http"):
86 tarball = os.basename(tarball)
88 url =
"http://cern.ch/atlas-computing/links/kitsDirectory/EvgenJobOpts/" + tarball
90 if not os.path.exists(tarball):
91 from EvgenJobTransforms.download
import downloadUsingProxy
94 raise EnvironmentError(
'Error downloading tarball %s. Downloader reports: %s' % (tarball, output))
95 msg.info(
'Evgen tarball download success: %s' % output)
97 expand_if_archive(tarball)
98 mk_jo_proxy(os.getcwd(),
"MC14JobOptions",
"_joproxy14")
99 mk_jo_proxy(os.getcwd(),
"MC15JobOptions",
"_joproxy15")
108 if os.path.exists(
"/cvmfs/atlas.cern.ch"):
110 mk_jo_proxy(
"/cvmfs/atlas.cern.ch/repo/sw/Generators/MC14JobOptions/latest/",
"MC14JobOptions",
"_joproxy14")
111 mk_jo_proxy(
"/cvmfs/atlas.cern.ch/repo/sw/Generators/MC15JobOptions/latest/",
"MC15JobOptions",
"_joproxy15")
112 msg.info(
"No evgenJobOpts tarball specified, using JOBOPTSEARCHPATH = '%s'" % os.environ[
"JOBOPTSEARCHPATH"])
113 elif os.path.exists(
"/afs/cern.ch/atlas/groups/Generators"):
114 mk_jo_proxy(
"/afs/cern.ch/atlas/groups/Generators/MC14JobOptions/latest/",
"MC14JobOptions",
"_joproxy14")
115 mk_jo_proxy(
"/afs/cern.ch/atlas/groups/Generators/MC15JobOptions/latest/",
"MC15JobOptions",
"_joproxy15")
116 msg.info(
"No evgenJobOpts tarball specified, no cvmfs, using JOBOPTSEARCHPATH = '%s'" % os.environ[
"JOBOPTSEARCHPATH"])
119 if "inputGeneratorFile" in self._trf.argdict:
120 expand_if_archive(self._trf.argdict[
"inputGeneratorFile"].value)
121 if "inputGenConfFile" in self._trf.argdict:
122 expand_if_archive(self._trf.argdict[
"inputGenConfFile"].value)
127 exeSet.add(
EvgenExecutor(
"EvgenJobTransforms/skeleton.ABtoEVGEN.py"))
128 exeSet.add(athenaExecutor(name =
"AODtoDPD", skeletonFile =
"PATJobTransforms/skeleton.AODtoDPD_tf.py",
129 substep =
"a2d", inData = [
"EVNT"], outData = [
"NTUP_TRUTH"], perfMonFile =
"ntuple_AODtoDPD.pmon.gz"))
136 @stdTrfExceptionHandler
139 msg.info(
"This is %s" % sys.argv[0])
141 trf.parseCmdLineArgs(sys.argv[1:])
144 msg.info(
"%s stopped at %s, trf exit code %d" % (sys.argv[0], time.asctime(), trf.exitCode))
145 sys.exit(trf.exitCode)
151 if __name__ ==
"__main__":