Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-01 23:40:07

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