Exemple #1
0
def printargs(cfg_parser,key):

    textcolors = config.textcolors()
    BLUE  = textcolors['BLUE']
    GREEN = textcolors['GREEN']
    END   = textcolors['END']

    print
    print GREEN+"    Configuration: "+END+key
    print
    max_len  = max(len(i) for i in cfg_parser.options(key))+1

    logging.info("\n    Configuration: "+key)
    logging.info("")
    for option in cfg_parser.options(key):
        item         = cfg_parser.get(key,option)
        neededlength = max_len-len(option)
        neededlength = ' '*neededlength
        print '        * {0}{1}: {2}'.format(option,neededlength,item)
        logging.info('        * {0}{1}: {2}'.format(option,neededlength,item))
    print
    print
    logging.info("\n\n")

    return
Exemple #2
0
def execute(cfg_parser):
    """
    Based on user input, start running the program!
    (Log information in the appropriate log file.)
    """
    textcolors = config.textcolors() # Colors for text printed to the terminal
    BLUE       = textcolors['BLUE']
    END        = textcolors['END']

    NAME       = {'miniSL':'MiniSL',\
                  'datamc':'Data/MC',\
                  'systematics':'Systematics'}

    # --- Processing input from the config file --- #
    setup   = getConfig(cfg_parser)
    nEvents = int(cfg_parser.get(setup,'nEvents'))
    # --------------------------------------------- #

    ## Logging levels
    LEVELS  = {'debug'   :logging.DEBUG,
               'info'    :logging.INFO,
               'warning' :logging.WARNING,
               'error'   :logging.ERROR,
               'critical':logging.CRITICAL}

    # Set the logging level based on number of events
    if nEvents == -1:  
        LEVEL=LEVELS['critical'] # Minimize the amount of logging
    else:
        LEVEL=LEVELS['debug']    # Maximize the amount of logging

    ## Setup the log file for the analysis
    if os.path.exists('share/{0}.log'.format(setup)):
        os.system('rm share/{0}.log'.format(setup))
    logging.basicConfig(filename='share/{0}.log'.format(setup),
                        level=LEVEL,
                        fmt='%(asctime)s %(levelname)-8s %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S')
    logging.info(" -- In file runMiniAna.py")

    print
    print BLUE+" :: "+NAME[setup]+" :: "+END
    print
    printargs(cfg_parser,setup)

    ## -- MiniSL -- ##
    if setup=='miniSL':

        # - Allow for inheritance
        minisl = cfg_parser.get("miniSL","minisl")
        minisl = minisl.split('/')
        minisl_directory = minisl[0]
        minisl_filename  = minisl[1].split('.')[0]
        minisl_classname = minisl_filename[0].upper()+minisl_filename[1:]

        full_mini_ntuple_file = minisl_directory+"."+minisl_filename
        mini_ntuple_file  = importlib.import_module(full_mini_ntuple_file)
        mini_ntuple_class = getattr(mini_ntuple_file,minisl_classname)

        MakeMiniNtuple = mini_ntuple_class()  # instance of class
        MakeMiniNtuple.execute(cfg_parser)

    ## -- DataMC -- ##
    elif setup=='datamc':

        from dataMC import DataMC
        MakeHistos = DataMC()
        MakeHistos.main(cfg_parser)

    ## -- Systematics -- ##
    elif setup=='systematics':

        from systematics import Systematics
        MakeSysts = Systematics()
        MakeSysts.main(cfg_parser)

    ## -- No Option -- ##
    else:
        print
        print " Should not be at this point..."
        print " Please check the configuration file and runMiniAna.py"
        print
        sys.exit(1)

    return