Mercurial > hg > audiodb
comparison audioDB.cpp @ 145:7162a8e9ab12 powertable
Hack in batchinsert support for power.
author | mas01cr |
---|---|
date | Tue, 30 Oct 2007 15:28:48 +0000 |
parents | 6ae986868114 |
children | c9c508be69b3 |
comparison
equal
deleted
inserted
replaced
144:6ae986868114 | 145:7162a8e9ab12 |
---|---|
266 timesFileName=args_info.timesList_arg; | 266 timesFileName=args_info.timesList_arg; |
267 if(strlen(timesFileName)>0){ | 267 if(strlen(timesFileName)>0){ |
268 if(!(timesFile = new ifstream(timesFileName,ios::in))) | 268 if(!(timesFile = new ifstream(timesFileName,ios::in))) |
269 error("Could not open timesList file for reading", timesFileName); | 269 error("Could not open timesList file for reading", timesFileName); |
270 usingTimes=1; | 270 usingTimes=1; |
271 } | |
272 } | |
273 if(args_info.powerList_given){ | |
274 powerFileName=args_info.powerList_arg; | |
275 if(strlen(powerFileName)>0){ | |
276 if(!(powerFile = new ifstream(powerFileName,ios::in))) | |
277 error("Could not open powerList file for reading", powerFileName); | |
278 usingPower=1; | |
271 } | 279 } |
272 } | 280 } |
273 return 0; | 281 return 0; |
274 } | 282 } |
275 | 283 |
682 if(!key) | 690 if(!key) |
683 key=inFile; | 691 key=inFile; |
684 ifstream *filesIn = 0; | 692 ifstream *filesIn = 0; |
685 ifstream *keysIn = 0; | 693 ifstream *keysIn = 0; |
686 ifstream* thisTimesFile = 0; | 694 ifstream* thisTimesFile = 0; |
695 int thispowerfd = 0; | |
687 | 696 |
688 if(!(filesIn = new ifstream(inFile))) | 697 if(!(filesIn = new ifstream(inFile))) |
689 error("Could not open batch in file", inFile); | 698 error("Could not open batch in file", inFile); |
690 if(key && key!=inFile) | 699 if(key && key!=inFile) |
691 if(!(keysIn = new ifstream(key))) | 700 if(!(keysIn = new ifstream(key))) |
696 | 705 |
697 unsigned totalVectors=0; | 706 unsigned totalVectors=0; |
698 char *thisKey = new char[MAXSTR]; | 707 char *thisKey = new char[MAXSTR]; |
699 char *thisFile = new char[MAXSTR]; | 708 char *thisFile = new char[MAXSTR]; |
700 char *thisTimesFileName = new char[MAXSTR]; | 709 char *thisTimesFileName = new char[MAXSTR]; |
710 char *thisPowerFileName = new char[MAXSTR]; | |
701 | 711 |
702 do{ | 712 do{ |
703 filesIn->getline(thisFile,MAXSTR); | 713 filesIn->getline(thisFile,MAXSTR); |
704 if(key && key!=inFile) | 714 if(key && key!=inFile) |
705 keysIn->getline(thisKey,MAXSTR); | 715 keysIn->getline(thisKey,MAXSTR); |
706 else | 716 else |
707 thisKey = thisFile; | 717 thisKey = thisFile; |
708 if(usingTimes) | 718 if(usingTimes) |
709 timesFile->getline(thisTimesFileName,MAXSTR); | 719 timesFile->getline(thisTimesFileName,MAXSTR); |
720 if(usingPower) | |
721 powerFile->getline(thisPowerFileName, MAXSTR); | |
710 | 722 |
711 if(filesIn->eof()) | 723 if(filesIn->eof()) |
712 break; | 724 break; |
713 | 725 |
714 // open the input file | 726 // open the input file |
762 if(!numVectors){ | 774 if(!numVectors){ |
763 if(verbosity) { | 775 if(verbosity) { |
764 cerr << "Warning: ignoring zero-length feature vector file:" << thisKey << endl; | 776 cerr << "Warning: ignoring zero-length feature vector file:" << thisKey << endl; |
765 } | 777 } |
766 } | 778 } |
767 else{ | 779 else{ |
768 if(usingTimes){ | 780 if(usingTimes){ |
769 if(timesFile->eof()) | 781 if(timesFile->eof()) |
770 error("not enough timestamp files in timesList"); | 782 error("not enough timestamp files in timesList"); |
771 thisTimesFile=new ifstream(thisTimesFileName,ios::in); | 783 thisTimesFile=new ifstream(thisTimesFileName,ios::in); |
772 if(!thisTimesFile->is_open()) | 784 if(!thisTimesFile->is_open()) |
777 assert(timesdata+numVectors<l2normTable); | 789 assert(timesdata+numVectors<l2normTable); |
778 insertTimeStamps(numVectors,thisTimesFile,timesdata); | 790 insertTimeStamps(numVectors,thisTimesFile,timesdata); |
779 if(thisTimesFile) | 791 if(thisTimesFile) |
780 delete thisTimesFile; | 792 delete thisTimesFile; |
781 } | 793 } |
782 | 794 |
795 if (usingPower) { | |
796 if(powerFile->eof()) { | |
797 error("not enough power files in powerList", powerFileName); | |
798 } | |
799 thispowerfd = open(thisPowerFileName, O_RDONLY); | |
800 if (thispowerfd < 0) { | |
801 error("failed to open power file", thisPowerFileName); | |
802 } | |
803 unsigned insertoffset = dbH->length; | |
804 unsigned poweroffset = insertoffset / (dbH->dim * sizeof(double)); | |
805 double *powerdata = powerTable + poweroffset; | |
806 insertPowerData(numVectors, thispowerfd, powerdata); | |
807 if (0 < thispowerfd) { | |
808 close(thispowerfd); | |
809 } | |
810 } | |
783 strncpy(fileTable + dbH->numFiles*O2_FILETABLESIZE, thisKey, strlen(thisKey)); | 811 strncpy(fileTable + dbH->numFiles*O2_FILETABLESIZE, thisKey, strlen(thisKey)); |
784 | 812 |
785 unsigned insertoffset = dbH->length;// Store current state | 813 unsigned insertoffset = dbH->length;// Store current state |
786 | 814 |
787 // Increment file count | 815 // Increment file count |