def do_submit(self,args,history): # Start time start_time=time.time() # No arguments if len(args)==0: dirlist = os.listdir(self.main.currentdir) ii = 0 while ('ANALYSIS_'+str(ii) in dirlist): ii = ii+1 args.append(self.main.currentdir+'/ANALYSIS_'+str(ii)) # Checking argument number if len(args)>1: self.logger.error("wrong number of arguments for the command 'submit'.") self.help() return # Checking if a dataset has been defined if len(self.main.datasets)==0: self.logger.error("no dataset found; please define a dataset (via the command import).") self.logger.error("job submission aborted.") return # Checking if a selection item has been defined # if len(self.main.selection)==0 and self.main.merging.enable==False and \ # self.main.output == "": # self.logger.error("no analysis found. Please define an analysis (via the command plot).") # self.logger.error("job submission aborted.") # return # Treat the filename filename = os.path.expanduser(args[0]) if not filename.startswith('/'): filename = self.main.currentdir + "/" + filename filename = os.path.normpath(filename) # Checking folder if filename in self.forbiddenpaths: self.logger.error("the folder '"+filename+"' is a MadAnalysis folder. " + \ "You cannot overwrite it. Please choose another folder.") return # Saving job name as global variable self.main.lastjob_name = filename self.main.lastjob_status = False # Submission self.logger.debug('Launching SampleAnalyzer ...') if not self.submit(filename,history): return # Reading info from job output self.logger.debug('Go back to the Python interface ...') layout = Layout(self.main) if not self.extract(filename,layout): return # Status = GOOD self.main.lastjob_status = True # Computing self.logger.info(" Preparing data for the reports ...") layout.Initialize() # Creating the reports if not self.main.recasting.status=="on": self.CreateReports(args,history,layout) # End time end_time=time.time() self.logger.info(" Well done! Elapsed time = " + CmdSubmit.chronometer_display(end_time-start_time) )
def ImportJob(self, filename, myinterpreter, history): self.logger.info("SampleAnalyzer job folder is detected") self.logger.info( "Restore MadAnalysis configuration used for this job ...") # Ask question if not self.main.forced: self.logger.warning( "You are going to reinitialize MadAnalysis 5. The current configuration will be lost." ) self.logger.warning("Are you sure to do that ? (Y/N)") allowed_answers = ['n', 'no', 'y', 'yes'] answer = "" while answer not in allowed_answers: answer = raw_input("Answer: ") answer = answer.lower() if answer == "no" or answer == "n": return False self.main.datasets.Reset() # Reset selection self.main.selection.Reset() # Reset main self.main.ResetParameters() # Reset multiparticles self.main.multiparticles.Reset() # Opening a CmdDefine cmd_define = CmdDefine(self.main) # Loading particles input = ParticleReader(self.main.archi_info.ma5dir, cmd_define, self.main.mode) input.Load() input = MultiparticleReader(self.main.archi_info.ma5dir, cmd_define, self.main.mode, self.main.forced) input.Load() # Reset history myinterpreter.history = [] # Load script myinterpreter.load(filename + '/history.ma5') # Saving job name as global variable self.main.lastjob_name = filename self.main.lastjob_status = False # Extract info from ROOT file layout = Layout(self.main) if not self.extract(filename, layout): return # Initialize selection for generating report self.main.selection.RefreshStat() # Status = GOOD self.main.lastjob_status = True # Computing layout.Initialize() # Cleaning the directories if not FolderWriter.RemoveDirectory(self.main.lastjob_name + '/HTML', False): return if self.main.session_info.has_pdflatex: if not FolderWriter.RemoveDirectory( self.main.lastjob_name + '/PDF', False): return if self.main.session_info.has_latex: if not FolderWriter.RemoveDirectory( self.main.lastjob_name + '/DVI', False): return # Creating the reports self.CreateReports([self.main.lastjob_name], history, layout)
def do(self, args, history): # Checking argument number if len(args) != 1: logging.error("wrong number of arguments for the command '" + self.cmdname + "'.") self.help() return # Checking presence of a valid job if not self.do_possible(): return # Getting filename filename = os.path.expanduser(args[0]) if not filename.startswith('/'): filename = self.main.currentdir + "/" + filename filename = os.path.normpath(filename) # Checking folder if filename in self.forbiddenpaths: logging.error("the folder '"+filename+"' is MadAnalysis folder. " + \ "You cannot overwrite it. Please choose another folder.") return layout = Layout(self.main, filename, self.format) logging.info(" Preparing data for the report...") if not layout.Open(): return if not layout.CopyLogo(): return logging.info(" Saving all plots as image files...") if not layout.DoPlots(): return logging.info(" Computing cut efficiencies...") if not layout.DoEfficiencies(): return logging.info(" Generating the report...") if not layout.GenerateReport(history): return if self.format != ReportFormatType.HTML: if not self.main.forced: logging.warning( "Would you like to launch latex for creating a pdf file ? (Y/N)" ) allowed_answers = ['n', 'no', 'y', 'yes'] answer = "" while answer not in allowed_answers: answer = raw_input("Answer : ") answer = answer.lower() if answer == "no" or answer == "n": return layout.CompileReport()
def do_resubmit(self, args, history): # Start time start_time = time.time() # Checking argument number if len(args) != 0: self.logger.warning( "Command 'resubmit' takes no argument. Any argument will be skipped." ) # Checking presence of a valid job if self.main.lastjob_name is "": self.logger.error( "an analysis must be defined and ran before using the resubmit command." ) return False self.main.lastjob_status = False # Checking if new plots or cuts have been performed ToReAnalyze = False # Look for the last submit and resubmit last_submit_cmd = -1 for i in range(len(history) - 1): # Last history entry should be resubmit if history[i].startswith('submit') or history[i].startswith( 'resubmit'): last_submit_cmd = i newhistory = [] if last_submit_cmd == -1: ToReAnalyze = True else: for i in range(last_submit_cmd + 1, len(history)): newhistory.append(history[i]) ReAnalyzeCmdList = [ 'plot', 'select', 'reject', 'set main.clustering', 'set main.merging', 'define', 'set main.recast', 'import', 'set main.isolation' ] # Determining if we have to resubmit the job for cmd in newhistory: # Split cmd line into words words = cmd.split() # Creating a line with one whitespace between each word cmd2 = '' for word in words: if word != '': cmd2 += word + ' ' # Looping over patterns for pattern in ReAnalyzeCmdList: if cmd2.startswith(pattern): ToReAnalyze = True break # Found? if ToReAnalyze: break if ToReAnalyze: self.logger.info( " Creating the new histograms and/or applying the new cuts..." ) # Submission if not self.submit(self.main.lastjob_name, history): return self.logger.info(" Updating the reports...") else: self.logger.info( " No new histogram / cut to account for. Updating the reports..." ) # Reading info from job output layout = Layout(self.main) if not self.extract(self.main.lastjob_name, layout): return # Status = GOOD self.main.lastjob_status = True # Computing layout.Initialize() # Creating the reports self.CreateReports([self.main.lastjob_name], history, layout) # End time end_time = time.time() self.logger.info(" Well done! Elapsed time = " + CmdSubmit.chronometer_display(end_time - start_time))