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-',
52 'relval_2017':
'2017-',
53 'relval_2026':
'2026-',
54 'relval_identity':
'id-',
55 'relval_machine':
'mach-',
56 'relval_premix':
'premix-'
59 self.
files = [
'relval_standard' ,
75 'relval_highstats':
True ,
77 'relval_generator':
True,
78 'relval_extendedgen':
True,
79 'relval_production':
True,
81 'relval_upgrade':
False,
85 'relval_identity':
False,
86 'relval_machine':
True,
99 for k,v
in step.items():
100 if 'no_exec' in k :
continue
101 if k.lower() ==
'cfg':
104 if k.lower() ==
'input':
111 cmd +=
' ' + k +
' ' +
str(v)
112 return cfg, input, cmd
116 if len(overrides) > 0:
117 copyStep=
merge([overrides]+[step])
122 def readMatrix(self, fileNameIn, useInput=None, refRel=None, fromScratch=None):
126 print(
"processing", fileNameIn)
129 _tmpMod = __import__(
'Configuration.PyReleaseValidation.'+fileNameIn )
130 self.
relvalModule = sys.modules[
'Configuration.PyReleaseValidation.'+fileNameIn]
131 except Exception
as e:
132 print(
"ERROR importing file ", fileNameIn,
str(e))
135 if useInput
is not None:
136 print(
"request for INPUT for ", useInput)
153 fromInput[
float(k)]=0
155 fromInput[
float(i)]=0
158 fromScratch=
map(float,fromScratch)
159 for num
in fromScratch:
170 refRels=refRel.split(
',')
171 if len(refRels)!=len(self.
relvalModule.baseDataSetRelease):
180 [(x,refRel)
for x
in self.
relvalModule.baseDataSetRelease]
188 stepOverrides=wfInfo.overrides
192 if isinstance(wfName, list)
and len(wfName)>1:
193 if len(wfName)>2: wfSuffix = wfName[2]
197 if wfName.strip() ==
'': wfName = stepList[0]
203 if not isinstance(addCom, list): addCom=[addCom]
208 while len(addTo)!=len(stepList):
214 name = name+
'+'+wfKey
215 if len(wfSuffix)>0: name = name+wfSuffix
221 ilevel=fromInput[num]
223 for (stepIr,step)
in enumerate(reversed(stepList)):
225 stepI=(len(stepList)-stepIr)-1
231 testName=
'__'.
join(stepList[0:stepI+1])+
'INPUT'
233 testName=step+
'INPUT'
237 stepList[stepI]=testName
240 for p
in range(stepI):
246 for (stepI,step)
in enumerate(stepList):
252 if stepName
in [
'SKIMD',
'SKIMCOSD',
'SKIMDreHLT']:
257 if len(name) > 0 : name +=
'+'
262 if step+'INPUT' in self.relvalModule.steps.keys():
263 stepName = step+"INPUT"
264 stepList.remove(step)
265 stepList.insert(stepIndex,stepName)
267 stepNameTmp = stepName
268 if len(wfKey)>0: stepNameTmp = stepNameTmp.replace(
'_'+wfKey,
"")
269 if len(wfSuffix)>0: stepNameTmp = stepNameTmp.replace(wfSuffix,
"")
271 if addCom
and (
not addTo
or addTo[stepIndex]==1):
274 cfg, input, opts = self.
makeCmd(copyStep)
279 msg =
"FATAL ERROR: found both cfg and input for workflow "+
str(num)+
' step '+stepName
288 cmd =
'cmsDriver.py '+cfg+
' '+opts
290 cmd =
'cmsDriver.py step'+
str(stepIndex+1)+
' '+opts
292 cmd+=
' --io %s.io --python %s.py'%(stepName,stepName)
295 if stepIndex
in self.
apply or stepName
in self.
apply:
300 cmd=cmd.replace(
'DQMIO',
'DQM')
301 cmd=cmd.replace(
'--filetype DQM',
'')
303 ranStepList.append(stepName)
306 self.
workFlowSteps[(num,prefix)] = (num, name, commands, ranStepList)
311 def showRaw(self, useInput, refRel=None, fromScratch=None, what='all',step1Only=False,selected=None):
314 selected=
map(float,selected)
315 for matrixFile
in self.
files:
319 if self.
what !=
'all' and not any(el
in matrixFile
for el
in self.
what.
split(
",")):
320 print(
"ignoring non-requested file",matrixFile)
324 print(
"ignoring file not used by default (enable with -w)",matrixFile)
328 self.
readMatrix(matrixFile, useInput, refRel, fromScratch)
329 except Exception
as e:
330 print(
"ERROR reading file:", matrixFile,
str(e))
335 dataFileName = matrixFile.replace(
'relval_',
'cmsDriver_')+
'_hlt.txt'
336 outFile = open(dataFileName,
'w')
344 if selected
and not (key[0]
in selected):
347 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
350 wfName,stepNames= name.split(
'+',1)
352 stepNames=stepNames.replace(
'+SKIMCOSD',
'')
353 stepNames=stepNames.replace(
'+SKIMD',
'')
354 if 'HARVEST' in stepNames:
356 exactb=stepNames.index(
'+HARVEST')
357 exacte=stepNames.index(
'+',exactb+1)
if (
'+' in stepNames[exactb+1:])
else (len(stepNames))
358 stepNames=stepNames.replace(stepNames[exactb:exacte],
'')
361 step1,otherSteps = stepNames.split(
'+',1)
363 line =
str(num) +
' ++ '+ wfName
364 if otherSteps
and not step1Only:
365 line +=
' ++ ' +otherSteps.replace(
'+',
',')
369 if not isinstance(commands[0],str):
370 inputInfo=commands[0]
372 for (i,c)
in enumerate(otherSteps.split(
'+')):
374 for p
in range(len(indexAndSteps),i+2):
375 indexAndSteps.append(set())
376 indexAndSteps[i+1].
add((c,commands[i+1]))
380 if step1Only:
continue
381 line +=
' ++ REALDATA: '+inputInfo.dataSet
382 if inputInfo.run!=[]: line +=
', RUN:'+
'|'.
join(
map(str,inputInfo.run))
383 line +=
', FILES: ' +
str(inputInfo.files)
384 line +=
', EVENTS: '+
str(inputInfo.events)
385 if inputInfo.label!=
'':
386 line +=
', LABEL: ' +inputInfo.label
387 line +=
', LOCATION:'+inputInfo.location
390 line +=
' @@@ '+commands[0]
392 line=line.replace(
'DQMIO',
'DQM')
394 outFile.write(line+
'\n')
397 outFile.write(
'\n'+
'\n')
398 if step1Only:
continue
400 for (index,s)
in enumerate(indexAndSteps):
401 for (stepName,cmd)
in s:
403 if 'dasquery.log' in cmd:
continue
404 line =
'STEP%d ++ '%(stepIndex,) +stepName +
' @@@ '+cmd
406 line=line.replace(
'DQMIO',
'DQM')
407 outFile.write(line+
'\n')
408 outFile.write(
'\n'+
'\n')
410 print(
"wrote ",writtenWF,
' workflow'+(
's' if (writtenWF!=1)
else ''),
' to ', outFile.name)
416 if 'cms/caf/cms' in os.environ[
'CMS_PATH']:
421 if isinstance(workflow.cmds[0], InputInfo):
422 if cafVeto
and (workflow.cmds[0].location ==
'CAF' and not onCAF):
424 workflows.append(workflow)
429 if selected: selected = list(
map(float,selected))
432 fmt1 =
"%-6s %-35s [1]: %s ..."
433 fmt2 =
" %35s [%d]: %s ..."
434 print(
"\nfound a total of ", len(wfs),
' workflows:')
436 print(
" of which the following", len(selected),
'were selected:')
439 fmt1 =
"%-6s %-35s [1]: %s "
440 fmt2 =
" %35s [%d]: %s"
444 if selected
and float(wf.numId)
not in selected:
continue
445 if extended:
print(
'')
447 for i
in range(len(N),len(wf.cmds)): N.append(0)
449 wfName, stepNames = wf.nameId.split(
'+',1)
450 for i,s
in enumerate(wf.cmds):
453 print(fmt1 % (wf.numId, stepNames, (
str(s)+
' ')[:maxLen]))
455 print(fmt2 % (
' ', i+1, (
str(s)+
' ')[:maxLen]))
457 print(
"%-6s %-35s "% (wf.numId, stepNames))
460 for i,n
in enumerate(N):
461 if n:
print(n,
'workflows with',i+1,
'steps')
474 if pref != prefixIn :
continue
479 num, name, commands, stepList = val
480 nameId =
str(num)+
'_'+name
482 print(
"==> duplicate name found for ", nameId)
484 print(
' ignoring : ', val)
492 def prepare(self, useInput=None, refRel='', fromScratch=None):
494 for matrixFile
in self.
files:
495 if self.
what !=
'all' and not any(el
in matrixFile
for el
in self.
what.
split(
",")):
496 print(
"ignoring non-requested file",matrixFile)
499 print(
"ignoring",matrixFile,
"from default matrix")
503 self.
readMatrix(matrixFile, useInput, refRel, fromScratch)
504 except Exception
as e:
505 print(
"ERROR reading file:", matrixFile,
str(e))
510 except Exception
as e:
511 print(
"ERROR creating workflows :",
str(e))
515 def show(self, selected=None, extended=True, cafVeto=True):
518 print(
'\n',
'-'*80,
'\n')
524 pickle.dump(self.
workFlows, open(
'theMatrix.pkl',
'w') )