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__':
101 'jetmc': [5.1, 13, 15, 25, 38, 39],
102 'metmc' : [5.1, 15, 25, 37, 38, 39],
103 'muonmc' : [5.1, 124.4, 124.5, 20, 21, 22, 23, 25, 30],
108 usage =
'usage: runTheMatrix.py --show -s '
110 parser = optparse.OptionParser(usage)
112 parser.add_option(
'-b',
'--batchName',
113 help=
'relval batch: suffix to be appended to Campaign name',
118 parser.add_option(
'-m',
'--memoryOffset',
119 help=
'memory of the wf for single core',
123 parser.add_option(
'--addMemPerCore',
124 help=
'increase of memory per each n > 1 core: memory(n_core) = memoryOffset + (n_core-1) * memPerCore',
128 parser.add_option(
'-j',
'--nproc',
129 help=
'number of processes. 0 Will use 4 processes, not execute anything but create the wfs',
133 parser.add_option(
'-t',
'--nThreads',
134 help=
'number of threads per process to use in cmsRun.',
138 parser.add_option(
'--nStreams',
139 help=
'number of streams to use in cmsRun.',
143 parser.add_option(
'--numberEventsInLuminosityBlock',
144 help=
'number of events in a luminosity block',
145 dest=
'numberEventsInLuminosityBlock',
149 parser.add_option(
'-n',
'--showMatrix',
150 help=
'Only show the worflows. Use --ext to show more',
155 parser.add_option(
'-e',
'--extended',
156 help=
'Show details of workflows, used with --show',
161 parser.add_option(
'-s',
'--selected',
162 help=
'Run a pre-defined selected matrix of wf. Deprecated, please use -l limited',
167 parser.add_option(
'-l',
'--list',
168 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',
172 parser.add_option(
'-r',
'--raw',
173 help=
'Temporary dump the .txt needed for prodAgent interface. To be discontinued soon. Argument must be the name of the set (standard, pileup,...)',
176 parser.add_option(
'-i',
'--useInput',
177 help=
'Use recyling where available. Either all, or a coma separated list of wf number.',
181 parser.add_option(
'-w',
'--what',
182 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 )',
186 parser.add_option(
'--step1',
187 help=
'Used with --raw. Limit the production to step1',
191 parser.add_option(
'--maxSteps',
192 help=
'Only run maximum on maxSteps. Used when we are only interested in first n steps.',
197 parser.add_option(
'--fromScratch',
198 help=
'Coma separated list of wf to be run without recycling. all is not supported as default.',
202 parser.add_option(
'--refRelease',
203 help=
'Allow to modify the recycling dataset version',
207 parser.add_option(
'--wmcontrol',
208 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',
209 choices=[
'init',
'test',
'submit',
'force'],
213 parser.add_option(
'--revertDqmio',
214 help=
'When submitting workflows to wmcontrol, force DQM outout to use pool and not DQMIO',
215 choices=[
'yes',
'no'],
219 parser.add_option(
'--optionswm',
220 help=
'Specify a few things for wm injection',
223 parser.add_option(
'--keep',
224 help=
'allow to specify for which coma separated steps the output is needed',
226 parser.add_option(
'--label',
227 help=
'allow to give a special label to the output dataset name',
229 parser.add_option(
'--command',
230 help=
'provide a way to add additional command to all of the cmsDriver commands in the matrix',
234 parser.add_option(
'--apply',
235 help=
'allow to use the --command only for 1 coma separeated',
238 parser.add_option(
'--workflow',
239 help=
'define a workflow to be created or altered from the matrix',
244 parser.add_option(
'--dryRun',
245 help=
'do not run the wf at all',
250 parser.add_option(
'--testbed',
251 help=
'workflow injection to cmswebtest (you need dedicated rqmgr account)',
256 parser.add_option(
'--noCafVeto',
257 help=
'Run from any source, ignoring the CAF label',
262 parser.add_option(
'--overWrite',
263 help=
'Change the content of a step for another. List of pairs.',
267 parser.add_option(
'--noRun',
268 help=
'Remove all run list selection from wfs',
273 parser.add_option(
'--das-options',
274 help=
'Options to be passed to dasgoclient.',
279 parser.add_option(
'--job-reports',
280 help=
'Dump framework job reports',
285 parser.add_option(
'--ibeos',
286 help=
'Use IB EOS site configuration',
291 parser.add_option(
'--sites',
292 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.',
294 default=
'T2_CH_CERN',
296 parser.add_option(
'--interactive',
297 help=
"Open the Matrix interactive shell",
301 parser.add_option(
'--dbs-url',
302 help=
'Overwrite DbsUrl value in JSON submitted to ReqMgr2',
307 opt,args = parser.parse_args()
308 os.environ[
"CMSSW_DAS_QUERY_SITES"]=opt.dasSites
310 try:
from commands
import getstatusoutput
as run_cmd
311 except:
from subprocess
import getstatusoutput
as run_cmd
313 ibeos_cache = os.path.join(os.getenv(
"LOCALRT"),
"ibeos_cache.txt")
314 if not os.path.exists(ibeos_cache):
315 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)
317 run_cmd(
"rm -f %s" % ibeos_cache)
318 print(
"Error: Unable to download ibeos cache information")
322 for cmssw_env
in [
"CMSSW_BASE",
"CMSSW_RELEASE_BASE" ]:
323 cmssw_base = os.getenv(cmssw_env,
None)
324 if not cmssw_base:
continue
325 cmssw_base = os.path.join(cmssw_base,
"src/Utilities/General/ibeos")
326 if os.path.exists(cmssw_base):
327 os.environ[
"PATH"]=cmssw_base+
":"+os.getenv(
"PATH")
328 os.environ[
"CMS_PATH"]=
"/cvmfs/cms-ib.cern.ch"
329 os.environ[
"CMSSW_USE_IBEOS"]=
"true"
330 print(
">> WARNING: You are using SITECONF from /cvmfs/cms-ib.cern.ch")
333 print(
'Deprecated, please use -l limited')
334 if opt.testList: opt.testList+=
',limited'
335 else: opt.testList=
'limited'
343 opt.apply=
map(stepOrIndex,opt.apply.split(
','))
345 opt.keep=
map(stepOrIndex,opt.keep.split(
','))
351 for entry
in opt.testList.split(
','):
352 if not entry:
continue
354 for k
in predefinedSet:
355 if k.lower().startswith(entry.lower())
or k.lower().endswith(entry.lower()):
356 testList.extend(predefinedSet[k])
361 testList.append(
float(entry))
363 print(entry,
'is not a possible selected entry')
365 opt.testList = list(set(testList))
368 if opt.useInput: opt.useInput = opt.useInput.split(
',')
369 if opt.fromScratch: opt.fromScratch = opt.fromScratch.split(
',')
370 if opt.nProcs: opt.nProcs=
int(opt.nProcs)
371 if opt.nThreads: opt.nThreads=
int(opt.nThreads)
372 if opt.nStreams: opt.nStreams=
int(opt.nStreams)
373 if (opt.numberEventsInLuminosityBlock): opt.numberEventsInLuminosityBlock=
int(opt.numberEventsInLuminosityBlock)
374 if (opt.memoryOffset): opt.memoryOffset=
int(opt.memoryOffset)
375 if (opt.memPerCore): opt.memPerCore=
int(opt.memPerCore)
380 opt.overWrite=eval(opt.overWrite)
385 intro =
"Welcome to the Matrix (? for help)"
389 cmd.Cmd.__init__(self)
393 for what
in tmp.files:
394 self.
opt_.what = what
397 self.
opt_.fromScratch)
401 """Clear the screen, put prompt at the top"""
405 print(
"Leaving the Matrix")
409 if inp ==
'x' or inp ==
'q':
413 print(
"\n".
join([
"predefined [predef1 [...]]\n",
414 "Run w/o argument, it will print the list of known predefined workflows.",
415 "Run with space-separated predefined workflows, it will print the workflow-ids registered to them"]))
418 if text
and len(text) > 0:
419 return [t
for t
in predefinedSet.keys()
if t.startswith(text)]
421 return predefinedSet.keys()
424 """Print the list of predefined workflows"""
425 print(
"List of predefined workflows")
427 for w
in arg.split():
428 if w
in predefinedSet.keys():
429 print(
"Predefined Set: %s" % w)
430 print(predefinedSet[w])
432 print(
"Unknown Set: %s" % w)
434 print(predefinedSet.keys())
437 print(
"\n".
join([
"showWorkflow [workflow1 [...]]\n",
438 "Run w/o arguments, it will print the list of registered macro-workflows.",
439 "Run with space-separated workflows, it will print the full list of workflow-ids registered to them"]))
442 if text
and len(text) > 0:
443 return [t
for t
in self.
matrices_.
keys()
if t.startswith(text)]
449 print(
"Available workflows:")
453 selected = arg.split()
456 print(
"Unknown workflow %s: skipping" % k)
459 wfName, stepNames = wfl.nameId.split(
'+',1)
460 print(
"%s %s %s" % (wfl.numId, wfName, stepNames))
461 print(
"%s contains %d workflows" % (k, len(self.
matrices_[k].workFlows)))
464 print(
"\n".
join([
"searchInWorkflow wfl_name search_regexp\n",
465 "This command will search for a match within all workflows registered to wfl_name.",
466 "The search is done on both the workflow name and the names of steps registered to it."]))
469 if text
and len(text) > 0:
470 return [t
for t
in self.
matrices_.
keys()
if t.startswith(text)]
477 print(
"searchInWorkflow name regexp")
480 print(
"Unknown workflow")
485 pattern = re.compile(args[1])
487 print(
"Failed to compile regexp %s" % args[1])
490 for wfl
in self.
matrices_[args[0]].workFlows:
491 wfName, stepNames = wfl.nameId.split(
'+',1)
492 if re.match(pattern, wfName)
or re.match(pattern, stepNames):
493 print(
"%s %s %s" % (wfl.numId, wfName, stepNames))
495 print(
"Found %d compatible workflows inside %s" % (counter, args[0]))
498 print(
"\n".
join([
"search search_regexp\n",
499 "This command will search for a match within all workflows registered.",
500 "The search is done on both the workflow name and the names of steps registered to it."]))
505 print(
"search regexp")
511 print(
"\n".
join([
"dumpWorkflowId [wfl-id1 [...]]\n",
512 "Dumps the details (cmsDriver commands for all steps) of the space-separated workflow-ids in input."]))
517 print(
"dumpWorkflowId [wfl-id1 [...]]")
524 for key, mrd
in self.
matrices_.iteritems():
525 for wfl
in mrd.workFlows:
526 if wfl.numId ==
float(wflid):
527 wfName, stepNames = wfl.nameId.split(
'+',1)
530 print(wfl.numId, stepNames)
531 for i,s
in enumerate(wfl.cmds):
533 print(
"\nWorkflow found in %s." % key)
535 print(
"Workflow also found in %s." % key)
542 if opt.raw
and opt.show: