changeset 146:c9c508be69b3 powertable

Define a power command-line option; use it to turn on the DB flag. Also enforce strict ordering: only accept power files if the DB has the flag set; error if they're provided and the DB doesn't have the flag.
author mas01cr
date Wed, 31 Oct 2007 10:20:09 +0000
parents 7162a8e9ab12
children a564e6d7a30c
files audioDB.cpp audioDB.h gengetopt.in
diffstat 3 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/audioDB.cpp	Tue Oct 30 15:28:48 2007 +0000
+++ b/audioDB.cpp	Wed Oct 31 10:20:09 2007 +0000
@@ -72,6 +72,9 @@
   else if(O2_ACTION(COM_L2NORM))
     l2norm(dbName);
   
+  else if(O2_ACTION(COM_POWER))
+    power_flag(dbName);
+
   else if(O2_ACTION(COM_DUMP))
     dump(dbName);
   
@@ -220,6 +223,12 @@
     return 0;
   }
        
+  if(args_info.POWER_given){
+    command=COM_POWER;
+    dbName=args_info.database_arg;
+    return 0;
+  }
+       
   if(args_info.INSERT_given){
     command=COM_INSERT;
     dbName=args_info.database_arg;
@@ -529,6 +538,9 @@
   if(!usingTimes && (dbH->flags & O2_FLAG_TIMES))
     error("Must use timestamps with timestamped database","use --times");
 
+  if(!usingPower && (dbH->flags & O2_FLAG_POWER))
+    error("Must use power with power-enabled database", dbName);
+
   // Check that there is room for at least 1 more file
   if((char*)timesTable<((char*)dataBuf+dbH->length+statbuf.st_size-sizeof(int)))
     error("No more room in database","insert failed: reason database is full.");
@@ -663,6 +675,10 @@
 
 void audioDB::insertPowerData(unsigned numVectors, int powerfd, double *powerdata) {
   if (usingPower) {
+    if (!(dbH->flags & O2_FLAG_POWER)) {
+      error("Cannot insert power data on non-power DB", dbName);
+    }
+
     int one;
     unsigned int count;
 
@@ -703,6 +719,9 @@
   if(!usingTimes && (dbH->flags & O2_FLAG_TIMES))
     error("Must use timestamps with timestamped database","use --times");
 
+  if(!usingPower && (dbH->flags & O2_FLAG_POWER))
+    error("Must use power with power-enabled database", dbName);
+
   unsigned totalVectors=0;
   char *thisKey = new char[MAXSTR];
   char *thisFile = new char[MAXSTR];
@@ -1060,7 +1079,15 @@
   dbH->flags = dbH->flags|O2_FLAG_L2NORM;
   memcpy (db, dbH, O2_HEADERSIZE);
 }
-  
+
+void audioDB::power_flag(const char *dbName) {
+  initTables(dbName, true, 0);
+  if (dbH->length > 0) {
+    error("cannot turn on power storage for non-empty database", dbName);
+  }
+  dbH->flags |= O2_FLAG_POWER;
+  memcpy(db, dbH, O2_HEADERSIZE);
+}
 
   
 void audioDB::query(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){  
--- a/audioDB.h	Tue Oct 30 15:28:48 2007 +0000
+++ b/audioDB.h	Wed Oct 31 10:20:09 2007 +0000
@@ -27,6 +27,7 @@
 #define COM_QUERY "--QUERY"
 #define COM_STATUS "--STATUS"
 #define COM_L2NORM "--L2NORM"
+#define COM_POWER "--POWER"
 #define COM_DUMP "--DUMP"
 #define COM_SERVER "--SERVER"
 
@@ -201,6 +202,7 @@
   void ws_status(const char*dbName, char* hostport);
   void ws_query(const char*dbName, const char *trackKey, const char* hostport);
   void l2norm(const char* dbName);
+  void power_flag(const char *dbName);
   void dump(const char* dbName);
 
   // web services
--- a/gengetopt.in	Tue Oct 30 15:28:48 2007 +0000
+++ b/gengetopt.in	Wed Oct 31 10:20:09 2007 +0000
@@ -14,6 +14,7 @@
 option "DUMP"   D "output all entries: index key size." dependon="database" optional
 option "output" - "output directory" string dependon="DUMP" default="audioDB.dump" optional
 option "L2NORM" L "unit norm vectors and norm all future inserts." dependon="database" optional
+option "POWER"  P "turn on power flag for database." dependon="database" optional
 
 section "Database Insertion" sectiondesc="The following commands insert feature files, with optional keys and timestamps.\n"
 option "INSERT"      I "add feature vectors to an existing database." dependon="features" optional