comparison audioDB.cpp @ 133:a5d5a55a412d

Friendlier Actionscript/SOAP behaviour. As suggested in the gsoap documentation, we wrap the struct that we actually want to return inside a response structure. (It should be said that I didn't understand a _word_ of the gsoap documentation; I want in particular to highlight section 8.1.1 of the gsoap 2.7.6 user guide, which reads in its entirety "If the single output parameter of a remote method is a complex data type such as a struct or class it is necessary to specify the response element of the remote method as a struct or class at all times. Otherwise, the output parameter will be considered the response element (!), because of the response element specification convention used by gSOAP, as discussed in 8.1.7." and tells me absolutely nothing of use.) Nevertheless, cargo-cult from the documentation...
author mas01cr
date Tue, 23 Oct 2007 17:21:08 +0000
parents 3d931368fab3
children ddd83d773d6c
comparison
equal deleted inserted replaced
132:7ae689fadb44 133:a5d5a55a412d
77 77
78 else 78 else
79 error("Unrecognized command",command); 79 error("Unrecognized command",command);
80 } 80 }
81 81
82 audioDB::audioDB(const unsigned argc, char* const argv[], adb__queryResult *adbQueryResult): O2_AUDIODB_INITIALIZERS 82 audioDB::audioDB(const unsigned argc, char* const argv[], adb__queryResponse *adbQueryResponse): O2_AUDIODB_INITIALIZERS
83 { 83 {
84 try { 84 try {
85 processArgs(argc, argv); 85 processArgs(argc, argv);
86 isServer = 1; // FIXME: Hack 86 isServer = 1; // FIXME: Hack
87 assert(O2_ACTION(COM_QUERY)); 87 assert(O2_ACTION(COM_QUERY));
88 query(dbName, inFile, adbQueryResult); 88 query(dbName, inFile, adbQueryResponse);
89 } catch(char *err) { 89 } catch(char *err) {
90 cleanup(); 90 cleanup();
91 throw(err); 91 throw(err);
92 } 92 }
93 } 93 }
94 94
95 audioDB::audioDB(const unsigned argc, char* const argv[], adb__statusResult *adbStatusResult): O2_AUDIODB_INITIALIZERS 95 audioDB::audioDB(const unsigned argc, char* const argv[], adb__statusResponse *adbStatusResponse): O2_AUDIODB_INITIALIZERS
96 { 96 {
97 try { 97 try {
98 processArgs(argc, argv); 98 processArgs(argc, argv);
99 isServer = 1; // FIXME: Hack 99 isServer = 1; // FIXME: Hack
100 assert(O2_ACTION(COM_STATUS)); 100 assert(O2_ACTION(COM_STATUS));
101 status(dbName, adbStatusResult); 101 status(dbName, adbStatusResponse);
102 } catch(char *err) { 102 } catch(char *err) {
103 cleanup(); 103 cleanup();
104 throw(err); 104 throw(err);
105 } 105 }
106 } 106 }
785 // FIXME: this can't propagate the sequence length argument (used for 785 // FIXME: this can't propagate the sequence length argument (used for
786 // dudCount). See adb__status() definition for the other half of 786 // dudCount). See adb__status() definition for the other half of
787 // this. -- CSR, 2007-10-01 787 // this. -- CSR, 2007-10-01
788 void audioDB::ws_status(const char*dbName, char* hostport){ 788 void audioDB::ws_status(const char*dbName, char* hostport){
789 struct soap soap; 789 struct soap soap;
790 adb__statusResult adbStatusResult; 790 adb__statusResponse adbStatusResponse;
791 791
792 // Query an existing adb database 792 // Query an existing adb database
793 soap_init(&soap); 793 soap_init(&soap);
794 if(soap_call_adb__status(&soap,hostport,NULL,(char*)dbName,adbStatusResult)==SOAP_OK) { 794 if(soap_call_adb__status(&soap,hostport,NULL,(char*)dbName,adbStatusResponse)==SOAP_OK) {
795 cout << "numFiles = " << adbStatusResult.numFiles << endl; 795 cout << "numFiles = " << adbStatusResponse.result.numFiles << endl;
796 cout << "dim = " << adbStatusResult.dim << endl; 796 cout << "dim = " << adbStatusResponse.result.dim << endl;
797 cout << "length = " << adbStatusResult.length << endl; 797 cout << "length = " << adbStatusResponse.result.length << endl;
798 cout << "dudCount = " << adbStatusResult.dudCount << endl; 798 cout << "dudCount = " << adbStatusResponse.result.dudCount << endl;
799 cout << "nullCount = " << adbStatusResult.nullCount << endl; 799 cout << "nullCount = " << adbStatusResponse.result.nullCount << endl;
800 cout << "flags = " << adbStatusResult.flags << endl; 800 cout << "flags = " << adbStatusResponse.result.flags << endl;
801 } else { 801 } else {
802 soap_print_fault(&soap,stderr); 802 soap_print_fault(&soap,stderr);
803 } 803 }
804 804
805 soap_destroy(&soap); 805 soap_destroy(&soap);
807 soap_done(&soap); 807 soap_done(&soap);
808 } 808 }
809 809
810 void audioDB::ws_query(const char*dbName, const char *trackKey, const char* hostport){ 810 void audioDB::ws_query(const char*dbName, const char *trackKey, const char* hostport){
811 struct soap soap; 811 struct soap soap;
812 adb__queryResult adbQueryResult; 812 adb__queryResponse adbQueryResponse;
813 813
814 soap_init(&soap); 814 soap_init(&soap);
815 if(soap_call_adb__query(&soap,hostport,NULL, 815 if(soap_call_adb__query(&soap,hostport,NULL,
816 (char*)dbName,(char*)trackKey,(char*)trackFileName,(char*)timesFileName, 816 (char*)dbName,(char*)trackKey,(char*)trackFileName,(char*)timesFileName,
817 queryType, queryPoint, pointNN, trackNN, sequenceLength, adbQueryResult)==SOAP_OK){ 817 queryType, queryPoint, pointNN, trackNN, sequenceLength, adbQueryResponse)==SOAP_OK){
818 //std::cerr << "result list length:" << adbQueryResult.__sizeRlist << std::endl; 818 //std::cerr << "result list length:" << adbQueryResponse.result.__sizeRlist << std::endl;
819 for(int i=0; i<adbQueryResult.__sizeRlist; i++) 819 for(int i=0; i<adbQueryResponse.result.__sizeRlist; i++)
820 std::cout << adbQueryResult.Rlist[i] << " " << adbQueryResult.Dist[i] 820 std::cout << adbQueryResponse.result.Rlist[i] << " " << adbQueryResponse.result.Dist[i]
821 << " " << adbQueryResult.Qpos[i] << " " << adbQueryResult.Spos[i] << std::endl; 821 << " " << adbQueryResponse.result.Qpos[i] << " " << adbQueryResponse.result.Spos[i] << std::endl;
822 } 822 }
823 else 823 else
824 soap_print_fault(&soap,stderr); 824 soap_print_fault(&soap,stderr);
825 825
826 soap_destroy(&soap); 826 soap_destroy(&soap);
828 soap_done(&soap); 828 soap_done(&soap);
829 829
830 } 830 }
831 831
832 832
833 void audioDB::status(const char* dbName, adb__statusResult *adbStatusResult){ 833 void audioDB::status(const char* dbName, adb__statusResponse *adbStatusResponse){
834 if(!dbH) 834 if(!dbH)
835 initTables(dbName, 0, 0); 835 initTables(dbName, 0, 0);
836 836
837 unsigned dudCount=0; 837 unsigned dudCount=0;
838 unsigned nullCount=0; 838 unsigned nullCount=0;
842 if(!trackTable[k]) 842 if(!trackTable[k])
843 nullCount++; 843 nullCount++;
844 } 844 }
845 } 845 }
846 846
847 if(adbStatusResult == 0) { 847 if(adbStatusResponse == 0) {
848 848
849 // Update Header information 849 // Update Header information
850 cout << "num files:" << dbH->numFiles << endl; 850 cout << "num files:" << dbH->numFiles << endl;
851 cout << "data dim:" << dbH->dim <<endl; 851 cout << "data dim:" << dbH->dim <<endl;
852 if(dbH->dim>0){ 852 if(dbH->dim>0){
858 (100.0*(dbH->timesTableOffset-(dbH->dataOffset+dbH->length)))/(dbH->timesTableOffset-dbH->dataOffset) << "%)" << endl; 858 (100.0*(dbH->timesTableOffset-(dbH->dataOffset+dbH->length)))/(dbH->timesTableOffset-dbH->dataOffset) << "%)" << endl;
859 cout << "flags:" << dbH->flags << endl; 859 cout << "flags:" << dbH->flags << endl;
860 860
861 cout << "null count: " << nullCount << " small sequence count " << dudCount-nullCount << endl; 861 cout << "null count: " << nullCount << " small sequence count " << dudCount-nullCount << endl;
862 } else { 862 } else {
863 adbStatusResult->numFiles = dbH->numFiles; 863 adbStatusResponse->result.numFiles = dbH->numFiles;
864 adbStatusResult->dim = dbH->dim; 864 adbStatusResponse->result.dim = dbH->dim;
865 adbStatusResult->length = dbH->length; 865 adbStatusResponse->result.length = dbH->length;
866 adbStatusResult->dudCount = dudCount; 866 adbStatusResponse->result.dudCount = dudCount;
867 adbStatusResult->nullCount = nullCount; 867 adbStatusResponse->result.nullCount = nullCount;
868 adbStatusResult->flags = dbH->flags; 868 adbStatusResponse->result.flags = dbH->flags;
869 } 869 }
870 } 870 }
871 871
872 void audioDB::dump(const char* dbName){ 872 void audioDB::dump(const char* dbName){
873 if(!dbH) { 873 if(!dbH) {
995 memcpy (db, dbH, O2_HEADERSIZE); 995 memcpy (db, dbH, O2_HEADERSIZE);
996 } 996 }
997 997
998 998
999 999
1000 void audioDB::query(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult){ 1000 void audioDB::query(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){
1001 switch(queryType){ 1001 switch(queryType){
1002 case O2_POINT_QUERY: 1002 case O2_POINT_QUERY:
1003 pointQuery(dbName, inFile, adbQueryResult); 1003 pointQuery(dbName, inFile, adbQueryResponse);
1004 break; 1004 break;
1005 case O2_SEQUENCE_QUERY: 1005 case O2_SEQUENCE_QUERY:
1006 if(radius==0) 1006 if(radius==0)
1007 trackSequenceQueryNN(dbName, inFile, adbQueryResult); 1007 trackSequenceQueryNN(dbName, inFile, adbQueryResponse);
1008 else 1008 else
1009 trackSequenceQueryRad(dbName, inFile, adbQueryResult); 1009 trackSequenceQueryRad(dbName, inFile, adbQueryResponse);
1010 break; 1010 break;
1011 case O2_TRACK_QUERY: 1011 case O2_TRACK_QUERY:
1012 trackPointQuery(dbName, inFile, adbQueryResult); 1012 trackPointQuery(dbName, inFile, adbQueryResponse);
1013 break; 1013 break;
1014 default: 1014 default:
1015 error("unrecognized queryType in query()"); 1015 error("unrecognized queryType in query()");
1016 1016
1017 } 1017 }
1025 error("Key not found",key); 1025 error("Key not found",key);
1026 return O2_ERR_KEYNOTFOUND; 1026 return O2_ERR_KEYNOTFOUND;
1027 } 1027 }
1028 1028
1029 // Basic point query engine 1029 // Basic point query engine
1030 void audioDB::pointQuery(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult){ 1030 void audioDB::pointQuery(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){
1031 1031
1032 initTables(dbName, 0, inFile); 1032 initTables(dbName, 0, inFile);
1033 1033
1034 // For each input vector, find the closest pointNN matching output vectors and report 1034 // For each input vector, find the closest pointNN matching output vectors and report
1035 // we use stdout in this stub version 1035 // we use stdout in this stub version
1146 gettimeofday(&tv2, NULL); 1146 gettimeofday(&tv2, NULL);
1147 if(verbosity>1) { 1147 if(verbosity>1) {
1148 cerr << endl << " elapsed time:" << ( tv2.tv_sec*1000 + tv2.tv_usec/1000 ) - ( tv1.tv_sec*1000+tv1.tv_usec/1000 ) << " msec" << endl; 1148 cerr << endl << " elapsed time:" << ( tv2.tv_sec*1000 + tv2.tv_usec/1000 ) - ( tv1.tv_sec*1000+tv1.tv_usec/1000 ) << " msec" << endl;
1149 } 1149 }
1150 1150
1151 if(adbQueryResult==0){ 1151 if(adbQueryResponse==0){
1152 // Output answer 1152 // Output answer
1153 // Loop over nearest neighbours 1153 // Loop over nearest neighbours
1154 for(k=0; k < pointNN; k++){ 1154 for(k=0; k < pointNN; k++){
1155 // Scan for key 1155 // Scan for key
1156 unsigned cumTrack=0; 1156 unsigned cumTrack=0;
1170 if(distances[k] == -DBL_MAX) 1170 if(distances[k] == -DBL_MAX)
1171 break; 1171 break;
1172 } 1172 }
1173 listLen = k; 1173 listLen = k;
1174 1174
1175 adbQueryResult->__sizeRlist=listLen; 1175 adbQueryResponse->result.__sizeRlist=listLen;
1176 adbQueryResult->__sizeDist=listLen; 1176 adbQueryResponse->result.__sizeDist=listLen;
1177 adbQueryResult->__sizeQpos=listLen; 1177 adbQueryResponse->result.__sizeQpos=listLen;
1178 adbQueryResult->__sizeSpos=listLen; 1178 adbQueryResponse->result.__sizeSpos=listLen;
1179 adbQueryResult->Rlist= new char*[listLen]; 1179 adbQueryResponse->result.Rlist= new char*[listLen];
1180 adbQueryResult->Dist = new double[listLen]; 1180 adbQueryResponse->result.Dist = new double[listLen];
1181 adbQueryResult->Qpos = new unsigned int[listLen]; 1181 adbQueryResponse->result.Qpos = new unsigned int[listLen];
1182 adbQueryResult->Spos = new unsigned int[listLen]; 1182 adbQueryResponse->result.Spos = new unsigned int[listLen];
1183 for(k=0; k<(unsigned)adbQueryResult->__sizeRlist; k++){ 1183 for(k=0; k<(unsigned)adbQueryResponse->result.__sizeRlist; k++){
1184 adbQueryResult->Rlist[k]=new char[O2_MAXFILESTR]; 1184 adbQueryResponse->result.Rlist[k]=new char[O2_MAXFILESTR];
1185 adbQueryResult->Dist[k]=distances[k]; 1185 adbQueryResponse->result.Dist[k]=distances[k];
1186 adbQueryResult->Qpos[k]=qIndexes[k]; 1186 adbQueryResponse->result.Qpos[k]=qIndexes[k];
1187 unsigned cumTrack=0; 1187 unsigned cumTrack=0;
1188 for(l=0 ; l<dbH->numFiles; l++){ 1188 for(l=0 ; l<dbH->numFiles; l++){
1189 cumTrack+=trackTable[l]; 1189 cumTrack+=trackTable[l];
1190 if(sIndexes[k]<cumTrack){ 1190 if(sIndexes[k]<cumTrack){
1191 sprintf(adbQueryResult->Rlist[k], "%s", fileTable+l*O2_FILETABLESIZE); 1191 sprintf(adbQueryResponse->result.Rlist[k], "%s", fileTable+l*O2_FILETABLESIZE);
1192 break; 1192 break;
1193 } 1193 }
1194 } 1194 }
1195 adbQueryResult->Spos[k]=sIndexes[k]+trackTable[l]-cumTrack; 1195 adbQueryResponse->result.Spos[k]=sIndexes[k]+trackTable[l]-cumTrack;
1196 } 1196 }
1197 } 1197 }
1198 1198
1199 // Clean up 1199 // Clean up
1200 if(queryCopy) 1200 if(queryCopy)
1208 } 1208 }
1209 1209
1210 // trackPointQuery 1210 // trackPointQuery
1211 // return the trackNN closest tracks to the query track 1211 // return the trackNN closest tracks to the query track
1212 // uses average of pointNN points per track 1212 // uses average of pointNN points per track
1213 void audioDB::trackPointQuery(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult){ 1213 void audioDB::trackPointQuery(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){
1214 initTables(dbName, 0, inFile); 1214 initTables(dbName, 0, inFile);
1215 1215
1216 // For each input vector, find the closest pointNN matching output vectors and report 1216 // For each input vector, find the closest pointNN matching output vectors and report
1217 unsigned numVectors = (statbuf.st_size-sizeof(int))/(sizeof(double)*dbH->dim); 1217 unsigned numVectors = (statbuf.st_size-sizeof(int))/(sizeof(double)*dbH->dim);
1218 double* query = (double*)(indata+sizeof(int)); 1218 double* query = (double*)(indata+sizeof(int));
1413 if(verbosity>1) { 1413 if(verbosity>1) {
1414 cerr << endl << "processed tracks :" << processedTracks 1414 cerr << endl << "processed tracks :" << processedTracks
1415 << " elapsed time:" << ( tv2.tv_sec*1000 + tv2.tv_usec/1000 ) - ( tv1.tv_sec*1000+tv1.tv_usec/1000 ) << " msec" << endl; 1415 << " elapsed time:" << ( tv2.tv_sec*1000 + tv2.tv_usec/1000 ) - ( tv1.tv_sec*1000+tv1.tv_usec/1000 ) << " msec" << endl;
1416 } 1416 }
1417 1417
1418 if(adbQueryResult==0){ 1418 if(adbQueryResponse==0){
1419 if(verbosity>1) { 1419 if(verbosity>1) {
1420 cerr<<endl; 1420 cerr<<endl;
1421 } 1421 }
1422 // Output answer 1422 // Output answer
1423 // Loop over nearest neighbours 1423 // Loop over nearest neighbours
1425 cout << fileTable+trackIDs[k]*O2_FILETABLESIZE 1425 cout << fileTable+trackIDs[k]*O2_FILETABLESIZE
1426 << " " << trackDistances[k] << " " << trackQIndexes[k] << " " << trackSIndexes[k] << endl; 1426 << " " << trackDistances[k] << " " << trackQIndexes[k] << " " << trackSIndexes[k] << endl;
1427 } 1427 }
1428 else{ // Process Web Services Query 1428 else{ // Process Web Services Query
1429 int listLen = min(trackNN, processedTracks); 1429 int listLen = min(trackNN, processedTracks);
1430 adbQueryResult->__sizeRlist=listLen; 1430 adbQueryResponse->result.__sizeRlist=listLen;
1431 adbQueryResult->__sizeDist=listLen; 1431 adbQueryResponse->result.__sizeDist=listLen;
1432 adbQueryResult->__sizeQpos=listLen; 1432 adbQueryResponse->result.__sizeQpos=listLen;
1433 adbQueryResult->__sizeSpos=listLen; 1433 adbQueryResponse->result.__sizeSpos=listLen;
1434 adbQueryResult->Rlist= new char*[listLen]; 1434 adbQueryResponse->result.Rlist= new char*[listLen];
1435 adbQueryResult->Dist = new double[listLen]; 1435 adbQueryResponse->result.Dist = new double[listLen];
1436 adbQueryResult->Qpos = new unsigned int[listLen]; 1436 adbQueryResponse->result.Qpos = new unsigned int[listLen];
1437 adbQueryResult->Spos = new unsigned int[listLen]; 1437 adbQueryResponse->result.Spos = new unsigned int[listLen];
1438 for(k=0; k<(unsigned)adbQueryResult->__sizeRlist; k++){ 1438 for(k=0; k<(unsigned)adbQueryResponse->result.__sizeRlist; k++){
1439 adbQueryResult->Rlist[k]=new char[O2_MAXFILESTR]; 1439 adbQueryResponse->result.Rlist[k]=new char[O2_MAXFILESTR];
1440 adbQueryResult->Dist[k]=trackDistances[k]; 1440 adbQueryResponse->result.Dist[k]=trackDistances[k];
1441 adbQueryResult->Qpos[k]=trackQIndexes[k]; 1441 adbQueryResponse->result.Qpos[k]=trackQIndexes[k];
1442 adbQueryResult->Spos[k]=trackSIndexes[k]; 1442 adbQueryResponse->result.Spos[k]=trackSIndexes[k];
1443 sprintf(adbQueryResult->Rlist[k], "%s", fileTable+trackIDs[k]*O2_FILETABLESIZE); 1443 sprintf(adbQueryResponse->result.Rlist[k], "%s", fileTable+trackIDs[k]*O2_FILETABLESIZE);
1444 } 1444 }
1445 } 1445 }
1446 1446
1447 1447
1448 // Clean up 1448 // Clean up
1462 1462
1463 // k nearest-neighbor (k-NN) search between query and target tracks 1463 // k nearest-neighbor (k-NN) search between query and target tracks
1464 // efficient implementation based on matched filter 1464 // efficient implementation based on matched filter
1465 // assumes normed shingles 1465 // assumes normed shingles
1466 // outputs distances of retrieved shingles, max retreived = pointNN shingles per per track 1466 // outputs distances of retrieved shingles, max retreived = pointNN shingles per per track
1467 void audioDB::trackSequenceQueryNN(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult){ 1467 void audioDB::trackSequenceQueryNN(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){
1468 1468
1469 initTables(dbName, 0, inFile); 1469 initTables(dbName, 0, inFile);
1470 1470
1471 // For each input vector, find the closest pointNN matching output vectors and report 1471 // For each input vector, find the closest pointNN matching output vectors and report
1472 // we use stdout in this stub version 1472 // we use stdout in this stub version
1912 cerr << endl << "processed tracks :" << processedTracks << " matched tracks: " << successfulTracks << " elapsed time:" 1912 cerr << endl << "processed tracks :" << processedTracks << " matched tracks: " << successfulTracks << " elapsed time:"
1913 << ( tv2.tv_sec*1000 + tv2.tv_usec/1000 ) - ( tv1.tv_sec*1000+tv1.tv_usec/1000 ) << " msec" << endl; 1913 << ( tv2.tv_sec*1000 + tv2.tv_usec/1000 ) - ( tv1.tv_sec*1000+tv1.tv_usec/1000 ) << " msec" << endl;
1914 cerr << "sampleCount: " << sampleCount << " sampleSum: " << sampleSum << " logSampleSum: " << logSampleSum 1914 cerr << "sampleCount: " << sampleCount << " sampleSum: " << sampleSum << " logSampleSum: " << logSampleSum
1915 << " minSample: " << minSample << " maxSample: " << maxSample << endl; 1915 << " minSample: " << minSample << " maxSample: " << maxSample << endl;
1916 } 1916 }
1917 if(adbQueryResult==0){ 1917 if(adbQueryResponse==0){
1918 if(verbosity>1) { 1918 if(verbosity>1) {
1919 cerr<<endl; 1919 cerr<<endl;
1920 } 1920 }
1921 // Output answer 1921 // Output answer
1922 // Loop over nearest neighbours 1922 // Loop over nearest neighbours
1924 cout << fileTable+trackIDs[k]*O2_FILETABLESIZE << " " << trackDistances[k] << " " 1924 cout << fileTable+trackIDs[k]*O2_FILETABLESIZE << " " << trackDistances[k] << " "
1925 << trackQIndexes[k] << " " << trackSIndexes[k] << endl; 1925 << trackQIndexes[k] << " " << trackSIndexes[k] << endl;
1926 } 1926 }
1927 else{ // Process Web Services Query 1927 else{ // Process Web Services Query
1928 int listLen = min(trackNN, processedTracks); 1928 int listLen = min(trackNN, processedTracks);
1929 adbQueryResult->__sizeRlist=listLen; 1929 adbQueryResponse->result.__sizeRlist=listLen;
1930 adbQueryResult->__sizeDist=listLen; 1930 adbQueryResponse->result.__sizeDist=listLen;
1931 adbQueryResult->__sizeQpos=listLen; 1931 adbQueryResponse->result.__sizeQpos=listLen;
1932 adbQueryResult->__sizeSpos=listLen; 1932 adbQueryResponse->result.__sizeSpos=listLen;
1933 adbQueryResult->Rlist= new char*[listLen]; 1933 adbQueryResponse->result.Rlist= new char*[listLen];
1934 adbQueryResult->Dist = new double[listLen]; 1934 adbQueryResponse->result.Dist = new double[listLen];
1935 adbQueryResult->Qpos = new unsigned int[listLen]; 1935 adbQueryResponse->result.Qpos = new unsigned int[listLen];
1936 adbQueryResult->Spos = new unsigned int[listLen]; 1936 adbQueryResponse->result.Spos = new unsigned int[listLen];
1937 for(k=0; k<(unsigned)adbQueryResult->__sizeRlist; k++){ 1937 for(k=0; k<(unsigned)adbQueryResponse->result.__sizeRlist; k++){
1938 adbQueryResult->Rlist[k]=new char[O2_MAXFILESTR]; 1938 adbQueryResponse->result.Rlist[k]=new char[O2_MAXFILESTR];
1939 adbQueryResult->Dist[k]=trackDistances[k]; 1939 adbQueryResponse->result.Dist[k]=trackDistances[k];
1940 adbQueryResult->Qpos[k]=trackQIndexes[k]; 1940 adbQueryResponse->result.Qpos[k]=trackQIndexes[k];
1941 adbQueryResult->Spos[k]=trackSIndexes[k]; 1941 adbQueryResponse->result.Spos[k]=trackSIndexes[k];
1942 sprintf(adbQueryResult->Rlist[k], "%s", fileTable+trackIDs[k]*O2_FILETABLESIZE); 1942 sprintf(adbQueryResponse->result.Rlist[k], "%s", fileTable+trackIDs[k]*O2_FILETABLESIZE);
1943 } 1943 }
1944 } 1944 }
1945 1945
1946 1946
1947 // Clean up 1947 // Clean up
1969 1969
1970 // Radius search between query and target tracks 1970 // Radius search between query and target tracks
1971 // efficient implementation based on matched filter 1971 // efficient implementation based on matched filter
1972 // assumes normed shingles 1972 // assumes normed shingles
1973 // outputs count of retrieved shingles, max retreived = one shingle per query shingle per track 1973 // outputs count of retrieved shingles, max retreived = one shingle per query shingle per track
1974 void audioDB::trackSequenceQueryRad(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult){ 1974 void audioDB::trackSequenceQueryRad(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){
1975 1975
1976 initTables(dbName, 0, inFile); 1976 initTables(dbName, 0, inFile);
1977 1977
1978 // For each input vector, find the closest pointNN matching output vectors and report 1978 // For each input vector, find the closest pointNN matching output vectors and report
1979 // we use stdout in this stub version 1979 // we use stdout in this stub version
2394 << ( tv2.tv_sec*1000 + tv2.tv_usec/1000 ) - ( tv1.tv_sec*1000+tv1.tv_usec/1000 ) << " msec" << endl; 2394 << ( tv2.tv_sec*1000 + tv2.tv_usec/1000 ) - ( tv1.tv_sec*1000+tv1.tv_usec/1000 ) << " msec" << endl;
2395 cerr << "sampleCount: " << sampleCount << " sampleSum: " << sampleSum << " logSampleSum: " << logSampleSum 2395 cerr << "sampleCount: " << sampleCount << " sampleSum: " << sampleSum << " logSampleSum: " << logSampleSum
2396 << " minSample: " << minSample << " maxSample: " << maxSample << endl; 2396 << " minSample: " << minSample << " maxSample: " << maxSample << endl;
2397 } 2397 }
2398 2398
2399 if(adbQueryResult==0){ 2399 if(adbQueryResponse==0){
2400 if(verbosity>1) { 2400 if(verbosity>1) {
2401 cerr<<endl; 2401 cerr<<endl;
2402 } 2402 }
2403 // Output answer 2403 // Output answer
2404 // Loop over nearest neighbours 2404 // Loop over nearest neighbours
2405 for(k=0; k < min(trackNN,successfulTracks); k++) 2405 for(k=0; k < min(trackNN,successfulTracks); k++)
2406 cout << fileTable+trackIDs[k]*O2_FILETABLESIZE << " " << trackDistances[k] << endl; 2406 cout << fileTable+trackIDs[k]*O2_FILETABLESIZE << " " << trackDistances[k] << endl;
2407 } 2407 }
2408 else{ // Process Web Services Query 2408 else{ // Process Web Services Query
2409 int listLen = min(trackNN, processedTracks); 2409 int listLen = min(trackNN, processedTracks);
2410 adbQueryResult->__sizeRlist=listLen; 2410 adbQueryResponse->result.__sizeRlist=listLen;
2411 adbQueryResult->__sizeDist=listLen; 2411 adbQueryResponse->result.__sizeDist=listLen;
2412 adbQueryResult->__sizeQpos=listLen; 2412 adbQueryResponse->result.__sizeQpos=listLen;
2413 adbQueryResult->__sizeSpos=listLen; 2413 adbQueryResponse->result.__sizeSpos=listLen;
2414 adbQueryResult->Rlist= new char*[listLen]; 2414 adbQueryResponse->result.Rlist= new char*[listLen];
2415 adbQueryResult->Dist = new double[listLen]; 2415 adbQueryResponse->result.Dist = new double[listLen];
2416 adbQueryResult->Qpos = new unsigned int[listLen]; 2416 adbQueryResponse->result.Qpos = new unsigned int[listLen];
2417 adbQueryResult->Spos = new unsigned int[listLen]; 2417 adbQueryResponse->result.Spos = new unsigned int[listLen];
2418 for(k=0; k<(unsigned)adbQueryResult->__sizeRlist; k++){ 2418 for(k=0; k<(unsigned)adbQueryResponse->result.__sizeRlist; k++){
2419 adbQueryResult->Rlist[k]=new char[O2_MAXFILESTR]; 2419 adbQueryResponse->result.Rlist[k]=new char[O2_MAXFILESTR];
2420 adbQueryResult->Dist[k]=trackDistances[k]; 2420 adbQueryResponse->result.Dist[k]=trackDistances[k];
2421 adbQueryResult->Qpos[k]=trackQIndexes[k]; 2421 adbQueryResponse->result.Qpos[k]=trackQIndexes[k];
2422 adbQueryResult->Spos[k]=trackSIndexes[k]; 2422 adbQueryResponse->result.Spos[k]=trackSIndexes[k];
2423 sprintf(adbQueryResult->Rlist[k], "%s", fileTable+trackIDs[k]*O2_FILETABLESIZE); 2423 sprintf(adbQueryResponse->result.Rlist[k], "%s", fileTable+trackIDs[k]*O2_FILETABLESIZE);
2424 } 2424 }
2425 } 2425 }
2426 2426
2427 // Clean up 2427 // Clean up
2428 if(trackOffsetTable) 2428 if(trackOffsetTable)
2577 2577
2578 2578
2579 // web services 2579 // web services
2580 2580
2581 // SERVER SIDE 2581 // SERVER SIDE
2582 int adb__status(struct soap* soap, xsd__string dbName, adb__statusResult &adbStatusResult){ 2582 int adb__status(struct soap* soap, xsd__string dbName, adb__statusResponse &adbStatusResponse){
2583 char* const argv[]={"audioDB",COM_STATUS,"-d",dbName}; 2583 char* const argv[]={"audioDB",COM_STATUS,"-d",dbName};
2584 const unsigned argc = 4; 2584 const unsigned argc = 4;
2585 try { 2585 try {
2586 audioDB(argc, argv, &adbStatusResult); 2586 audioDB(argc, argv, &adbStatusResponse);
2587 return SOAP_OK; 2587 return SOAP_OK;
2588 } catch(char *err) { 2588 } catch(char *err) {
2589 soap_receiver_fault(soap, err, ""); 2589 soap_receiver_fault(soap, err, "");
2590 return SOAP_FAULT; 2590 return SOAP_FAULT;
2591 } 2591 }
2592 } 2592 }
2593 2593
2594 // Literal translation of command line to web service 2594 // Literal translation of command line to web service
2595 2595
2596 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){ 2596 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){
2597 char queryType[256]; 2597 char queryType[256];
2598 for(int k=0; k<256; k++) 2598 for(int k=0; k<256; k++)
2599 queryType[k]='\0'; 2599 queryType[k]='\0';
2600 if(qType == O2_POINT_QUERY) 2600 if(qType == O2_POINT_QUERY)
2601 strncpy(queryType, "point", strlen("point")); 2601 strncpy(queryType, "point", strlen("point"));
2644 seqLenStr 2644 seqLenStr
2645 }; 2645 };
2646 2646
2647 const unsigned argc = 19; 2647 const unsigned argc = 19;
2648 try { 2648 try {
2649 audioDB(argc, (char* const*)argv, &adbQueryResult); 2649 audioDB(argc, (char* const*)argv, &adbQueryResponse);
2650 return SOAP_OK; 2650 return SOAP_OK;
2651 } catch (char *err) { 2651 } catch (char *err) {
2652 soap_receiver_fault(soap, err, ""); 2652 soap_receiver_fault(soap, err, "");
2653 return SOAP_FAULT; 2653 return SOAP_FAULT;
2654 } 2654 }