1 from __future__
import print_function
4 from Configuration.PyReleaseValidation.WorkFlow
import WorkFlow
5 from Configuration.PyReleaseValidation.MatrixUtil
import InputInfo
44 'relval_highstats':
'hi-' ,
45 'relval_pileup':
'PU-' ,
46 'relval_generator':
'gen-',
47 'relval_extendedgen':
'genExt-',
48 'relval_production':
'prod-' ,
50 'relval_upgrade':
'upg-',
51 'relval_2017':
'2017-',
52 'relval_2026':
'2026-',
53 'relval_identity':
'id-',
54 'relval_machine':
'mach-',
55 'relval_premix':
'premix-'
58 self.
files = [
'relval_standard' ,
73 'relval_highstats':
True ,
75 'relval_generator':
True,
76 'relval_extendedgen':
True,
77 'relval_production':
True,
79 'relval_upgrade':
False,
82 'relval_identity':
False,
83 'relval_machine':
True,
96 for k,v
in step.items():
97 if 'no_exec' in k :
continue
98 if k.lower() ==
'cfg':
101 if k.lower() ==
'input':
108 cmd +=
' ' + k +
' ' +
str(v)
109 return cfg, input, cmd
113 if len(overrides) > 0:
114 copyStep=
merge([overrides]+[step])
119 def readMatrix(self, fileNameIn, useInput=None, refRel=None, fromScratch=None):
123 print(
"processing", fileNameIn)
126 _tmpMod = __import__(
'Configuration.PyReleaseValidation.'+fileNameIn )
127 self.
relvalModule = sys.modules[
'Configuration.PyReleaseValidation.'+fileNameIn]
128 except Exception
as e:
129 print(
"ERROR importing file ", fileNameIn,
str(e))
132 if useInput
is not None:
133 print(
"request for INPUT for ", useInput)
150 fromInput[
float(k)]=0
152 fromInput[
float(i)]=0
155 fromScratch=
map(float,fromScratch)
156 for num
in fromScratch:
167 refRels=refRel.split(
',')
168 if len(refRels)!=len(self.
relvalModule.baseDataSetRelease):
177 [(x,refRel)
for x
in self.
relvalModule.baseDataSetRelease]
185 stepOverrides=wfInfo.overrides
189 if isinstance(wfName, list)
and len(wfName)>1:
190 if len(wfName)>2: wfSuffix = wfName[2]
194 if wfName.strip() ==
'': wfName = stepList[0]
200 if not isinstance(addCom, list): addCom=[addCom]
205 while len(addTo)!=len(stepList):
211 name = name+
'+'+wfKey
212 if len(wfSuffix)>0: name = name+wfSuffix
218 ilevel=fromInput[num]
220 for (stepIr,step)
in enumerate(reversed(stepList)):
222 stepI=(len(stepList)-stepIr)-1
228 testName=
'__'.
join(stepList[0:stepI+1])+
'INPUT'
230 testName=step+
'INPUT'
234 stepList[stepI]=testName
237 for p
in range(stepI):
243 for (stepI,step)
in enumerate(stepList):
249 if stepName
in [
'SKIMD',
'SKIMCOSD',
'SKIMDreHLT']:
254 if len(name) > 0 : name +=
'+'
259 if step+'INPUT' in self.relvalModule.steps.keys():
260 stepName = step+"INPUT"
261 stepList.remove(step)
262 stepList.insert(stepIndex,stepName)
264 stepNameTmp = stepName
265 if len(wfKey)>0: stepNameTmp = stepNameTmp.replace(
'_'+wfKey,
"")
266 if len(wfSuffix)>0: stepNameTmp = stepNameTmp.replace(wfSuffix,
"")
268 if addCom
and (
not addTo
or addTo[stepIndex]==1):
271 cfg, input, opts = self.
makeCmd(copyStep)
276 msg =
"FATAL ERROR: found both cfg and input for workflow "+
str(num)+
' step '+stepName
285 cmd =
'cmsDriver.py '+cfg+
' '+opts
287 cmd =
'cmsDriver.py step'+
str(stepIndex+1)+
' '+opts
289 cmd+=
' --io %s.io --python %s.py'%(stepName,stepName)
292 if stepIndex
in self.
apply or stepName
in self.
apply:
297 cmd=cmd.replace(
'DQMIO',
'DQM')
298 cmd=cmd.replace(
'--filetype DQM',
'')
300 ranStepList.append(stepName)
303 self.
workFlowSteps[(num,prefix)] = (num, name, commands, ranStepList)
308 def showRaw(self, useInput, refRel=None, fromScratch=None, what='all',step1Only=False,selected=None):
311 selected=
map(float,selected)
312 for matrixFile
in self.
files:
316 if self.
what !=
'all' and self.
what not in matrixFile:
317 print(
"ignoring non-requested file",matrixFile)
321 print(
"ignoring file not used by default (enable with -w)",matrixFile)
325 self.
readMatrix(matrixFile, useInput, refRel, fromScratch)
326 except Exception
as e:
327 print(
"ERROR reading file:", matrixFile,
str(e))
332 dataFileName = matrixFile.replace(
'relval_',
'cmsDriver_')+
'_hlt.txt'
333 outFile = open(dataFileName,
'w')
341 if selected
and not (key[0]
in selected):
344 if key[0]==203.1
or key[0]==204.1
or key[0]==205.1
or key[0]==4.51
or key[0]==4.52:
continue
347 wfName,stepNames= name.split(
'+',1)
349 stepNames=stepNames.replace(
'+SKIMCOSD',
'')
350 stepNames=stepNames.replace(
'+SKIMD',
'')
351 if 'HARVEST' in stepNames:
353 exactb=stepNames.index(
'+HARVEST')
354 exacte=stepNames.index(
'+',exactb+1)
if (
'+' in stepNames[exactb+1:])
else (len(stepNames))
355 stepNames=stepNames.replace(stepNames[exactb:exacte],
'')
358 step1,otherSteps = stepNames.split(
'+',1)
360 line =
str(num) +
' ++ '+ wfName
361 if otherSteps
and not step1Only:
362 line +=
' ++ ' +otherSteps.replace(
'+',
',')
366 if not isinstance(commands[0],str):
367 inputInfo=commands[0]
369 for (i,c)
in enumerate(otherSteps.split(
'+')):
371 for p
in range(len(indexAndSteps),i+2):
372 indexAndSteps.append(set())
373 indexAndSteps[i+1].
add((c,commands[i+1]))
377 if step1Only:
continue
378 line +=
' ++ REALDATA: '+inputInfo.dataSet
379 if inputInfo.run!=[]: line +=
', RUN:'+
'|'.
join(
map(str,inputInfo.run))
380 line +=
', FILES: ' +
str(inputInfo.files)
381 line +=
', EVENTS: '+
str(inputInfo.events)
382 if inputInfo.label!=
'':
383 line +=
', LABEL: ' +inputInfo.label
384 line +=
', LOCATION:'+inputInfo.location
387 line +=
' @@@ '+commands[0]
389 line=line.replace(
'DQMIO',
'DQM')
391 outFile.write(line+
'\n')
394 outFile.write(
'\n'+
'\n')
395 if step1Only:
continue
397 for (index,s)
in enumerate(indexAndSteps):
398 for (stepName,cmd)
in s:
400 if 'dasquery.log' in cmd:
continue
401 line =
'STEP%d ++ '%(stepIndex,) +stepName +
' @@@ '+cmd
403 line=line.replace(
'DQMIO',
'DQM')
404 outFile.write(line+
'\n')
405 outFile.write(
'\n'+
'\n')
407 print(
"wrote ",writtenWF,
' workflow'+(
's' if (writtenWF!=1)
else ''),
' to ', outFile.name)
413 if 'cms/caf/cms' in os.environ[
'CMS_PATH']:
418 if isinstance(workflow.cmds[0], InputInfo):
419 if cafVeto
and (workflow.cmds[0].location ==
'CAF' and not onCAF):
421 workflows.append(workflow)
426 if selected: selected = list(
map(float,selected))
429 fmt1 =
"%-6s %-35s [1]: %s ..."
430 fmt2 =
" %35s [%d]: %s ..."
431 print(
"\nfound a total of ", len(wfs),
' workflows:')
433 print(
" of which the following", len(selected),
'were selected:')
436 fmt1 =
"%-6s %-35s [1]: %s "
437 fmt2 =
" %35s [%d]: %s"
441 if selected
and float(wf.numId)
not in selected:
continue
442 if extended:
print(
'')
444 for i
in range(len(N),len(wf.cmds)): N.append(0)
446 wfName, stepNames = wf.nameId.split(
'+',1)
447 for i,s
in enumerate(wf.cmds):
450 print(fmt1 % (wf.numId, stepNames, (
str(s)+
' ')[:maxLen]))
452 print(fmt2 % (
' ', i+1, (
str(s)+
' ')[:maxLen]))
454 print(
"%-6s %-35s "% (wf.numId, stepNames))
457 for i,n
in enumerate(N):
458 if n:
print(n,
'workflows with',i+1,
'steps')
471 if pref != prefixIn :
continue
476 num, name, commands, stepList = val
477 nameId =
str(num)+
'_'+name
479 print(
"==> duplicate name found for ", nameId)
481 print(
' ignoring : ', val)
489 def prepare(self, useInput=None, refRel='', fromScratch=None):
491 for matrixFile
in self.
files:
492 if self.
what !=
'all' and self.
what not in matrixFile:
493 print(
"ignoring non-requested file",matrixFile)
496 print(
"ignoring",matrixFile,
"from default matrix")
500 self.
readMatrix(matrixFile, useInput, refRel, fromScratch)
501 except Exception
as e:
502 print(
"ERROR reading file:", matrixFile,
str(e))
507 except Exception
as e:
508 print(
"ERROR creating workflows :",
str(e))
512 def show(self, selected=None, extended=True, cafVeto=True):
515 print(
'\n',
'-'*80,
'\n')
521 pickle.dump(self.
workFlows, open(
'theMatrix.pkl',
'w') )