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])
84 result = subprocess.check_output(submission,
85 stderr=subprocess.STDOUT,
87 except subprocess.CalledProcessError
as e:
90 result = result.strip()
93 match = re.search(
'Job <(\d+)> is submitted', result)
96 lib.JOBSTATUS[i] =
'SUBTD'
97 lib.JOBID[i] = int(match.group(1))
99 print 'Submission of %03d seems to have failed: %s' % (lib.JOBNUMBER[i],result),
106 resources = lib.get_class(
'pede')
107 if 'cmscafspec' in resources:
109 queue = queue.replace(
'cmscafspec',
'cmscaf')
110 resources =
'-q '+queue+
' -R cmscafspec'
111 resources =
'-q cmscafalcamille'
113 resources =
'-q '+resources
116 resources = resources+
' -R \"rusage[mem="%s"]\"' % str(lib.pedeMem)
120 for i
in xrange(lib.nJobs):
121 if lib.JOBSTATUS[i] !=
'OK':
122 if 'DISABLED' not in lib.JOBSTATUS[i]:
128 while i<len(lib.JOBDIR):
132 if lib.JOBSTATUS[i] !=
'SETUP':
133 print 'Merge job %d status %s not submitted.' % \
134 (jobNumFrom1, lib.JOBSTATUS[i])
135 elif not (mergeOK
or args.forceMerge):
136 print 'Merge job',jobNumFrom1,
'not submitted since Mille jobs error/unfinished (Use -m -f to force).'
139 Path =
'%s/%s' % (theJobData,lib.JOBDIR[i])
140 backupScriptPath = Path+
'/theScript.sh.bak'
141 scriptPath = Path+
'/theScript.sh'
147 if not os.path.isfile(backupScriptPath):
148 os.system(
'cp -p '+scriptPath+
' '+backupScriptPath)
151 command =
'cat '+backupScriptPath+
' | grep cmsRun | grep "\.py" | head -1 | awk \'{gsub("^.*cmsRun ","");print $1}\''
152 mergeCfg = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=
True)
153 command =
'basename '+mergeCfg
154 mergeCfg = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=
True)
155 mergeCfg = mergeCfg.replace(
'\n',
'')
158 backupCfgPath = Path+
'/%s.bak' % mergeCfg
159 cfgPath = Path+
'/%s' % mergeCfg
160 if not os.path.isfile(backupCfgPath):
161 os.system(
'cp -p '+cfgPath+
' '+backupCfgPath)
164 inCfgPath = theJobData+
'/'+lib.JOBDIR[0]+
'/the.py'
165 command =
'mps_merge.py -c '+inCfgPath+
' '+Path+
'/'+mergeCfg+
' '+Path+
' '+str(lib.nJobs)
169 command =
'mps_scriptm.pl -c '+lib.mergeScript+
' '+scriptPath+
' '+Path+
' '+mergeCfg+
' '+str(lib.nJobs)+
' '+lib.mssDir+
' '+lib.mssDirPool
174 if os.path.isfile(backupScriptPath):
175 os.system(
'cp -pf '+backupScriptPath+
' '+scriptPath)
178 command =
'cat '+scriptPath+
' | grep cmsRun | grep "\.py" | head -1 | awk \'{gsub("^.*cmsRun ","");print $1}\''
179 mergeCfg = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=
True)
180 command =
'basename '+mergeCfg
181 mergeCfg = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=
True)
182 mergeCfg = mergeCfg.replace(
'\n',
'')
185 backupCfgPath = Path+
'/%s.bak' % mergeCfg
186 cfgPath = Path+
'/%s' % mergeCfg
187 if os.path.isfile(backupCfgPath):
188 os.system(
'cp -pf '+backupCfgPath+
' '+cfgPath)
194 curJobName =
'm'+str(nMerge)+
'_'+theJobName
195 submission =
'bsub -J %s %s %s' % (curJobName,resources,scriptPath)
196 result = subprocess.check_output(submission, stderr=subprocess.STDOUT, shell=
True)
198 result = result.strip()
201 match = re.search(
'Job <(\d+)> is submitted', result)
204 lib.JOBSTATUS[i] =
'SUBTD'
205 lib.JOBID[i] = int(match.group(1))
206 print 'jobid is',lib.JOBID[i]
208 print 'Submission of merge job seems to have failed:',result,