Mercurial > hg > audiodb
changeset 144:6ae986868114 powertable
Hack in power table filling for single track insert.
author | mas01cr |
---|---|
date | Tue, 30 Oct 2007 15:13:01 +0000 |
parents | 9bcece53de9e |
children | 7162a8e9ab12 |
files | audioDB.cpp audioDB.h |
diffstat | 2 files changed, 41 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/audioDB.cpp Tue Oct 30 14:39:12 2007 +0000 +++ b/audioDB.cpp Tue Oct 30 15:13:01 2007 +0000 @@ -234,6 +234,15 @@ usingTimes=1; } } + if (args_info.power_given) { + powerFileName = args_info.power_arg; + if (strlen(powerFileName) > 0) { + if (!(powerfd = open(powerFileName, O_RDONLY))) { + error("Could not open power file for reading", powerFileName, "open"); + } + usingPower = 1; + } + } return 0; } @@ -556,6 +565,9 @@ assert(timesdata+numVectors<l2normTable); insertTimeStamps(numVectors, timesFile, timesdata); + double *powerdata = powerTable + timesoffset; + insertPowerData(numVectors, powerfd, powerdata); + // Increment file count dbH->numFiles++; @@ -641,6 +653,28 @@ } } +void audioDB::insertPowerData(unsigned numVectors, int powerfd, double *powerdata) { + if (usingPower) { + int one; + unsigned int count; + + count = read(powerfd, &one, sizeof(unsigned int)); + if (count != sizeof(unsigned int)) { + error("powerfd read failed", "int", "read"); + } + if (one != 1) { + error("dimensionality of power file not 1", powerFileName); + } + + // FIXME: should check that the powerfile is the right size for + // this. -- CSR, 2007-10-30 + count = read(powerfd, powerdata, numVectors * sizeof(double)); + if (count != numVectors * sizeof(double)) { + error("powerfd read failed", "double", "read"); + } + } +} + void audioDB::batchinsert(const char* dbName, const char* inFile) { initDBHeader(dbName, true);
--- a/audioDB.h Tue Oct 30 14:39:12 2007 +0000 +++ b/audioDB.h Tue Oct 30 15:13:01 2007 +0000 @@ -125,6 +125,8 @@ const char *output; const char *timesFileName; ifstream *timesFile; + const char *powerFileName; + int powerfd; int dbfid; int infid; @@ -154,6 +156,7 @@ unsigned queryPoint; unsigned usingQueryPoint; unsigned usingTimes; + unsigned usingPower; unsigned isClient; unsigned isServer; unsigned port; @@ -176,6 +179,7 @@ void unitNorm(double* X, unsigned d, unsigned n, double* qNorm); void unitNormAndInsertL2(double* X, unsigned dim, unsigned n, unsigned append); void insertTimeStamps(unsigned n, ifstream* timesFile, double* timesdata); + void insertPowerData(unsigned n, int powerfd, double *powerdata); unsigned getKeyPos(char* key); public: @@ -214,6 +218,8 @@ output(0), \ timesFileName(0), \ timesFile(0), \ + powerFileName(0), \ + powerfd(0), \ dbfid(0), \ infid(0), \ db(0), \ @@ -235,6 +241,7 @@ queryPoint(0), \ usingQueryPoint(0), \ usingTimes(0), \ + usingPower(0), \ isClient(0), \ isServer(0), \ port(0), \