Esempio n. 1
0
    def do_resubmit(self,args,history):

        # Start time
        start_time=time.time()

        # Checking argument number
        if len(args)!=0:
            logging.warning("Command 'resubmit' takes no argument. Any argument will be skipped.")

        # Checking presence of a valid job
        if self.main.lastjob_name is "":
            logging.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
        newhistory = []
        ToAdd = False
        Inside = False
        for cmd in history:
            if 'submit' in cmd and 'resubmit' not in cmd:
                ToAdd = True
                Inside = True
            elif ToAdd:
                if not Inside:
                    newhistory=[]
                    Inside = True
                if 'resubmit' in cmd:
                    Inside = False
                newhistory.append(cmd)
        ToReAnalyze = False
        ReAnalyzeCmdList = ['plot','select','reject','set main.clustering',
                            'set main.merging', 'set main.shower', 'define',
                            '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:
            logging.info("   Creating the new histograms and/or applying the new cuts...")
            # Submission
            if not self.submit(self.main.lastjob_name,history):
                return
            logging.info("   Updating the reports...")
        else:
            logging.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()

        # Cleaning the directories
        if not FolderWriter.RemoveDirectory(self.main.lastjob_name+'/HTML',False):
            return
        if self.main.pdflatex:
            if not FolderWriter.RemoveDirectory(self.main.lastjob_name+'/PDF',False):
                return
        if self.main.latex:
            if not FolderWriter.RemoveDirectory(self.main.lastjob_name+'/DVI',False):
                return 

        # Creating the reports
        self.CreateReports([self.main.lastjob_name],history,layout)

        # End time 
        end_time=time.time()
           
        logging.info("   Well done! Elapsed time = " + CmdSubmit.chronometer_display(end_time-start_time) )
Esempio n. 2
0
    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)
Esempio n. 3
0
    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:
             logging.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:
            logging.error("no dataset found; please define a dataset (via the command import).")
            logging.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 == "":
#            logging.error("no analysis found. Please define an analysis (via the command plot).")
#            logging.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:
            logging.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
        if not self.submit(filename,history):
            return

        # Reading info from job output
        layout = Layout(self.main)
        if not self.extract(filename,layout):
            return

        # Status = GOOD
        self.main.lastjob_status = True

        # Computing
        logging.info("   Preparing data for the reports ...")
        layout.Initialize()

        # Creating the reports
        self.CreateReports(args,history,layout)

        # End time 
        end_time=time.time()
           
        logging.info("   Well done! Elapsed time = " + CmdSubmit.chronometer_display(end_time-start_time) )
Esempio n. 4
0
    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))