50 """Unsigned int type""" 53 msg =
'{0} is negative'.
format(string)
54 raise argparse.ArgumentTypeError(msg)
60 """Takes the cmsRun filem, removes all occurences of runMode, jobs, 61 maxJobs and integrationList parameters in the process.generator 63 The the parameters in par_list are set instead and saved. 66 with open(cmsrunfilename,
'r') as readfile: 67 parsestring = readfile.read() 70 begin_gen_step = parsestring.find(
'(', parsestring.find(
'process.generator'))
73 end_gen_step = begin_gen_step
75 for position
in range(begin_gen_step+1, len(parsestring)):
76 if parsestring[position] ==
'(':
78 if parsestring[position] ==
')':
80 if not bracket_counter:
81 end_gen_step = position
85 gen_string = parsestring[begin_gen_step+1:end_gen_step]
88 gen_string = re.sub(
r',\s*runModeList\s*=\s*cms.untracked.string\((.*?)\)',
'', gen_string)
89 gen_string = re.sub(
r',\s*jobs\s*=\s*cms.untracked.int32\((.*?)\)',
'', gen_string)
90 gen_string = re.sub(
r',\s*integrationList\s*=\s*cms.untracked.string\((.*?)\)',
'', gen_string)
91 gen_string = re.sub(
r',\s*maxJobs\s*=\s*cms.untracked.uint32\((.*?)\)',
'', gen_string)
92 gen_string = re.sub(
r',\s*seed\s*=\s*cms.untracked.int32\((.*?)\)',
'', gen_string)
96 with open(savefilename,
'w')
as savefile:
97 savefile.write(parsestring[:begin_gen_step+1])
98 savefile.write(gen_string)
100 savefile.write(
',\n')
102 savefile.write(parsestring[end_gen_step:])
107 """Delete the files in filelist and exit""" 108 for filename
in filelist:
119 parser = argparse.ArgumentParser()
121 parser.add_argument(
'cmsRunfile', help=
'filename of the cmsRun configuration')
122 parser.add_argument(
'-b',
'--build', help=
'set the number of build jobs', type=int, choices=range(0,11), default=0)
123 parser.add_argument(
'-i',
'--integrate', help=
'set the maximal number of integration jobs', type=uint, default=0)
124 parser.add_argument(
'-r',
'--run', help=
'set the number of run jobs', type=int, choices=range(0,11), default=0)
125 parser.add_argument(
'--nointegration', help=
'build -i integration jobs without actually integrating', action=
'store_true')
126 parser.add_argument(
'--keepfiles', help=
'don\'t delete temporary files', action=
'store_true')
127 parser.add_argument(
'--stoprun', help=
'stop after creating the cmsRun files for the run step', action=
'store_true')
128 parser.add_argument(
'--resumerun', help=
'use existing \'temporary\' files for the run step', action=
'store_true')
129 parser.add_argument(
'-l',
'--log', help=
'write the output of each process in a separate log file', action=
'store_true')
131 args = parser.parse_args()
137 template_name = args.cmsRunfile.replace(
'.',
'_')
153 parameters = [
'runModeList = cms.untracked.string(\'build\')']
154 parameters.append(
'jobs = cms.untracked.int32(' +
str(args.build) +
')')
155 if args.integrate != 0:
156 parameters.append(
'maxJobs = cms.untracked.uint32(' +
str(args.integrate) +
')')
158 build_name = template_name +
'_build.py' 159 adjust_pset(args.cmsRunfile, build_name, parameters)
161 cleanupfiles.append(build_name)
164 print 'Setting up {0} build jobs.'.
format(
str(args.build))
165 print 'Setting up a maximum of {0} integration jobs.'.
format(
str(args.integrate))
166 print 'Calling\t\'cmsRun ' + build_name +
'\'' 169 print 'Writing ouput to log file: ' + build_name[:-2] +
'log' 170 with open(build_name[:-2] +
'log',
'w')
as build_log:
171 process = subprocess.Popen([
'cmsRun', build_name], stdout=build_log, stderr=subprocess.STDOUT)
173 process = subprocess.Popen([
'cmsRun ' + build_name], shell=
True)
176 print '--------------------' 177 print 'Build step finished.' 178 print '--------------------' 185 if args.nointegration:
186 print '--nointegration: Run will be stopped here.' 189 if args.integrate != 0:
191 actual_int_jobs = len([string
for string
in os.listdir(
'Herwig-scratch/Build')
if re.match(
r'integrationJob[0-9]+', string)])
194 if actual_int_jobs > args.integrate:
195 print 'Actual number of integration jobs {0} exceeds \'--integrate {1}\'.'.
format(actual_int_jobs, args.integrate)
196 print 'Integration will not be performed.' 200 print 'Found {0} integration jobs, a maxiumum of {1} was given.'.
format(actual_int_jobs, args.integrate)
201 print 'Starting all jobs.' 203 print '--- Output may be cluttered. (Try the option -l/--log) ---' 205 for i
in range(actual_int_jobs):
207 parameters = [
'runModeList = cms.untracked.string(\'integrate\')']
208 parameters.append(
'integrationList = cms.untracked.string(\'' +
str(i) +
'\')')
210 integration_name = template_name +
'_integrate_' +
str(i) +
'.py' 211 adjust_pset(args.cmsRunfile, integration_name, parameters)
213 cleanupfiles.append(integration_name)
215 print 'Calling\t\'cmsRun ' + integration_name +
'\'' 217 print 'Writing ouput to log file: ' + integration_name[:-2] +
'log' 218 with open(integration_name[:-2] +
'log',
'w')
as integration_log:
219 processes.append( subprocess.Popen([
'cmsRun', integration_name], stdout=integration_log, stderr=subprocess.STDOUT) )
221 processes.append( subprocess.Popen([
'cmsRun', integration_name]) )
225 for process
in processes:
227 print '--------------------------' 228 print 'Integration step finished.' 229 print '--------------------------' 260 if args.stoprun
and args.resumerun:
261 print '--stoprun AND --resumerun are chosen: run step will be omitted.' 266 print 'Setting up {0} runs.'.
format(args.run)
268 print '--- Output may be cluttered. (Try the option -l/--log) ---' 270 for i
in range(args.run):
271 run_name = template_name +
'_run_' +
str(i) +
'.py' 274 if not args.resumerun:
275 parameters = [
'runModeList = cms.untracked.string(\'run\')']
277 parameters.append(
'seed = cms.untracked.int32(' +
str(i) +
')')
283 if not args.resumerun:
284 cleanupfiles.append(run_name)
286 if not os.path.isfile(run_name):
287 print '\'' + run_name +
'\' not found. It will be skipped.' 290 print 'Calling\t\'cmsRun ' + run_name +
'\'' 292 print 'Writing ouput to log file: ' + run_name[:-2] +
'log' 293 with open(run_name[:-2] +
'log',
'w')
as run_log:
294 processes.append( subprocess.Popen([
'cmsRun', run_name], stdout=run_log, stderr=subprocess.STDOUT) )
296 processes.append( subprocess.Popen([
'cmsRun', run_name]) )
300 for process
in processes:
303 print '--stoprun: kept run files and stopped before calling cmsRun' 304 print '------------------' 305 print 'Run step finished.' 306 print '------------------' 310 if not args.keepfiles:
def cleanupandexit(filelist)
def adjust_pset(cmsrunfilename, savefilename, par_list)