comparison audioDB.cpp @ 12:a206d3e91f8b

fixed keyList logic (in sequence match only) to avoid halting just because the database's last key was visited before end of keylist sequence.
author mas01mc
date Thu, 26 Jul 2007 14:08:11 +0000
parents 3d134836ea14
children c633f3819a49
comparison
equal deleted inserted replaced
11:3d134836ea14 12:a206d3e91f8b
815 // CLEAN UP 815 // CLEAN UP
816 munmap(indata,statbuf.st_size); 816 munmap(indata,statbuf.st_size);
817 close(infid); 817 close(infid);
818 munmap(db,O2_DEFAULTDBSIZE); 818 munmap(db,O2_DEFAULTDBSIZE);
819 }while(!filesIn->eof()); 819 }while(!filesIn->eof());
820
821 // mmap the database file
822 if ((db = (char*) mmap(0, O2_DEFAULTDBSIZE, PROT_READ | PROT_WRITE,
823 MAP_SHARED, dbfid, 0)) == (caddr_t) -1)
824 error("mmap error for creating database");
820 825
821 if(verbosity) 826 if(verbosity)
822 cerr << COM_BATCHINSERT << " " << dbName << " " << totalVectors << " vectors " 827 cerr << COM_BATCHINSERT << " " << dbName << " " << totalVectors << " vectors "
823 << totalVectors*dbH->dim*sizeof(double) << " bytes." << endl; 828 << totalVectors*dbH->dim*sizeof(double) << " bytes." << endl;
824 829
825 // Report status 830 // Report status
826 status(dbName); 831 status(dbName);
827 832
833 munmap(db,O2_DEFAULTDBSIZE);
828 } 834 }
829 835
830 void audioDB::ws_status(const char*dbName, char* hostport){ 836 void audioDB::ws_status(const char*dbName, char* hostport){
831 struct soap soap; 837 struct soap soap;
832 int adbStatusResult; 838 int adbStatusResult;
1231 for(seg=0 ; seg < dbH->numFiles ; seg++, processedSegs++){ 1237 for(seg=0 ; seg < dbH->numFiles ; seg++, processedSegs++){
1232 if(segFile){ 1238 if(segFile){
1233 if(!segFile->eof()){ 1239 if(!segFile->eof()){
1234 //*segFile>>seg; 1240 //*segFile>>seg;
1235 segFile->getline(nextKey,MAXSTR); 1241 segFile->getline(nextKey,MAXSTR);
1242 if(verbosity>3){
1243 cerr << nextKey << endl;
1244 cerr.flush();
1245 }
1236 seg=getKeyPos(nextKey); 1246 seg=getKeyPos(nextKey);
1237 } 1247 }
1238 else 1248 else
1239 break; 1249 break;
1240 } 1250 }
1453 *pn+=*ps++; 1463 *pn+=*ps++;
1454 *pn/=segTable[i]-sequenceLength+1; 1464 *pn/=segTable[i]-sequenceLength+1;
1455 SILENCE_THRESH+=*pn; 1465 SILENCE_THRESH+=*pn;
1456 processedSegs++; 1466 processedSegs++;
1457 } 1467 }
1468 ps = sNorm + segTable[i];
1458 } 1469 }
1459 if(verbosity>1) 1470 if(verbosity>1)
1460 cerr << "processedSegs: " << processedSegs << endl; 1471 cerr << "processedSegs: " << processedSegs << endl;
1461 SILENCE_THRESH/=processedSegs; 1472 SILENCE_THRESH/=processedSegs;
1462 USE_THRESH=1; // Turn thresholding on 1473 USE_THRESH=1; // Turn thresholding on
1588 segOffsetTable[k]=cumSeg; 1599 segOffsetTable[k]=cumSeg;
1589 cumSeg+=segTable[k]*dbH->dim; 1600 cumSeg+=segTable[k]*dbH->dim;
1590 } 1601 }
1591 1602
1592 char nextKey [MAXSTR]; 1603 char nextKey [MAXSTR];
1593 for(seg=0 ; seg < dbH->numFiles ; seg++, processedSegs++){ 1604 for(processedSegs=0, seg=0 ; processedSegs < dbH->numFiles ; seg++, processedSegs++){
1594 1605
1595 // get segID from file if using a control file 1606 // get segID from file if using a control file
1596 if(segFile){ 1607 if(segFile){
1597 if(!segFile->eof()){ 1608 if(!segFile->eof()){
1598 segFile->getline(nextKey,MAXSTR); 1609 segFile->getline(nextKey,MAXSTR);
1599 seg=getKeyPos(nextKey); 1610 seg=getKeyPos(nextKey);
1600 } 1611 }
1601 else 1612 else
1602 break; 1613 break;
1603 } 1614 }
1615
1604 segOffset=segOffsetTable[seg]; // numDoubles offset 1616 segOffset=segOffsetTable[seg]; // numDoubles offset
1605 segIndexOffset=segOffset/dbH->dim; // numVectors offset 1617 segIndexOffset=segOffset/dbH->dim; // numVectors offset
1606 1618
1607 if(sequenceLength<segTable[seg]){ // test for short sequences 1619 if(sequenceLength<segTable[seg]){ // test for short sequences
1608 1620
1659 spd+=HOP_SIZE; 1671 spd+=HOP_SIZE;
1660 } 1672 }
1661 } 1673 }
1662 } 1674 }
1663 1675
1664 if(verbosity>3){ 1676 if(verbosity>3 && usingTimes){
1665 cerr << "meanQdur=" << meanQdur << " meanDBdur=" << meanDBdur[seg] << endl; 1677 cerr << "meanQdur=" << meanQdur << " meanDBdur=" << meanDBdur[seg] << endl;
1666 cerr.flush(); 1678 cerr.flush();
1667 } 1679 }
1668 1680
1669 if(!usingTimes || 1681 if(!usingTimes ||
1670 (usingTimes 1682 (usingTimes
1671 && fabs(meanDBdur[seg]-meanQdur)<meanQdur*timesTol)){ 1683 && fabs(meanDBdur[seg]-meanQdur)<meanQdur*timesTol)){
1672 1684
1673 if(verbosity>3){ 1685 if(verbosity>3 && usingTimes){
1674 cerr << "within duration tolerance." << endl; 1686 cerr << "within duration tolerance." << endl;
1675 cerr.flush(); 1687 cerr.flush();
1676 } 1688 }
1677 1689
1678 // Search for minimum distance by shingles (concatenated vectors) 1690 // Search for minimum distance by shingles (concatenated vectors)
1683 // Power test 1695 // Power test
1684 if(!USE_THRESH || 1696 if(!USE_THRESH ||
1685 // Threshold on mean L2 of Q and S sequences 1697 // Threshold on mean L2 of Q and S sequences
1686 (USE_THRESH && qNorm[j]>SILENCE_THRESH && sNorm[k]>SILENCE_THRESH && 1698 (USE_THRESH && qNorm[j]>SILENCE_THRESH && sNorm[k]>SILENCE_THRESH &&
1687 // Are both query and target windows above mean energy? 1699 // Are both query and target windows above mean energy?
1688 (qNorm[j]>qMeanL2*.25 && sNorm[k]>sMeanL2[seg]*.25 && diffL2 < DIFF_THRESH ))) 1700 (qNorm[j]>qMeanL2 && sNorm[k]>sMeanL2[seg] && diffL2 < DIFF_THRESH )))
1689 thisDist=DD[j][k]*oneOverWL; 1701 thisDist=DD[j][k]*oneOverWL;
1690 else 1702 else
1691 thisDist=0.0; 1703 thisDist=0.0;
1692 1704
1693 // NBest match algorithm 1705 // NBest match algorithm
1713 thisDist=0.0; 1725 thisDist=0.0;
1714 for(m=0; m<pointNN; m++) 1726 for(m=0; m<pointNN; m++)
1715 thisDist+=distances[m]; 1727 thisDist+=distances[m];
1716 thisDist/=pointNN; 1728 thisDist/=pointNN;
1717 1729
1730 // Let's see the distances then...
1731 if(verbosity>3)
1732 cerr << "d[" << fileTable+seg*O2_FILETABLESIZE << "]=" << thisDist << endl;
1733
1718 // All the seg stuff goes here 1734 // All the seg stuff goes here
1719 n=segNN; 1735 n=segNN;
1720 while(n--){ 1736 while(n--){
1721 if(thisDist>=segDistances[n]){ 1737 if(thisDist>=segDistances[n]){
1722 if((n==0 || thisDist<=segDistances[n-1])){ 1738 if((n==0 || thisDist<=segDistances[n-1])){