def run(self): """ Runs the job template makerFunction with the set job execParams. Raises an exception if attempted to run more than once. execParam: "number_of_runs": the number of times this job should be run. The logbook from all the runs will be averaged. If more than one run is used, the JobResult.result will contain a list containing all the individualy returned job results. Returns a JobResult which contains a reference to this Job and the results of the run. """ if(self.jobResult != None): raise Exception("Cannot run a job more than once.") if(self.execParams.get == None or self.execParams["number_of_runs"] <= 0): raise ValueError("Must run Job zero or more times") logbooks = [] fResults = [] for i in range(self.execParams["number_of_runs"]): resultTuple = self.jobTempate.makerFunction(**self.execParams) if(resultTuple == None): raise Exception("Template makerFunction must return a tuple of the format (logbook, result)") logbook, result = resultTuple logbooks.append(logbook) fResults.append(result) if(len(logbooks) == 1): self.jobResult = JobResult(self, logbooks[0], fResults[0]) else: averagedLogbook = LogBookTools.averageLogbookValues(logbooks) self.jobResult = JobResult(self, averagedLogbook, fResults) return self.jobResult