diff audioDB.cpp @ 136:5bac833c41b5 audiodb-debian

Merge trunk changes -r146:155 to audio-debian branch. Also minor adjustments to debian/ files for new .txt files, and new debian/changelog version. (-13, for those keeping count at home...)
author mas01cr
date Tue, 23 Oct 2007 19:57:06 +0000
parents b9f1c375f28a
children 100b7ba08df3
line wrap: on
line diff
--- a/audioDB.cpp	Wed Oct 17 14:52:39 2007 +0000
+++ b/audioDB.cpp	Tue Oct 23 19:57:06 2007 +0000
@@ -79,26 +79,26 @@
     error("Unrecognized command",command);
 }
 
-audioDB::audioDB(const unsigned argc, char* const argv[], adb__queryResult *adbQueryResult): O2_AUDIODB_INITIALIZERS
+audioDB::audioDB(const unsigned argc, char* const argv[], adb__queryResponse *adbQueryResponse): O2_AUDIODB_INITIALIZERS
 {
   try {
     processArgs(argc, argv);
     isServer = 1; // FIXME: Hack
     assert(O2_ACTION(COM_QUERY));
-    query(dbName, inFile, adbQueryResult);
+    query(dbName, inFile, adbQueryResponse);
   } catch(char *err) {
     cleanup();
     throw(err);
   }
 }
 
-audioDB::audioDB(const unsigned argc, char* const argv[], adb__statusResult *adbStatusResult): O2_AUDIODB_INITIALIZERS
+audioDB::audioDB(const unsigned argc, char* const argv[], adb__statusResponse *adbStatusResponse): O2_AUDIODB_INITIALIZERS
 {
   try {
     processArgs(argc, argv);
     isServer = 1; // FIXME: Hack
     assert(O2_ACTION(COM_STATUS));
-    status(dbName, adbStatusResult);
+    status(dbName, adbStatusResponse);
   } catch(char *err) {
     cleanup();
     throw(err);
@@ -110,7 +110,7 @@
   if(indata)
     munmap(indata,statbuf.st_size);
   if(db)
-    munmap(db,O2_DEFAULTDBSIZE);
+    munmap(db,dbH->dbSize);
   if(dbfid>0)
     close(dbfid);
   if(infid>0)
@@ -152,6 +152,13 @@
     }
   }
 
+  if(args_info.size_given) {
+    if (args_info.size_arg < 250 || args_info.size_arg > 4000) {
+      error("Size out of range", "");
+    }
+    size = args_info.size_arg * 1000000;
+  }
+
   if(args_info.radius_given){
     radius=args_info.radius_arg;
     if(radius<=0 || radius>1000000000){
@@ -203,6 +210,7 @@
   if(args_info.DUMP_given){
     command=COM_DUMP;
     dbName=args_info.database_arg;
+    output = args_info.output_arg;
     return 0;
   }
 
@@ -372,7 +380,7 @@
   get_lock(dbfid, 1);
 
   // go to the location corresponding to the last byte
-  if (lseek (dbfid, O2_DEFAULTDBSIZE - 1, SEEK_SET) == -1)
+  if (lseek (dbfid, size - 1, SEEK_SET) == -1)
     error("lseek error in db file", "", "lseek");
 
   // write a dummy byte at the last location
@@ -383,7 +391,7 @@
   if(verbosity) {
     cerr << "header size:" << O2_HEADERSIZE << endl;
   }
-  if ((db = (char*) mmap(0, O2_DEFAULTDBSIZE, PROT_READ | PROT_WRITE,
+  if ((db = (char*) mmap(0, size, PROT_READ | PROT_WRITE,
 			 MAP_SHARED, dbfid, 0)) == (caddr_t) -1)
     error("mmap error for creating database", "", "mmap");
   
@@ -400,8 +408,9 @@
   dbH->fileTableOffset = ALIGN_UP(O2_HEADERSIZE, 8);
   dbH->trackTableOffset = ALIGN_UP(dbH->fileTableOffset + O2_FILETABLESIZE*O2_MAXFILES, 8);
   dbH->dataOffset = ALIGN_UP(dbH->trackTableOffset + O2_TRACKTABLESIZE*O2_MAXFILES, 8);
-  dbH->l2normTableOffset = ALIGN_DOWN(O2_DEFAULTDBSIZE - O2_MAXFILES*O2_MEANNUMVECTORS*sizeof(double), 8);
+  dbH->l2normTableOffset = ALIGN_DOWN(size - O2_MAXFILES*O2_MEANNUMVECTORS*sizeof(double), 8);
   dbH->timesTableOffset = ALIGN_DOWN(dbH->l2normTableOffset - O2_MAXFILES*O2_MEANNUMVECTORS*sizeof(double), 8);
+  dbH->dbSize = size;
 
   memcpy (db, dbH, O2_HEADERSIZE);
   if(verbosity) {
@@ -443,8 +452,13 @@
     error("database file has incorect version", dbName);
   }
 
+  // FIXME: when changing file format version, remove this workaround.
+  if(dbH->dbSize == 0) {
+    dbH->dbSize = O2_DEFAULTDBSIZE;
+  }
+
   // mmap the database file
-  if ((db = (char*) mmap(0, O2_DEFAULTDBSIZE, PROT_READ | (forWrite ? PROT_WRITE : 0),
+  if ((db = (char*) mmap(0, dbH->dbSize, PROT_READ | (forWrite ? PROT_WRITE : 0),
 			 MAP_SHARED, dbfid, 0)) == (caddr_t) -1)
     error("mmap error for initting tables of database", "", "mmap");
 
@@ -523,7 +537,7 @@
     }
     // CLEAN UP
     munmap(indata,statbuf.st_size);
-    munmap(db,O2_DEFAULTDBSIZE);
+    munmap(db,dbH->dbSize);
     close(infid);
     return;
   }
@@ -583,7 +597,7 @@
    if(!timesFile->is_open()){
      if(dbH->flags & O2_FLAG_TIMES){
        munmap(indata,statbuf.st_size);
-       munmap(db,O2_DEFAULTDBSIZE);
+       munmap(db,dbH->dbSize);
        error("problem opening times file on timestamped database",timesFileName);
      }
      else{
@@ -611,7 +625,7 @@
      }
      if(numtimes<numVectors || numtimes>numVectors+2){
        munmap(indata,statbuf.st_size);
-       munmap(db,O2_DEFAULTDBSIZE);
+       munmap(db,dbH->dbSize);
        close(infid);
        cerr << "expected " << numVectors << " found " << numtimes << endl;
        error("Times file is incorrect length for features file",inFile);
@@ -773,17 +787,17 @@
 // this.  -- CSR, 2007-10-01
 void audioDB::ws_status(const char*dbName, char* hostport){
   struct soap soap;
-  adb__statusResult adbStatusResult;  
+  adb__statusResponse adbStatusResponse;  
   
   // Query an existing adb database
   soap_init(&soap);
-  if(soap_call_adb__status(&soap,hostport,NULL,(char*)dbName,adbStatusResult)==SOAP_OK) {
-    cout << "numFiles = " << adbStatusResult.numFiles << endl;
-    cout << "dim = " << adbStatusResult.dim << endl;
-    cout << "length = " << adbStatusResult.length << endl;
-    cout << "dudCount = " << adbStatusResult.dudCount << endl;
-    cout << "nullCount = " << adbStatusResult.nullCount << endl;
-    cout << "flags = " << adbStatusResult.flags << endl;
+  if(soap_call_adb__status(&soap,hostport,NULL,(char*)dbName,adbStatusResponse)==SOAP_OK) {
+    cout << "numFiles = " << adbStatusResponse.result.numFiles << endl;
+    cout << "dim = " << adbStatusResponse.result.dim << endl;
+    cout << "length = " << adbStatusResponse.result.length << endl;
+    cout << "dudCount = " << adbStatusResponse.result.dudCount << endl;
+    cout << "nullCount = " << adbStatusResponse.result.nullCount << endl;
+    cout << "flags = " << adbStatusResponse.result.flags << endl;
   } else {
     soap_print_fault(&soap,stderr);
   }
@@ -795,16 +809,16 @@
 
 void audioDB::ws_query(const char*dbName, const char *trackKey, const char* hostport){
   struct soap soap;
-  adb__queryResult adbQueryResult;  
+  adb__queryResponse adbQueryResponse;  
 
   soap_init(&soap);  
   if(soap_call_adb__query(&soap,hostport,NULL,
 			  (char*)dbName,(char*)trackKey,(char*)trackFileName,(char*)timesFileName,
-			  queryType, queryPoint, pointNN, trackNN, sequenceLength, adbQueryResult)==SOAP_OK){
-    //std::cerr << "result list length:" << adbQueryResult.__sizeRlist << std::endl;
-    for(int i=0; i<adbQueryResult.__sizeRlist; i++)
-      std::cout << adbQueryResult.Rlist[i] << " " << adbQueryResult.Dist[i] 
-		<< " " << adbQueryResult.Qpos[i] << " " << adbQueryResult.Spos[i] << std::endl;
+			  queryType, queryPoint, pointNN, trackNN, sequenceLength, adbQueryResponse)==SOAP_OK){
+    //std::cerr << "result list length:" << adbQueryResponse.result.__sizeRlist << std::endl;
+    for(int i=0; i<adbQueryResponse.result.__sizeRlist; i++)
+      std::cout << adbQueryResponse.result.Rlist[i] << " " << adbQueryResponse.result.Dist[i] 
+		<< " " << adbQueryResponse.result.Qpos[i] << " " << adbQueryResponse.result.Spos[i] << std::endl;
   }
   else
     soap_print_fault(&soap,stderr);
@@ -816,7 +830,7 @@
 }
 
 
-void audioDB::status(const char* dbName, adb__statusResult *adbStatusResult){
+void audioDB::status(const char* dbName, adb__statusResponse *adbStatusResponse){
   if(!dbH)
     initTables(dbName, 0, 0);
 
@@ -830,7 +844,7 @@
     }
   }
   
-  if(adbStatusResult == 0) {
+  if(adbStatusResponse == 0) {
 
     // Update Header information
     cout << "num files:" << dbH->numFiles << endl;
@@ -846,24 +860,127 @@
     
     cout << "null count: " << nullCount << " small sequence count " << dudCount-nullCount << endl;    
   } else {
-    adbStatusResult->numFiles = dbH->numFiles;
-    adbStatusResult->dim = dbH->dim;
-    adbStatusResult->length = dbH->length;
-    adbStatusResult->dudCount = dudCount;
-    adbStatusResult->nullCount = nullCount;
-    adbStatusResult->flags = dbH->flags;
+    adbStatusResponse->result.numFiles = dbH->numFiles;
+    adbStatusResponse->result.dim = dbH->dim;
+    adbStatusResponse->result.length = dbH->length;
+    adbStatusResponse->result.dudCount = dudCount;
+    adbStatusResponse->result.nullCount = nullCount;
+    adbStatusResponse->result.flags = dbH->flags;
   }
 }
 
 void audioDB::dump(const char* dbName){
-  if(!dbH)
+  if(!dbH) {
     initTables(dbName, 0, 0);
-  
-  for(unsigned k=0, j=0; k<dbH->numFiles; k++){
-    cout << fileTable+k*O2_FILETABLESIZE << " " << trackTable[k] << endl;
-    j+=trackTable[k];
   }
 
+  if((mkdir(output, S_IRWXU|S_IRWXG|S_IRWXO)) < 0) {
+    error("error making output directory", output, "mkdir");
+  }
+
+  char *cwd = new char[PATH_MAX];
+
+  if ((getcwd(cwd, PATH_MAX)) == 0) {
+    error("error getting working directory", "", "getcwd");
+  }
+
+  if((chdir(output)) < 0) {
+    error("error changing working directory", output, "chdir");
+  }
+
+  int fLfd, tLfd = 0, kLfd;
+  FILE *fLFile, *tLFile = 0, *kLFile;
+
+  if ((fLfd = open("featureList.txt", O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) {
+    error("error creating featureList file", "featureList.txt", "open");
+  }
+  int times = dbH->flags & O2_FLAG_TIMES;
+  if (times) {
+    if ((tLfd = open("timesList.txt", O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) {
+      error("error creating timesList file", "timesList.txt", "open");
+    }
+  }
+  if ((kLfd = open("keyList.txt", O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) {
+    error("error creating keyList file", "keyList.txt", "open");
+  }
+  
+  /* can these fail?  I sincerely hope not. */
+  fLFile = fdopen(fLfd, "w");
+  if (times) {
+    tLFile = fdopen(tLfd, "w");
+  }
+  kLFile = fdopen(kLfd, "w");
+
+  char *fName = new char[256];
+  int ffd;
+  FILE *tFile;
+  unsigned pos = 0;
+  for(unsigned k = 0; k < dbH->numFiles; k++) {
+    fprintf(kLFile, "%s\n", fileTable + k*O2_FILETABLESIZE);
+    snprintf(fName, 256, "%05d.features", k);
+    if ((ffd = open(fName, O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) {
+      error("error creating feature file", fName, "open");
+    }
+    if ((write(ffd, &dbH->dim, sizeof(uint32_t))) < 0) {
+      error("error writing dimensions", fName, "write");
+    }
+      
+    if ((write(ffd, dataBuf + pos * dbH->dim, trackTable[k] * dbH->dim * sizeof(double))) < 0) {
+      error("error writing data", fName, "write");
+    }
+    fprintf(fLFile, "%s\n", fName);
+    close(ffd);
+
+    if(times) {
+      snprintf(fName, 256, "%05d.times", k);
+      tFile = fopen(fName, "w");
+      for(unsigned i = 0; i < trackTable[k]; i++) {
+        // KLUDGE: specifying 16 digits of precision after the decimal
+        // point is (but check this!) sufficient to uniquely identify
+        // doubles; however, that will cause ugliness, as that's
+        // vastly too many for most values of interest.  Moving to %a
+        // here and scanf() in the timesFile reading might fix this.
+        // -- CSR, 2007-10-19
+        fprintf(tFile, "%.16e\n", *(timesTable + pos + i));
+      }
+      fprintf(tLFile, "%s\n", fName);
+    }
+
+    pos += trackTable[k];
+    cout << fileTable+k*O2_FILETABLESIZE << " " << trackTable[k] << endl;
+  }
+
+  FILE *scriptFile;
+  scriptFile = fopen("restore.sh", "w");
+  fprintf(scriptFile, "\
+#! /bin/sh\n\
+#\n\
+# usage: AUDIODB=/path/to/audioDB sh ./restore.sh <newdb>\n\
+\n\
+if [ -z \"${AUDIODB}\" ]; then echo set AUDIODB variable; exit 1; fi\n\
+if [ -z \"$1\" ]; then echo usage: $0 newdb; exit 1; fi\n\n\
+\"${AUDIODB}\" -d \"$1\" -N --size=%d\n", dbH->dbSize / 1000000);
+  if(dbH->flags & O2_FLAG_L2NORM) {
+    fprintf(scriptFile, "\"${AUDIODB}\" -d \"$1\" -L\n");
+  }
+  fprintf(scriptFile, "\"${AUDIODB}\" -d \"$1\" -B -F featureList.txt -K keyList.txt");
+  if(times) {
+    fprintf(scriptFile, " -T timesList.txt");
+  }
+  fprintf(scriptFile, "\n");
+  fclose(scriptFile);
+
+  if((chdir(cwd)) < 0) {
+    error("error changing working directory", cwd, "chdir");
+  }
+
+  fclose(fLFile);
+  if(times) {
+    fclose(tLFile);
+  }
+  fclose(kLFile);
+  delete[] fName;
+    
   status(dbName);
 }
 
@@ -880,19 +997,19 @@
   
 
   
-void audioDB::query(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult){  
+void audioDB::query(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){  
   switch(queryType){
   case O2_POINT_QUERY:
-    pointQuery(dbName, inFile, adbQueryResult);
+    pointQuery(dbName, inFile, adbQueryResponse);
     break;
   case O2_SEQUENCE_QUERY:
     if(radius==0)
-      trackSequenceQueryNN(dbName, inFile, adbQueryResult);
+      trackSequenceQueryNN(dbName, inFile, adbQueryResponse);
     else
-      trackSequenceQueryRad(dbName, inFile, adbQueryResult);
+      trackSequenceQueryRad(dbName, inFile, adbQueryResponse);
     break;
   case O2_TRACK_QUERY:
-    trackPointQuery(dbName, inFile, adbQueryResult);
+    trackPointQuery(dbName, inFile, adbQueryResponse);
     break;
   default:
     error("unrecognized queryType in query()");
@@ -910,7 +1027,7 @@
 }
 
 // Basic point query engine
-void audioDB::pointQuery(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult){
+void audioDB::pointQuery(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){
   
   initTables(dbName, 0, inFile);
   
@@ -1031,7 +1148,7 @@
     cerr << endl << " elapsed time:" << ( tv2.tv_sec*1000 + tv2.tv_usec/1000 ) - ( tv1.tv_sec*1000+tv1.tv_usec/1000 ) << " msec" << endl;
   }
 
-  if(adbQueryResult==0){
+  if(adbQueryResponse==0){
     // Output answer
     // Loop over nearest neighbours    
     for(k=0; k < pointNN; k++){
@@ -1055,27 +1172,27 @@
     }
     listLen = k;
 
-    adbQueryResult->__sizeRlist=listLen;
-    adbQueryResult->__sizeDist=listLen;
-    adbQueryResult->__sizeQpos=listLen;
-    adbQueryResult->__sizeSpos=listLen;
-    adbQueryResult->Rlist= new char*[listLen];
-    adbQueryResult->Dist = new double[listLen];
-    adbQueryResult->Qpos = new unsigned int[listLen];
-    adbQueryResult->Spos = new unsigned int[listLen];
-    for(k=0; k<(unsigned)adbQueryResult->__sizeRlist; k++){
-      adbQueryResult->Rlist[k]=new char[O2_MAXFILESTR];
-      adbQueryResult->Dist[k]=distances[k];
-      adbQueryResult->Qpos[k]=qIndexes[k];
+    adbQueryResponse->result.__sizeRlist=listLen;
+    adbQueryResponse->result.__sizeDist=listLen;
+    adbQueryResponse->result.__sizeQpos=listLen;
+    adbQueryResponse->result.__sizeSpos=listLen;
+    adbQueryResponse->result.Rlist= new char*[listLen];
+    adbQueryResponse->result.Dist = new double[listLen];
+    adbQueryResponse->result.Qpos = new unsigned int[listLen];
+    adbQueryResponse->result.Spos = new unsigned int[listLen];
+    for(k=0; k<(unsigned)adbQueryResponse->result.__sizeRlist; k++){
+      adbQueryResponse->result.Rlist[k]=new char[O2_MAXFILESTR];
+      adbQueryResponse->result.Dist[k]=distances[k];
+      adbQueryResponse->result.Qpos[k]=qIndexes[k];
       unsigned cumTrack=0;
       for(l=0 ; l<dbH->numFiles; l++){
 	cumTrack+=trackTable[l];
 	if(sIndexes[k]<cumTrack){
-	  sprintf(adbQueryResult->Rlist[k], "%s", fileTable+l*O2_FILETABLESIZE);
+	  sprintf(adbQueryResponse->result.Rlist[k], "%s", fileTable+l*O2_FILETABLESIZE);
 	  break;
 	}
       }
-      adbQueryResult->Spos[k]=sIndexes[k]+trackTable[l]-cumTrack;
+      adbQueryResponse->result.Spos[k]=sIndexes[k]+trackTable[l]-cumTrack;
     }
   }
   
@@ -1093,7 +1210,7 @@
 // trackPointQuery  
 // return the trackNN closest tracks to the query track
 // uses average of pointNN points per track 
-void audioDB::trackPointQuery(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult){  
+void audioDB::trackPointQuery(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){  
   initTables(dbName, 0, inFile);
   
   // For each input vector, find the closest pointNN matching output vectors and report
@@ -1298,7 +1415,7 @@
 	 << " elapsed time:" << ( tv2.tv_sec*1000 + tv2.tv_usec/1000 ) - ( tv1.tv_sec*1000+tv1.tv_usec/1000 ) << " msec" << endl;
   }
 
-  if(adbQueryResult==0){
+  if(adbQueryResponse==0){
     if(verbosity>1) {
       cerr<<endl;
     }
@@ -1310,20 +1427,20 @@
   }
   else{ // Process Web Services Query
     int listLen = min(trackNN, processedTracks);
-    adbQueryResult->__sizeRlist=listLen;
-    adbQueryResult->__sizeDist=listLen;
-    adbQueryResult->__sizeQpos=listLen;
-    adbQueryResult->__sizeSpos=listLen;
-    adbQueryResult->Rlist= new char*[listLen];
-    adbQueryResult->Dist = new double[listLen];
-    adbQueryResult->Qpos = new unsigned int[listLen];
-    adbQueryResult->Spos = new unsigned int[listLen];
-    for(k=0; k<(unsigned)adbQueryResult->__sizeRlist; k++){
-      adbQueryResult->Rlist[k]=new char[O2_MAXFILESTR];
-      adbQueryResult->Dist[k]=trackDistances[k];
-      adbQueryResult->Qpos[k]=trackQIndexes[k];
-      adbQueryResult->Spos[k]=trackSIndexes[k];
-      sprintf(adbQueryResult->Rlist[k], "%s", fileTable+trackIDs[k]*O2_FILETABLESIZE);
+    adbQueryResponse->result.__sizeRlist=listLen;
+    adbQueryResponse->result.__sizeDist=listLen;
+    adbQueryResponse->result.__sizeQpos=listLen;
+    adbQueryResponse->result.__sizeSpos=listLen;
+    adbQueryResponse->result.Rlist= new char*[listLen];
+    adbQueryResponse->result.Dist = new double[listLen];
+    adbQueryResponse->result.Qpos = new unsigned int[listLen];
+    adbQueryResponse->result.Spos = new unsigned int[listLen];
+    for(k=0; k<(unsigned)adbQueryResponse->result.__sizeRlist; k++){
+      adbQueryResponse->result.Rlist[k]=new char[O2_MAXFILESTR];
+      adbQueryResponse->result.Dist[k]=trackDistances[k];
+      adbQueryResponse->result.Qpos[k]=trackQIndexes[k];
+      adbQueryResponse->result.Spos[k]=trackSIndexes[k];
+      sprintf(adbQueryResponse->result.Rlist[k], "%s", fileTable+trackIDs[k]*O2_FILETABLESIZE);
     }
   }
     
@@ -1347,7 +1464,7 @@
 // efficient implementation based on matched filter
 // assumes normed shingles
 // outputs distances of retrieved shingles, max retreived = pointNN shingles per per track
-void audioDB::trackSequenceQueryNN(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult){
+void audioDB::trackSequenceQueryNN(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){
   
   initTables(dbName, 0, inFile);
   
@@ -1797,7 +1914,7 @@
     cerr << "sampleCount: " << sampleCount << " sampleSum: " << sampleSum << " logSampleSum: " << logSampleSum 
 	 << " minSample: " << minSample << " maxSample: " << maxSample << endl;
   }  
-  if(adbQueryResult==0){
+  if(adbQueryResponse==0){
     if(verbosity>1) {
       cerr<<endl;
     }
@@ -1809,20 +1926,20 @@
   }
   else{ // Process Web Services Query
     int listLen = min(trackNN, processedTracks);
-    adbQueryResult->__sizeRlist=listLen;
-    adbQueryResult->__sizeDist=listLen;
-    adbQueryResult->__sizeQpos=listLen;
-    adbQueryResult->__sizeSpos=listLen;
-    adbQueryResult->Rlist= new char*[listLen];
-    adbQueryResult->Dist = new double[listLen];
-    adbQueryResult->Qpos = new unsigned int[listLen];
-    adbQueryResult->Spos = new unsigned int[listLen];
-    for(k=0; k<(unsigned)adbQueryResult->__sizeRlist; k++){
-      adbQueryResult->Rlist[k]=new char[O2_MAXFILESTR];
-      adbQueryResult->Dist[k]=trackDistances[k];
-      adbQueryResult->Qpos[k]=trackQIndexes[k];
-      adbQueryResult->Spos[k]=trackSIndexes[k];
-      sprintf(adbQueryResult->Rlist[k], "%s", fileTable+trackIDs[k]*O2_FILETABLESIZE);
+    adbQueryResponse->result.__sizeRlist=listLen;
+    adbQueryResponse->result.__sizeDist=listLen;
+    adbQueryResponse->result.__sizeQpos=listLen;
+    adbQueryResponse->result.__sizeSpos=listLen;
+    adbQueryResponse->result.Rlist= new char*[listLen];
+    adbQueryResponse->result.Dist = new double[listLen];
+    adbQueryResponse->result.Qpos = new unsigned int[listLen];
+    adbQueryResponse->result.Spos = new unsigned int[listLen];
+    for(k=0; k<(unsigned)adbQueryResponse->result.__sizeRlist; k++){
+      adbQueryResponse->result.Rlist[k]=new char[O2_MAXFILESTR];
+      adbQueryResponse->result.Dist[k]=trackDistances[k];
+      adbQueryResponse->result.Qpos[k]=trackQIndexes[k];
+      adbQueryResponse->result.Spos[k]=trackSIndexes[k];
+      sprintf(adbQueryResponse->result.Rlist[k], "%s", fileTable+trackIDs[k]*O2_FILETABLESIZE);
     }
   }
 
@@ -1854,7 +1971,7 @@
 // efficient implementation based on matched filter
 // assumes normed shingles
 // outputs count of retrieved shingles, max retreived = one shingle per query shingle per track
-void audioDB::trackSequenceQueryRad(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult){
+void audioDB::trackSequenceQueryRad(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){
   
   initTables(dbName, 0, inFile);
   
@@ -2279,7 +2396,7 @@
 	 << " minSample: " << minSample << " maxSample: " << maxSample << endl;
   }
   
-  if(adbQueryResult==0){
+  if(adbQueryResponse==0){
     if(verbosity>1) {
       cerr<<endl;
     }
@@ -2290,20 +2407,20 @@
   }
   else{ // Process Web Services Query
     int listLen = min(trackNN, processedTracks);
-    adbQueryResult->__sizeRlist=listLen;
-    adbQueryResult->__sizeDist=listLen;
-    adbQueryResult->__sizeQpos=listLen;
-    adbQueryResult->__sizeSpos=listLen;
-    adbQueryResult->Rlist= new char*[listLen];
-    adbQueryResult->Dist = new double[listLen];
-    adbQueryResult->Qpos = new unsigned int[listLen];
-    adbQueryResult->Spos = new unsigned int[listLen];
-    for(k=0; k<(unsigned)adbQueryResult->__sizeRlist; k++){
-      adbQueryResult->Rlist[k]=new char[O2_MAXFILESTR];
-      adbQueryResult->Dist[k]=trackDistances[k];
-      adbQueryResult->Qpos[k]=trackQIndexes[k];
-      adbQueryResult->Spos[k]=trackSIndexes[k];
-      sprintf(adbQueryResult->Rlist[k], "%s", fileTable+trackIDs[k]*O2_FILETABLESIZE);
+    adbQueryResponse->result.__sizeRlist=listLen;
+    adbQueryResponse->result.__sizeDist=listLen;
+    adbQueryResponse->result.__sizeQpos=listLen;
+    adbQueryResponse->result.__sizeSpos=listLen;
+    adbQueryResponse->result.Rlist= new char*[listLen];
+    adbQueryResponse->result.Dist = new double[listLen];
+    adbQueryResponse->result.Qpos = new unsigned int[listLen];
+    adbQueryResponse->result.Spos = new unsigned int[listLen];
+    for(k=0; k<(unsigned)adbQueryResponse->result.__sizeRlist; k++){
+      adbQueryResponse->result.Rlist[k]=new char[O2_MAXFILESTR];
+      adbQueryResponse->result.Dist[k]=trackDistances[k];
+      adbQueryResponse->result.Qpos[k]=trackQIndexes[k];
+      adbQueryResponse->result.Spos[k]=trackSIndexes[k];
+      sprintf(adbQueryResponse->result.Rlist[k], "%s", fileTable+trackIDs[k]*O2_FILETABLESIZE);
     }
   }
 
@@ -2462,11 +2579,11 @@
 // web services
 
 // SERVER SIDE
-int adb__status(struct soap* soap, xsd__string dbName, adb__statusResult &adbStatusResult){
+int adb__status(struct soap* soap, xsd__string dbName, adb__statusResponse &adbStatusResponse){
   char* const argv[]={"audioDB",COM_STATUS,"-d",dbName};
   const unsigned argc = 4;
   try {
-    audioDB(argc, argv, &adbStatusResult);
+    audioDB(argc, argv, &adbStatusResponse);
     return SOAP_OK;
   } catch(char *err) {
     soap_receiver_fault(soap, err, "");
@@ -2476,7 +2593,7 @@
 
 // Literal translation of command line to web service
 
-int adb__query(struct soap* soap, xsd__string dbName, xsd__string qKey, xsd__string keyList, xsd__string timesFileName, xsd__int qType, xsd__int qPos, xsd__int pointNN, xsd__int trackNN, xsd__int seqLen, adb__queryResult &adbQueryResult){
+int adb__query(struct soap* soap, xsd__string dbName, xsd__string qKey, xsd__string keyList, xsd__string timesFileName, xsd__int qType, xsd__int qPos, xsd__int pointNN, xsd__int trackNN, xsd__int seqLen, adb__queryResponse &adbQueryResponse){
   char queryType[256];
   for(int k=0; k<256; k++)
     queryType[k]='\0';
@@ -2529,7 +2646,7 @@
 
   const unsigned argc = 19;
   try {
-    audioDB(argc, (char* const*)argv, &adbQueryResult);
+    audioDB(argc, (char* const*)argv, &adbQueryResponse);
     return SOAP_OK;
   } catch (char *err) {
     soap_receiver_fault(soap, err, "");