15 import Alignment.MillePedeAlignmentAlgorithm.mpslib.Mpslibclass
as mpslib
23 description=
"Submit jobs that are setup in local mps database to batch system.",
25 parser.add_argument(
"maxJobs", type=int, nargs=
'?', default=1,
26 help=
"number of Mille jobs to be submitted (default: %(default)d)")
27 parser.add_argument(
"-a",
"--all", dest=
"allMille", default=
False,
29 help=
"submit all setup Mille jobs; maxJobs is ignored")
30 parser.add_argument(
"-m",
"--merge", dest=
"fireMerge", default=
False,
32 help=
"submit all setup Pede jobs; maxJobs is ignored")
33 parser.add_argument(
"-f",
"--force-merge", dest=
"forceMerge", default=
False,
35 help=(
"force the submission of the Pede job in case some "+
36 "Mille jobs are not in the OK state"))
37 args = parser.parse_args(sys.argv[1:])
40 lib = mpslib.jobdatabase()
45 args.maxJobs = lib.nJobs
48 theJobData = os.path.join(os.getcwd(),
"jobData")
51 theJobName =
'mpalign'
52 if lib.addFiles !=
'':
53 theJobName = lib.addFiles
56 if not args.fireMerge:
58 resources = lib.get_class(
'mille')
61 if 'cmscafspec' in resources:
62 print '\nWARNING:\n Running mille jobs on cmscafspec, intended for pede only!\n\n'
64 queue = queue.replace(
'cmscafspec',
'cmscaf')
65 resources =
'-q'+queue+
'-R cmscafspec'
66 resources =
'-q cmscafalcamille'
68 elif 'cmscaf' in resources:
70 resources =
'-q'+resources+
' -m g_cmscaf'
72 resources =
'-q '+resources
75 for i
in xrange(lib.nJobs):
76 if lib.JOBSTATUS[i] ==
'SETUP':
77 if nSub < args.maxJobs:
80 submission =
'bsub -J %s %s %s/%s/theScript.sh' % \
81 (theJobName, resources, theJobData, lib.JOBDIR[i])
83 result = subprocess.check_output(submission, stderr=subprocess.STDOUT, shell=
True)
85 result = result.strip()
88 match = re.search(
'Job <(\d+)> is submitted', result)
91 lib.JOBSTATUS[i] =
'SUBTD'
92 lib.JOBID[i] = int(match.group(1))
94 print 'Submission of %03d seems to have failed: %s' % (lib.JOBNUMBER[i],result),
101 resources = lib.get_class(
'pede')
102 if 'cmscafspec' in resources:
104 queue = queue.replace(
'cmscafspec',
'cmscaf')
105 resources =
'-q '+queue+
' -R cmscafspec'
106 resources =
'-q cmscafalcamille'
108 resources =
'-q '+resources
111 resources = resources+
' -R \"rusage[mem="%s"]\"' % str(lib.pedeMem)
115 for i
in xrange(lib.nJobs):
116 if lib.JOBSTATUS[i] !=
'OK':
117 if 'DISABLED' not in lib.JOBSTATUS[i]:
123 while i<len(lib.JOBDIR):
127 if lib.JOBSTATUS[i] !=
'SETUP':
128 print 'Merge job %d status %s not submitted.' % \
129 (jobNumFrom1, lib.JOBSTATUS[i])
130 elif not (mergeOK
or args.forceMerge):
131 print 'Merge job',jobNumFrom1,
'not submitted since Mille jobs error/unfinished (Use -m -f to force).'
134 Path =
'%s/%s' % (theJobData,lib.JOBDIR[i])
135 backupScriptPath = Path+
'/theScript.sh.bak'
136 scriptPath = Path+
'/theScript.sh'
142 if not os.path.isfile(backupScriptPath):
143 os.system(
'cp -p '+scriptPath+
' '+backupScriptPath)
146 command =
'cat '+backupScriptPath+
' | grep cmsRun | grep "\.py" | head -1 | awk \'{gsub("^.*cmsRun ","");print $1}\''
147 mergeCfg = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=
True)
148 command =
'basename '+mergeCfg
149 mergeCfg = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=
True)
150 mergeCfg = mergeCfg.replace(
'\n',
'')
153 backupCfgPath = Path+
'/%s.bak' % mergeCfg
154 cfgPath = Path+
'/%s' % mergeCfg
155 if not os.path.isfile(backupCfgPath):
156 os.system(
'cp -p '+cfgPath+
' '+backupCfgPath)
159 inCfgPath = theJobData+
'/'+lib.JOBDIR[0]+
'/the.py'
160 command =
'mps_merge.py -c '+inCfgPath+
' '+Path+
'/'+mergeCfg+
' '+Path+
' '+str(lib.nJobs)
164 command =
'mps_scriptm.pl -c '+lib.mergeScript+
' '+scriptPath+
' '+Path+
' '+mergeCfg+
' '+str(lib.nJobs)+
' '+lib.mssDir+
' '+lib.mssDirPool
169 if os.path.isfile(backupScriptPath):
170 os.system(
'cp -pf '+backupScriptPath+
' '+scriptPath)
173 command =
'cat '+scriptPath+
' | grep cmsRun | grep "\.py" | head -1 | awk \'{gsub("^.*cmsRun ","");print $1}\''
174 mergeCfg = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=
True)
175 command =
'basename '+mergeCfg
176 mergeCfg = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=
True)
177 mergeCfg = mergeCfg.replace(
'\n',
'')
180 backupCfgPath = Path+
'/%s.bak' % mergeCfg
181 cfgPath = Path+
'/%s' % mergeCfg
182 if os.path.isfile(backupCfgPath):
183 os.system(
'cp -pf '+backupCfgPath+
' '+cfgPath)
189 curJobName =
'm'+str(nMerge)+
'_'+theJobName
190 submission =
'bsub -J %s %s %s' % (curJobName,resources,scriptPath)
191 result = subprocess.check_output(submission, stderr=subprocess.STDOUT, shell=
True)
193 result = result.strip()
196 match = re.search(
'Job <(\d+)> is submitted', result)
199 lib.JOBSTATUS[i] =
'SUBTD'
200 lib.JOBID[i] = int(match.group(1))
201 print 'jobid is',lib.JOBID[i]
203 print 'Submission of merge job seems to have failed:',result,