Changeset: e0856fa91049 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e0856fa91049
Removed Files:
        sql/backends/monet5/bamloader/bam_globals.c
Modified Files:
        sql/backends/monet5/bamloader/Makefile.ag
        sql/backends/monet5/bamloader/Tests/test.SQL.py
        sql/backends/monet5/bamloader/bam_db_interface.c
        sql/backends/monet5/bamloader/bam_globals.h
        sql/backends/monet5/bamloader/bam_loader.c
        sql/backends/monet5/bamloader/bam_wrapper.c
Branch: bamloader
Log Message:

Removed hashes from beginning of log message strings since they are now 
automatically added. Moved global functionality into .h file and removed .c 
file. Tiny change in test.SQL.py.


diffs (truncated from 372 to 300 lines):

diff --git a/sql/backends/monet5/bamloader/Makefile.ag 
b/sql/backends/monet5/bamloader/Makefile.ag
--- a/sql/backends/monet5/bamloader/Makefile.ag
+++ b/sql/backends/monet5/bamloader/Makefile.ag
@@ -36,7 +36,7 @@ INCLUDES = .. \
 lib__bam = {
        MODULE
        DIR = libdir/monetdb5
-       SOURCES = bam_loader.c bam_loader.h bam_wrapper.c bam_wrapper.h 
bam_db_interface.c bam_db_interface.h bam_globals.c bam_globals.h bam_lib.h 
bam_lib.c
+       SOURCES = bam_loader.c bam_loader.h bam_wrapper.c bam_wrapper.h 
bam_db_interface.c bam_db_interface.h bam_globals.h bam_lib.c bam_lib.h
        LIBS = ../../../../monetdb5/tools/libmonetdb5 \
                   ../../../../gdk/libbat \
        $(SAMTOOLS_LIBS)
diff --git a/sql/backends/monet5/bamloader/Tests/test.SQL.py 
b/sql/backends/monet5/bamloader/Tests/test.SQL.py
--- a/sql/backends/monet5/bamloader/Tests/test.SQL.py
+++ b/sql/backends/monet5/bamloader/Tests/test.SQL.py
@@ -31,14 +31,14 @@ sys.stderr.write(err)
 
 # now retrieve the file ids that have been inserted
 c = new_client()
-c.stdin.write("SELECT file_id, dbschema FROM bam.files WHERE file_location 
LIKE '%bam_test_file%';")
+c.stdin.write("SELECT file_id, dbschema FROM bam.files;")
 out, err = c.communicate()
 p = re.compile('^\s*\[\s*(\d)\s*,\s*(\d)\s*\]\s*$', re.MULTILINE)
 files_to_test = []
 for match in p.finditer(out):
     files_to_test.append((int(match.group(1)), int(match.group(2))))
 
-#now we will execute all benchmark queries on all BAM files in the bam.files 
table that contain 'bam_test_file' in their path
+#now we will execute all benchmark queries on all BAM files in the bam.files 
table
 c = new_client()
 set_var(c, 'rname_1_3', 'chr22', numeric=False)
 set_var(c, 'pos_1_3_1', 1000000)
diff --git a/sql/backends/monet5/bamloader/bam_db_interface.c 
b/sql/backends/monet5/bamloader/bam_db_interface.c
--- a/sql/backends/monet5/bamloader/bam_db_interface.c
+++ b/sql/backends/monet5/bamloader/bam_db_interface.c
@@ -227,7 +227,7 @@ create_schema_if_not_exists(Client cntxt
                snprintf(sql_create_schema, 64, "CREATE SCHEMA %s;",
                         schemaname);
 
-               TO_LOG("#<bam_loader> Creating schema '%s'...\n", schemaname);
+               TO_LOG("<bam_loader> Creating schema '%s'...\n", schemaname);
                RUN_SQL(cntxt, &sql_create_schema, descr, msg);
                if (msg != MAL_SUCCEED) {
                        REUSE_EXCEPTION(msg, MAL,
@@ -263,7 +263,7 @@ create_table_if_not_exists(Client cntxt,
        str msg;
 
        if ((result = mvc_bind_table(m, s, tablename)) == NULL) {
-               TO_LOG("#<bam_loader> Creating table '%s'...\n", tablename);
+               TO_LOG("<bam_loader> Creating table '%s'...\n", tablename);
 
                RUN_SQL(cntxt, &sql_creation, descr, msg);
                if (msg != MAL_SUCCEED) {
diff --git a/sql/backends/monet5/bamloader/bam_globals.c 
b/sql/backends/monet5/bamloader/bam_globals.c
deleted file mode 100644
--- a/sql/backends/monet5/bamloader/bam_globals.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * The contents of this file are subject to the MonetDB Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.monetdb.org/Legal/MonetDBLicense
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is the MonetDB Database System.
- *
- * The Initial Developer of the Original Code is CWI.
- * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
- * Copyright August 2008-2014 MonetDB B.V.
- * All Rights Reserved.
- */
-
-/*
- * (author) R Cijvat
- * This file contains some global definitions, used by multiple bam library 
files
- */
-
-#include "monetdb_config.h"
-
-#include "bam_globals.h"
-
-
-#ifdef BAM_DEBUG
-/**
- * Function prepares a string for the log by adding hashes in front of every 
line
- * Returned string has to be freed
- */
-char *
-prepare_for_log(const char *str, bit first_line_dash) {
-    int l = strlen(str);
-    char *prepared = (char *)GDKmalloc(3 * l * sizeof(char)); /* Worst case: 
every character is newline */
-    int i, j = 0;
-    
-    if(prepared == NULL) return NULL;
-    
-    if(first_line_dash) {
-        prepared[j++] = '#';
-        prepared[j++] = ' ';
-    }
-    for(i=0; i<l; ++i) {
-        prepared[j++] = str[i];
-        if(str[i] == '\n') {
-            prepared[j++] = '#';
-            prepared[j++] = ' ';
-        }
-    }
-    prepared[j] = '\0';
-    return prepared;
-}
-
-/** 
- * Function that adds a dash before every printed line, so Mtest.py will not 
notice a difference in whether or not we are
- * debugging. Arguments to this function should already follow this 
convention. So calling functions should use
- * prepare_for_log to prepare all arguments.
- */
-int 
-dash_fprintf(FILE *f, const char *format, ...) {
-    va_list arg;
-    int done;
-    
-    char *format_prepared = prepare_for_log(format, TRUE);
-    
-    if(format_prepared == NULL) return -1;
-    
-    va_start(arg, format);
-    done = vfprintf(f, format_prepared, arg);
-    va_end(arg);
-
-    GDKfree(format_prepared);
-    return done;
-}
-
-
-#endif
diff --git a/sql/backends/monet5/bamloader/bam_globals.h 
b/sql/backends/monet5/bamloader/bam_globals.h
--- a/sql/backends/monet5/bamloader/bam_globals.h
+++ b/sql/backends/monet5/bamloader/bam_globals.h
@@ -45,17 +45,53 @@
  * Function prepares a string for the log by adding hashes in front of every 
line
  * Returned string has to be freed
  */
-char *prepare_for_log(const char *str, bit first_line_dash);
+static inline char *
+prepare_for_log(const char *str, bit first_line_hash) {
+    int l = strlen(str);
+    char *prepared = (char *)GDKmalloc(3 * l * sizeof(char)); /* Worst case: 
every character is newline */
+    int i, j = 0;
+    
+    if(prepared == NULL) return NULL;
+    
+    if(first_line_hash) {
+        prepared[j++] = '#';
+        prepared[j++] = ' ';
+    }
+    for(i=0; i<l; ++i) {
+        prepared[j++] = str[i];
+        if(str[i] == '\n') {
+            prepared[j++] = '#';
+            prepared[j++] = ' ';
+        }
+    }
+    prepared[j] = '\0';
+    return prepared;
+}
 
-/* Function that adds a dash before every printed line, so Mtest.py will not 
notice a difference in whether or not we are debugging. Arguments to this 
function should  */
-int dash_fprintf(FILE *f, const char *format, ...) __attribute__ ((format 
(printf, 2, 3) ));
+/* Function that adds a hash before every printed line, so Mtest.py will not 
notice a difference in whether or not we are debugging. Arguments to this 
function should  */
+static inline int 
+hash_fprintf(FILE *f, const char *format, ...) __attribute__ ((format (printf, 
2, 3) ));
+
+static inline int
+hash_fprintf(FILE *f, const char *format, ...) {
+    va_list arg;
+    int done;
+    
+    char *format_prepared = prepare_for_log(format, TRUE);
+    
+    if(format_prepared == NULL) return -1;
+    
+    va_start(arg, format);
+    done = vfprintf(f, format_prepared, arg);
+    va_end(arg);
+
+    GDKfree(format_prepared);
+    return done;
+}
 
 
 /* Macro that enables writing to a log. If the debug flag is not set, it does 
not do anything */
-#define TO_LOG(...) { \
-    dash_fprintf(stderr, __VA_ARGS__); \
-    fprintf(stderr, "\n"); \
-}
+#define TO_LOG(...) hash_fprintf(stderr, __VA_ARGS__)
 
 /* We are in 'debug-mode' if --enable-assert was set during
  * configuration, since in that case NDEBUG will not be set. */
diff --git a/sql/backends/monet5/bamloader/bam_loader.c 
b/sql/backends/monet5/bamloader/bam_loader.c
--- a/sql/backends/monet5/bamloader/bam_loader.c
+++ b/sql/backends/monet5/bamloader/bam_loader.c
@@ -107,27 +107,27 @@ run_process_bam_alignments(void *d)
        reader_thread_data *data = (reader_thread_data *) d;
        bam_wrapper *bw;
 
-       TO_LOG("#<Thread %d> Starting on next file...\n", data->thread_id);
+       TO_LOG("<Thread %d> Starting on next file...\n", data->thread_id);
        /* First, find out on which bam wrapper we have to work */
        MT_lock_set(data->reader_lock, data->reader_lock_ref);
        if (*data->cur_file == data->nr_files - 1) {
                /* The last file is already (being) processed, this
                 * thread is done */
                MT_lock_unset(data->reader_lock, data->reader_lock_ref);
-               TO_LOG("#<Thread %d> No files left to work on; thread done\n",
+               TO_LOG("<Thread %d> No files left to work on; thread done\n",
                       data->thread_id);
                return;
        }
        (*data->cur_file) += 1;
        bw = &data->bws[*data->cur_file];
        MT_lock_unset(data->reader_lock, data->reader_lock_ref);
-       TO_LOG("#<Thread %d> Processing alignments of file '%s' (file id "
+       TO_LOG("<Thread %d> Processing alignments of file '%s' (file id "
               LLFMT ")...\n", data->thread_id, bw->file_location,
               bw->file_id);
 
        if ((data->msg =
             process_bam_alignments(bw, data->failure)) != MAL_SUCCEED) {
-               TO_LOG("#<Thread %d> Error while processing alignments of file 
'%s' (file id " LLFMT ") (%s)\n", data->thread_id, bw->file_location, 
bw->file_id, data->msg);
+               TO_LOG("<Thread %d> Error while processing alignments of file 
'%s' (file id " LLFMT ") (%s)\n", data->thread_id, bw->file_location, 
bw->file_id, data->msg);
                REUSE_EXCEPTION(data->msg, MAL, "run_process_bam_alignments",
                                "Error while processing alignments of file '%s' 
(file id "
                                LLFMT "): %s", bw->file_location, bw->file_id,
@@ -137,12 +137,12 @@ run_process_bam_alignments(void *d)
        if (*data->failure) {
                /* process_bam_alignments returned because another
                 * thread failed and not because this thread failed */
-               TO_LOG("#<Thread %d> Exit due to failure in other thread\n",
+               TO_LOG("<Thread %d> Exit due to failure in other thread\n",
                       data->thread_id);
                return;
        }
 
-       TO_LOG("#<Thread %d> All alignments in file '%s' (file id " LLFMT
+       TO_LOG("<Thread %d> All alignments in file '%s' (file id " LLFMT
               ") processed!\n", data->thread_id, bw->file_location,
               bw->file_id);
        run_process_bam_alignments(d);
@@ -176,7 +176,7 @@ bam_loader(Client cntxt, MalBlkPtr mb, s
        int i, errnr;
        str msg = MAL_SUCCEED;
 
-       TO_LOG("#<bam_loader>: Loader started for %d BAM file%s...\n",
+       TO_LOG("<bam_loader>: Loader started for %d BAM file%s...\n",
               nr_files, (nr_files != 1 ? "s" : ""));
 
        /* Check sanity of input */
@@ -233,7 +233,7 @@ bam_loader(Client cntxt, MalBlkPtr mb, s
                goto cleanup;
 
        /* Get next file id */
-       TO_LOG("#<bam_loader> Retrieving next file id...\n");
+       TO_LOG("<bam_loader> Retrieving next file id...\n");
        if ((msg = next_file_id(m, files_table, &cur_file_id)) != MAL_SUCCEED) {
                goto cleanup;
        }
@@ -250,7 +250,7 @@ bam_loader(Client cntxt, MalBlkPtr mb, s
        memset(bws, 0, nr_files * sizeof(bam_wrapper));
 
        for (i = 0; i < nr_files; ++i) {
-               TO_LOG("#<bam_loader> Initializing BAM wrapper for file 
'%s'...\n", filenames[i]);
+               TO_LOG("<bam_loader> Initializing BAM wrapper for file 
'%s'...\n", filenames[i]);
                if ((msg =
                     init_bam_wrapper(bws + i, filenames[i], cur_file_id++,
                                      dbschema)) != MAL_SUCCEED) {
@@ -260,7 +260,7 @@ bam_loader(Client cntxt, MalBlkPtr mb, s
 
        /* Parse all headers */
        for (i = 0; i < nr_files; ++i) {
-               TO_LOG("#<bam_loader> Parsing BAM header for file '%s'...\n",
+               TO_LOG("<bam_loader> Parsing BAM header for file '%s'...\n",
                       filenames[i]);
                if ((msg = process_bam_header(bws + i)) != MAL_SUCCEED) {
                        goto cleanup;
@@ -272,7 +272,7 @@ bam_loader(Client cntxt, MalBlkPtr mb, s
         * QNAME */
        if (dbschema == 1) {
                for (i = 0; i < nr_files; ++i) {
-                       TO_LOG("#<bam_loader> Checking sortedness for BAM file 
'%s'...\n", filenames[i]);
+                       TO_LOG("<bam_loader> Checking sortedness for BAM file 
'%s'...\n", filenames[i]);
                        if (bws[i].ord != ORDERING_QUERYNAME) {
                                msg = createException(MAL, "bam_loader",
                                                      "Only BAM files that are 
sorted on queryname can be inserted into the pairwise storage schema; "
@@ -287,7 +287,7 @@ bam_loader(Client cntxt, MalBlkPtr mb, s
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to