41 from __future__
import print_function
51 """Unsigned int type""" 54 msg =
'{0} is negative'.
format(string)
55 raise argparse.ArgumentTypeError(msg)
61 """Takes the cmsRun filem, removes all occurences of runMode, jobs, 62 maxJobs and integrationList parameters in the process.generator 64 The the parameters in par_list are set instead and saved. 67 with open(cmsrunfilename,
'r') as readfile: 68 parsestring = readfile.read() 71 begin_gen_step = parsestring.find(
'(', parsestring.find(
'process.generator'))
74 end_gen_step = begin_gen_step
76 for position
in range(begin_gen_step+1, len(parsestring)):
77 if parsestring[position] ==
'(':
79 if parsestring[position] ==
')':
81 if not bracket_counter:
82 end_gen_step = position
86 gen_string = parsestring[begin_gen_step+1:end_gen_step]
89 gen_string = re.sub(
r',\s*runModeList\s*=\s*cms.untracked.string\((.*?)\)',
'', gen_string)
90 gen_string = re.sub(
r',\s*jobs\s*=\s*cms.untracked.int32\((.*?)\)',
'', gen_string)
91 gen_string = re.sub(
r',\s*integrationList\s*=\s*cms.untracked.string\((.*?)\)',
'', gen_string)
92 gen_string = re.sub(
r',\s*maxJobs\s*=\s*cms.untracked.uint32\((.*?)\)',
'', gen_string)
93 gen_string = re.sub(
r',\s*seed\s*=\s*cms.untracked.int32\((.*?)\)',
'', gen_string)
97 with open(savefilename,
'w')
as savefile:
98 savefile.write(parsestring[:begin_gen_step+1])
99 savefile.write(gen_string)
100 for item
in par_list:
101 savefile.write(
',\n')
103 savefile.write(parsestring[end_gen_step:])
108 """Delete the files in filelist and exit""" 109 for filename
in filelist:
120 parser = argparse.ArgumentParser()
122 parser.add_argument(
'cmsRunfile', help=
'filename of the cmsRun configuration')
123 parser.add_argument(
'-b',
'--build', help=
'set the number of build jobs', type=int, choices=
range(0,11), default=0)
124 parser.add_argument(
'-i',
'--integrate', help=
'set the maximal number of integration jobs', type=uint, default=0)
125 parser.add_argument(
'-r',
'--run', help=
'set the number of run jobs', type=int, choices=
range(0,11), default=0)
126 parser.add_argument(
'--nointegration', help=
'build -i integration jobs without actually integrating', action=
'store_true')
127 parser.add_argument(
'--keepfiles', help=
'don\'t delete temporary files', action=
'store_true')
128 parser.add_argument(
'--stoprun', help=
'stop after creating the cmsRun files for the run step', action=
'store_true')
129 parser.add_argument(
'--resumerun', help=
'use existing \'temporary\' files for the run step', action=
'store_true')
130 parser.add_argument(
'-l',
'--log', help=
'write the output of each process in a separate log file', action=
'store_true')
132 args = parser.parse_args()
138 template_name = args.cmsRunfile.replace(
'.',
'_')
154 parameters = [
'runModeList = cms.untracked.string(\'build\')']
155 parameters.append(
'jobs = cms.untracked.int32(' +
str(args.build) +
')')
156 if args.integrate != 0:
157 parameters.append(
'maxJobs = cms.untracked.uint32(' +
str(args.integrate) +
')')
159 build_name = template_name +
'_build.py' 160 adjust_pset(args.cmsRunfile, build_name, parameters)
162 cleanupfiles.append(build_name)
166 print(
'Setting up a maximum of {0} integration jobs.'.
format(
str(args.integrate)))
167 print(
'Calling\t\'cmsRun ' + build_name +
'\'')
170 print(
'Writing ouput to log file: ' + build_name[:-2] +
'log')
171 with open(build_name[:-2] +
'log',
'w')
as build_log:
172 process = subprocess.Popen([
'cmsRun', build_name], stdout=build_log, stderr=subprocess.STDOUT)
174 process = subprocess.Popen([
'cmsRun ' + build_name], shell=
True)
177 print(
'--------------------')
178 print(
'Build step finished.')
179 print(
'--------------------')
186 if args.nointegration:
187 print(
'--nointegration: Run will be stopped here.')
190 if args.integrate != 0:
192 actual_int_jobs = len([string
for string
in os.listdir(
'Herwig-scratch/Build')
if re.match(
r'integrationJob[0-9]+', string)])
195 if actual_int_jobs > args.integrate:
196 print(
'Actual number of integration jobs {0} exceeds \'--integrate {1}\'.'.
format(actual_int_jobs, args.integrate))
197 print(
'Integration will not be performed.')
201 print(
'Found {0} integration jobs, a maxiumum of {1} was given.'.
format(actual_int_jobs, args.integrate))
202 print(
'Starting all jobs.')
204 print(
'--- Output may be cluttered. (Try the option -l/--log) ---')
206 for i
in range(actual_int_jobs):
208 parameters = [
'runModeList = cms.untracked.string(\'integrate\')']
209 parameters.append(
'integrationList = cms.untracked.string(\'' +
str(i) +
'\')')
211 integration_name = template_name +
'_integrate_' +
str(i) +
'.py' 212 adjust_pset(args.cmsRunfile, integration_name, parameters)
214 cleanupfiles.append(integration_name)
216 print(
'Calling\t\'cmsRun ' + integration_name +
'\'')
218 print(
'Writing ouput to log file: ' + integration_name[:-2] +
'log')
219 with open(integration_name[:-2] +
'log',
'w')
as integration_log:
220 processes.append( subprocess.Popen([
'cmsRun', integration_name], stdout=integration_log, stderr=subprocess.STDOUT) )
222 processes.append( subprocess.Popen([
'cmsRun', integration_name]) )
226 for process
in processes:
228 print(
'--------------------------')
229 print(
'Integration step finished.')
230 print(
'--------------------------')
261 if args.stoprun
and args.resumerun:
262 print(
'--stoprun AND --resumerun are chosen: run step will be omitted.')
269 print(
'--- Output may be cluttered. (Try the option -l/--log) ---')
271 for i
in range(args.run):
272 run_name = template_name +
'_run_' +
str(i) +
'.py' 275 if not args.resumerun:
276 parameters = [
'runModeList = cms.untracked.string(\'run\')']
278 parameters.append(
'seed = cms.untracked.int32(' +
str(i) +
')')
284 if not args.resumerun:
285 cleanupfiles.append(run_name)
287 if not os.path.isfile(run_name):
288 print(
'\'' + run_name +
'\' not found. It will be skipped.')
291 print(
'Calling\t\'cmsRun ' + run_name +
'\'')
293 print(
'Writing ouput to log file: ' + run_name[:-2] +
'log')
294 with open(run_name[:-2] +
'log',
'w')
as run_log:
295 processes.append( subprocess.Popen([
'cmsRun', run_name], stdout=run_log, stderr=subprocess.STDOUT) )
297 processes.append( subprocess.Popen([
'cmsRun', run_name]) )
301 for process
in processes:
304 print(
'--stoprun: kept run files and stopped before calling cmsRun')
305 print(
'------------------')
306 print(
'Run step finished.')
307 print(
'------------------')
311 if not args.keepfiles:
S & print(S &os, JobReport::InputFile const &f)
def cleanupandexit(filelist)
def adjust_pset(cmsrunfilename, savefilename, par_list)