12 from pandatools
import PandaToolsPkgInfo
14 print (
"prun needs additional setup, try:")
15 print (
" lsetup panda")
35 'addNthFieldOfInDSToLFN',
43 switches = [
'express',
54 using_nEventsPerJob =
False
57 arg = sample.meta().castDouble(
'nc_' + opt, -1, SH.MetaObject.CAST_NOCAST_DEFAULT)
58 if abs(arg + 1) > 1e-6 :
60 if opt==
"nEventsPerJob":
61 using_nEventsPerJob=
True
63 arg = sample.meta().castString(
'nc_' + opt)
65 cmd += [
"--" + opt +
"=" + arg]
68 if using_nEventsPerJob:
69 cmd = [ x
for x
in cmd
if "nGBPerJob" not in x ]
72 for switch
in switches :
73 arg = sample.meta().castDouble(
'nc_' + switch, 0, SH.MetaObject.CAST_NOCAST_DEFAULT)
75 cmd += [
"--" + switch]
77 arg = sample.meta().castString(
'nc_' + switch)
79 if arg !=
"False" and arg !=
"false" and arg !=
"FALSE" :
80 cmd += [
"--" + switch]
83 internalOpts = [
'exec',
91 for opt
in internalOpts :
92 value = sample.meta().castString(
'nc_' + opt)
93 if opt ==
"exec" and using_nEventsPerJob:
94 value +=
" %SKIPEVENTS %MAXEVENTS"
95 cmd += [
"--" + opt +
"=" + value]
97 if sample.meta().castDouble(
'nc_mergeOutput', 1, SH.MetaObject.CAST_NOCAST_DEFAULT) == 0
or sample.meta().castString(
'nc_mergeOutput').
upper() ==
'FALSE' :
101 cmd += [
"--mergeScript=" + sample.meta().castString(
'nc_mergeScript')]
103 if len(sample.meta().castString(
'nc_EventLoop_SubmitFlags')) :
104 cmd += shlex.split (sample.meta().castString(
'nc_EventLoop_SubmitFlags'))
106 if sample.meta().castDouble(
'nc_showCmd', 0, SH.MetaObject.CAST_NOCAST_DEFAULT) != 0 :
109 if not os.path.isfile(
'jobcontents.tgz') :
111 dummycmd = copy.deepcopy(cmd)
112 dummycmd += [
"--outTarBall=jobcontents.tgz"]
113 if len(sample.meta().castString(
'nc_EventLoop_UserFiles')) :
114 dummycmd += [
"--extFile=jobdef.root,runjob.sh," + sample.meta().castString(
'nc_EventLoop_UserFiles').
replace(
" ",
",")]
117 dummycmd += [
"--extFile=jobdef.root,runjob.sh"]
119 dummycmd += [
"--noSubmit"]
122 out = subprocess.check_output(dummycmd, stderr=subprocess.STDOUT)
123 except subprocess.CalledProcessError
as e:
125 if b
'Need to generate a grid proxy' in e.output
and any( [
'%nickname%' in x
for x
in cmd ] ):
126 print(
'Detected nickname still undefined. Trying to replace it.')
128 from pandatools
import PsubUtils
129 nickname = PsubUtils.getNickname()
130 dummycmd = [ x.replace(
'%nickname%',nickname)
for x
in dummycmd ]
131 cmd = [ x.replace(
'%nickname%',nickname)
for x
in cmd ]
132 except Exception
as e_rep:
133 print(f
'Nickname replacement failed with error {e_rep.returncode}: {e_rep.output}')
136 out = subprocess.check_output(dummycmd, stderr=subprocess.STDOUT)
137 except subprocess.CalledProcessError
as e_take2:
140 print (
"failed with return code " , e_take2.returncode)
141 print (
"output was:")
142 print (e_take2.output)
147 print (
"failed with return code " , e.returncode)
148 print (
"output was:")
152 cmd += [
"--inTarBall=jobcontents.tgz"]
156 out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
157 except subprocess.CalledProcessError
as e:
160 print (
"failed with return code ", e.returncode)
161 print (
"output was:")
167 line = re.findall(
r'TaskID=\d+',
str(out))[0]
168 jediTaskID =
int(re.findall(
r'\d+', line)[0])