28 def preExecute(self, input=set(), output=
set()):
29 "Get input tarball, unpack and set up env if an evgenJobOpts arg was provided."
32 super(EvgenExecutor, self).preExecute(input, output)
34 def expand_if_archive(filename):
35 "Function to expand a file if it is a zip archive or tarball"
36 if ".tar" in filename:
38 with tarfile.open(filename)
as tf:
40 elif filename.endswith(
".zip"):
42 zf = zipfile.ZipFile(filename)
47 return [name
for name
in os.listdir(a_dir)
48 if os.path.isdir(os.path.join(a_dir, name))]
52 os.environ[
'LOCAL_INSTALL_DIR'] = (os.environ[
'JOBOPTSEARCHPATH']).
split(
":")[0]
53 if os.path.exists(
'/cvmfs/atlas.cern.ch/repo/sw/Generators/MCJobOptions/common'):
54 CommonCvmfsDir =
'/cvmfs/atlas.cern.ch/repo/sw/Generators/MCJobOptions/common'
55 os.environ[
"JOBOPTSEARCHPATH"] = CommonCvmfsDir+
":"+os.environ[
"JOBOPTSEARCHPATH"]
56 if os.path.exists(
'/cvmfs/atlas.cern.ch/repo/sw/Generators/MCJobOptions/common/MadGraphControl/dat/'):
57 datCvmfsDir =
'/cvmfs/atlas.cern.ch/repo/sw/Generators/MCJobOptions/common/MadGraphControl/dat/'
58 os.environ[
"DATAPATH"] = datCvmfsDir+
":"+os.environ[
"DATAPATH"]
60 dsidpar = (self._trf.argdict[
"jobConfig"].value).
values()
61 dsidparam =
list(dsidpar)[0][0]
63 if os.path.exists(
'/cvmfs/atlas.cern.ch/repo/sw/Generators/MCJobOptions/'):
64 BaseCvmfsPath =
"/cvmfs/atlas.cern.ch/repo/sw/Generators/MCJobOptions/"
66 if dsidparam.isdigit()
and (len(dsidparam)==6
or len(dsidparam)==7):
68 Jodir = dsidparam[:3]+
'xxx'
70 Jodir = dsidparam[0] +
'/' + dsidparam[:4]+
'xxx'
72 cwd_ful = os.path.join(cwdir, dsidparam)
73 if (os.path.isdir(cwd_ful)):
74 os.environ[
"JOBOPTSEARCHPATH"] = cwd_ful+
":"+os.environ[
"JOBOPTSEARCHPATH"]
75 os.environ[
"DATAPATH"] = cwd_ful+
":"+os.environ[
"DATAPATH"]
77 cwd_Jodir = os.path.join(cwdir,Jodir)
78 cwd_Jodir_ful = os.path.join(cwd_Jodir,dsidparam)
79 if (os.path.isdir(cwd_Jodir_ful)):
80 os.environ[
"JOBOPTSEARCHPATH"] = cwd_Jodir_ful+
":"+os.environ[
"JOBOPTSEARCHPATH"]
81 os.environ[
"DATAPATH"] = cwd_Jodir_ful+
":"+os.environ[
"DATAPATH"]
83 if (os.path.isdir(BaseCvmfsPath)):
84 JoCvmfsPath = os.path.join(BaseCvmfsPath, Jodir)
85 JoCvmfsPath_ful = os.path.join(JoCvmfsPath, dsidparam)
86 os.environ[
"JOBOPTSEARCHPATH"] = JoCvmfsPath_ful+
":"+os.environ[
"JOBOPTSEARCHPATH"]
87 os.environ[
"DATAPATH"] = JoCvmfsPath_ful+
":"+os.environ[
"DATAPATH"]
89 msg.error(
"No access to JOs cvmfs location. JOs should be placed in working directory or full path should be given.")
90 raise RuntimeError(
"JOs not found - no cvmfs access")
92 if dsidparam.startswith(
"Test"):
93 for token
in (os.environ[
'JOBOPTSEARCHPATH']).
split(
":"):
94 if "jobOptions" in token:
97 search_token +=
"/EvgenJobTransforms/EvgenTest/" + dsidparam.split(
"Test")[-1]
98 os.environ[
"JOBOPTSEARCHPATH"] = search_token+
":"+os.environ[
"JOBOPTSEARCHPATH"]
99 os.environ[
"DATAPATH"] = search_token+
":"+os.environ[
"DATAPATH"]
100 elif (os.path.isdir(dsidparam)):
101 os.environ[
"JOBOPTSEARCHPATH"] = dsidparam+
":"+os.environ[
"JOBOPTSEARCHPATH"]
102 os.environ[
"DATAPATH"] = dsidparam+
":"+os.environ[
"DATAPATH"]
104 msg.error(
"JOs not found, please check = '%s'" % dsidparam)
105 raise RuntimeError(
"JOs not found")
107 msg.info(
"Using JOBOPTSEARCHPATH = '%s'" % os.environ[
"JOBOPTSEARCHPATH"])
108 msg.info(
"Using DATAPATH = '%s'" % os.environ[
"DATAPATH"])
110 if "evgenJobOpts" in self._trf.argdict:
111 tarball = self._trf.argdict[
"evgenJobOpts"].value
114 if tarball.startswith(
"http"):
116 tarball = os.basename(tarball)
118 url =
"http://cern.ch/atlas-computing/links/kitsDirectory/EvgenJobOpts/" + tarball
120 if not os.path.exists(tarball):
121 from EvgenJobTransforms.download
import downloadUsingProxy
124 raise EnvironmentError(
'Error downloading tarball %s. Downloader reports: %s' % (tarball, output))
125 msg.info(
'Evgen tarball download success: %s' % output)
127 expand_if_archive(tarball)
132 FIRST_DIR = (os.environ[
'JOBOPTSEARCHPATH']).
split(
":")[0]
133 configFiles = [f
for f
in os.listdir(FIRST_DIR)
if (
"GRID" in f)]
135 if len(configFiles) == 1:
136 confFile = os.path.join(FIRST_DIR, configFiles[0])
137 elif len(configFiles) >1:
138 msg.info(
"more then one gridpack ! ")
139 if "--ecmEnergy" in str(sys.argv[1:]):
140 split_args=
str(sys.argv[1:]).
split(
"ecmEnergy=",1)[1]
141 ener_GeV=split_args.split(
",")[0].strip(
"\'")
143 msg.info(
"Should be used gridpack for energy "+energy)
146 for x
in configFiles:
147 gridS=
"mc_"+energy+
"TeV"
148 msg.info(
"Gridpack should start from "+gridS)
149 if x.startswith(gridS):
150 confFile = os.path.join(FIRST_DIR, x)
151 msg.info(
"using gridpack = "+confFile)
153 msg.error(
"No *GRID* config files, for requested energy = '%s' please check = '%s'" %(energy,dsidparam))
155 if confFile
is not None:
156 expand_if_archive(confFile)
158 msg.info(
"Configuration input gridpack found " + confFile)
161 loc_files = os.listdir(os.getcwd())
162 for loc_file
in loc_files:
163 if "GRID" not in loc_file:
164 expand_if_archive(loc_file)
167 if "inputGeneratorFile" in self._trf.argdict:
169 myinputfiles = self._trf.argdict[
"inputGeneratorFile"].value
170 genInputFiles = myinputfiles.split(
',')
171 for file
in genInputFiles:
172 expand_if_archive(file)
173 if "inputGenConfFile" in self._trf.argdict:
174 expand_if_archive(self._trf.argdict[
"inputGenConfFile"].value)