Example #1
0
def LaunchMA5(version, date, ma5dir):
    
    # Configuring the logger
    import colored_log
    colored_log.init()
    log = logging.getLogger()
    log.setLevel(logging.INFO)

    # Setting global variables of MadAnalysis main
    from madanalysis.core.main import Main

    # Configurating tab completion
    try: 
        import readline
    except ImportError:
        try:
            import pyreadline as readline
        except:
            print "For tab completion and history, install module readline."
    else:
        import rlcompleter
    
        if 'r261:67515' in sys.version and  'GCC 4.2.1 (Apple Inc. build 5646)' in sys.version:
            readline.parse_and_bind("bind ^I rl_complete")
            readline.__doc__ = 'libedit'  
    
        elif hasattr(readline, '__doc__'):
            if 'libedit' not in readline.__doc__:
                readline.parse_and_bind("tab: complete")
            else:
                readline.parse_and_bind("bind ^I rl_complete")
        else:
            readline.__doc__ = 'GNU'
            readline.parse_and_bind("tab: complete")

    # Read arguments
    mode,arglist = DecodeArguments(version, date)

    # Deal with the scripts in normal mode
    if not mode.expertmode:
        for arg in arglist:
            ScriptStack.AddScript(arg)

    # Loop over MA5 sessions
    # Goal: allowing to restart
    while True:

        # Launch the interpreter
        repeat = MainSession(mode,arglist,ma5dir,version,date)

        # Normal end
        if not repeat:
            break

        # Restart
        logging.getLogger('MA5').info("")
        logging.getLogger('MA5').info(StringTools.Fill('-',40))
        logging.getLogger('MA5').info(StringTools.Center('RESTART THE MADANALYSIS 5 SESSION',40))
        logging.getLogger('MA5').info(StringTools.Fill('-',40))
        logging.getLogger('MA5').info("")
Example #2
0
 def analysis_header(self, version, card):
     ## Printing
     logging.getLogger('MA5').info("   **********************************************************")
     logging.getLogger('MA5').info("   "+StringTools.Center(version+' running of the PAD'+\
            ' on events generated with',57))
     logging.getLogger('MA5').info("   "+StringTools.Center(card,57))
     logging.getLogger('MA5').info("   **********************************************************")
Example #3
0
 def fastsim_header(self, version):
     ## Gettign the version dependent stuff
     to_print = False
     if version=="1.1" and self.first11:
         to_print = True
         tag = version
         self.first11 = False
     elif version!="1.1" and self.first12:
         to_print = True
         tag = "v1.2+"
         self.first12 = False
     ## Printing
     if to_print:
         logging.getLogger('MA5').info("   **********************************************************")
         logging.getLogger('MA5').info("   "+StringTools.Center(tag+' detector simulations',57))
         logging.getLogger('MA5').info("   **********************************************************")
Example #4
0
    def submit(self,dirname,history):
        # checking if the needed version of delphes is activated
        forced_bkp = self.main.forced
        self.main.forced=True
        if self.main.fastsim.package == 'delphes' and not self.main.archi_info.has_delphes:
            installer=InstallManager(self.main)
            if self.main.archi_info.has_delphesMA5tune:
                if not installer.Deactivate('delphesMA5tune'):
                    return False
            if installer.Activate('delphes')==-1:
                return False
        if self.main.fastsim.package == 'delphesMA5tune' and not self.main.archi_info.has_delphesMA5tune:
            installer=InstallManager(self.main)
            if self.main.archi_info.has_delphes:
                if not installer.Deactivate('delphes'):
                    return False
            if installer.Activate('delphesMA5tune')==-1:
                return False
        self.main.forced=forced_bkp

        # Initializing the JobWriter
        jobber = JobWriter(self.main,dirname,self.resubmit)

        # Writing process
        if not self.resubmit:
            self.logger.info("   Creating folder '"+dirname.split('/')[-1] \
                +"'...")
        else:
            self.logger.info("   Checking the structure of the folder '"+\
               dirname.split('/')[-1]+"'...")
        if not jobber.Open():
            self.logger.error("job submission aborted.")
            return False

        if not self.resubmit:
            if self.main.recasting.status != 'on':
                self.logger.info("   Copying 'SampleAnalyzer' source files...")
            if not jobber.CopyLHEAnalysis():
                self.logger.error("   job submission aborted.")
                return False
            if self.main.recasting.status != 'on' and not jobber.CreateBldDir():
                self.logger.error("   job submission aborted.")
                return False
            if self.main.recasting.status == 'on':
                if not FolderWriter.CreateDirectory(dirname+'/Events'):
                    return False

        # In the case of recasting, there is no need to create a standard Job
        if self.main.recasting.status == "on":

            ### First, the analyses to take care off
            self.editRecastingCard(dirname)
            self.logger.info("   Getting the list of delphes simulation to be performed...")

            ### Second, which delphes run must be performed, and running them
            if not self.main.recasting.GetDelphesRuns(dirname+"/Input/recasting_card.dat"):
                return False
            firstv11 = True
            firstv13 = True
            forced_bkp = self.main.forced
            self.main.forced=True
            if len(self.main.recasting.delphesruns)==0:
                self.logger.warning('No recasting to do... Please check the recasting card')
                return False
            for mydelphescard in sorted(self.main.recasting.delphesruns):
                version=mydelphescard[:4]
                card=mydelphescard[5:]
                if version=="v1.1":
                    if not self.main.recasting.ma5tune:
                        self.logger.error('The DelphesMA5tune library is not present... v1.1 analyses cannot be used')
                        return False

                    if firstv11:
                        self.logger.info("   **********************************************************")
                        self.logger.info("   "+StringTools.Center('v1.1 detector simulations',57))
                        self.logger.info("   **********************************************************")
                        firstv11=False

                    ## Deactivating delphes
                    installer=InstallManager(self.main)
                    if not installer.Deactivate('delphes'):
                        return False

                    ## Activating and compile the MA5Tune
                    if installer.Activate('delphesMA5tune')==-1:
                        return False

                    ## running delphesMA5tune
                    for item in self.main.datasets:
                        if not os.path.isfile(dirname + '/Events/' + item.name + '_v1x1_' + \
                             card.replace('.tcl','')+'.root'):
                            self.main.recasting.status="off"
                            self.main.fastsim.package="delphesMA5tune"
                            self.main.fastsim.clustering=0
                            self.main.fastsim.delphes=0
                            self.main.fastsim.delphesMA5tune = DelphesMA5tuneConfiguration()
                            self.main.fastsim.delphesMA5tune.card = os.path.normpath("../../../../PADForMA5tune/Input/Cards/"+card)
                            self.submit(dirname+'_DelphesForMa5tuneRun',[])
                            self.main.recasting.status="on"
                            self.main.fastsim.package="none"
                            ## saving the output
                            shutil.move(dirname+'_DelphesForMa5tuneRun/Output/_'+item.name+'/TheMouth.root',\
                              dirname+'/Events/'+item.name+'_v1x1_'+card.replace('.tcl','')+'.root')
                        if not FolderWriter.RemoveDirectory(os.path.normpath(dirname+'_DelphesForMa5tuneRun')):
                            return False
                elif version in ['v1.2', 'v1.3']:
                    if not self.main.recasting.delphes:
                        self.logger.error('The Delphes library is not present... v1.2+ analyses cannot be used')
                        return False

                    if firstv13:
                        self.logger.info("   **********************************************************")
                        self.logger.info("   "+StringTools.Center('v1.2+ detector simulations',57))
                        self.logger.info("   **********************************************************")
                        firstv13=False

                    ## Deactivating delphesMA5tune
                    installer=InstallManager(self.main)
                    if not installer.Deactivate('delphesMA5tune'):
                        return False

                    ## Activating and compile Delphes
                    if installer.Activate('delphes')==-1:
                        return False

                    ## running delphesMA5tune
                    for item in self.main.datasets:
                        if not os.path.isfile(dirname+'/Events/' + item.name +\
                         '_v1x2_'+card.replace('.tcl','')+'.root'):
                            self.main.recasting.status="off"
                            self.main.fastsim.package="delphes"
                            self.main.fastsim.clustering=0
                            self.main.fastsim.delphesMA5tune=0
                            self.main.fastsim.delphes = DelphesConfiguration()
                            self.main.fastsim.delphes.card = os.path.normpath("../../../../PAD/Input/Cards/"+card)
                            self.submit(dirname+'_DelphesRun',[])
                            self.main.recasting.status="on"
                            self.main.fastsim.package="none"
                            ## saving the output
                            shutil.move(dirname+'_DelphesRun/Output/_'+item.name+'/TheMouth.root',\
                              dirname+'/Events/'+item.name+'_v1x2_'+card.replace('.tcl','')+'.root')
                        if not FolderWriter.RemoveDirectory(os.path.normpath(dirname+'_DelphesRun')):
                            return False
                else:
                    self.logger.error('An analysis can only be compatible with ma5 v1.1, v1.2 or v1.3...')
                    return False
            self.main.forced=forced_bkp

            ### Third, executing the analyses
            if not self.main.recasting.GetAnalysisRuns(dirname+"/Input/recasting_card.dat"):
                return False
            forced_bkp = self.main.forced
            self.main.forced=True
            for mydelphescard in list(set(sorted(self.main.recasting.delphesruns))):
                ## checking the PAD Version
                myversion  = mydelphescard[:4]
                if myversion=='v1.2':
                    PADdir = self.main.archi_info.ma5dir+'/PAD'
                elif myversion=='v1.1':
                    PADdir = self.main.archi_info.ma5dir+'/PADForMA5tune'
                else:
                    self.logger.error('Unknown PAD version')
                    self.main.forced=forced_bkp
                    return False
                ## current delphes card
                mycard     = mydelphescard[5:]
                ## print out
                self.logger.info("   **********************************************************")
                self.logger.info("   "+StringTools.Center(myversion+' running of the PAD'+\
                       ' on events generated with',57))
                self.logger.info("   "+StringTools.Center(mycard,57))
                self.logger.info("   **********************************************************")
                ## setting up Delphes
                installer=InstallManager(self.main)
                if myversion=='v1.1':
                    if not installer.Deactivate('delphes'):
                        self.main.forced=forced_bkp
                        return False
                    if installer.Activate('delphesMA5tune')==-1:
                        self.main.forced=forced_bkp
                        return False
                elif myversion=='v1.2':
                    if not installer.Deactivate('delphesMA5tune'):
                        self.main.forced=forced_bkp
                        return False
                    if installer.Activate('delphes')==-1:
                        self.main.forced=forced_bkp
                        return False
                ## Analyses
                myanalyses = self.main.recasting.analysisruns
                myanalyses = [ x for x in myanalyses if myversion in x ]
                myanalyses = [ x.replace(myversion+'_','') for x in myanalyses ]
                for card,analysislist in self.main.recasting.DelphesDic.items():
                      if card == mycard:
                          tmpanalyses=analysislist
                          break
                myanalyses = [ x for x in myanalyses if x in tmpanalyses]
                ## event file
                for myset in self.main.datasets:
                    myevents=os.path.normpath(dirname + '/Events/' + myset.name + '_' +\
                       myversion.replace('.','x')+'_' + mycard.replace('.tcl','')+'.root')
                    ## preparing and running the PAD
                    if not self.main.recasting.UpdatePADMain(myanalyses,PADdir):
                        self.main.forced=forced_bkp
                        return False
                    time.sleep(1.);
                    if not self.main.recasting.MakePAD(PADdir,dirname,self.main):
                        self.main.forced=forced_bkp
                        return False
                    time.sleep(1.);
                    if not self.main.recasting.RunPAD(PADdir,myevents):
                        self.main.forced=forced_bkp
                        return False
                    time.sleep(1.);
                    ## Restoring the PAD as it was before
                    if not self.main.recasting.RestorePADMain(PADdir,dirname,self.main):
                        self.main.forced=forced_bkp
                        return False
                    time.sleep(1.);
                    ## saving the output
                    if not self.main.recasting.SavePADOutput(PADdir,dirname,myanalyses,myset.name):
                        self.main.forced=forced_bkp
                        return False
                    if not self.main.recasting.store_root:
                        os.remove(os.path.normpath(dirname + '/Events/' + myset.name + '_' +\
                       myversion.replace('.','x')+'_' + mycard.replace('.tcl','')+'.root'))
                    time.sleep(1.);
                    ## Running the CLs exclusion script (if available)
                    if not self.main.recasting.GetCLs(PADdir,dirname,myanalyses,myset.name,myset.xsection,myset.name):
                        self.main.forced=forced_bkp
                        return False
                    ## Saving the results
            self.main.forced=forced_bkp
        else:
            self.logger.info("   Inserting your selection into 'SampleAnalyzer'...")
            if not jobber.WriteSelectionHeader(self.main):
                self.logger.error("job submission aborted.")
                return False
            if not jobber.WriteSelectionSource(self.main):
                self.logger.error("job submission aborted.")
                return False

        self.logger.info("   Writing the list of datasets...")
        for item in self.main.datasets:
            jobber.WriteDatasetList(item)

        self.logger.info("   Writing the command line history...")
        jobber.WriteHistory(history,self.main.firstdir)
        if self.main.recasting.status == "on":
            self.main.recasting.collect_outputs(dirname,self.main.datasets)
            self.logger.info('    -> the results can be found in:') 
            self.logger.info('       '+ dirname + '/Output/CLs_output_summary.dat')
            for item in self.main.datasets:
                self.logger.info('       '+ dirname + '/Output/'+ item.name + '/CLs_output.dat')
        else:
            layouter = LayoutWriter(self.main, dirname)
            layouter.WriteLayoutConfig()

        if not self.main.recasting.status=='on' and not self.resubmit:
            self.logger.info("   Creating Makefiles...")
            if not jobber.WriteMakefiles():
                self.logger.error("job submission aborted.")
                return False

        # Edit the delphes or recasting cards
        if self.main.fastsim.package in ["delphes","delphesMA5tune"]:
            self.editDelphesCard(dirname)

        if self.resubmit and not self.main.recasting.status=='on':
            self.logger.info("   Cleaning 'SampleAnalyzer'...")
            if not jobber.MrproperJob():
                self.logger.error("job submission aborted.")
                return False

        if not self.main.recasting.status=='on':
            self.logger.info("   Compiling 'SampleAnalyzer'...")
            if not jobber.CompileJob():
                self.logger.error("job submission aborted.")
                return False

            self.logger.info("   Linking 'SampleAnalyzer'...")
            if not jobber.LinkJob():
                self.logger.error("job submission aborted.")
                return False

            for item in self.main.datasets:
                self.logger.info("   Running 'SampleAnalyzer' over dataset '"
                             +item.name+"'...")
                self.logger.info("    *******************************************************")
                if not jobber.RunJob(item):
                    self.logger.error("run over '"+item.name+"' aborted.")
                self.logger.info("    *******************************************************")
        return True
Example #5
0
    def WriteSetupFile(bash, path, archi_info):

        # Variable to check at the end
        toCheck = []

        # Opening file in write-only mode
        import os
        if bash:
            filename = os.path.normpath(path + "/setup.sh")
        else:
            filename = os.path.normpath(path + "/setup.csh")
        try:
            file = open(filename, "w")
        except:
            logging.getLogger('MA5').error('Impossible to create the file "' +
                                           filename + '"')
            return False

        # Calling the good shell
        if bash:
            file.write('#!/bin/sh\n')
        else:
            file.write('#!/bin/csh -f\n')
        file.write('\n')

        # Defining colours
        file.write('# Defining colours for shell\n')
        if bash:
            file.write('GREEN="\\\\033[1;32m"\n')
            file.write('RED="\\\\033[1;31m"\n')
            file.write('PINK="\\\\033[1;35m"\n')
            file.write('BLUE="\\\\033[1;34m"\n')
            file.write('YELLOW="\\\\033[1;33m"\n')
            file.write('CYAN="\\\\033[1;36m"\n')
            file.write('NORMAL="\\\\033[0;39m"\n')
            # using ' ' could be more convenient to code
            # but in this case, the colour code are interpreted
            # by the linux command 'more'
        else:
            file.write('set GREEN  = "\\033[1;32m"\n')
            file.write('set RED    = "\\033[1;31m"\n')
            file.write('set PINK   = "\\033[1;35m"\n')
            file.write('set BLUE   = "\\033[1;34m"\n')
            file.write('set YELLOW = "\\033[1;33m"\n')
            file.write('set CYAN   = "\\033[1;36m"\n')
            file.write('set NORMAL = "\\033[0;39m"\n')
        file.write('\n')

        # Treating ma5dir
        ma5dir = archi_info.ma5dir
        if ma5dir.endswith('/'):
            ma5dir = ma5dir[:-1]

        # Configuring PATH environment variable
        file.write('# Configuring MA5 environment variable\n')
        if bash:
            file.write('export MA5_BASE=' + (ma5dir) + '\n')
        else:
            file.write('setenv MA5_BASE ' + (ma5dir) + '\n')
        toCheck.append('MA5_BASE')
        file.write('\n')

        # Treating PATH
        toPATH, toPATHsh, toPATHcsh = SetupWriter.OrderPath(
            archi_info.toPATH1, '$PATH', archi_info.toPATH2, ma5dir)
        toLDPATH, toLDPATHsh, toLDPATHcsh = SetupWriter.OrderPath(
            archi_info.toLDPATH1, '$LD_LIBRARY_PATH', archi_info.toLDPATH2,
            ma5dir)
        toDYLDPATH, toDYLDPATHsh, toDYLDPATHcsh = SetupWriter.OrderPath(
            archi_info.toLDPATH1, '$DYLD_LIBRARY_PATH', archi_info.toLDPATH2,
            ma5dir)

        # Configuring PATH environment variable
        if len(toPATH) != 0:
            file.write('# Configuring PATH environment variable\n')
            if bash:
                file.write('if [ $PATH ]; then\n')
                file.write('export PATH=' + (':'.join(toPATHsh)) + '\n')
                file.write('else\n')
                file.write('export PATH=' + (':'.join(toPATH)) + '\n')
                file.write('fi\n')
            else:
                file.write('if ( $?PATH ) then\n')
                file.write('setenv PATH ' + (':'.join(toPATHcsh)) + '\n')
                file.write('else\n')
                file.write('setenv PATH ' + (':'.join(toPATH)) + '\n')
                file.write('endif\n')
            toCheck.append('PATH')
            file.write('\n')

        if len(toLDPATH) != 0:

            # Configuring LD_LIBRARY_PATH environment variable
            file.write('# Configuring LD_LIBRARY_PATH environment variable\n')
            if bash:
                file.write('if [ $LD_LIBRARY_PATH ]; then\n')
                file.write('export LD_LIBRARY_PATH=' + (':'.join(toLDPATHsh)) +
                           '\n')
                file.write('else\n')
                file.write('export LD_LIBRARY_PATH=' + (':'.join(toLDPATH)) +
                           '\n')
                file.write('fi\n')
            else:
                file.write('if ( $?LD_LIBRARY_PATH ) then\n')
                file.write('setenv LD_LIBRARY_PATH ' +
                           (':'.join(toLDPATHcsh)) + '\n')
                file.write('else\n')
                file.write('setenv LD_LIBRARY_PATH ' + (':'.join(toLDPATH)) +
                           '\n')
                file.write('endif\n')
            toCheck.append('LD_LIBRARY_PATH')
            file.write('\n')

            # Configuring LIBRARY_PATH environment variable
            #file.write('# Configuring LIBRARY_PATH environment variable\n')
            #if bash:
            #    file.write('export LIBRARY_PATH=' + (os.environ['LD_LIBRARY_PATH'])+'\n')
            #else:
            #    file.write('setenv LIBRARY_PATH ' + (os.environ['LD_LIBRARY_PATH'])+'\n')
            #file.write('\n')

            # Configuring DYLD_LIBRARY_PATH environment variable
            if archi_info.isMac:
                file.write(
                    '# Configuring DYLD_LIBRARY_PATH environment variable\n')
                if bash:
                    file.write('if [ $DYLD_LIBRARY_PATH ]; then\n')
                    file.write('export DYLD_LIBRARY_PATH=' +
                               (':'.join(toDYLDPATHsh)) + '\n')
                    file.write('else\n')
                    file.write('export DYLD_LIBRARY_PATH=' +
                               (':'.join(toLDPATH)) + '\n')
                    file.write('fi\n')
                else:
                    file.write('if ( $?DYLD_LIBRARY_PATH ) then\n')
                    file.write('setenv DYLD_LIBRARY_PATH ' +
                               (':'.join(toDYLDPATHcsh)) + '\n')
                    file.write('else\n')
                    file.write('setenv DYLD_LIBRARY_PATH ' +
                               (':'.join(toLDPATH)) + '\n')
                    file.write('endif\n')
                toCheck.append('DYLD_LIBRARY_PATH')
                file.write('\n')

            # Configuring CPLUS_INCLUDE_PATH environment variable
            #file.write('# Configuring CPLUS_INCLUDE_PATH environment variable\n')
            #if bash:
            #    file.write('export CPLUS_INCLUDE_PATH=' + (os.environ['CPLUS_INCLUDE_PATH'])+'\n')
            #else:
            #    file.write('setenv CPLUS_INCLUDE_PATH ' + (os.environ['CPLUS_INCLUDE_PATH'])+'\n')
            #file.write('\n')

        # Checking that all environment variables are defined
        file.write('# Checking that all environment variables are defined\n')
        if bash:
            file.write('if [[ ')
            for ind in range(0, len(toCheck)):
                if ind != 0:
                    file.write(' && ')
                file.write('$' + toCheck[ind])
            file.write(' ]]; then\n')
            file.write('echo -e $YELLOW"' + StringTools.Fill('-', 56) + '"\n')
            file.write('echo -e "' + StringTools.Center(
                'Your environment is properly configured for MA5', 56) + '"\n')
            file.write('echo -e "' + StringTools.Fill('-', 56) + '"$NORMAL\n')
            file.write('fi\n')
        else:
            file.write('if ( ')
            for ind in range(0, len(toCheck)):
                if ind != 0:
                    file.write(' && ')
                file.write('$?' + toCheck[ind])
            file.write(' ) then\n')
            file.write('echo $YELLOW"' + StringTools.Fill('-', 56) + '"\n')
            file.write('echo "' + StringTools.Center(
                'Your environment is properly configured for MA5', 56) + '"\n')
            file.write('echo "' + StringTools.Fill('-', 56) + '"$NORMAL\n')
            file.write('endif\n')

        # Closing the file
        try:
            file.close()
        except:
            logging.getLogger('MA5').error('Impossible to close the file "' +
                                           filename + '"')
            return False

        return True
Example #6
0
    def UserfriendlyMakefileForSampleAnalyzer(filename, options):

        # Open the Makefile
        try:
            file = open(filename, "w")
        except:
            logging.getLogger('MA5').error('impossible to write the file ' +
                                           filename)
            return False

        # Header
        file.write(StringTools.Fill('#', 80) + '\n')
        file.write('#' + StringTools.Center(
            'GENERAL MAKEFILE DEVOTED TO SAMPLEANALYZER', 78) + '#\n')
        file.write(StringTools.Fill('#', 80) + '\n')
        file.write('\n')

        # Defining colours for shell
        MakefileWriter.DefineColours(file)

        # All
        file.write('# All target\n')
        file.write('all:\n')
        if options.has_commons:
            file.write('\tcd Commons && $(MAKE)\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_commons\n')
        if options.has_zlib:
            file.write('\tcd Interfaces && $(MAKE) -f Makefile_zlib\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_zlib\n')
        if options.has_fastjet:
            file.write('\tcd Interfaces && $(MAKE) -f Makefile_fastjet\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_fastjet\n')
        if options.has_delphes:
            file.write('\tcd Interfaces && $(MAKE) -f Makefile_delphes\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_delphes\n')
        if options.has_root:
            file.write('\tcd Interfaces && $(MAKE) -f Makefile_root\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_root\n')
        if options.has_delphesMA5tune:
            file.write(
                '\tcd Interfaces && $(MAKE) -f Makefile_delphesMA5tune\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_delphesMA5tune\n')
        if options.has_process:
            file.write('\tcd Process && $(MAKE) -f Makefile\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_process\n')
        file.write('\n')

        # Clean
        file.write('# Clean target\n')
        file.write('clean:\n')
        if options.has_commons:
            file.write('\tcd Commons && $(MAKE) clean\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_commons clean\n')
        if options.has_zlib:
            file.write('\tcd Interfaces && $(MAKE) -f Makefile_zlib clean\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_zlib clean\n')
        if options.has_fastjet:
            file.write(
                '\tcd Interfaces && $(MAKE) -f Makefile_fastjet clean\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_fastjet clean\n')
        if options.has_delphes:
            file.write(
                '\tcd Interfaces && $(MAKE) -f Makefile_delphes clean\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_delphes clean\n')
        if options.has_root:
            file.write('\tcd Interfaces && $(MAKE) -f Makefile_root clean\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_root clean\n')
        if options.has_delphesMA5tune:
            file.write(
                '\tcd Interfaces && $(MAKE) -f Makefile_delphesMA5tune clean\n'
            )
            file.write(
                '\tcd Test && $(MAKE) -f Makefile_delphesMA5tune clean\n')
        if options.has_process:
            file.write('\tcd Process && $(MAKE) -f Makefile clean\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_process clean\n')
        file.write('\n')

        # Mrproper
        file.write('# Mrproper target\n')
        file.write('mrproper:\n')
        file.write('\t@rm -f *~ */*~\n')
        if options.has_commons:
            file.write('\tcd Commons && $(MAKE) mrproper\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_commons mrproper\n')
        if options.has_zlib:
            file.write(
                '\tcd Interfaces && $(MAKE) -f Makefile_zlib mrproper\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_zlib mrproper\n')
        if options.has_fastjet:
            file.write(
                '\tcd Interfaces && $(MAKE) -f Makefile_fastjet mrproper\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_fastjet mrproper\n')
        if options.has_delphes:
            file.write(
                '\tcd Interfaces && $(MAKE) -f Makefile_delphes mrproper\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_delphes mrproper\n')
        if options.has_root:
            file.write(
                '\tcd Interfaces && $(MAKE) -f Makefile_root mrproper\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_root mrproper\n')
        if options.has_delphesMA5tune:
            file.write(
                '\tcd Interfaces && $(MAKE) -f Makefile_delphesMA5tune mrproper\n'
            )
            file.write(
                '\tcd Test && $(MAKE) -f Makefile_delphesMA5tune mrproper\n')
        if options.has_process:
            file.write('\tcd Process && $(MAKE) -f Makefile mrproper\n')
            file.write('\tcd Test && $(MAKE) -f Makefile_process mrproper\n')
        file.write('\n')

        # Closing the file
        file.close()

        return True
Example #7
0
    def Makefile(MakefileName,
                 title,
                 ProductName,
                 ProductPath,
                 isLibrary,
                 cppfiles,
                 hfiles,
                 options,
                 archi_info,
                 toRemove,
                 moreIncludes=[]):

        import os
        # Open the Makefile
        try:
            file = open(MakefileName, "w")
        except:
            logging.getLogger('MA5').error('impossible to write the file ' +
                                           MakefileName)
            return False

        # Header
        file.write(StringTools.Fill('#', 80) + '\n')
        file.write('#' +
                   StringTools.Center('MAKEFILE DEVOTED TO ' +
                                      title.upper(), 78) + '#\n')
        file.write(StringTools.Fill('#', 80) + '\n')
        file.write('\n')

        # Compilers
        file.write('# Compilers\n')
        if archi_info.has_root and archi_info.root_compiler != '':
            file.write('CXX = ' + archi_info.root_compiler + '\n')
        else:
            file.write('CXX = g++\n')
        file.write('\n')

        # Options for C++ compilation
        file.write('# C++ Compilation options\n')

        # - general
        cxxflags = []
        cxxflags.extend(['-Wall', '-O3', '-fPIC',
                         '-I$(MA5_BASE)/tools/'])  # general
        file.write('CXXFLAGS  = ' + ' '.join(cxxflags) + '\n')
        for item in moreIncludes:
            file.write('CXXFLAGS += ' + ' -I' + item + '\n')

        # - root
        if options.has_root_inc:
            cxxflags = []
            cxxflags.extend([
                '$(shell $(MA5_BASE)/tools/SampleAnalyzer/ExternalSymLink/Bin/root-config --cflags)'
            ])
            file.write('CXXFLAGS += ' + ' '.join(cxxflags) + '\n')

        # - fastjet
        if options.has_fastjet_inc:
            cxxflags = []
            cxxflags.extend([
                '$(shell $(MA5_BASE)/tools/SampleAnalyzer/ExternalSymLink/Bin/fastjet-config --cxxflags)'
            ])
            #            cxxflags.extend(['$(shell fastjet-config --cxxflags)'])
            file.write('CXXFLAGS += ' + ' '.join(cxxflags) + '\n')

        # - zlib
        if options.has_zlib_inc:
            cxxflags = []
            cxxflags.extend(['-I' + archi_info.zlib_inc_path])
            file.write('CXXFLAGS += ' + ' '.join(cxxflags) + '\n')

        # - delphes
        if options.has_delphes_inc:
            cxxflags = []
            for header in archi_info.delphes_inc_paths:
                cxxflags.extend(['-I' + header])
            file.write('CXXFLAGS += ' + ' '.join(cxxflags) + '\n')

        # - delphesMA5tune
        if options.has_delphesMA5tune_inc:
            cxxflags = []
            for header in archi_info.delphesMA5tune_inc_paths:
                cxxflags.extend(['-I' + header])
            file.write('CXXFLAGS += ' + ' '.join(cxxflags) + '\n')

        # - tags
        cxxflags = []
        if options.has_root_tag:
            cxxflags.extend(['-DROOT_USE'])
        if options.has_fastjet_tag:
            cxxflags.extend(['-DFASTJET_USE'])
        if options.has_zlib_tag:
            cxxflags.extend(['-DZIP_USE'])
        if options.has_delphes_tag:
            cxxflags.extend(['-DDELPHES_USE'])
        if options.has_delphesMA5tune_tag:
            cxxflags.extend(['-DDELPHESMA5TUNE_USE'])
        if len(cxxflags) != 0:
            file.write('CXXFLAGS += ' + ' '.join(cxxflags) + '\n')
        file.write('\n')

        # Options for C++ linking
        file.write('# Linking options\n')

        # - general
        libs = []
        file.write('LIBFLAGS  = \n')

        # - commons
        if options.has_commons:
            libs = []
            libs.append('-L$(MA5_BASE)/tools/SampleAnalyzer/Lib')
            libs.append(
                '-L$(MA5_BASE)/tools/SampleAnalyzer/ExternalSymLink/Lib')
            file.write('LIBFLAGS += ' + ' '.join(libs) + '\n')

        # - process
        if options.has_process:
            libs = []
            libs.extend(['-lprocess_for_ma5'])
            file.write('LIBFLAGS += ' + ' '.join(libs) + '\n')

        # - zlib
        if options.has_zlib_ma5lib or options.has_zlib_lib:
            libs = []
            if options.has_zlib_ma5lib:
                libs.extend(['-lzlib_for_ma5'])
            if options.has_zlib_lib:
                #                libs.extend(['-L'+archi_info.zlib_lib_path,'-lz'])
                libs.extend(['-lz'])
            file.write('LIBFLAGS += ' + ' '.join(libs) + '\n')

        # - root
        if options.has_root_ma5lib:
            libs = []
            if options.has_root_ma5lib:
                libs.extend(['-lroot_for_ma5'])
            if options.has_root_lib:
                libs.extend([
                    '$(shell $(MA5_BASE)/tools/SampleAnalyzer/ExternalSymLink/Bin/root-config --libs) -lEG'
                ])
            file.write('LIBFLAGS += ' + ' '.join(libs) + '\n')
        else:
            if options.has_root_lib:
                libs.extend([
                    '$(shell $(MA5_BASE)/tools/SampleAnalyzer/ExternalSymLink/Bin/root-config --libs) -lEG'
                ])
                file.write('LIBFLAGS += ' + ' '.join(libs) + '\n')

            # - fastjet
        if options.has_fastjet_ma5lib or options.has_fastjet_lib:
            libs = []
            if options.has_fastjet_ma5lib:
                libs.extend(['-lfastjet_for_ma5'])
            if options.has_fastjet_lib:
                #                libs.extend(['$(shell fastjet-config --libs --plugins)']) # --rpath=no)'])
                libs.extend([
                    '$(shell $(MA5_BASE)/tools/SampleAnalyzer/ExternalSymLink/Bin/fastjet-config --libs --plugins)'
                ])  # --rpath=no)'])
            file.write('LIBFLAGS += ' + ' '.join(libs) + '\n')

        # - delphes
        if options.has_delphes_ma5lib or options.has_delphes_lib:
            libs = []
            if options.has_delphes_ma5lib:
                libs.extend(['-ldelphes_for_ma5'])
            if options.has_delphes_lib:
                #                libs.extend(['-L'+archi_info.delphes_lib_paths[0],'-lDelphes'])
                libs.extend(['-lDelphes'])
            file.write('LIBFLAGS += ' + ' '.join(libs) + '\n')

        # - delphesMA5tune
        if options.has_delphesMA5tune_ma5lib or options.has_delphesMA5tune_lib:
            libs = []
            if options.has_delphesMA5tune_ma5lib:
                libs.extend(['-ldelphesMA5tune_for_ma5'])
            if options.has_delphesMA5tune_lib:
                #                libs.extend(['-L'+archi_info.delphesMA5tune_lib_paths[0],'-lDelphesMA5tune'])
                libs.extend(['-lDelphesMA5tune'])
            file.write('LIBFLAGS += ' + ' '.join(libs) + '\n')

        # - Commons
        if options.has_commons:
            libs = []
            libs.extend(['-lcommons_for_ma5'])
            file.write('LIBFLAGS += ' + ' '.join(libs) + '\n')

        # - Root
        libs = []
        #libs.extend(['-L'+archi_info.root_lib_path, \
        #            '-lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -lEG'])
        # becareful: to not forget -lEG
        if options.has_root:
            libs.extend([
                '$(shell $(MA5_BASE)/tools/SampleAnalyzer/ExternalSymLink/Bin/root-config --libs)',
                '-lEG'
            ])
        if len(libs) != 0:
            file.write('LIBFLAGS += ' + ' '.join(libs) + '\n')
        file.write('\n')

        # Lib to check
        libs = []
        if options.has_commons:
            libs.append(
                '$(MA5_BASE)/tools/SampleAnalyzer/Lib/libcommons_for_ma5.so')
        if options.has_process:
            libs.append(
                '$(MA5_BASE)/tools/SampleAnalyzer/Lib/libprocess_for_ma5.so')
        if options.has_zlib_ma5lib:
            libs.append(
                '$(MA5_BASE)/tools/SampleAnalyzer/Lib/libzlib_for_ma5.so')
        if options.has_delphes_ma5lib:
            libs.append(
                '$(MA5_BASE)/tools/SampleAnalyzer/Lib/libdelphes_for_ma5.so')
        if options.has_root_ma5lib:
            libs.append(
                '$(MA5_BASE)/tools/SampleAnalyzer/Lib/libroot_for_ma5.so')
        if options.has_delphesMA5tune_ma5lib:
            libs.append(
                '$(MA5_BASE)/tools/SampleAnalyzer/Lib/libdelphesMA5tune_for_ma5.so'
            )
        if options.has_fastjet_ma5lib:
            libs.append(
                '$(MA5_BASE)/tools/SampleAnalyzer/Lib/libfastjet_for_ma5.so')
        if len(libs) != 0:
            file.write('# Requirements to check before building\n')
            for ind in range(0, len(libs)):
                file.write('REQUIRED' + str(ind + 1) + ' = ' + libs[ind] +
                           '\n')
            file.write('\n')

        # Files for analyzers
        file.write('# Files\n')
        for ind in range(0, len(cppfiles)):
            if ind == 0:
                file.write('SRCS  = $(wildcard ' + cppfiles[ind] + ')\n')
            else:
                file.write('SRCS += $(wildcard ' + cppfiles[ind] + ')\n')
        for ind in range(0, len(hfiles)):
            if ind == 0:
                file.write('HDRS  = $(wildcard ' + hfiles[ind] + ')\n')
            else:
                file.write('HDRS += $(wildcard ' + hfiles[ind] + ')\n')
        file.write('OBJS  = $(SRCS:.cpp=.o)\n')
        file.write('\n')

        # Name of the library
        if isLibrary:
            file.write('# Name of the library\n')
            file.write('LIBRARY = ' + ProductName + '\n')
        else:
            file.write('# Name of the executable\n')
            file.write('PROGRAM = ' + ProductName + '\n')
        file.write('\n')

        # Defining colours for shell
        MakefileWriter.DefineColours(file)

        # All
        file.write('# All target\n')
        if len(libs) == 0:
            file.write('all: header compile_header compile link_header link\n')
        else:
            file.write(
                'all: header library_check compile_header compile link_header link\n'
            )
        file.write('\n')

        # Check library
        if len(libs) != 0:
            file.write('# Check library\n')
            file.write('library_check:\n')
            for ind in range(0, len(libs)):
                file.write('ifeq ($(wildcard $(REQUIRED' + str(ind + 1) +
                           ')),)\n')
                file.write('\t@echo -e $(RED)"The shared library "$(REQUIRED' +
                           str(ind + 1) + ')" is not found"\n')
                file.write(
                    '\t@echo -e $(RED)" 1) Please check that MadAnalysis 5 is installed in the folder : "$(MA5_BASE)\n'
                )
                file.write(
                    '\t@echo -e $(RED)" 2) Launch MadAnalysis 5 in normal mode in order to build this library."\n'
                )
                file.write('\t@echo -e $(NORMAL)\n')
                file.write('\t@false\n')
                file.write('endif\n')
            file.write('\n')

        # Header target
        file.write('# Header target\n')
        file.write('header:\n')
        file.write('\t@echo -e $(YELLOW)"' + StringTools.Fill('-', 50) + '"\n')
        file.write('\t@echo -e "' +
                   StringTools.Center('Building ' + title, 50) + '"\n')
        file.write('\t@echo -e "' + StringTools.Fill('-', 50) + '"$(NORMAL)\n')
        file.write('\n')

        # Compile_header target
        file.write('# Compile_header target\n')
        file.write('compile_header:\n')
        file.write('\t@echo -e $(YELLOW)"' + StringTools.Fill('-', 50) + '"\n')
        file.write('\t@echo -e "' + StringTools.Center('Compilation', 50) +
                   '"\n')
        file.write('\t@echo -e "' + StringTools.Fill('-', 50) + '"$(NORMAL)\n')
        file.write('\n')

        # Linking_header target
        file.write('# Link_header target\n')
        file.write('link_header:\n')
        file.write('\t@echo -e $(YELLOW)"' + StringTools.Fill('-', 50) + '"\n')
        file.write('\t@echo -e "' + StringTools.Center('Linking', 50) + '"\n')
        file.write('\t@echo -e "' + StringTools.Fill('-', 50) + '"$(NORMAL)\n')
        file.write('\n')

        # Clean_header target
        file.write('# clean_header target\n')
        file.write('clean_header:\n')
        file.write('\t@echo -e $(YELLOW)"' + StringTools.Fill('-', 50) + '"\n')
        file.write('\t@echo -e "' + StringTools.Center(
            'Removing intermediate files from building', 50) + '"\n')
        file.write('\t@echo -e "' + StringTools.Fill('-', 50) + '"$(NORMAL)\n')
        file.write('\n')

        # Mrproper_header target
        file.write('# mrproper_header target\n')
        file.write('mrproper_header:\n')
        file.write('\t@echo -e $(YELLOW)"' + StringTools.Fill('-', 50) + '"\n')
        file.write('\t@echo -e "' +
                   StringTools.Center('Cleaning all the project', 50) + '"\n')
        file.write('\t@echo -e "' + StringTools.Fill('-', 50) + '"$(NORMAL)\n')
        file.write('\n')

        # Precompile
        file.write('# Precompile target\n')
        file.write('precompile:\n')
        file.write('\n')

        # Compile
        file.write('# Compile target\n')
        file.write('compile: precompile $(OBJS)\n')
        file.write('\n')

        # Compile each file
        # TO NOT FORGET HDRS -> handling header dependencies
        file.write('# Compile each file\n')
        file.write('%.o: %.cpp $(HDRS)\n')
        file.write('\t$(CXX) $(CXXFLAGS) -o $@ -c $<\n')
        file.write('\n')

        # Link
        file.write('# Link target\n')
        file.write('link: $(OBJS)\n')
        if not ProductPath.endswith('/'):
            ProductPath = ProductPath + '/'
        if isLibrary:
            if options.isMac:
                file.write(
                    '\t$(CXX) -shared -flat_namespace -dynamiclib -undefined suppress -o '
                    + ProductPath + '$(LIBRARY) $(OBJS) $(LIBFLAGS)\n')
            else:
                file.write('\t$(CXX) -shared -o ' + ProductPath +
                           '$(LIBRARY) $(OBJS) $(LIBFLAGS)\n')
        else:
            file.write('\t$(CXX) $(OBJS) $(LIBFLAGS) -o ' + ProductPath +
                       '$(PROGRAM)\n')
        file.write('\n')

        # Phony target
        file.write('# Phony target\n')
        file.write('.PHONY: do_clean header compile_header link_header\n')
        file.write('\n')

        # Cleaning
        file.write('# Clean target\n')
        file.write('clean: clean_header do_clean\n')
        file.write('\n')
        file.write('# Do clean target\n')
        file.write('do_clean: \n')
        file.write('\t@rm -f $(OBJS)\n')
        file.write('\n')

        # Mr Proper
        file.write('# Mr Proper target \n')
        file.write('mrproper: mrproper_header do_mrproper\n')
        file.write('\n')
        file.write('# Do Mr Proper target \n')
        file.write('do_mrproper: do_clean\n')
        if isLibrary:
            file.write('\t@rm -f ' + ProductPath + '$(LIBRARY)\n')
        else:
            file.write('\t@rm -f ' + ProductPath + '$(PROGRAM)\n')
        file.write('\t@rm -f *~ */*~\n')
        file.write('\t@rm -f ' + ' '.join(toRemove) + '\n')
        file.write('\n')

        # Closing the file
        file.close()

        return True
    def Execute(self, rawpackage):

        # Selection of the package
        package = rawpackage.lower()
        if package == 'zlib':
            from madanalysis.install.install_zlib import InstallZlib
            installer = InstallZlib(self.main)
        elif package == 'fastjet':
            from madanalysis.install.install_fastjet import InstallFastjet
            installer = InstallFastjet(self.main)
        elif package == 'fastjet-contrib':
            from madanalysis.install.install_fastjetcontrib import InstallFastjetContrib
            installer = InstallFastjetContrib(self.main)
        elif package == 'delphes':
            if self.main.archi_info.has_root:
                from madanalysis.install.install_delphes import InstallDelphes
                installer = InstallDelphes(self.main)
            else:
                self.logger.warning(
                    'the package "' + rawpackage +
                    '" cannot be installed without root; installation skipped')
                return True
        elif package == 'delphesma5tune':
            if self.main.archi_info.has_root:
                from madanalysis.install.install_delphesMA5tune import InstallDelphesMA5tune
                installer = InstallDelphesMA5tune(self.main)
            else:
                self.logger.warning(
                    'the package "' + rawpackage +
                    '" cannot be installed without root; installation skipped')
                return True
        elif package == 'samples':
            from madanalysis.install.install_samples import InstallSamples
            installer = InstallSamples(self.main)
        elif package == 'gnuplot':
            from madanalysis.install.install_gnuplot import InstallGnuplot
            installer = InstallGnuplot(self.main)
        elif package == 'matplotlib':
            from madanalysis.install.install_matplotlib import InstallMatplotlib
            installer = InstallMatplotlib(self.main)
        elif package == 'root':
            from madanalysis.install.install_root import InstallRoot
            installer = InstallRoot(self.main)
        elif package == 'numpy':
            from madanalysis.install.install_numpy import InstallNumpy
            installer = InstallNumpy(self.main)
        elif package == 'padforma5tune':
            if self.main.archi_info.has_root:
                from madanalysis.install.install_padma5tune import InstallPadForMA5tune
                installer = InstallPadForMA5tune(self.main)
            else:
                self.logger.warning(
                    'the package "' + rawpackage +
                    '" cannot be installed without root; installation skipped')
                return True
        elif package == 'pad':
            if self.main.archi_info.has_root:
                from madanalysis.install.install_pad import InstallPad
                installer = InstallPad(self.main)
            else:
                self.logger.warning(
                    'the package "' + rawpackage +
                    '" cannot be installed without root; installation skipped')
                return True
        else:
            self.logger.error('the package "' + rawpackage + '" is unknown')
            return False

        # Writing the Makefiles
        self.logger.info("")
        self.logger.info(
            "   **********************************************************")
        self.logger.info("   " +
                         StringTools.Center('Installing ' + rawpackage, 57))
        self.logger.info(
            "   **********************************************************")

        # Get list of the methods of the installer class
        # If the method does not exist, the method is not called
        methods = dir(installer)

        # 0. Detecting previous installation
        if 'Detect' in methods:
            self.logger.info("   Detecting a previous installation ...")
            if installer.Detect():
                self.logger.info("   => found")
                self.logger.info("   Removing the previous installation ...")
                ok1, ok2 = installer.Remove(question=True)
                if not ok1 and not ok2:
                    self.PrintBad()
                    return False
                elif not ok1 and ok2:
                    self.PrintSkip()
                    return True
            else:
                self.logger.info("   => not found. OK")

        # 1. Asking for number of cores
        if 'GetNcores' in methods:
            installer.GetNcores()
            self.logger.info(
                "   **********************************************************"
            )

        # 2. Creating a folder
        if 'CreatePackageFolder' in methods:
            self.logger.info("   Creating a devoted folder ...")
            if not installer.CreatePackageFolder():
                self.PrintBad()
                return False

        # 3. Creating a temporary folder
        if 'CreateTmpFolder' in methods:
            self.logger.info("   Creating a temporary folder ...")
            if not installer.CreateTmpFolder():
                self.PrintBad()
                return False

        # 4. Downloading
        if 'Download' in methods:
            if self.main.session_info.has_web:
                self.logger.info("   Downloading the package ...")
                if not installer.Download():
                    self.PrintBad()
                    return False
            else:
                self.logger.warning(
                    "   Download is not allowed because the internet access is disabled."
                )

        # 5. Unpacking
        if 'Unpack' in methods:
            self.logger.info("   Unpacking the package ...")
            if not installer.Unpack():
                self.PrintBad()
                return False

        # 6. Configuring
        if 'Configure' in methods:
            self.logger.info("   Configuring the package ...")
            if not installer.Configure():
                self.PrintBad()
                return False

        # 7. Compiling
        if 'Build' in methods:
            self.logger.info("   Building the package ...")
            if not installer.Build():
                self.PrintBad()
                return False

        # 8. Checking
        if 'PreCheck' in methods:
            self.logger.info("   Checking the building ...")
            if not installer.PreCheck():
                self.PrintBad()
                return False

        # 9. Clean
        if 'Clean' in methods:
            self.logger.info("   Cleaning the building ...")
            if not installer.Clean():
                self.PrintBad()
                return False

        # 9. Install
        if 'Install' in methods:
            self.logger.info(
                "   Transfering the data from the temporary to the definitive folder ..."
            )
            if not installer.Install():
                self.PrintBad()
                return False

        # 10. Checking (again)
        if 'Check' in methods:
            self.logger.info("   Checking the installation ...")
            if not installer.Check():
                self.PrintBad()
                return False

        # 11. End: restart MA5 session?
        self.PrintGood()

        if installer.NeedToRestart():
            return 'restart'
        else:
            return True
Example #9
0
    def WriteLayoutConfig(self):

        # open the file in write-only mode
        filename = os.path.normpath(self.jobdir + "/layout.ma5")
        try:
            file = open(filename, "w")
        except:
            logging.getLogger('MA5').error("impossible to create the file '" +
                                           filename + "'")

        # Writing header
        from madanalysis.core.main import Main
        file.write(StringTools.Fill('#', 80) + '\n')
        file.write('#' + StringTools.Center(
            'MADANALYSIS5 CONFIGURATION FILE FOR PLOTS', 78) + '#\n')
        file.write('#' + StringTools.Center(
            'produced by MadAnalysis5 version ' + Main.version, 78) + '#\n')
        file.write('#' + StringTools.Center(Main.date, 78) + '#\n')
        file.write(StringTools.Fill('#', 80) + '\n')
        file.write('\n')

        # Writing file block
        file.write(StringTools.Fill('#', 80) + '\n')
        file.write('#' + StringTools.Center('Files and Paths', 78) + '#\n')
        file.write(StringTools.Fill('#', 80) + '\n')
        file.write('<Files>\n')
        file.write('  jodir = ' + self.jobdir + '\n')
        file.write('  html = 1\n')
        file.write('  latex = 1\n')
        file.write('  pdflatex = 1\n')
        file.write('</Files>\n')
        file.write('\n')

        # Writing main block
        file.write(StringTools.Fill('#', 80) + '\n')
        file.write('#' + StringTools.Center(
            'Global information related to the layout', 78) + '#\n')
        file.write(StringTools.Fill('#', 80) + '\n')
        file.write('<Main>\n')
        file.write('  lumi = ' + str(self.main.lumi) + ' # fb^{-1}\n')
        #        file.write('  S_over_B = "'+ str(self.main.SBratio)+'"\n')
        #        file.write('  S_over_B_error = "'+str(self.main.SBerror)+ '"\n')
        file.write('  stack = ' + str(self.main.stack) + '\n')
        file.write('</Main>\n')
        file.write('\n')

        # Writing dataset
        file.write(StringTools.Fill('#', 80) + '\n')
        file.write('#' + StringTools.Center('Definition of datasets', 78) +
                   '#\n')
        file.write(StringTools.Fill('#', 80) + '\n')
        for dataset in self.main.datasets:
            file.write('<Dataset name="' + dataset.name + '">\n')
            file.write('  <Physics>\n')
            file.write('    background = ' + str(dataset.background) + '\n')
            file.write('    weight = ' + str(dataset.weight) + '\n')
            file.write('    xsection = ' + str(dataset.xsection) + '\n')
            file.write('  </Physics>\n')
            file.write('  <Layout>\n')
            file.write('    title = ' + str(dataset.title) + '\n')
            file.write('    linecolor = ' + str(dataset.linecolor) + '\n')
            file.write('    linestyle = ' + str(dataset.linestyle) + '\n')
            file.write('    lineshade = ' + str(dataset.lineshade) + '\n')
            file.write('    linewidth = ' + str(dataset.linewidth) + '\n')
            file.write('    backcolor = ' + str(dataset.backcolor) + '\n')
            file.write('    backstyle = ' + str(dataset.backstyle) + '\n')
            file.write('    backshade = ' + str(dataset.backshade) + '\n')
            file.write('  </Layout>\n')
            file.write('</Dataset>\n')
            file.write('\n')

        # Writing selection
        file.write(StringTools.Fill('#', 80) + '\n')
        file.write('#' + StringTools.Center(
            'Definition of the selection : histograms and cuts', 78) + '#\n')
        file.write(StringTools.Fill('#', 80) + '\n')
        counter = 0
        for item in self.main.selection:
            if item.__class__.__name__ == "Histogram":
                file.write('<Histogram name="selection' + str(counter) +
                           '">\n')
                file.write('  stack = ' + str(item.stack) + '\n')
                file.write('  titleX = "' + str(item.GetXaxis_Root()) + '"\n')
                file.write('  titleY = "' + str(item.GetYaxis()) + '"\n')
                file.write('  xmin = ' + str(item.xmin) + '\n')
                file.write('  xmax = ' + str(item.xmax) + '\n')
                file.write('</Histogram>\n')
                file.write('\n')

            if item.__class__.__name__ == "HistogramFrequency":
                pass

            elif item.__class__.__name__ == "Cut":
                file.write('<Cut name="selection' + str(counter) + '"/>\n')
                file.write('\n')

            counter += 1

        # Must we definite multiparticles ?
        MustBeDefined = False
        for item in self.main.selection:
            if item.__class__.__name__=="Histogram" and \
               item.observable.name in ["NPID","NAPID"]:
                MustBeDefined = True
                break

        # Definition of multiparticles
        if MustBeDefined:
            file.write(StringTools.Fill('#', 80) + '\n')
            file.write('#' + StringTools.Center(
                'Definition of the multiparticles used', 78) + '#\n')
            file.write(StringTools.Fill('#', 80) + '\n')
            sorted_keys = sorted(self.main.multiparticles.table.keys())
            for key in sorted_keys:
                file.write('<Multiparticle name="' + str(key) + '">\n')
                file.write('  ')
                for id in self.main.multiparticles.table[key]:
                    file.write(str(id) + '  ')
                file.write('\n')
                file.write('</Multiparticle>\n')

        # close the file
        try:
            file.close()
        except:
            logging.getLogger('MA5').error("impossible to close the file '" +
                                           filename + "'")
Example #10
0
    def CheckArchitecture(self):

        # Fill with Python info
        import sys
        self.archi_info.python_version = sys.version.replace('\n', '')

        # Fill with Platform info
        import platform
        self.archi_info.platform = platform.system()
        self.archi_info.release = platform.release()

        # Fill with number of cores
        import multiprocessing
        self.archi_info.ncores = multiprocessing.cpu_count()

        # Is Mac
        platform_text = "Platform: " + self.archi_info.platform + " " + self.archi_info.release + " "
        if self.archi_info.platform.lower() in ['darwin', 'mac', 'macosx']:
            self.archi_info.isMac = True
            platform_text += '\x1b[32m' + '[MAC/OSX mode]' + '\x1b[0m'
        else:
            self.archi_info.isMac = False
            platform_text += '\x1b[32m' + '[Linux mode]' + '\x1b[0m'
        self.logger.info(platform_text)

        # Info for debug mode
        if self.debug:

            # Machine general
            import platform
            self.logger.debug("")
            self.logger.debug("Machine - Cross platform information")
            self.logger.debug(
                StringTools.Left("  Machine type:     ", 28) +
                str(platform.machine()))
            self.logger.debug(
                StringTools.Left("  Processor name:   ", 28) +
                str(platform.processor()))
            self.logger.debug(
                StringTools.Left("  Platform:         ", 28) +
                str(platform.platform()))
            self.logger.debug(
                StringTools.Left("  Platform release: ", 28) +
                str(platform.release()))
            self.logger.debug(
                StringTools.Left("  System:           ", 28) +
                str(platform.system()))
            self.logger.debug(
                StringTools.Left("  Node:             ", 28) +
                str(platform.node()))
            self.logger.debug(
                StringTools.Left("  Number of cores:  ", 28) +
                str(self.archi_info.ncores))
            self.logger.debug("")

            # Machine OS
            self.logger.debug("Machine - OS-specific information")
            try:
                tmp = platform.java_ver()
            except:
                tmp = ''
            self.logger.debug(
                StringTools.Left("  Java version:     ", 28) + str(tmp))
            try:
                tmp = platform.win32_ver()
            except:
                tmp = ''
            self.logger.debug(
                StringTools.Left("  Windows version:  ", 28) + str(tmp))
            try:
                tmp = platform.mac_ver()
            except:
                tmp = ''
            self.logger.debug(
                StringTools.Left("  Mac Os version:   ", 28) + str(tmp))
            try:
                tmp = platform.dist()
            except:
                tmp = ''
            self.logger.debug(
                StringTools.Left("  Unix distribution:", 28) +
                str(platform.platform()))
            self.logger.debug("")

        return True
Example #11
0
    def CheckSessionInfo(self):

        # Fill with user name
        try:
            import getpass
            self.session_info.username = getpass.getuser()
        except:
            self.session_info.username = '******'

        # Display user info
        if self.debug:
            self.logger.debug('')
            self.logger.debug("User")
            self.logger.debug(
                StringTools.Left("  User name:", 28) +
                str(self.session_info.username))
            import os
            self.logger.debug(
                StringTools.Left("  User ID:", 28) + str(os.getuid()))
            self.logger.debug(
                StringTools.Left("  Expanding folder ~/:", 28) +
                str(os.path.expanduser("~/")))
            for name in [
                    "USER", "USERNAME", "LNAME", "LOGNAME", "HOME",
                    "HOMEDRIVE", "posix", "HOMEPATH"
            ]:
                if name in os.environ:
                    tmp = os.environ[name]
                else:
                    tmp = ''
                self.logger.debug(
                    StringTools.Left("  Variable $" + name + ":", 28) +
                    str(tmp))
            self.logger.debug('')

        # Web access
        self.logger.debug("Web access")
        if self.user_info.webaccess_veto:
            self.session_info.has_web = False
            self.logger.debug('  disable')
        else:
            self.session_info.has_web = True
            self.logger.debug('  enable')
        self.logger.debug('')

        # Fill with tmp folder
        import os
        self.logger.debug("Temporary folder")
        tmpdir = ''

        # force by the user?
        if self.user_info.tmp_dir != None:
            self.logger.debug('  Folder forced by the user: '******'-> found')
            else:
                self.logger.debug('-> not found')
                self.logger.debug('Try to create the folder ' + tmpdir +
                                  ' ...')
                try:
                    os.mkdir(tmpdir)
                except:
                    self.logger.debug('-> impossible to create it')
                    tmpdir = ''

        # environment variable
        if tmpdir == '':
            for name in ["TMPDIR", "TMP", "TEMP"]:
                if name in os.environ:
                    tmp = os.environ[name]
                else:
                    tmp = ''
                self.logger.debug(
                    StringTools.Left("  Variable $" + name + ":", 28) +
                    str(tmp))
                if tmp != '' and tmpdir == '':
                    tmp = os.path.normpath(tmp)
                    self.logger.debug('Check if the folder ' + tmp +
                                      ' exists ...')
                    if os.path.isdir(tmp):
                        self.logger.debug('-> found')
                        tmpdir = tmp
                    else:
                        self.logger.debug('-> not found')
                        self.logger.debug('Try to create this folder ...')
                        try:
                            os.mkdir(tmp)
                            self.logger.debug('-> ok')
                            tmpdir = tmp
                        except:
                            self.logger.debug('-> impossible to create it')

        # /tmp/ + username
        if tmpdir == '':
            pathname = os.path.normpath('/tmp/' + self.session_info.username)
            self.logger.debug('Check if the folder ' + pathname +
                              ' exists ...')
            if os.path.isdir(pathname):
                self.logger.debug('-> found')
                tmpdir = pathname
            else:
                self.logger.debug('-> not found')
                self.logger.debug('Try to create the folder ' + pathname +
                                  ' ...')
                try:
                    os.mkdir(pathname)
                    tmpdir = pathname
                except:
                    self.logger.debug('-> impossible to create it')

        if tmpdir != '':
            self.session_info.tmpdir = tmpdir
            self.logger.debug('temporary folder will be used for MA5: ' +
                              tmpdir)
        else:
            self.logger.error('Impossible to create a tmp folder')
            return False
        self.logger.debug('')

        # Download dir
        self.logger.debug("Download dir")
        tmpdir = ''

        # -> forced by the user?
        if self.user_info.download_dir != None:
            self.logger.debug('  Folder forced by the user: '******'-> found')
            else:
                self.logger.debug('-> not found')
                self.logger.debug('Try to create the folder ' + tmpdir +
                                  ' ...')
                try:
                    os.mkdir(tmpdir)
                except:
                    self.logger.debug('-> impossible to create it')
                    tmpdir = ''

        # -> temporary folder + 'MA5_download'
        if tmpdir == '':
            pathname = os.path.normpath(self.session_info.tmpdir +
                                        '/MA5_downloads/')
            self.logger.debug('Check if the folder ' + pathname +
                              ' exists ...')
            if os.path.isdir(pathname):
                self.logger.debug('-> found')
                tmpdir = pathname
            else:
                self.logger.debug('-> not found')
                self.logger.debug('Try to create the folder ' + pathname +
                                  ' ...')
                try:
                    os.mkdir(pathname)
                    tmpdir = pathname
                except:
                    self.logger.debug('-> impossible to create it')

        if tmpdir != '':
            self.session_info.downloaddir = tmpdir
            self.logger.debug('download folder will be used for MA5: ' +
                              tmpdir)
        else:
            self.logger.error('Impossible to create a download folder')
            return False
        self.logger.debug('')

        # Fill with editor program
        self.logger.debug("Text editor")
        self.logger.debug("Look for the global variable $EDITOR ...")
        if 'EDITOR' in os.environ:
            self.session_info.editor = os.environ['EDITOR']
            self.session_info.editor = self.session_info.editor.lstrip()
            self.session_info.editor = self.session_info.editor.rstrip()
            self.logger.debug("-> variable $EDITOR found : " +
                              self.session_info.editor)
        else:
            self.session_info.editor = 'vi'
            self.logger.debug(
                '-> variable not found. VI editor is set by default.')
        if self.session_info.editor == '':
            self.session_info.editor = 'vi'
            self.logger.debug(
                '-> variable empty. VI editor is set by default.')
        self.logger.debug('')

        # Ok
        return True