Ejemplo n.º 1
0
    def ImportUFO(self,filename):
        self.logger.info("UFO model folder is detected")

        # UFO mode is forbidden in RECO level
        if self.main.mode==MA5RunningType.RECO:
            self.logger.error("cannot import particles in MA5 reconstructed mode")
            return False
        
        # Other modes : parton and hadron
        self.logger.info("Import all particles defined in the model ...")
        cmd_define = CmdDefine(self.main)
        
        ufo = UFOReader(filename,cmd_define)
        if not ufo.OpenParticle():
            return False
        if not ufo.ReadParticle():
            return False
        if not ufo.CloseParticle():
            return False
        if not ufo.OpenParameter():
            return False
        if not ufo.ReadParameter():
            return False
        if not ufo.CloseParameter():
            return False

        if len(ufo.parts.parts)==0:
            self.logger.warning("UFO model contained no particles")
            return

        # Reseting only particles, kept multiparticles
        self.main.multiparticles.ResetParticles()

        # Use new particles
        ufo.CreateParticle()
Ejemplo n.º 2
0
    def ImportJob(self, filename, myinterpreter):
        logging.info("SampleAnalyzer job folder is detected")
        logging.info("Restore MadAnalysis configuration used for this job ...")

        # Ask question
        if not self.main.forced:
            logging.warning(
                "You are going to reinitialize MadAnalysis 5. The current configuration will be lost."
            )
            logging.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.ma5dir, cmd_define, self.main.mode)
        input.Load()
        input = MultiparticleReader(self.main.ma5dir, cmd_define,
                                    self.main.mode)
        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
        if not self.extract(filename):
            return

        # Initialize selection for generating report
        self.main.selection.RefreshStat()

        # Status = GOOD
        self.main.lastjob_status = True
Ejemplo n.º 3
0
    def __init__(self, main, *arg, **opt):

        # Calling constructor from InterpreterBase
        InterpreterBase.__init__(self, *arg, **opt)

        # Getting back main
        self.main = main

        # Getting back all commands
        self.cmd_set = CmdSet(main)
        self.cmd_define = CmdDefine(main)
        self.cmd_display = CmdDisplay(main)
        self.cmd_display_datasets = CmdDisplayDatasets(main)
        self.cmd_display_particles = CmdDisplayParticles(main)
        self.cmd_display_multiparticles = CmdDisplayMultiparticles(main)
        self.cmd_import = CmdImport(main)
        self.cmd_remove = CmdRemove(main)
        self.cmd_swap = CmdSwap(main)
        self.cmd_plot = CmdPlot(main)
        self.cmd_reject = CmdCut(main, CutType.REJECT)
        self.cmd_select = CmdCut(main, CutType.SELECT)
        self.cmd_preview = CmdPreview(main)
        self.cmd_reset = CmdReset(main)
        self.cmd_open = CmdOpen(main)
        self.cmd_submit = CmdSubmit(main)
        self.cmd_resubmit = CmdSubmit(main, resubmit=True)
        self.cmd_generate_latex         = CmdGenerate(main,\
                                                      ReportFormatType.LATEX)
        self.cmd_generate_pdflatex      = CmdGenerate(main,\
                                                      ReportFormatType.PDFLATEX)
        self.cmd_generate_html          = CmdGenerate(main,\
                                                      ReportFormatType.HTML)
        self.cmd_install = CmdInstall(main)

        # Initializing multiparticle
        self.InitializeParticle()
        self.InitializeMultiparticle()

        # Importing history
        self.history_file = os.path.normpath(self.main.ma5dir + '/.ma5history')
        try:
            readline.read_history_file(self.history_file)
        except:
            pass
Ejemplo n.º 4
0
    def ResetMultiparticles(self):

        # 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()
Ejemplo n.º 5
0
    def __init__(self, main,*arg, **opt):

        # Calling constructor from InterpreterBase
        InterpreterBase.__init__(self, *arg, **opt)

        # Getting back main
        self.main = main

        # Getting back all commands
        self.cmd_set                    = CmdSet(main)
        self.cmd_define                 = CmdDefine(main)
        self.cmd_display                = CmdDisplay(main)
        self.cmd_display_datasets       = CmdDisplayDatasets(main)
        self.cmd_display_particles      = CmdDisplayParticles(main)
        self.cmd_display_multiparticles = CmdDisplayMultiparticles(main)
        self.cmd_import                 = CmdImport(main)
        self.cmd_remove                 = CmdRemove(main)
        self.cmd_swap                   = CmdSwap(main) 
        self.cmd_plot                   = CmdPlot(main)
        self.cmd_reject                 = CmdCut(main,CutType.REJECT)
        self.cmd_select                 = CmdCut(main,CutType.SELECT)
        self.cmd_preview                = CmdPreview(main)
        self.cmd_reset                  = CmdReset(main)
        self.cmd_open                   = CmdOpen(main)
        self.cmd_submit                 = CmdSubmit(main)
        self.cmd_resubmit               = CmdSubmit(main,resubmit=True)
        self.cmd_generate_latex         = CmdGenerate(main,\
                                                      ReportFormatType.LATEX) 
        self.cmd_generate_pdflatex      = CmdGenerate(main,\
                                                      ReportFormatType.PDFLATEX) 
        self.cmd_generate_html          = CmdGenerate(main,\
                                                      ReportFormatType.HTML)
        self.cmd_install                = CmdInstall(main)
        
        # Initializing multiparticle
        self.InitializeParticle()
        self.InitializeMultiparticle()

        # Importing history
        self.history_file = os.path.normpath(self.main.ma5dir + '/.ma5history')
        try:
            readline.read_history_file(self.history_file)
        except:
            pass
Ejemplo n.º 6
0
class Interpreter(InterpreterBase):
    """Particularisation of the cmd command for MA5"""

    def __init__(self, main,*arg, **opt):

        # Calling constructor from InterpreterBase
        InterpreterBase.__init__(self, *arg, **opt)

        # Getting back main
        self.main = main

        # Getting back all commands
        self.cmd_set                    = CmdSet(main)
        self.cmd_define                 = CmdDefine(main)
        self.cmd_display                = CmdDisplay(main)
        self.cmd_display_datasets       = CmdDisplayDatasets(main)
        self.cmd_display_particles      = CmdDisplayParticles(main)
        self.cmd_display_multiparticles = CmdDisplayMultiparticles(main)
        self.cmd_import                 = CmdImport(main)
        self.cmd_remove                 = CmdRemove(main)
        self.cmd_swap                   = CmdSwap(main) 
        self.cmd_plot                   = CmdPlot(main)
        self.cmd_reject                 = CmdCut(main,CutType.REJECT)
        self.cmd_select                 = CmdCut(main,CutType.SELECT)
        self.cmd_reset                  = CmdReset(main)
        self.cmd_open                   = CmdOpen(main)
        self.cmd_submit                 = CmdSubmit(main)
        self.cmd_resubmit               = CmdSubmit(main,resubmit=True)
        self.cmd_install                = CmdInstall(main)
        
        # Initializing multiparticle
        self.InitializeParticle()
        self.InitializeMultiparticle()

        # Importing history
        self.history_file = os.path.normpath(self.main.ma5dir + '/.ma5history')
        try:
            readline.read_history_file(self.history_file)
        except:
            pass
                                    
    def __del__(self):
        try:
            readline.set_history_length(100)
            readline.write_history_file(self.history_file)
        except:
            pass
                

    def do_set(self,line):
        self.cmd_set.do(self.split_arg(line),line)

    def help_set(self):
        self.cmd_set.help()

    def complete_set(self,text,line,begidx,endidx):
        return self.cmd_set.complete(text,line,begidx,endidx)

    def do_define(self,line):
        self.cmd_define.do(self.split_arg(line))

    def help_define(self):
        self.cmd_define.help()

    def complete_define(self,text,line,begidx,endidx):
        return self.cmd_define.complete(text,line,begidx,endidx)

    def do_display(self,line):
        self.cmd_display.do(self.split_arg(line))

    def help_display(self):
        self.cmd_display.help()

    def complete_display(self,text,line,begidx,endidx):
        return self.cmd_display.complete(text,line,begidx,endidx)

    def do_display_particles(self,line):
        self.cmd_display_particles.do(self.split_arg(line))

    def help_display_particles(self):
        self.cmd_display_particles.help()

    def complete_display_particles(self,text,line,begidx,endidx):
        return self.cmd_display_particles.complete(text,line,begidx,endidx)

    def do_display_multiparticles(self,line):
        self.cmd_display_multiparticles.do(self.split_arg(line))

    def help_display_multiparticles(self):
        self.cmd_display_multiparticles.help()

    def complete_display_multiparticles(self,text,line,begidx,endidx):
        return self.cmd_display_multiparticles.complete(text,line,begidx,endidx)

    def do_display_datasets(self,line):
        self.cmd_display_datasets.do(self.split_arg(line))

    def help_display_datasets(self):
        self.cmd_display_datasets.help()

    def complete_display_datasets(self,text,line,begidx,endidx):
        return self.cmd_display_datasets.complete(text,line,begidx,endidx)

    def do_import(self,line):
        self.cmd_import.do(self.split_arg(line),self,self.history)

    def help_import(self):
        self.cmd_import.help()

    def complete_import(self,text,line,begidx,endidx):
        return self.cmd_import.complete(text,line,begidx,endidx)

     # Restart
    def do_restart(self, line):
        """ sending a signal allowing to restart the interpreter """
        if self.main.script:
            logging.warning("'restart' command is not allowed in script mode.")
        else:
            YES=False
            # Asking the safety question
            if not Main.forced:
                logging.warning("Are you sure to restart the MadAnalysis 5 session? (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":
                       YES=False
                       break
                   elif answer=='yes' or answer=='y':
                       YES=True
                       break
            if YES:
                self.main.repeatSession=True
                return True
            else:
                pass

    def help_restart(self):
        logging.info("   Syntax: restart ")
        logging.info("   Quit the current MadAnalysis sessiona and open a new one.")
        logging.info("   All the information will be discarded.")

    def do_remove(self,line):
        self.cmd_remove.do(self.split_arg(line))

    def help_remove(self):
        self.cmd_remove.help()

    def complete_remove(self,text,line,begidx,endidx):
        return self.cmd_remove.complete(text,line,begidx,endidx)

    def do_swap(self,line):
        self.cmd_swap.do(self.split_arg(line))

    def help_swap(self):
        self.cmd_swap.help()

    def complete_swap(self,text,line,begidx,endidx):
        return self.cmd_swap.complete(text,line,begidx,endidx)

    def do_install(self,line):
        result = self.cmd_install.do(self.split_arg(line))
        if result=='restart':
            logging.info(" ")
            logging.info("MadAnalysis 5 must be restarted for taking into account the present installation.")
            return self.do_restart('restart')

    def help_install(self):
        self.cmd_install.help()

    def complete_install(self,text,line,begidx,endidx):
        return self.cmd_install.complete(text,self.split_arg(line),begidx,endidx)

    def do_open(self,line):
        self.cmd_open.do(self.split_arg(line))

    def help_open(self):
        self.cmd_open.help()

    def complete_open(self,text,line,begidx,endidx):
        return self.cmd_open.complete(text,line,begidx,endidx)

    def do_reset(self,line):
        self.cmd_reset.do(self.split_arg(line),self)

    def help_reset(self):
        self.cmd_reset.help()

    def complete_reset(self,text,line,begidx,endidx):
        return self.cmd_reset.complete(text,line,begidx,endidx)

    def do_submit(self,line):
        self.cmd_submit.do(self.split_arg(line),self.history)

    def help_submit(self):
        self.cmd_submit.help()

    def complete_submit(self,text,line,begidx,endidx):
        return self.cmd_submit.complete(text,line,begidx,endidx)

    def do_resubmit(self,line):
        self.cmd_resubmit.do(self.split_arg(line),self.history)

    def help_resubmit(self):
        self.cmd_resubmit.help()

    def complete_resubmit(self,text,line,begidx,endidx):
        return self.cmd_resubmit.complete(text,line,begidx,endidx)

    def do_plot(self,line):
        self.cmd_plot.do(self.split_arg(line))

    def help_plot(self):
        self.cmd_plot.help()

    def complete_plot(self,text,line,begidx,endidx):
        tmp = line.replace("["," [ ")
        tmp = tmp.replace("]"," ] ")
        tmp = tmp.replace(")"," ) ")
        tmp = tmp.replace("("," ( ")
        tmp = tmp.replace(","," , ")
        return self.cmd_plot.complete(text,self.split_arg(tmp),begidx,endidx)

    def do_reject(self,line):
        self.cmd_reject.do(self.split_arg(line))

    def help_reject(self):
        self.cmd_reject.help()

    def complete_reject(self,text,line,begidx,endidx):
        tmp = line.replace("["," [ ")
        tmp = tmp.replace("]"," ] ")
        tmp = tmp.replace("("," ( ")
        tmp = tmp.replace(")"," ) ")
        return self.cmd_reject.complete(text,self.split_arg(tmp),begidx,endidx)

    def do_select(self,line):
        self.cmd_select.do(self.split_arg(line))

    def help_select(self):
        self.cmd_select.help()

    def complete_select(self,text,line,begidx,endidx):
        tmp = line.replace("["," [ ")
        tmp = tmp.replace("]"," ] ")
        tmp = tmp.replace("("," ( ")
        tmp = tmp.replace(")"," ) ")
        return self.cmd_select.complete(text,self.split_arg(tmp),begidx,endidx)

    def InitializeParticle(self):
        input = ParticleReader(self.main.ma5dir,self.cmd_define,self.main.mode)
        input.Load()

    def InitializeMultiparticle(self):
        input = MultiparticleReader(self.main.ma5dir,self.cmd_define,self.main.mode,self.main.forced)
        input.Load()

    # PreLoop
    def preloop(self):
        """Initializing before starting the main loop"""
        self.prompt = 'ma5>'
#        if readline and not 'libedit' in readline.__doc__:
#            readline.set_completion_display_matches_hook(self.print_suggestions)
            

    def deal_multiple_categories(self, dico):
        """convert the multiple category in a formatted list understand by our
        specific readline parser"""

        if 'libedit' in readline.__doc__:
            # No parser in this case, just send all the valid options
            out = []
            for name, opt in dico.items():
                out += opt
            return out

        # That's the real work
        out = []
        valid=0
        # if the key starts with number order the key with that number.
        for name, opt in dico.items():
            if not opt:
                continue
            name = name.replace(' ', '_')
            valid += 1
            out.append(opt[0].rstrip()+'@@'+name+'@@')
            # Remove duplicate
            d = {}
            for x in opt:
                d[x] = 1    
            opt = list(d.keys())
            opt.sort()
            out += opt

            
        if valid == 1:
            out = out[1:]
        return out
    
    def print_suggestions(self, substitution, matches, longest_match_length) :
        """print auto-completions by category"""
        longest_match_length += len(self.completion_prefix)
        try:
            if len(matches) == 1:
                self.stdout.write(matches[0]+' ')
                return
            self.stdout.write('\n')
            l2 = [a[-2:] for a in matches]
            if '@@' in l2:
                nb_column = self.getTerminalSize()//(longest_match_length+1)
                pos=0
                for val in self.completion_matches:
                    if val.endswith('@@'):
                        category = val.rsplit('@@',2)[1]
                        category = category.replace('_',' ')
                        self.stdout.write('\n %s:\n%s\n' % (category, '=' * (len(category)+2)))
                        start = 0
                        pos = 0
                        continue
                    elif pos and pos % nb_column ==0:
                        self.stdout.write('\n')
                    self.stdout.write(self.completion_prefix + val + \
                                      ' ' * (longest_match_length +1 -len(val)))
                    pos +=1
                self.stdout.write('\n')
            else:
                # nb column
                nb_column = self.getTerminalSize()//(longest_match_length+1)
                for i,val in enumerate(matches):
                    if i and i%nb_column ==0:
                        self.stdout.write('\n')
                    self.stdout.write(self.completion_prefix + val + \
                                     ' ' * (longest_match_length +1 -len(val)))
                self.stdout.write('\n')
    
            self.stdout.write(self.prompt+readline.get_line_buffer())
            self.stdout.flush()
        except Exception, error:
            if __debug__:
                 print error
Ejemplo n.º 7
0
class Interpreter(InterpreterBase):
    """Particularisation of the cmd command for MA5"""

    def __init__(self, main,*arg, **opt):

        # Calling constructor from InterpreterBase
        InterpreterBase.__init__(self, *arg, **opt)

        # Getting back main
        self.main = main

        # Getting back all commands
        self.cmd_set                    = CmdSet(main)
        self.cmd_define                 = CmdDefine(main)
        self.cmd_define_region          = CmdDefineRegion(main)
        self.cmd_display                = CmdDisplay(main)
        self.cmd_display_datasets       = CmdDisplayDatasets(main)
        self.cmd_display_multiparticles = CmdDisplayMultiparticles(main)
        self.cmd_display_particles      = CmdDisplayParticles(main)
        self.cmd_display_regions        = CmdDisplayRegions(main)
        self.cmd_import                 = CmdImport(main)
        self.cmd_remove                 = CmdRemove(main)
        self.cmd_swap                   = CmdSwap(main) 
        self.cmd_plot                   = CmdPlot(main)
        self.cmd_reject                 = CmdCut(main,CutType.REJECT)
        self.cmd_select                 = CmdCut(main,CutType.SELECT)
        self.cmd_reset                  = CmdReset(main)
        self.cmd_open                   = CmdOpen(main)
        self.cmd_submit                 = CmdSubmit(main)
        self.cmd_resubmit               = CmdSubmit(main,resubmit=True)
        self.cmd_install                = CmdInstall(main)

        # Initializing multiparticle
        self.InitializeParticle()
        self.InitializeMultiparticle()

        # Importing history
        self.history_file = os.path.normpath(self.main.archi_info.ma5dir + '/.ma5history')
        try:
            readline.read_history_file(self.history_file)
        except:
            pass
                                    
    def __del__(self):
        try:
            readline.set_history_length(100)
            readline.write_history_file(self.history_file)
        except:
            pass
                

    def do_set(self,line):
        self.cmd_set.do(self.split_arg(line),line)

    def help_set(self):
        self.cmd_set.help()

    def complete_set(self,text,line,begidx,endidx):
        return self.cmd_set.complete(text,line,begidx,endidx)

    def do_define(self,line):
        self.cmd_define.do(self.split_arg(line))

    def do_define_region(self,line):
        self.cmd_define_region.do(self.split_arg(line))

    def help_define(self):
        self.cmd_define.help()

    def help_define_region(self):
        self.cmd_define_region.help()

    def complete_define(self,text,line,begidx,endidx):
        return self.cmd_define.complete(text,line,begidx,endidx)

    def complete_define_region(self,text,line,begidx,endidx):
        return self.cmd_define_region.complete(text,line,begidx,endidx)

    def do_display(self,line):
        self.cmd_display.do(self.split_arg(line))

    def help_display(self):
        self.cmd_display.help()

    def complete_display(self,text,line,begidx,endidx):
        return self.cmd_display.complete(text,line,begidx,endidx)

    def do_display_particles(self,line):
        self.cmd_display_particles.do(self.split_arg(line))

    def help_display_particles(self):
        self.cmd_display_particles.help()

    def complete_display_particles(self,text,line,begidx,endidx):
        return self.cmd_display_particles.complete(text,line,begidx,endidx)

    def do_display_multiparticles(self,line):
        self.cmd_display_multiparticles.do(self.split_arg(line))

    def help_display_multiparticles(self):
        self.cmd_display_multiparticles.help()

    def complete_display_multiparticles(self,text,line,begidx,endidx):
        return self.cmd_display_multiparticles.complete(text,line,begidx,endidx)

    def do_display_datasets(self,line):
        self.cmd_display_datasets.do(self.split_arg(line))

    def do_display_regions(self,line):
        self.cmd_display_regions.do(self.split_arg(line))

    def help_display_datasets(self):
        self.cmd_display_datasets.help()

    def help_display_regions(self):
        self.cmd_display_regions.help()

    def complete_display_datasets(self,text,line,begidx,endidx):
        return self.cmd_display_datasets.complete(text,line,begidx,endidx)

    def complete_display_regionss(self,text,line,begidx,endidx):
        return self.cmd_display_regions.complete(text,line,begidx,endidx)

    def do_import(self,line):
        self.cmd_import.do(self.split_arg(line),self,self.history)

    def help_import(self):
        self.cmd_import.help()

    def complete_import(self,text,line,begidx,endidx):
        return self.cmd_import.complete(text,line,begidx,endidx)

     # Restart
    def do_restart(self, line):
        """ sending a signal allowing to restart the interpreter """

        # Note: Restart is available in script mode
        # Asking the safety question
        YES=True
        if not Main.forced:
           logging.getLogger('MA5').warning("Are you sure to restart the MadAnalysis 5 session? (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":
                   YES=False
                   break
              elif answer=='yes' or answer=='y':
                   YES=True
                   break

        # Restart?
        if YES:
            self.main.repeatSession=True
            return True
        else:
            return None

    def help_restart(self):
        logging.getLogger('MA5').info("   Syntax: restart ")
        logging.getLogger('MA5').info("   Quit the current MadAnalysis sessiona and open a new one.")
        logging.getLogger('MA5').info("   All the information will be discarded.")

    def do_remove(self,line):
        self.cmd_remove.do(self.split_arg(line))

    def help_remove(self):
        self.cmd_remove.help()

    def complete_remove(self,text,line,begidx,endidx):
        return self.cmd_remove.complete(text,line,begidx,endidx)

    def do_swap(self,line):
        self.cmd_swap.do(self.split_arg(line))

    def help_swap(self):
        self.cmd_swap.help()

    def complete_swap(self,text,line,begidx,endidx):
        return self.cmd_swap.complete(text,line,begidx,endidx)

    def do_install(self,line):
        result = self.cmd_install.do(self.split_arg(line))
        if result=='restart':
            logging.getLogger('MA5').info(" ")
            logging.getLogger('MA5').info("MadAnalysis 5 must be restarted for taking into account the present installation.")
            return self.do_restart('restart')

    def help_install(self):
        self.cmd_install.help()

    def complete_install(self,text,line,begidx,endidx):
        return self.cmd_install.complete(text,self.split_arg(line),begidx,endidx)

    def do_open(self,line):
        self.cmd_open.do(self.split_arg(line))

    def help_open(self):
        self.cmd_open.help()

    def complete_open(self,text,line,begidx,endidx):
        return self.cmd_open.complete(text,line,begidx,endidx)

    def do_reset(self,line):
        self.cmd_reset.do(self.split_arg(line),self)

    def help_reset(self):
        self.cmd_reset.help()

    def complete_reset(self,text,line,begidx,endidx):
        return self.cmd_reset.complete(text,line,begidx,endidx)

    def do_submit(self,line):
        self.cmd_submit.do(self.split_arg(line),self.history)

    def help_submit(self):
        self.cmd_submit.help()

    def complete_submit(self,text,line,begidx,endidx):
        return self.cmd_submit.complete(text,line,begidx,endidx)

    def do_resubmit(self,line):
        self.cmd_resubmit.do(self.split_arg(line),self.history)

    def help_resubmit(self):
        self.cmd_resubmit.help()

    def complete_resubmit(self,text,line,begidx,endidx):
        return self.cmd_resubmit.complete(text,line,begidx,endidx)

    def do_plot(self,line):
        self.cmd_plot.do(self.split_arg(line))

    def help_plot(self):
        self.cmd_plot.help()

    def complete_plot(self,text,line,begidx,endidx):
        tmp = line.replace("["," [ ")
        tmp = tmp.replace("]"," ] ")
        tmp = tmp.replace(")"," ) ")
        tmp = tmp.replace("("," ( ")
        tmp = tmp.replace(","," , ")
        return self.cmd_plot.complete(text,self.split_arg(tmp),begidx,endidx)

    def do_reject(self,line):
        self.cmd_reject.do(self.split_arg(line))

    def help_reject(self):
        self.cmd_reject.help()

    def complete_reject(self,text,line,begidx,endidx):
        tmp = line.replace("["," [ ")
        tmp = tmp.replace("]"," ] ")
        tmp = tmp.replace("("," ( ")
        tmp = tmp.replace(")"," ) ")
        return self.cmd_reject.complete(text,self.split_arg(tmp),begidx,endidx)

    def do_select(self,line):
        self.cmd_select.do(self.split_arg(line))

    def help_select(self):
        self.cmd_select.help()

    def complete_select(self,text,line,begidx,endidx):
        tmp = line.replace("["," [ ")
        tmp = tmp.replace("]"," ] ")
        tmp = tmp.replace("("," ( ")
        tmp = tmp.replace(")"," ) ")
        return self.cmd_select.complete(text,self.split_arg(tmp),begidx,endidx)

    def InitializeParticle(self):
        input = ParticleReader(self.main.archi_info.ma5dir,self.cmd_define,self.main.mode)
        input.Load()

    def InitializeMultiparticle(self):
        input = MultiparticleReader(self.main.archi_info.ma5dir,self.cmd_define,self.main.mode,self.main.forced)
        input.Load()

    # PreLoop
    def preloop(self):
        """Initializing before starting the main loop"""
        self.prompt = 'ma5>'
#        if readline and not 'libedit' in readline.__doc__:
#            readline.set_completion_display_matches_hook(self.print_suggestions)
            

    def deal_multiple_categories(self, dico):
        """convert the multiple category in a formatted list understand by our
        specific readline parser"""

        if 'libedit' in readline.__doc__:
            # No parser in this case, just send all the valid options
            out = []
            for name, opt in dico.items():
                out += opt
            return out

        # That's the real work
        out = []
        valid=0
        # if the key starts with number order the key with that number.
        for name, opt in dico.items():
            if not opt:
                continue
            name = name.replace(' ', '_')
            valid += 1
            out.append(opt[0].rstrip()+'@@'+name+'@@')
            # Remove duplicate
            d = {}
            for x in opt:
                d[x] = 1    
            opt = list(d.keys())
            opt.sort()
            out += opt

            
        if valid == 1:
            out = out[1:]
        return out
    
    def print_suggestions(self, substitution, matches, longest_match_length) :
        """print auto-completions by category"""
        longest_match_length += len(self.completion_prefix)
        try:
            if len(matches) == 1:
                self.stdout.write(matches[0]+' ')
                return
            self.stdout.write('\n')
            l2 = [a[-2:] for a in matches]
            if '@@' in l2:
                nb_column = self.getTerminalSize()//(longest_match_length+1)
                pos=0
                for val in self.completion_matches:
                    if val.endswith('@@'):
                        category = val.rsplit('@@',2)[1]
                        category = category.replace('_',' ')
                        self.stdout.write('\n %s:\n%s\n' % (category, '=' * (len(category)+2)))
                        start = 0
                        pos = 0
                        continue
                    elif pos and pos % nb_column ==0:
                        self.stdout.write('\n')
                    self.stdout.write(self.completion_prefix + val + \
                                      ' ' * (longest_match_length +1 -len(val)))
                    pos +=1
                self.stdout.write('\n')
            else:
                # nb column
                nb_column = self.getTerminalSize()//(longest_match_length+1)
                for i,val in enumerate(matches):
                    if i and i%nb_column ==0:
                        self.stdout.write('\n')
                    self.stdout.write(self.completion_prefix + val + \
                                     ' ' * (longest_match_length +1 -len(val)))
                self.stdout.write('\n')
    
            self.stdout.write(self.prompt+readline.get_line_buffer())
            self.stdout.flush()
        except Exception, error:
            if __debug__:
                 print error
Ejemplo n.º 8
0
class Interpreter(InterpreterBase):
    """Particularisation of the cmd command for MA5"""

    def __init__(self, main,*arg, **opt):

        # Calling constructor from InterpreterBase
        InterpreterBase.__init__(self, *arg, **opt)

        # Getting back main
        self.main = main

        # Getting back all commands
        self.cmd_set                    = CmdSet(main)
        self.cmd_define                 = CmdDefine(main)
        self.cmd_display                = CmdDisplay(main)
        self.cmd_display_datasets       = CmdDisplayDatasets(main)
        self.cmd_display_particles      = CmdDisplayParticles(main)
        self.cmd_display_multiparticles = CmdDisplayMultiparticles(main)
        self.cmd_import                 = CmdImport(main)
        self.cmd_remove                 = CmdRemove(main)
        self.cmd_swap                   = CmdSwap(main) 
        self.cmd_plot                   = CmdPlot(main)
        self.cmd_reject                 = CmdCut(main,CutType.REJECT)
        self.cmd_select                 = CmdCut(main,CutType.SELECT)
        self.cmd_preview                = CmdPreview(main)
        self.cmd_reset                  = CmdReset(main)
        self.cmd_open                   = CmdOpen(main)
        self.cmd_submit                 = CmdSubmit(main)
        self.cmd_resubmit               = CmdSubmit(main,resubmit=True)
        self.cmd_generate_latex         = CmdGenerate(main,\
                                                      ReportFormatType.LATEX) 
        self.cmd_generate_pdflatex      = CmdGenerate(main,\
                                                      ReportFormatType.PDFLATEX) 
        self.cmd_generate_html          = CmdGenerate(main,\
                                                      ReportFormatType.HTML)
        self.cmd_install                = CmdInstall(main)
        
        # Initializing multiparticle
        self.InitializeParticle()
        self.InitializeMultiparticle()

        # Importing history
        self.history_file = os.path.normpath(self.main.ma5dir + '/.ma5history')
        try:
            readline.read_history_file(self.history_file)
        except:
            pass
                                    
    def __del__(self):
        try:
            readline.set_history_length(100)
            readline.write_history_file(self.history_file)
        except:
            pass
                

    def do_set(self,line):
        self.cmd_set.do(self.split_arg(line),line)

    def help_set(self):
        self.cmd_set.help()

    def complete_set(self,text,line,begidx,endidx):
        return self.cmd_set.complete(text,line,begidx,endidx)

    def do_define(self,line):
        self.cmd_define.do(self.split_arg(line))

    def help_define(self):
        self.cmd_define.help()

    def complete_define(self,text,line,begidx,endidx):
        return self.cmd_define.complete(text,line,begidx,endidx)

    def do_display(self,line):
        self.cmd_display.do(self.split_arg(line))

    def help_display(self):
        self.cmd_display.help()

    def complete_display(self,text,line,begidx,endidx):
        return self.cmd_display.complete(text,line,begidx,endidx)

    def do_display_particles(self,line):
        self.cmd_display_particles.do(self.split_arg(line))

    def help_display_particles(self):
        self.cmd_display_particles.help()

    def complete_display_particles(self,text,line,begidx,endidx):
        return self.cmd_display_particles.complete(text,line,begidx,endidx)

    def do_display_multiparticles(self,line):
        self.cmd_display_multiparticles.do(self.split_arg(line))

    def help_display_multiparticles(self):
        self.cmd_display_multiparticles.help()

    def complete_display_multiparticles(self,text,line,begidx,endidx):
        return self.cmd_display_multiparticles.complete(text,line,begidx,endidx)

    def do_display_datasets(self,line):
        self.cmd_display_datasets.do(self.split_arg(line))

    def help_display_datasets(self):
        self.cmd_display_datasets.help()

    def complete_display_datasets(self,text,line,begidx,endidx):
        return self.cmd_display_datasets.complete(text,line,begidx,endidx)

    def do_generate_html(self,line):
        self.cmd_generate_html.do(self.split_arg(line),self.history)

    def help_generate_html(self):
        self.cmd_generate_html.help()

    def complete_generate_html(self,text,line,begidx,endidx):
        return self.cmd_generate_html.complete(text,line,begidx,endidx)

    def do_generate_latex(self,line):
        self.cmd_generate_latex.do(self.split_arg(line),self.history)

    def help_generate_latex(self):
        self.cmd_generate_latex.help()

    def complete_generate_latex(self,text,line,begidx,endidx):
        return self.cmd_generate_latex.complete(text,line,begidx,endidx)

    def do_generate_pdflatex(self,line):
        self.cmd_generate_pdflatex.do(self.split_arg(line),self.history)

    def help_generate_pdflatex(self):
        self.cmd_generate_pdflatex.help()

    def complete_generate_pdflatex(self,text,line,begidx,endidx):
        return self.cmd_generate_pdflatex.complete(text,line,begidx,endidx)

    def do_import(self,line):
        self.cmd_import.do(self.split_arg(line),self)

    def help_import(self):
        self.cmd_import.help()

    def complete_import(self,text,line,begidx,endidx):
        return self.cmd_import.complete(text,line,begidx,endidx)

    def do_remove(self,line):
        self.cmd_remove.do(self.split_arg(line))

    def help_remove(self):
        self.cmd_remove.help()

    def complete_remove(self,text,line,begidx,endidx):
        return self.cmd_remove.complete(text,line,begidx,endidx)

    def do_swap(self,line):
        self.cmd_swap.do(self.split_arg(line))

    def help_swap(self):
        self.cmd_swap.help()

    def complete_swap(self,text,line,begidx,endidx):
        return self.cmd_swap.complete(text,line,begidx,endidx)

    def do_install(self,line):
        self.cmd_install.do(self.split_arg(line))

    def help_install(self):
        self.cmd_install.help()

    def complete_install(self,text,line,begidx,endidx):
        return self.cmd_install.complete(text,self.split_arg(line),begidx,endidx)

    def do_preview(self,line):
        self.cmd_preview.do(self.split_arg(line))

    def help_preview(self):
        self.cmd_preview.help()

    def complete_preview(self,text,line,begidx,endidx):
        return self.cmd_preview.complete(text,line,begidx,endidx)

    def do_open(self,line):
        self.cmd_open.do(self.split_arg(line))

    def help_open(self):
        self.cmd_open.help()

    def complete_open(self,text,line,begidx,endidx):
        return self.cmd_open.complete(text,line,begidx,endidx)

    def do_reset(self,line):
        self.cmd_reset.do(self.split_arg(line),self)

    def help_reset(self):
        self.cmd_reset.help()

    def complete_reset(self,text,line,begidx,endidx):
        return self.cmd_reset.complete(text,line,begidx,endidx)

    def do_submit(self,line):
        self.cmd_submit.do(self.split_arg(line),self.history)

    def help_submit(self):
        self.cmd_submit.help()

    def complete_submit(self,text,line,begidx,endidx):
        return self.cmd_submit.complete(text,line,begidx,endidx)

    def do_resubmit(self,line):
        self.cmd_resubmit.do(self.split_arg(line),self.history)

    def help_resubmit(self):
        self.cmd_resubmit.help()

    def complete_resubmit(self,text,line,begidx,endidx):
        return self.cmd_resubmit.complete(text,line,begidx,endidx)

    def do_plot(self,line):
        self.cmd_plot.do(self.split_arg(line))

    def help_plot(self):
        self.cmd_plot.help()

    def complete_plot(self,text,line,begidx,endidx):
        tmp = line.replace("["," [ ")
        tmp = tmp.replace("]"," ] ")
        tmp = tmp.replace(")"," ) ")
        tmp = tmp.replace("("," ( ")
        tmp = tmp.replace(","," , ")
        return self.cmd_plot.complete(text,self.split_arg(tmp),begidx,endidx)

    def do_reject(self,line):
        self.cmd_reject.do(self.split_arg(line))

    def help_reject(self):
        self.cmd_reject.help()

    def complete_reject(self,text,line,begidx,endidx):
        tmp = line.replace("["," [ ")
        tmp = tmp.replace("]"," ] ")
        tmp = tmp.replace("("," ( ")
        tmp = tmp.replace(")"," ) ")
        return self.cmd_reject.complete(text,self.split_arg(tmp),begidx,endidx)

    def do_select(self,line):
        self.cmd_select.do(self.split_arg(line))

    def help_select(self):
        self.cmd_select.help()

    def complete_select(self,text,line,begidx,endidx):
        tmp = line.replace("["," [ ")
        tmp = tmp.replace("]"," ] ")
        tmp = tmp.replace("("," ( ")
        tmp = tmp.replace(")"," ) ")
        return self.cmd_select.complete(text,self.split_arg(tmp),begidx,endidx)

    def InitializeParticle(self):
        input = ParticleReader(self.main.ma5dir,self.cmd_define,self.main.mode)
        input.Load()

    def InitializeMultiparticle(self):
        input = MultiparticleReader(self.main.ma5dir,self.cmd_define,self.main.mode)
        input.Load()

    # PreLoop
    def preloop(self):
        """Initializing before starting the main loop"""
        self.prompt = 'ma5>'
#        if readline and not 'libedit' in readline.__doc__:
#            readline.set_completion_display_matches_hook(self.print_suggestions)
            

    def deal_multiple_categories(self, dico):
        """convert the multiple category in a formatted list understand by our
        specific readline parser"""

        if 'libedit' in readline.__doc__:
            # No parser in this case, just send all the valid options
            out = []
            for name, opt in dico.items():
                out += opt
            return out

        # That's the real work
        out = []
        valid=0
        # if the key starts with number order the key with that number.
        for name, opt in dico.items():
            if not opt:
                continue
            name = name.replace(' ', '_')
            valid += 1
            out.append(opt[0].rstrip()+'@@'+name+'@@')
            # Remove duplicate
            d = {}
            for x in opt:
                d[x] = 1    
            opt = list(d.keys())
            opt.sort()
            out += opt

            
        if valid == 1:
            out = out[1:]
        return out
    
    def print_suggestions(self, substitution, matches, longest_match_length) :
        """print auto-completions by category"""
        longest_match_length += len(self.completion_prefix)
        try:
            if len(matches) == 1:
                self.stdout.write(matches[0]+' ')
                return
            self.stdout.write('\n')
            l2 = [a[-2:] for a in matches]
            if '@@' in l2:
                nb_column = self.getTerminalSize()//(longest_match_length+1)
                pos=0
                for val in self.completion_matches:
                    if val.endswith('@@'):
                        category = val.rsplit('@@',2)[1]
                        category = category.replace('_',' ')
                        self.stdout.write('\n %s:\n%s\n' % (category, '=' * (len(category)+2)))
                        start = 0
                        pos = 0
                        continue
                    elif pos and pos % nb_column ==0:
                        self.stdout.write('\n')
                    self.stdout.write(self.completion_prefix + val + \
                                      ' ' * (longest_match_length +1 -len(val)))
                    pos +=1
                self.stdout.write('\n')
            else:
                # nb column
                nb_column = self.getTerminalSize()//(longest_match_length+1)
                for i,val in enumerate(matches):
                    if i and i%nb_column ==0:
                        self.stdout.write('\n')
                    self.stdout.write(self.completion_prefix + val + \
                                     ' ' * (longest_match_length +1 -len(val)))
                self.stdout.write('\n')
    
            self.stdout.write(self.prompt+readline.get_line_buffer())
            self.stdout.flush()
        except Exception, error:
            if __debug__:
                 print error
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
    def do_main(self, args):

        # Looking for '='
        if args[1] != '=':
            logging.getLogger('MA5').error(
                "syntax error with the command 'set'.")
            self.help()
            return

        # Looking for one dot in the name
        object = args[0]
        #        object = object.lower()
        object = object.replace('fastsim.bjet_id.', 'fastsim.bjet_idXXX')
        object = object.replace('fastsim.tau_id.', 'fastsim.tau_idXXX')
        objs = object.split('.')
        for i in range(len(objs)):
            objs[i] = objs[i].replace('XXX', '.')

        if len(objs) == 2 and objs[0].lower() == 'main' and objs[1].lower(
        ) == 'recast':
            user_info = UserInfo()
            user_info.ReadUserOptions(
                self.main.archi_info.ma5dir +
                '/madanalysis/input/installation_options.dat')
            checker = ConfigChecker(self.main.archi_info, user_info,
                                    self.main.session_info, self.main.script,
                                    False)
            hasdelphes = checker.checkDelphes(True)
            hasMA5tune = checker.checkDelphesMA5tune(True)
            hasPAD = checker.checkPAD()
            hasPADtune = checker.checkPADForMA5tune()
            self.main.recasting.user_SetParameter(
                "status", args[2], self.main.mode,
                self.main.archi_info.has_root, hasdelphes, hasMA5tune,
                self.main.datasets, hasPAD, hasPADtune)
            if args[2] == 'on' and self.main.fastsim.package != 'none':
                logging.getLogger('MA5').warning(
                    "Fastsim package switched off and internally handled")
                self.main.fastsim.package = "none"
        elif len(objs) == 2 and objs[0].lower() == 'main':
            if objs[1] == 'mode' and args[2] == 'parton':
                self.main.mode = MA5RunningType.PARTON
                self.main.ResetParameters()
                self.main.AutoSetGraphicalRenderer()
                self.main.InitObservables(self.main.mode)
                lvl = logging.getLogger('MA5').getEffectiveLevel()
                logging.getLogger('MA5').setLevel(100)
                self.main.multiparticles.Reset()
                cmd_define = CmdDefine(self.main)
                input = ParticleReader(self.main.archi_info.ma5dir, cmd_define,
                                       self.main.mode, self.main.forced)
                input.Load()
                input = MultiparticleReader(self.main.archi_info.ma5dir,
                                            cmd_define, self.main.mode,
                                            self.main.forced)
                input.Load()
                logging.getLogger('MA5').setLevel(lvl)
            else:
                self.main.user_SetParameter(objs[1], args[2])
        elif len(objs) == 3 and objs[0].lower() == 'main' and objs[1].lower(
        ) == 'isolation':
            self.main.isolation.user_SetParameter(objs[2], args[2])
        elif len(objs) == 3 and objs[0].lower() == 'main' and objs[1].lower(
        ) == 'fom':
            self.main.fom.user_SetParameter(objs[2], args[2])
        elif len(objs) == 3 and objs[0].lower() == 'main' and objs[1].lower(
        ) == 'merging':
            self.main.merging.user_SetParameter(
                objs[2], args[2], self.main.mode,
                self.main.archi_info.has_fastjet)
        elif len(objs) == 3 and objs[0].lower() == 'main' and objs[1].lower(
        ) == 'fastsim':
            user_info = UserInfo()
            user_info.ReadUserOptions(
                self.main.archi_info.ma5dir +
                '/madanalysis/input/installation_options.dat')
            checker = ConfigChecker(self.main.archi_info, user_info,
                                    self.main.session_info, self.main.script,
                                    False)
            hasdelphes = checker.checkDelphes(True)
            hasMA5tune = checker.checkDelphesMA5tune(True)
            self.main.fastsim.user_SetParameter(
                objs[2], args[2], self.main.datasets, self.main.mode,
                self.main.archi_info.has_fastjet, hasdelphes, hasMA5tune)
            if objs[2] == 'package' and args[2] in [
                    'fastjet', 'delphes', 'delphesMA5tune'
            ] and self.main.recasting.status == 'on':
                logging.getLogger('MA5').warning("Recasting mode switched off")
                self.main.recasting.status = "off"
        elif len(objs) == 3 and objs[0].lower() == 'main' and objs[1].lower(
        ) == 'recast':
            user_info = UserInfo()
            user_info.ReadUserOptions(
                self.main.archi_info.ma5dir +
                '/madanalysis/input/installation_options.dat')
            checker = ConfigChecker(self.main.archi_info, user_info,
                                    self.main.session_info, self.main.script,
                                    False)
            hasdelphes = checker.checkDelphes(True)
            hasMA5tune = checker.checkDelphesMA5tune(True)
            hasPAD = checker.checkPAD()
            hasPADtune = checker.checkPADForMA5tune()
            self.main.recasting.user_SetParameter(
                objs[2], args[2], self.main.mode,
                self.main.archi_info.has_root, hasdelphes, hasMA5tune,
                self.main.datasets, hasPAD, hasPADtune)
        else:
            logging.getLogger('MA5').error(
                "syntax error with the command 'set'.")
            self.help()
            return
Ejemplo n.º 11
0
class Interpreter(InterpreterBase):
    """Particularisation of the cmd command for MA5"""
    def __init__(self, main, *arg, **opt):

        # Calling constructor from InterpreterBase
        InterpreterBase.__init__(self, *arg, **opt)

        # Getting back main
        self.main = main

        # Getting back all commands
        self.cmd_set = CmdSet(main)
        self.cmd_define = CmdDefine(main)
        self.cmd_display = CmdDisplay(main)
        self.cmd_display_datasets = CmdDisplayDatasets(main)
        self.cmd_display_particles = CmdDisplayParticles(main)
        self.cmd_display_multiparticles = CmdDisplayMultiparticles(main)
        self.cmd_import = CmdImport(main)
        self.cmd_remove = CmdRemove(main)
        self.cmd_swap = CmdSwap(main)
        self.cmd_plot = CmdPlot(main)
        self.cmd_reject = CmdCut(main, CutType.REJECT)
        self.cmd_select = CmdCut(main, CutType.SELECT)
        self.cmd_preview = CmdPreview(main)
        self.cmd_reset = CmdReset(main)
        self.cmd_open = CmdOpen(main)
        self.cmd_submit = CmdSubmit(main)
        self.cmd_resubmit = CmdSubmit(main, resubmit=True)
        self.cmd_generate_latex         = CmdGenerate(main,\
                                                      ReportFormatType.LATEX)
        self.cmd_generate_pdflatex      = CmdGenerate(main,\
                                                      ReportFormatType.PDFLATEX)
        self.cmd_generate_html          = CmdGenerate(main,\
                                                      ReportFormatType.HTML)
        self.cmd_install = CmdInstall(main)

        # Initializing multiparticle
        self.InitializeParticle()
        self.InitializeMultiparticle()

        # Importing history
        self.history_file = os.path.normpath(self.main.ma5dir + '/.ma5history')
        try:
            readline.read_history_file(self.history_file)
        except:
            pass

    def __del__(self):
        try:
            readline.set_history_length(100)
            readline.write_history_file(self.history_file)
        except:
            pass

    def do_set(self, line):
        self.cmd_set.do(self.split_arg(line), line)

    def help_set(self):
        self.cmd_set.help()

    def complete_set(self, text, line, begidx, endidx):
        return self.cmd_set.complete(text, line, begidx, endidx)

    def do_define(self, line):
        self.cmd_define.do(self.split_arg(line))

    def help_define(self):
        self.cmd_define.help()

    def complete_define(self, text, line, begidx, endidx):
        return self.cmd_define.complete(text, line, begidx, endidx)

    def do_display(self, line):
        self.cmd_display.do(self.split_arg(line))

    def help_display(self):
        self.cmd_display.help()

    def complete_display(self, text, line, begidx, endidx):
        return self.cmd_display.complete(text, line, begidx, endidx)

    def do_display_particles(self, line):
        self.cmd_display_particles.do(self.split_arg(line))

    def help_display_particles(self):
        self.cmd_display_particles.help()

    def complete_display_particles(self, text, line, begidx, endidx):
        return self.cmd_display_particles.complete(text, line, begidx, endidx)

    def do_display_multiparticles(self, line):
        self.cmd_display_multiparticles.do(self.split_arg(line))

    def help_display_multiparticles(self):
        self.cmd_display_multiparticles.help()

    def complete_display_multiparticles(self, text, line, begidx, endidx):
        return self.cmd_display_multiparticles.complete(
            text, line, begidx, endidx)

    def do_display_datasets(self, line):
        self.cmd_display_datasets.do(self.split_arg(line))

    def help_display_datasets(self):
        self.cmd_display_datasets.help()

    def complete_display_datasets(self, text, line, begidx, endidx):
        return self.cmd_display_datasets.complete(text, line, begidx, endidx)

    def do_generate_html(self, line):
        self.cmd_generate_html.do(self.split_arg(line), self.history)

    def help_generate_html(self):
        self.cmd_generate_html.help()

    def complete_generate_html(self, text, line, begidx, endidx):
        return self.cmd_generate_html.complete(text, line, begidx, endidx)

    def do_generate_latex(self, line):
        self.cmd_generate_latex.do(self.split_arg(line), self.history)

    def help_generate_latex(self):
        self.cmd_generate_latex.help()

    def complete_generate_latex(self, text, line, begidx, endidx):
        return self.cmd_generate_latex.complete(text, line, begidx, endidx)

    def do_generate_pdflatex(self, line):
        self.cmd_generate_pdflatex.do(self.split_arg(line), self.history)

    def help_generate_pdflatex(self):
        self.cmd_generate_pdflatex.help()

    def complete_generate_pdflatex(self, text, line, begidx, endidx):
        return self.cmd_generate_pdflatex.complete(text, line, begidx, endidx)

    def do_import(self, line):
        self.cmd_import.do(self.split_arg(line), self)

    def help_import(self):
        self.cmd_import.help()

    def complete_import(self, text, line, begidx, endidx):
        return self.cmd_import.complete(text, line, begidx, endidx)

    def do_remove(self, line):
        self.cmd_remove.do(self.split_arg(line))

    def help_remove(self):
        self.cmd_remove.help()

    def complete_remove(self, text, line, begidx, endidx):
        return self.cmd_remove.complete(text, line, begidx, endidx)

    def do_swap(self, line):
        self.cmd_swap.do(self.split_arg(line))

    def help_swap(self):
        self.cmd_swap.help()

    def complete_swap(self, text, line, begidx, endidx):
        return self.cmd_swap.complete(text, line, begidx, endidx)

    def do_install(self, line):
        self.cmd_install.do(self.split_arg(line))

    def help_install(self):
        self.cmd_install.help()

    def complete_install(self, text, line, begidx, endidx):
        return self.cmd_install.complete(text, self.split_arg(line), begidx,
                                         endidx)

    def do_preview(self, line):
        self.cmd_preview.do(self.split_arg(line))

    def help_preview(self):
        self.cmd_preview.help()

    def complete_preview(self, text, line, begidx, endidx):
        return self.cmd_preview.complete(text, line, begidx, endidx)

    def do_open(self, line):
        self.cmd_open.do(self.split_arg(line))

    def help_open(self):
        self.cmd_open.help()

    def complete_open(self, text, line, begidx, endidx):
        return self.cmd_open.complete(text, line, begidx, endidx)

    def do_reset(self, line):
        self.cmd_reset.do(self.split_arg(line), self)

    def help_reset(self):
        self.cmd_reset.help()

    def complete_reset(self, text, line, begidx, endidx):
        return self.cmd_reset.complete(text, line, begidx, endidx)

    def do_submit(self, line):
        self.cmd_submit.do(self.split_arg(line), self.history)

    def help_submit(self):
        self.cmd_submit.help()

    def complete_submit(self, text, line, begidx, endidx):
        return self.cmd_submit.complete(text, line, begidx, endidx)

    def do_resubmit(self, line):
        self.cmd_resubmit.do(self.split_arg(line), self.history)

    def help_resubmit(self):
        self.cmd_resubmit.help()

    def complete_resubmit(self, text, line, begidx, endidx):
        return self.cmd_resubmit.complete(text, line, begidx, endidx)

    def do_plot(self, line):
        self.cmd_plot.do(self.split_arg(line))

    def help_plot(self):
        self.cmd_plot.help()

    def complete_plot(self, text, line, begidx, endidx):
        tmp = line.replace("[", " [ ")
        tmp = tmp.replace("]", " ] ")
        tmp = tmp.replace(")", " ) ")
        tmp = tmp.replace("(", " ( ")
        tmp = tmp.replace(",", " , ")
        return self.cmd_plot.complete(text, self.split_arg(tmp), begidx,
                                      endidx)

    def do_reject(self, line):
        self.cmd_reject.do(self.split_arg(line))

    def help_reject(self):
        self.cmd_reject.help()

    def complete_reject(self, text, line, begidx, endidx):
        tmp = line.replace("[", " [ ")
        tmp = tmp.replace("]", " ] ")
        tmp = tmp.replace("(", " ( ")
        tmp = tmp.replace(")", " ) ")
        return self.cmd_reject.complete(text, self.split_arg(tmp), begidx,
                                        endidx)

    def do_select(self, line):
        self.cmd_select.do(self.split_arg(line))

    def help_select(self):
        self.cmd_select.help()

    def complete_select(self, text, line, begidx, endidx):
        tmp = line.replace("[", " [ ")
        tmp = tmp.replace("]", " ] ")
        tmp = tmp.replace("(", " ( ")
        tmp = tmp.replace(")", " ) ")
        return self.cmd_select.complete(text, self.split_arg(tmp), begidx,
                                        endidx)

    def InitializeParticle(self):
        input = ParticleReader(self.main.ma5dir, self.cmd_define,
                               self.main.mode)
        input.Load()

    def InitializeMultiparticle(self):
        input = MultiparticleReader(self.main.ma5dir, self.cmd_define,
                                    self.main.mode)
        input.Load()

    # PreLoop
    def preloop(self):
        """Initializing before starting the main loop"""
        self.prompt = 'ma5>'
#        if readline and not 'libedit' in readline.__doc__:
#            readline.set_completion_display_matches_hook(self.print_suggestions)

    def deal_multiple_categories(self, dico):
        """convert the multiple category in a formatted list understand by our
        specific readline parser"""

        if 'libedit' in readline.__doc__:
            # No parser in this case, just send all the valid options
            out = []
            for name, opt in dico.items():
                out += opt
            return out

        # That's the real work
        out = []
        valid = 0
        # if the key starts with number order the key with that number.
        for name, opt in dico.items():
            if not opt:
                continue
            name = name.replace(' ', '_')
            valid += 1
            out.append(opt[0].rstrip() + '@@' + name + '@@')
            # Remove duplicate
            d = {}
            for x in opt:
                d[x] = 1
            opt = list(d.keys())
            opt.sort()
            out += opt

        if valid == 1:
            out = out[1:]
        return out

    def print_suggestions(self, substitution, matches, longest_match_length):
        """print auto-completions by category"""
        longest_match_length += len(self.completion_prefix)
        try:
            if len(matches) == 1:
                self.stdout.write(matches[0] + ' ')
                return
            self.stdout.write('\n')
            l2 = [a[-2:] for a in matches]
            if '@@' in l2:
                nb_column = self.getTerminalSize() // (longest_match_length +
                                                       1)
                pos = 0
                for val in self.completion_matches:
                    if val.endswith('@@'):
                        category = val.rsplit('@@', 2)[1]
                        category = category.replace('_', ' ')
                        self.stdout.write('\n %s:\n%s\n' %
                                          (category, '=' *
                                           (len(category) + 2)))
                        start = 0
                        pos = 0
                        continue
                    elif pos and pos % nb_column == 0:
                        self.stdout.write('\n')
                    self.stdout.write(self.completion_prefix + val + \
                                      ' ' * (longest_match_length +1 -len(val)))
                    pos += 1
                self.stdout.write('\n')
            else:
                # nb column
                nb_column = self.getTerminalSize() // (longest_match_length +
                                                       1)
                for i, val in enumerate(matches):
                    if i and i % nb_column == 0:
                        self.stdout.write('\n')
                    self.stdout.write(self.completion_prefix + val + \
                                     ' ' * (longest_match_length +1 -len(val)))
                self.stdout.write('\n')

            self.stdout.write(self.prompt + readline.get_line_buffer())
            self.stdout.flush()
        except Exception, error:
            if __debug__:
                print error