23 from pandatools
import PandaToolsPkgInfo
25 print (
"prun needs additional setup, try:")
26 print (
" lsetup panda")
46 'addNthFieldOfInDSToLFN',
54 switches = [
'express',
65 using_nEventsPerJob =
False
68 arg = sample.meta().castDouble(
'nc_' + opt, -1, SH.MetaObject.CAST_NOCAST_DEFAULT)
69 if abs(arg + 1) > 1e-6 :
71 if opt==
"nEventsPerJob":
72 using_nEventsPerJob=
True
74 arg = sample.meta().castString(
'nc_' + opt)
76 cmd += [
"--" + opt +
"=" + arg]
79 if using_nEventsPerJob:
80 cmd = [ x
for x
in cmd
if "nGBPerJob" not in x ]
83 for switch
in switches :
84 arg = sample.meta().castDouble(
'nc_' + switch, 0, SH.MetaObject.CAST_NOCAST_DEFAULT)
86 cmd += [
"--" + switch]
88 arg = sample.meta().castString(
'nc_' + switch)
90 if arg !=
"False" and arg !=
"false" and arg !=
"FALSE" :
91 cmd += [
"--" + switch]
94 internalOpts = [
'exec',
102 for opt
in internalOpts :
103 value = sample.meta().castString(
'nc_' + opt)
104 if opt ==
"exec" and using_nEventsPerJob:
105 value +=
" %SKIPEVENTS %MAXEVENTS"
106 cmd += [
"--" + opt +
"=" + value]
108 if sample.meta().castDouble(
'nc_mergeOutput', 1, SH.MetaObject.CAST_NOCAST_DEFAULT) == 0
or sample.meta().castString(
'nc_mergeOutput').
upper() ==
'FALSE' :
112 cmd += [
"--mergeScript=" + sample.meta().castString(
'nc_mergeScript')]
114 if len(sample.meta().castString(
'nc_EventLoop_SubmitFlags')) :
115 cmd += shlex.split (sample.meta().castString(
'nc_EventLoop_SubmitFlags'))
117 if sample.meta().castDouble(
'nc_showCmd', 0, SH.MetaObject.CAST_NOCAST_DEFAULT) != 0 :
122 if not os.path.isfile(
'jobcontents.tgz') :
124 dummycmd = copy.deepcopy(cmd)
125 dummycmd += [
"--outTarBall=jobcontents.tgz"]
126 if len(sample.meta().castString(
'nc_EventLoop_UserFiles')) :
127 dummycmd += [
"--extFile=jobdef.root,runjob.sh," + sample.meta().castString(
'nc_EventLoop_UserFiles').
replace(
" ",
",")]
130 dummycmd += [
"--extFile=jobdef.root,runjob.sh"]
132 dummycmd += [
"--noSubmit"]
135 out = subprocess.check_output(dummycmd, stderr=subprocess.STDOUT, encoding=
"utf-8")
136 except subprocess.CalledProcessError
as e:
138 if 'Need to generate a grid proxy' in e.output
and any( [
'%nickname%' in x
for x
in cmd ] ):
139 print(
'Detected nickname still undefined. Trying to replace it.')
141 from pandatools
import PsubUtils
142 nickname = PsubUtils.getNickname()
143 dummycmd = [ x.replace(
'%nickname%',nickname)
for x
in dummycmd ]
144 cmd = [ x.replace(
'%nickname%',nickname)
for x
in cmd ]
145 except Exception
as e_rep:
146 print(f
'Nickname replacement failed with error {e_rep.returncode}: {e_rep.output}')
149 out = subprocess.check_output(dummycmd, stderr=subprocess.STDOUT, encoding=
"utf-8")
150 except subprocess.CalledProcessError
as e_take2:
154 print (
"failed with return code " , e_take2.returncode)
155 print (
"output was:")
156 print (e_take2.output)
158 except Exception
as e:
163 print (
"failed and output was:")
170 print (
"failed with return code " , e.returncode)
171 print (
"output was:")
175 except Exception
as e:
180 print (
"failed and output was:")
184 cmd += [
"--inTarBall=jobcontents.tgz"]
187 nSubmitTries =
int( sample.meta().castDouble(
"nc_prunNRetrySubmitToGrid", -1, SH.MetaObject.CAST_NOCAST_DEFAULT) )
195 successSubmission =
False
199 listErrorsMessagesTries = []
200 while (iTry < nSubmitTries)
and (
not successSubmission):
206 out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, encoding=
"utf-8")
208 successSubmission =
True
209 except subprocess.CalledProcessError
as e:
213 errorMsg +=
"-"*60 +
"\n"
214 errorMsg += f
"iTry={iTry+1} out of nTries={nSubmitTries}\n"
215 errorMsg +=
"-"*60 +
"\n"
216 errorMsg +=
"Command:\n"
217 errorMsg += f
"{e.cmd}\n"
218 errorMsg += f
"failed with return code {e.returncode}\n"
219 errorMsg +=
"output was:\n"
220 errorMsg += f
"{e.output}\n"
223 listErrorsMessagesTries.append(errorMsg)
227 except Exception
as e:
232 errorMsg +=
"-"*60 +
"\n"
233 errorMsg += f
"iTry={iTry+1} out of nTries={nSubmitTries}\n"
234 errorMsg +=
"-"*60 +
"\n"
235 errorMsg +=
"Command:\n"
236 errorMsg += f
"{cmd}\n"
237 errorMsg += f
"failed and output was:\n"
240 listErrorsMessagesTries.append(errorMsg)
246 if (
not successSubmission):
249 print(f
"Failed submission after nTries={nSubmitTries}")
250 print(
"\n".
join(listErrorsMessagesTries))
255 line = re.findall(
r'TaskID=\d+',
str(out))[0]
256 jediTaskID =
int(re.findall(
r'\d+', line)[0])