changeset 314:b671a46873c2

working SIIGRAPH08 version. Fixed powerTable mmap memory leak in WS calls (only showed up in big databases). Implements radius queries over WS with new wsdl file
author mas01mc
date Tue, 12 Aug 2008 01:21:44 +0000
parents f9dde18f556a
children d2c56d4f841e
files Makefile audioDB.cpp audioDB.h audioDBws.h query.cpp soap.cpp
diffstat 6 files changed, 67 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sat Aug 09 15:46:42 2008 +0000
+++ b/Makefile	Tue Aug 12 01:21:44 2008 +0000
@@ -14,7 +14,7 @@
 
 ifeq ($(shell uname),Darwin)
 ifeq ($(shell sysctl -n hw.optional.x86_64),1)
-override CFLAGS+=-arch x86_64
+#override CFLAGS+=-arch x86_64
 endif
 endif
 
--- a/audioDB.cpp	Sat Aug 09 15:46:42 2008 +0000
+++ b/audioDB.cpp	Tue Aug 12 01:21:44 2008 +0000
@@ -121,6 +121,8 @@
     munmap(dataBuf, dataBufLength);
   if(timesTable)
     munmap(timesTable, timesTableLength);
+  if(powerTable)
+    munmap(powerTable, powerTableLength);
   if(l2normTable)
     munmap(l2normTable, l2normTableLength);
   if(trackOffsetTable)
--- a/audioDB.h	Sat Aug 09 15:46:42 2008 +0000
+++ b/audioDB.h	Tue Aug 12 01:21:44 2008 +0000
@@ -62,6 +62,13 @@
 #define COM_EXHAUSTIVE "--exhaustive"
 #define COM_LSH_EXACT "--lsh_exact"
 
+// Because LSH returns NN with P(1)<1 we want to return exact
+// points above this boundary. 
+// Because we work in Radius^2 units,
+// The sqrt of this number is the multiplier on the radius
+
+#define O2_LSH_EXACT_MULT 9
+
 #define O2_OLD_MAGIC ('O'|'2'<<8|'D'<<16|'B'<<24)
 #define O2_MAGIC ('o'|'2'<<8|'d'<<16|'b'<<24)
 #define O2_FORMAT_VERSION (4U)
@@ -378,6 +385,7 @@
     dataBuf(0),					\
     l2normTable(0),				\
     timesTable(0),				\
+    powerTable(0),                              \
     fileTableLength(0),				\
     trackTableLength(0),			\
     dataBufLength(0),				\
--- a/audioDBws.h	Sat Aug 09 15:46:42 2008 +0000
+++ b/audioDBws.h	Tue Aug 12 01:21:44 2008 +0000
@@ -46,21 +46,4 @@
 // Query an existing adb database
 int adb__query(xsd__string dbName, xsd__string qKey, xsd__string keyList, xsd__string timesFileName, xsd__int qType, xsd__int qPos, xsd__int pointNN, xsd__int segNN, xsd__int segLen, struct adb__queryResponse &adbQueryResponse);
 
-struct adb__sequenceQueryParms {
-  xsd__string keyList;
-  xsd__string timesFileName;
-  xsd__int queryPoint;
-  xsd__int pointNN;
-  xsd__int trackNN;
-  xsd__int sequenceLength;
-  xsd__double radius;
-  xsd__double relative_threshold;
-  xsd__double absolute_threshold;
-  xsd__int usingQueryPoint;
-  xsd__int lsh_exact;
-};
-
-// Perform a sequence query
-int adb__sequenceQuery_by_key(xsd__string dbName, xsd__string qKey, xsd__int qType,
-		       struct adb__sequenceQueryParms *parms, 
-		       struct adb__queryResponse &adbQueryResponse);
+int adb__sequenceQueryByKey(xsd__string dbName,xsd__string trackKey,xsd__int queryType,xsd__string trackFileName,xsd__string timesFileName,xsd__int queryPoint,xsd__int pointNN,xsd__int trackNN,xsd__int sequenceLength,xsd__double radius,xsd__double absolute_threshold,xsd__int usingQueryPoint,xsd__int lsh_exact,struct adb__queryResponse &adbQueryResponse);
--- a/query.cpp	Sat Aug 09 15:46:42 2008 +0000
+++ b/query.cpp	Tue Aug 12 01:21:44 2008 +0000
@@ -525,7 +525,7 @@
 	  dist = qnPtr[usingQueryPoint?0:pp.qpos]*qnPtr[usingQueryPoint?0:pp.qpos]+sNorm[trackIndexOffset+pp.spos]*sNorm[trackIndexOffset+pp.spos] - 2*dist;
       // else
       // dist = dist;      
-      if((!radius) || dist <= (radius+O2_DISTANCE_TOLERANCE)) 
+      if((!radius) || dist <= (O2_LSH_EXACT_MULT*radius+O2_DISTANCE_TOLERANCE)) 
 	reporter->add_point(pp.trackID, pp.qpos, pp.spos, dist);
     }
     exact_evaluation_queue->pop();
--- a/soap.cpp	Sat Aug 09 15:46:42 2008 +0000
+++ b/soap.cpp	Tue Aug 12 01:21:44 2008 +0000
@@ -54,23 +54,38 @@
 void audioDB::ws_query_by_key(const char*dbName, const char *trackKey, const char* hostport){
   struct soap soap;
   adb__queryResponse adbQueryResponse;  
-  adb__sequenceQueryParms asqp;
-  
-  asqp.keyList = (char*)trackFileName;
-  asqp.timesFileName = (char*)timesFileName;
-  asqp.queryPoint = queryPoint;
-  asqp.pointNN = pointNN;
-  asqp.trackNN = trackNN;
-  asqp.sequenceLength = sequenceLength;
-  asqp.radius = radius;
-  asqp.relative_threshold = relative_threshold;
-  asqp.absolute_threshold = absolute_threshold;
-  asqp.usingQueryPoint = usingQueryPoint;
-  asqp.lsh_exact = lsh_exact;
+  /*  JUST TRY TO USE A DATA STRUCTURE WITH PHP
+      adb__sequenceQueryParms asqp;
+      asqp.keyList = (char*)trackFileName;
+      asqp.timesFileName = (char*)timesFileName;
+      asqp.queryPoint = queryPoint;
+      asqp.pointNN = pointNN;
+      asqp.trackNN = trackNN;
+      asqp.sequenceLength = sequenceLength;
+      asqp.radius = radius;
+      asqp.relative_threshold = relative_threshold;
+      asqp.absolute_threshold = absolute_threshold;
+      asqp.usingQueryPoint = usingQueryPoint;
+      asqp.lsh_exact = lsh_exact;
+  */
 
   soap_init(&soap);  
   if(queryType==O2_SEQUENCE_QUERY || queryType==O2_N_SEQUENCE_QUERY){
-    if(soap_call_adb__sequenceQuery_by_key(&soap,hostport,NULL,(char*)dbName,(char*)trackKey,queryType,&asqp,adbQueryResponse)==SOAP_OK){
+    if(soap_call_adb__sequenceQueryByKey(&soap,hostport,NULL,
+					   (char*)dbName,
+					   (char*)trackKey,
+					   queryType,
+					   (char*)trackFileName,
+					   (char*)timesFileName,
+					   queryPoint,
+					   pointNN,
+					   trackNN,
+					   sequenceLength,
+					   radius,
+					   absolute_threshold,
+					   usingQueryPoint,
+					   lsh_exact,
+					 adbQueryResponse)==SOAP_OK){
       //std::std::cerr << "result list length:" << adbQueryResponse.result.__sizeRlist << std::std::endl;
       for(int i=0; i<adbQueryResponse.result.__sizeRlist; i++)
 	std::cout << adbQueryResponse.result.Rlist[i] << " " << adbQueryResponse.result.Dist[i] 
@@ -162,17 +177,25 @@
   }
 }
 
-// A sequence query using radius and a query key
-int adb__sequenceQuery_by_key(struct soap* soap, xsd__string dbName, xsd__string qKey, int qType,
-		       adb__sequenceQueryParms* parms,
-		       adb__queryResponse& adbQueryResponse) {
-
+int adb__sequenceQueryByKey(struct soap* soap,xsd__string dbName,
+			    xsd__string trackKey,
+			    xsd__int queryType,
+			    xsd__string trackFileName,
+			    xsd__string timesFileName,
+			    xsd__int queryPoint,
+			    xsd__int pointNN,
+			    xsd__int trackNN,
+			    xsd__int sequenceLength,
+			    xsd__double radius,
+			    xsd__double absolute_threshold,
+			    xsd__int usingQueryPoint,
+			    xsd__int lsh_exact,
+			    struct adb__queryResponse& adbQueryResponse){
   char radiusStr[256];
   char qPosStr[256];
   char pointNNStr[256];
   char trackNNStr[256];
   char seqLenStr[256];
-  char relative_thresholdStr[256];
   char absolute_thresholdStr[256];
   char qtypeStr[256];
 
@@ -183,19 +206,16 @@
 #define DOUBLESTRINGIFY(val, str) \
   snprintf(str, 256, "%f", val);
 
-  INTSTRINGIFY(parms->queryPoint, qPosStr);
-  INTSTRINGIFY(parms->pointNN, pointNNStr);
-  INTSTRINGIFY(parms->trackNN, trackNNStr);
-  INTSTRINGIFY(parms->sequenceLength, seqLenStr);
-
-  DOUBLESTRINGIFY(parms->relative_threshold, relative_thresholdStr);
-  DOUBLESTRINGIFY(parms->absolute_threshold, absolute_thresholdStr);
-  DOUBLESTRINGIFY(parms->radius, radiusStr);  
+  INTSTRINGIFY(queryPoint, qPosStr);
+  INTSTRINGIFY(pointNN, pointNNStr);
+  INTSTRINGIFY(trackNN, trackNNStr);
+  INTSTRINGIFY(sequenceLength, seqLenStr);
+  DOUBLESTRINGIFY(absolute_threshold, absolute_thresholdStr);
+  DOUBLESTRINGIFY(radius, radiusStr);
 
   // WS queries only support 1-nearest neighbour point reporting
   // at the moment, until we figure out how to better serve results
   snprintf(qtypeStr, 256, "nsequence");
-
   const char *argv[]={
     "./audioDB",
     COM_QUERY,
@@ -203,11 +223,11 @@
     COM_DATABASE,
     dbName, 
     COM_QUERYKEY,
-    ENSURE_STRING(qKey),
+    ENSURE_STRING(trackKey),
     COM_KEYLIST,
-    ENSURE_STRING(parms->keyList),
-    parms->usingQueryPoint?COM_QPOINT:COM_EXHAUSTIVE, 
-    parms->usingQueryPoint?qPosStr:"",
+    ENSURE_STRING(trackFileName),
+    usingQueryPoint?COM_QPOINT:COM_EXHAUSTIVE,
+    usingQueryPoint?qPosStr:"",
     COM_POINTNN,
     pointNNStr,
     COM_TRACKNN,
@@ -218,7 +238,7 @@
     seqLenStr,
     COM_ABSOLUTE_THRESH,
     absolute_thresholdStr,
-    parms->lsh_exact?COM_LSH_EXACT:""
+    lsh_exact?COM_LSH_EXACT:""
   };
 
   const unsigned argc = 22;