2 from __future__
import print_function
5 from Configuration.PyReleaseValidation.MatrixReader
import MatrixReader
6 from Configuration.PyReleaseValidation.MatrixRunner
import MatrixRunner
7 from Configuration.PyReleaseValidation.MatrixInjector
import MatrixInjector,performInjectionOptionTest
14 mrd.showRaw(opt.useInput, opt.refRel, opt.fromScratch, opt.raw, opt.step1Only, selected=opt.testList)
23 mrd.prepare(opt.useInput, opt.refRel, opt.fromScratch)
27 definedWf = [dwf.numId
for dwf
in mrd.workFlows]
28 definedSet = set(definedWf)
29 testSet = set(opt.testList)
30 undefSet = testSet - definedSet
31 if len(undefSet)>0:
raise ValueError(
'Undefined workflows: '+
', '.
join(
map(str,list(undefSet))))
32 duplicates = [wf
for wf
in testSet
if definedWf.count(wf)>1 ]
33 if len(duplicates)>0:
raise ValueError(
'Duplicated workflows: '+
', '.
join(
map(str,list(duplicates))))
37 mrd.show(opt.testList, opt.extended, opt.cafVeto)
38 if opt.testList :
print(
'testListected items:', opt.testList)
40 mRunnerHi =
MatrixRunner(mrd.workFlows, opt.nProcs, opt.nThreads)
41 ret = mRunnerHi.runTests(opt)
45 print(
'Cannot go on with wmagent injection with failing workflows')
47 wfInjector =
MatrixInjector(opt,mode=opt.wmcontrol,options=opt.wmoptions)
48 ret= wfInjector.prepare(mrd,
57 if __name__ ==
'__main__':
100 'jetmc': [5.1, 13, 15, 25, 38, 39],
101 'metmc' : [5.1, 15, 25, 37, 38, 39],
102 'muonmc' : [5.1, 124.4, 124.5, 20, 21, 22, 23, 25, 30],
107 usage =
'usage: runTheMatrix.py --show -s '
109 parser = optparse.OptionParser(usage)
111 parser.add_option(
'-b',
'--batchName',
112 help=
'relval batch: suffix to be appended to Campaign name',
117 parser.add_option(
'-m',
'--memoryOffset',
118 help=
'memory of the wf for single core',
122 parser.add_option(
'--addMemPerCore',
123 help=
'increase of memory per each n > 1 core: memory(n_core) = memoryOffset + (n_core-1) * memPerCore',
127 parser.add_option(
'-j',
'--nproc',
128 help=
'number of processes. 0 Will use 4 processes, not execute anything but create the wfs',
132 parser.add_option(
'-t',
'--nThreads',
133 help=
'number of threads per process to use in cmsRun.',
137 parser.add_option(
'--nStreams',
138 help=
'number of streams to use in cmsRun.',
142 parser.add_option(
'--numberEventsInLuminosityBlock',
143 help=
'number of events in a luminosity block',
144 dest=
'numberEventsInLuminosityBlock',
148 parser.add_option(
'-n',
'--showMatrix',
149 help=
'Only show the worflows. Use --ext to show more',
154 parser.add_option(
'-e',
'--extended',
155 help=
'Show details of workflows, used with --show',
160 parser.add_option(
'-s',
'--selected',
161 help=
'Run a pre-defined selected matrix of wf. Deprecated, please use -l limited',
166 parser.add_option(
'-l',
'--list',
167 help=
'Coma separated list of workflow to be shown or ran. Possible keys are also '+
str(predefinedSet.keys())+
'. and wild card like muon, or mc',
171 parser.add_option(
'-r',
'--raw',
172 help=
'Temporary dump the .txt needed for prodAgent interface. To be discontinued soon. Argument must be the name of the set (standard, pileup,...)',
175 parser.add_option(
'-i',
'--useInput',
176 help=
'Use recyling where available. Either all, or a coma separated list of wf number.',
180 parser.add_option(
'-w',
'--what',
181 help=
'Specify the set to be used. Argument must be the name of a set (standard, pileup,...) or multiple sets separated by commas (--what standard,pileup )',
185 parser.add_option(
'--step1',
186 help=
'Used with --raw. Limit the production to step1',
190 parser.add_option(
'--maxSteps',
191 help=
'Only run maximum on maxSteps. Used when we are only interested in first n steps.',
196 parser.add_option(
'--fromScratch',
197 help=
'Coma separated list of wf to be run without recycling. all is not supported as default.',
201 parser.add_option(
'--refRelease',
202 help=
'Allow to modify the recycling dataset version',
206 parser.add_option(
'--wmcontrol',
207 help=
'Create the workflows for injection to WMAgent. In the WORKING. -wmcontrol init will create the the workflows, -wmcontrol test will dryRun a test, -wmcontrol submit will submit to wmagent',
208 choices=[
'init',
'test',
'submit',
'force'],
212 parser.add_option(
'--revertDqmio',
213 help=
'When submitting workflows to wmcontrol, force DQM outout to use pool and not DQMIO',
214 choices=[
'yes',
'no'],
218 parser.add_option(
'--optionswm',
219 help=
'Specify a few things for wm injection',
222 parser.add_option(
'--keep',
223 help=
'allow to specify for which coma separated steps the output is needed',
225 parser.add_option(
'--label',
226 help=
'allow to give a special label to the output dataset name',
228 parser.add_option(
'--command',
229 help=
'provide a way to add additional command to all of the cmsDriver commands in the matrix',
233 parser.add_option(
'--apply',
234 help=
'allow to use the --command only for 1 coma separeated',
237 parser.add_option(
'--workflow',
238 help=
'define a workflow to be created or altered from the matrix',
243 parser.add_option(
'--dryRun',
244 help=
'do not run the wf at all',
249 parser.add_option(
'--testbed',
250 help=
'workflow injection to cmswebtest (you need dedicated rqmgr account)',
255 parser.add_option(
'--noCafVeto',
256 help=
'Run from any source, ignoring the CAF label',
261 parser.add_option(
'--overWrite',
262 help=
'Change the content of a step for another. List of pairs.',
266 parser.add_option(
'--noRun',
267 help=
'Remove all run list selection from wfs',
272 parser.add_option(
'--das-options',
273 help=
'Options to be passed to dasgoclient.',
278 parser.add_option(
'--job-reports',
279 help=
'Dump framework job reports',
284 parser.add_option(
'--ibeos',
285 help=
'Use IB EOS site configuration',
290 parser.add_option(
'--sites',
291 help=
'Run DAS query to get data from a specific site (default is T2_CH_CERN). Set it to empty string to search all sites.',
293 default=
'T2_CH_CERN',
295 parser.add_option(
'--interactive',
296 help=
"Open the Matrix interactive shell",
300 parser.add_option(
'--dbs-url',
301 help=
'Overwrite DbsUrl value in JSON submitted to ReqMgr2',
306 opt,args = parser.parse_args()
307 os.environ[
"CMSSW_DAS_QUERY_SITES"]=opt.dasSites
309 try:
from commands
import getstatusoutput
as run_cmd
310 except:
from subprocess
import getstatusoutput
as run_cmd
312 ibeos_cache = os.path.join(os.getenv(
"LOCALRT"),
"ibeos_cache.txt")
313 if not os.path.exists(ibeos_cache):
314 err, out = run_cmd(
"curl -L -s -o %s https://raw.githubusercontent.com/cms-sw/cms-sw.github.io/master/das_queries/ibeos.txt" % ibeos_cache)
316 run_cmd(
"rm -f %s" % ibeos_cache)
317 print(
"Error: Unable to download ibeos cache information")
321 for cmssw_env
in [
"CMSSW_BASE",
"CMSSW_RELEASE_BASE" ]:
322 cmssw_base = os.getenv(cmssw_env,
None)
323 if not cmssw_base:
continue
324 cmssw_base = os.path.join(cmssw_base,
"src/Utilities/General/ibeos")
325 if os.path.exists(cmssw_base):
326 os.environ[
"PATH"]=cmssw_base+
":"+os.getenv(
"PATH")
327 os.environ[
"CMS_PATH"]=
"/cvmfs/cms-ib.cern.ch"
328 os.environ[
"CMSSW_USE_IBEOS"]=
"true"
329 print(
">> WARNING: You are using SITECONF from /cvmfs/cms-ib.cern.ch")
332 print(
'Deprecated, please use -l limited')
333 if opt.testList: opt.testList+=
',limited'
334 else: opt.testList=
'limited'
342 opt.apply=
map(stepOrIndex,opt.apply.split(
','))
344 opt.keep=
map(stepOrIndex,opt.keep.split(
','))
350 for entry
in opt.testList.split(
','):
351 if not entry:
continue
353 for k
in predefinedSet:
354 if k.lower().startswith(entry.lower())
or k.lower().endswith(entry.lower()):
355 testList.extend(predefinedSet[k])
360 testList.append(
float(entry))
362 print(entry,
'is not a possible selected entry')
364 opt.testList = list(set(testList))
367 if opt.useInput: opt.useInput = opt.useInput.split(
',')
368 if opt.fromScratch: opt.fromScratch = opt.fromScratch.split(
',')
369 if opt.nProcs: opt.nProcs=
int(opt.nProcs)
370 if opt.nThreads: opt.nThreads=
int(opt.nThreads)
371 if opt.nStreams: opt.nStreams=
int(opt.nStreams)
372 if (opt.numberEventsInLuminosityBlock): opt.numberEventsInLuminosityBlock=
int(opt.numberEventsInLuminosityBlock)
373 if (opt.memoryOffset): opt.memoryOffset=
int(opt.memoryOffset)
374 if (opt.memPerCore): opt.memPerCore=
int(opt.memPerCore)
379 opt.overWrite=eval(opt.overWrite)
384 intro =
"Welcome to the Matrix (? for help)"
388 cmd.Cmd.__init__(self)
392 for what
in tmp.files:
393 self.
opt_.what = what
396 self.
opt_.fromScratch)
400 """Clear the screen, put prompt at the top"""
404 print(
"Leaving the Matrix")
408 if inp ==
'x' or inp ==
'q':
412 print(
"\n".
join([
"predefined [predef1 [...]]\n",
413 "Run w/o argument, it will print the list of known predefined workflows.",
414 "Run with space-separated predefined workflows, it will print the workflow-ids registered to them"]))
417 if text
and len(text) > 0:
418 return [t
for t
in predefinedSet.keys()
if t.startswith(text)]
420 return predefinedSet.keys()
423 """Print the list of predefined workflows"""
424 print(
"List of predefined workflows")
426 for w
in arg.split():
427 if w
in predefinedSet.keys():
428 print(
"Predefined Set: %s" % w)
429 print(predefinedSet[w])
431 print(
"Unknown Set: %s" % w)
433 print(predefinedSet.keys())
436 print(
"\n".
join([
"showWorkflow [workflow1 [...]]\n",
437 "Run w/o arguments, it will print the list of registered macro-workflows.",
438 "Run with space-separated workflows, it will print the full list of workflow-ids registered to them"]))
441 if text
and len(text) > 0:
442 return [t
for t
in self.
matrices_.
keys()
if t.startswith(text)]
448 print(
"Available workflows:")
452 selected = arg.split()
455 print(
"Unknown workflow %s: skipping" % k)
458 wfName, stepNames = wfl.nameId.split(
'+',1)
459 print(
"%s %s %s" % (wfl.numId, wfName, stepNames))
460 print(
"%s contains %d workflows" % (k, len(self.
matrices_[k].workFlows)))
463 print(
"\n".
join([
"searchInWorkflow wfl_name search_regexp\n",
464 "This command will search for a match within all workflows registered to wfl_name.",
465 "The search is done on both the workflow name and the names of steps registered to it."]))
468 if text
and len(text) > 0:
469 return [t
for t
in self.
matrices_.
keys()
if t.startswith(text)]
476 print(
"searchInWorkflow name regexp")
479 print(
"Unknown workflow")
484 pattern = re.compile(args[1])
486 print(
"Failed to compile regexp %s" % args[1])
489 for wfl
in self.
matrices_[args[0]].workFlows:
490 wfName, stepNames = wfl.nameId.split(
'+',1)
491 if re.match(pattern, wfName)
or re.match(pattern, stepNames):
492 print(
"%s %s %s" % (wfl.numId, wfName, stepNames))
494 print(
"Found %d compatible workflows inside %s" % (counter, args[0]))
497 print(
"\n".
join([
"search search_regexp\n",
498 "This command will search for a match within all workflows registered.",
499 "The search is done on both the workflow name and the names of steps registered to it."]))
504 print(
"search regexp")
510 print(
"\n".
join([
"dumpWorkflowId [wfl-id1 [...]]\n",
511 "Dumps the details (cmsDriver commands for all steps) of the space-separated workflow-ids in input."]))
516 print(
"dumpWorkflowId [wfl-id1 [...]]")
523 for key, mrd
in self.
matrices_.iteritems():
524 for wfl
in mrd.workFlows:
525 if wfl.numId ==
float(wflid):
526 wfName, stepNames = wfl.nameId.split(
'+',1)
529 print(wfl.numId, stepNames)
530 for i,s
in enumerate(wfl.cmds):
532 print(
"\nWorkflow found in %s." % key)
534 print(
"Workflow also found in %s." % key)
541 if opt.raw
and opt.show: