13 from pandatools
import PandaToolsPkgInfo
15 print (
"prun needs additional setup, try:")
16 print (
" lsetup panda")
36 'addNthFieldOfInDSToLFN',
44 switches = [
'express',
55 using_nEventsPerJob =
False
58 arg = sample.meta().castDouble(
'nc_' + opt, -1, SH.MetaObject.CAST_NOCAST_DEFAULT)
59 if abs(arg + 1) > 1e-6 :
61 if opt==
"nEventsPerJob":
62 using_nEventsPerJob=
True
64 arg = sample.meta().castString(
'nc_' + opt)
66 cmd += [
"--" + opt +
"=" + arg]
69 if using_nEventsPerJob:
70 cmd = [ x
for x
in cmd
if "nGBPerJob" not in x ]
73 for switch
in switches :
74 arg = sample.meta().castDouble(
'nc_' + switch, 0, SH.MetaObject.CAST_NOCAST_DEFAULT)
76 cmd += [
"--" + switch]
78 arg = sample.meta().castString(
'nc_' + switch)
80 if arg !=
"False" and arg !=
"false" and arg !=
"FALSE" :
81 cmd += [
"--" + switch]
84 internalOpts = [
'exec',
92 for opt
in internalOpts :
93 value = sample.meta().castString(
'nc_' + opt)
94 if opt ==
"exec" and using_nEventsPerJob:
95 value +=
" %SKIPEVENTS %MAXEVENTS"
96 cmd += [
"--" + opt +
"=" + value]
98 if sample.meta().castDouble(
'nc_mergeOutput', 1, SH.MetaObject.CAST_NOCAST_DEFAULT) == 0
or sample.meta().castString(
'nc_mergeOutput').
upper() ==
'FALSE' :
102 cmd += [
"--mergeScript=" + sample.meta().castString(
'nc_mergeScript')]
104 if len(sample.meta().castString(
'nc_EventLoop_SubmitFlags')) :
105 cmd += shlex.split (sample.meta().castString(
'nc_EventLoop_SubmitFlags'))
107 if sample.meta().castDouble(
'nc_showCmd', 0, SH.MetaObject.CAST_NOCAST_DEFAULT) != 0 :
110 if not os.path.isfile(
'jobcontents.tgz') :
112 dummycmd = copy.deepcopy(cmd)
113 dummycmd += [
"--outTarBall=jobcontents.tgz"]
114 if len(sample.meta().castString(
'nc_EventLoop_UserFiles')) :
115 dummycmd += [
"--extFile=jobdef.root,runjob.sh," + sample.meta().castString(
'nc_EventLoop_UserFiles').
replace(
" ",
",")]
118 dummycmd += [
"--extFile=jobdef.root,runjob.sh"]
120 dummycmd += [
"--noSubmit"]
123 out = subprocess.check_output(dummycmd, stderr=subprocess.STDOUT)
124 except subprocess.CalledProcessError
as e:
126 if b
'Need to generate a grid proxy' in e.output
and any( [
'%nickname%' in x
for x
in cmd ] ):
127 print(
'Detected nickname still undefined. Trying to replace it.')
129 from pandatools
import PsubUtils
130 nickname = PsubUtils.getNickname()
131 dummycmd = [ x.replace(
'%nickname%',nickname)
for x
in dummycmd ]
132 cmd = [ x.replace(
'%nickname%',nickname)
for x
in cmd ]
133 except Exception
as e_rep:
134 print(f
'Nickname replacement failed with error {e_rep.returncode}: {e_rep.output}')
137 out = subprocess.check_output(dummycmd, stderr=subprocess.STDOUT)
138 except subprocess.CalledProcessError
as e_take2:
141 print (
"failed with return code " , e_take2.returncode)
142 print (
"output was:")
143 print (e_take2.output)
148 print (
"failed with return code " , e.returncode)
149 print (
"output was:")
153 cmd += [
"--inTarBall=jobcontents.tgz"]
157 out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
158 except subprocess.CalledProcessError
as e:
161 print (
"failed with return code ", e.returncode)
162 print (
"output was:")
168 line = re.findall(
r'TaskID=\d+',
str(out))[0]
169 jediTaskID =
int(re.findall(
r'\d+', line)[0])