changeset 334:100cf66a5825

Added command-line and WS methods to (LI)st key-(S)trings and si(Z)es of (T)racks --LISZT --lisztOffset offset --lisztLength len
author mas01mc
date Tue, 02 Sep 2008 16:16:59 +0000
parents cc3f9d1ca2cd
children 69d5649d3e1c
files audioDB.cpp audioDB.h audioDBws.h dump.cpp gengetopt.in soap.cpp
diffstat 6 files changed, 134 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/audioDB.cpp	Mon Sep 01 15:35:05 2008 +0000
+++ b/audioDB.cpp	Tue Sep 02 16:16:59 2008 +0000
@@ -87,6 +87,12 @@
   else if(O2_ACTION(COM_DUMP))
     dump(dbName);
 
+  else if(O2_ACTION(COM_LISZT))
+    if(isClient)
+      ws_liszt(dbName, (char*) hostport);
+    else
+      liszt(dbName, lisztOffset, lisztLength);
+
   else if(O2_ACTION(COM_INDEX))
     index_index_db(dbName);
   
@@ -130,6 +136,22 @@
   }
 }
 
+audioDB::audioDB(const unsigned argc, char* const argv[], adb__lisztResponse *adbLisztResponse): O2_AUDIODB_INITIALIZERS
+{
+  try {
+    isServer = 1; // FIXME: Hack
+    processArgs(argc, argv);
+    // Perform database prefix substitution
+    if(dbName && adb_root)
+      prefix_name((char** const)&dbName, adb_root);
+    assert(O2_ACTION(COM_LISZT));
+    liszt(dbName, lisztOffset, lisztLength, adbLisztResponse);
+  } catch(char *err) {
+    cleanup();
+    throw(err);
+  }
+}
+
 void audioDB::cleanup() {
   cmdline_parser_free(&args_info);
   if(indata)
@@ -546,6 +568,21 @@
     }
     return 0;
   }
+  
+  if(args_info.LISZT_given){
+    command = COM_LISZT;
+    dbName=args_info.database_arg;
+    lisztOffset = args_info.lisztOffset_arg;
+    lisztLength = args_info.lisztLength_arg;
+    if(args_info.lisztOffset_arg<0) // check upper bound later when database is opened
+      error("lisztOffset cannot be negative");
+    if(args_info.lisztLength_arg<0)
+      error("lisztLength cannot be negative");
+    if(lisztLength >1000000)
+      error("lisztLength too large (>1000000)");
+    return 0;
+  }
+  
   return -1; // no command found
 }
 
--- a/audioDB.h	Mon Sep 01 15:35:05 2008 +0000
+++ b/audioDB.h	Tue Sep 02 16:16:59 2008 +0000
@@ -41,6 +41,7 @@
 #define COM_SERVER "--SERVER"
 #define COM_INDEX "--INDEX"
 #define COM_SAMPLE "--SAMPLE"
+#define COM_LISZT "--LISZT"
 
 // parameters
 #define COM_CLIENT "--client"
@@ -277,14 +278,18 @@
   double absolute_threshold;
   bool use_relative_threshold;
   double relative_threshold;
-
+  
   ReporterBase* reporter;  // track/point reporter
   priority_queue<PointPair, std::vector<PointPair>, std::less<PointPair> >* exact_evaluation_queue;
 
   // Timers
   struct timeval tv1;
   struct timeval tv2;
-    
+
+  // LISZT parameters
+  unsigned lisztOffset;
+  unsigned lisztLength;
+
   // private methods
   void error(const char* a, const char* b = "", const char *sysFunc = 0);
   void sequence_sum(double *buffer, int length, int seqlen);
@@ -316,6 +321,8 @@
   audioDB(const unsigned argc, char* const argv[]);
   audioDB(const unsigned argc, char* const argv[], adb__queryResponse *adbQueryResponse);
   audioDB(const unsigned argc, char* const argv[], adb__statusResponse *adbStatusResponse);
+  audioDB(const unsigned argc, char* const argv[], adb__lisztResponse *adbLisztResponse);
+
   void cleanup();
   ~audioDB();
   int processArgs(const unsigned argc, char* const argv[]);
@@ -336,6 +343,7 @@
   void power_flag(const char *dbName);
   bool powers_acceptable(double p1, double p2);
   void dump(const char* dbName);
+  void liszt(const char* dbName, unsigned offset, unsigned numLines, adb__lisztResponse* adbLisztResponse=0);
 
   // LSH indexing parameters and data structures
   LSH* lsh;
@@ -384,7 +392,8 @@
   void ws_status(const char*dbName, char* hostport);
   void ws_query(const char*dbName, const char *featureFileName, const char* hostport);
   void ws_query_by_key(const char*dbName, const char *trackKey, const char* featureFileName, const char* hostport);
-  
+  void ws_liszt(const char* dbName, char* hostport);
+
 };
 
 #define O2_AUDIODB_INITIALIZERS			\
@@ -456,6 +465,8 @@
     relative_threshold(0.0),			\
     reporter(0),                                \
     exact_evaluation_queue(0),                  \
+    lisztOffset(0),                             \
+    lisztLength(0),                             \
     lsh(0),					\
     lsh_in_core(false),				\
     lsh_use_u_functions(false),                 \
--- a/audioDBws.h	Mon Sep 01 15:35:05 2008 +0000
+++ b/audioDBws.h	Tue Sep 02 16:16:59 2008 +0000
@@ -40,9 +40,23 @@
   struct adb__queryResult result;
 };
 
+struct adb__lisztResult {
+  int __sizeRkey;
+  char **Rkey;
+  int __sizeRlen;
+  unsigned int *Rlen;
+};
+
+struct adb__lisztResponse {
+  struct adb__lisztResult result;
+};
+
 // Print the status of an existing adb database
 int adb__status(xsd__string dbName, struct adb__statusResponse &adbStatusResponse);
 
+// Print the status of an existing adb database
+int adb__liszt(xsd__string dbName, xsd__int lisztOffset, xsd__int lisztLength, struct adb__lisztResponse &adbLisztResponse);
+
 // Query an existing adb database
 int adb__query(xsd__string dbName, xsd__string qKey, xsd__string keyList, xsd__string timesFileName, xsd__string powerFileName, xsd__int qType, xsd__int qPos, xsd__int pointNN, xsd__int segNN, xsd__int segLen, xsd__double radius, xsd__double absolute_threshold, xsd__double relative_threshold, xsd__int exhaustive, xsd__int lsh_exact, struct adb__queryResponse &adbQueryResponse);
 
--- a/dump.cpp	Mon Sep 01 15:35:05 2008 +0000
+++ b/dump.cpp	Tue Sep 02 16:16:59 2008 +0000
@@ -184,3 +184,36 @@
     
   status(dbName);
 }
+
+void audioDB::liszt(const char* dbName, unsigned offset, unsigned numLines, adb__lisztResponse* adbLisztResponse){
+  if(!dbH) {
+    initTables(dbName, 0);
+  }
+
+  assert(trackTable && fileTable);
+
+  if(offset>dbH->numFiles){
+    char tmpStr[MAXSTR];
+    sprintf(tmpStr, "numFiles=%u, lisztOffset=%u", dbH->numFiles, offset);
+    error("listKeys offset out of range", tmpStr);
+  }
+
+  if(!adbLisztResponse){
+    for(Uns32T k=0; k<numLines && offset+k<dbH->numFiles; k++){
+      fprintf(stdout, "[%d] %s (%d)\n", offset+k, fileTable+(offset+k)*O2_FILETABLE_ENTRY_SIZE, trackTable[offset+k]);
+    }
+  }
+  else{
+    adbLisztResponse->result.Rkey = new char*[numLines];
+    adbLisztResponse->result.Rlen = new unsigned int[numLines];
+    Uns32T k = 0;
+    for( ; k<numLines && offset+k<dbH->numFiles; k++){    
+      adbLisztResponse->result.Rkey[k] = new char[MAXSTR];
+      snprintf(adbLisztResponse->result.Rkey[k], O2_MAXFILESTR, "%s", fileTable+(offset+k)*O2_FILETABLE_ENTRY_SIZE);
+      adbLisztResponse->result.Rlen[k] = trackTable[offset+k];
+    }
+    adbLisztResponse->result.__sizeRkey = k;
+    adbLisztResponse->result.__sizeRlen = k;
+  }
+  
+}
--- a/gengetopt.in	Mon Sep 01 15:35:05 2008 +0000
+++ b/gengetopt.in	Tue Sep 02 16:16:59 2008 +0000
@@ -24,6 +24,9 @@
 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
+option "LISZT"  Z "LIst keyS and siZes of Tracks" dependon="database" optional
+option "lisztOffset" - "LISZT track offset (0-based index)" int typestr="number" default="0" dependon="LISZT" optional
+option "lisztLength" - "number of LISZT items to return" int typestr="number" default="32" dependon="LISZT" optional
 
 section "Database Information" sectiondesc="Information about databases."
 
--- a/soap.cpp	Mon Sep 01 15:35:05 2008 +0000
+++ b/soap.cpp	Tue Sep 02 16:16:59 2008 +0000
@@ -28,6 +28,21 @@
   soap_done(&soap);
 }
 
+void audioDB::ws_liszt(const char* dbName, char* Hostport){
+  struct soap soap;
+  adb__lisztResponse adbLisztResponse;
+
+  soap_init(&soap);
+  if(soap_call_adb__liszt(&soap, hostport, NULL, (char*)dbName, lisztOffset, lisztLength, adbLisztResponse)==SOAP_OK){
+    for(int i = 0; i < adbLisztResponse.result.__sizeRkey; i++) {
+      std::cout << "[" << i+lisztOffset << "] " << adbLisztResponse.result.Rkey[i] << " (" 
+		<< adbLisztResponse.result.Rlen[i] << ")" << std::endl;
+    }
+  } else {
+    soap_print_fault(&soap, stderr);
+  }
+}
+
 // WS_QUERY (CLIENT SIDE)
 void audioDB::ws_query(const char*dbName, const char *featureFileName, const char* hostport){
   struct soap soap;
@@ -138,7 +153,24 @@
     return SOAP_FAULT;
   }
 }
- 
+
+int adb__liszt(struct soap* soap, xsd__string dbName, xsd__int lisztOffset, xsd__int lisztLength, 
+	       adb__lisztResponse& adbLisztResponse){
+
+  INTSTRINGIFY(lisztOffset, lisztOffsetStr);
+  INTSTRINGIFY(lisztLength, lisztLengthStr);
+
+  char* const argv[] = {"./audioDB", COM_LISZT, "-d",dbName, "--lisztOffset", lisztOffsetStr, "--lisztLength", lisztLengthStr};
+  const unsigned argc = 8;
+  try{
+    audioDB(argc, argv, &adbLisztResponse);
+    return SOAP_OK;
+  } catch(char *err) {
+    soap_receiver_fault(soap, err, "");
+    return SOAP_FAULT;
+  }
+} 
+
 // Literal translation of command line to web service
 int adb__query(struct soap* soap, xsd__string dbName, 
 	       xsd__string qKey, xsd__string keyList,