comparison audioDB.cpp @ 144:6ae986868114 powertable

Hack in power table filling for single track insert.
author mas01cr
date Tue, 30 Oct 2007 15:13:01 +0000
parents c74048e9b569
children 7162a8e9ab12
comparison
equal deleted inserted replaced
143:9bcece53de9e 144:6ae986868114
232 if(!(timesFile = new ifstream(timesFileName,ios::in))) 232 if(!(timesFile = new ifstream(timesFileName,ios::in)))
233 error("Could not open times file for reading", timesFileName); 233 error("Could not open times file for reading", timesFileName);
234 usingTimes=1; 234 usingTimes=1;
235 } 235 }
236 } 236 }
237 if (args_info.power_given) {
238 powerFileName = args_info.power_arg;
239 if (strlen(powerFileName) > 0) {
240 if (!(powerfd = open(powerFileName, O_RDONLY))) {
241 error("Could not open power file for reading", powerFileName, "open");
242 }
243 usingPower = 1;
244 }
245 }
237 return 0; 246 return 0;
238 } 247 }
239 248
240 if(args_info.BATCHINSERT_given){ 249 if(args_info.BATCHINSERT_given){
241 command=COM_BATCHINSERT; 250 command=COM_BATCHINSERT;
553 // Check times status and insert times from file 562 // Check times status and insert times from file
554 unsigned timesoffset=insertoffset/(dbH->dim*sizeof(double)); 563 unsigned timesoffset=insertoffset/(dbH->dim*sizeof(double));
555 double* timesdata=timesTable+timesoffset; 564 double* timesdata=timesTable+timesoffset;
556 assert(timesdata+numVectors<l2normTable); 565 assert(timesdata+numVectors<l2normTable);
557 insertTimeStamps(numVectors, timesFile, timesdata); 566 insertTimeStamps(numVectors, timesFile, timesdata);
567
568 double *powerdata = powerTable + timesoffset;
569 insertPowerData(numVectors, powerfd, powerdata);
558 570
559 // Increment file count 571 // Increment file count
560 dbH->numFiles++; 572 dbH->numFiles++;
561 573
562 // Update Header information 574 // Update Header information
637 if(verbosity>2) { 649 if(verbosity>2) {
638 cerr << "numtimes: " << numtimes << endl; 650 cerr << "numtimes: " << numtimes << endl;
639 } 651 }
640 } 652 }
641 } 653 }
654 }
655
656 void audioDB::insertPowerData(unsigned numVectors, int powerfd, double *powerdata) {
657 if (usingPower) {
658 int one;
659 unsigned int count;
660
661 count = read(powerfd, &one, sizeof(unsigned int));
662 if (count != sizeof(unsigned int)) {
663 error("powerfd read failed", "int", "read");
664 }
665 if (one != 1) {
666 error("dimensionality of power file not 1", powerFileName);
667 }
668
669 // FIXME: should check that the powerfile is the right size for
670 // this. -- CSR, 2007-10-30
671 count = read(powerfd, powerdata, numVectors * sizeof(double));
672 if (count != numVectors * sizeof(double)) {
673 error("powerfd read failed", "double", "read");
674 }
675 }
642 } 676 }
643 677
644 void audioDB::batchinsert(const char* dbName, const char* inFile) { 678 void audioDB::batchinsert(const char* dbName, const char* inFile) {
645 679
646 initDBHeader(dbName, true); 680 initDBHeader(dbName, true);