def SLCT(para, log_format, rex):
    startTime = datetime.now()
    logname = os.path.join(para['dataPath'], para['dataName'])
    logger.info('Parsing file: {}'.format(logname))
    if (not os.path.isfile('../SLCT/slct')):
        try:
            logger.info('Compile SLCT...\n>> gcc -o ../logparser/SLCT/slct -O2 ../logparser/SLCT/cslct.c')
            subprocess.check_output('gcc -o ../logparser/SLCT/slct -O2 ../logparser/SLCT/cslct.c', stderr=subprocess.STDOUT, shell=True)
        except:
            logger.info('Compile error! Please check GCC installed.\n')
            raise
    (headers, regex) = generate_logformat_regex(log_format)
    df_log = log_to_dataframe(logname, regex, headers, log_format)
    with open('slct_input.log', 'w') as fw:
        for line in df_log['Content']:
            if rex:
                for currentRex in rex:
                    line = re.sub(currentRex, '<*>', line)
            fw.write((line + '\n'))
    SLCT_command = extract_command(para, 'slct_input.log')
    try:
        logger.info('Run SLCT...\n>> {}'.format(SLCT_command))
        subprocess.check_call(SLCT_command, shell=True)
    except:
        logger.info('SLCT executable is invalid! Please compile it using GCC.\n')
        raise
    tempParameter = TempPara(path='./', savePath=para['savePath'], logname='slct_input.log')
    tempProcess(tempParameter)
    matcher = regexmatch.PatternMatch(outdir=para['savePath'], logformat=log_format)
    matched_df = matcher.match(logname, 'temp_templates.csv')
    os.remove('slct_input.log')
    os.remove('slct_outliers.log')
    os.remove('slct_templates.txt')
    os.remove('temp_templates.csv')
    for (idx, line) in matched_df.iterrows():
        if (line['EventTemplate'] == 'None'):
            content = line['Content']
            matched_df.loc[(idx, 'EventTemplate')] = content
            matched_df.loc[(idx, 'EventId')] = hashlib.md5(content.encode('utf-8')).hexdigest()[0:8]
    occ_dict = dict(matched_df['EventTemplate'].value_counts())
    df_event = pd.DataFrame()
    df_event['EventTemplate'] = matched_df['EventTemplate'].unique()
    df_event['EventId'] = df_event['EventTemplate'].map((lambda x: hashlib.md5(x.encode('utf-8')).hexdigest()[0:8]))
    df_event['Occurrences'] = df_event['EventTemplate'].map(occ_dict)
    df_event.to_csv(os.path.join(para['savePath'], (para['dataName'] + '_templates.csv')), index=False, columns=['EventId', 'EventTemplate', 'Occurrences'])
    matched_df.to_csv(os.path.join(para['savePath'], (para['dataName'] + '_structured.csv')), index=False)
    logger.info('Parsing done. [Time: {!s}]'.format((datetime.now() - startTime)))
def SLCT(para, log_format, rex):
    startTime = datetime.now()
    logname = os.path.join(para['dataPath'], para['dataName'])
    logger.info('Parsing file: {}'.format(logname))
    if (not os.path.isfile('../SLCT/slct')):
        try:
            logger.info('Compile SLCT...\n>> gcc -o ../logparser/SLCT/slct -O2 ../logparser/SLCT/cslct.c')
            subprocess.check_output('gcc -o ../logparser/SLCT/slct -O2 ../logparser/SLCT/cslct.c', stderr=subprocess.STDOUT, shell=True)
        except:
            logger.info('Compile error! Please check GCC installed.\n')
            raise
    (headers, regex) = generate_logformat_regex(log_format)
    df_log = log_to_dataframe(logname, regex, headers, log_format)
    with open('slct_input.log', 'w') as fw:
        for line in df_log['Content']:
            if rex:
                for currentRex in rex:
                    line = re.sub(currentRex, '<*>', line)
            fw.write((line + '\n'))
    SLCT_command = extract_command(para, 'slct_input.log')
    try:
        logger.info('Run SLCT...\n>> {}'.format(SLCT_command))
        subprocess.check_call(SLCT_command, shell=True)
    except:
        logger.info('SLCT executable is invalid! Please compile it using GCC.\n')
        raise
    tempParameter = TempPara(path='./', savePath=para['savePath'], logname='slct_input.log')
    tempProcess(tempParameter)
    matcher = regexmatch.PatternMatch(outdir=para['savePath'], logformat=log_format)
    matched_df = matcher.match(logname, 'temp_templates.csv')
    os.remove('slct_input.log')
    os.remove('slct_outliers.log')
    os.remove('slct_templates.txt')
    os.remove('temp_templates.csv')
    for (idx, line) in matched_df.iterrows():
        if (line['EventTemplate'] == 'None'):
            content = line['Content']
            matched_df.loc[(idx, 'EventTemplate')] = content
            matched_df.loc[(idx, 'EventId')] = hashlib.md5(content.encode('utf-8')).hexdigest()[0:8]
    occ_dict = dict(matched_df['EventTemplate'].value_counts())
    df_event = pd.DataFrame()
    df_event['EventTemplate'] = matched_df['EventTemplate'].unique()
    df_event['EventId'] = df_event['EventTemplate'].map((lambda x: hashlib.md5(x.encode('utf-8')).hexdigest()[0:8]))
    df_event['Occurrences'] = df_event['EventTemplate'].map(occ_dict)
    df_event.to_csv(os.path.join(para['savePath'], (para['dataName'] + '_templates.csv')), index=False, columns=['EventId', 'EventTemplate', 'Occurrences'])
    matched_df.to_csv(os.path.join(para['savePath'], (para['dataName'] + '_structured.csv')), index=False)
    logger.info('Parsing done. [Time: {!s}]'.format((datetime.now() - startTime)))