Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:39

0001 #!/usr/bin/env python3
0002 
0003 
0004 from __future__ import print_function
0005 class MatrixToProcess:
0006 
0007     def __init__(self,what='standard',strict=True):
0008         from Configuration.PyReleaseValidation.MatrixReader import MatrixReader
0009         self.mrd = MatrixReader(what,noRun=True)
0010         self.mrd.prepare('all','',None)
0011         self.configBuilders={}
0012         self.processes={}
0013         self.strict=strict
0014     def getKey(self,wfNumber,step):
0015         return str(wfNumber)+':'+str(step)
0016     
0017     def getProcess(self,wfNumber,step):
0018         key=self.getKey(wfNumber,step)
0019         if not key in self.configBuilders:
0020             self.load(wfNumber,step)
0021         if not key in self.configBuilders:
0022             return None
0023         return self.configBuilders[key].process
0024 
0025     def load(self,wfNumber,step):
0026         from Configuration.Applications.ConfigBuilder import ConfigBuilder
0027         from Configuration.Applications.cmsDriverOptions import OptionsFromCommand
0028         import copy
0029 
0030         if len(self.configBuilders)!=0 and self.strict:
0031             raise Exception('one should never be loading more than one process at a time due to python loading/altering feature')
0032         key=self.getKey(wfNumber,step)
0033         if key in self.configBuilders:
0034             return True
0035         
0036         for wf in self.mrd.workFlows:
0037             if float(wf.numId)!=wfNumber: continue
0038 
0039             if not hasattr(wf,'cmdStep%d'%(step)): continue
0040             if not getattr(wf,'cmdStep%d'%(step)): continue
0041             
0042             command=getattr(wf,'cmdStep%d'%(step))
0043             opt=OptionsFromCommand(command)
0044             if opt:
0045                 cb = ConfigBuilder(opt,with_input=True,with_output=True)
0046                 cb.prepare()
0047                 self.configBuilders[key]=copy.copy(cb)
0048                 return True
0049         print("could not satisfy the request for step",step,"of workflow",wfNumber)
0050         return False
0051                              
0052     def getConfig(self,wfNumber,step):
0053         key=self.getKey(wfNumber,step)
0054         if not key in self.configBuilders:   self.getProcess(wfNumber,step)
0055         if not key in self.configBuilders: return None
0056         return self.configBuilders[key].pythonCfgCode
0057 
0058     def identityTest(self,wfNumber,step):
0059         self.getProcess(wfNumber,step)
0060         key=self.getKey(wfNumber,step)
0061         if not key in self.configBuilders: return None
0062 
0063         cb=self.configBuilders[key]
0064         #need to compare those two for identity
0065         cb.process
0066         cd.pythonCfgCode
0067 
0068                     
0069     def listAll(self):
0070         for wf in self.mrd.workFlows:
0071             step=1
0072             print('---------------------') 
0073             print('process workflow',wf.numId)
0074             print()
0075             while self.load(float(wf.numId),step):
0076                 p=self.getProcess(float(wf.numId),step)
0077                 print(', '.join(s.label() for s in p.schedule))
0078                 #print p.outputModules()
0079                 step+=1
0080