comparison audioDB.h @ 243:15b8ff55ea5b audiodb-debian

Merge trunk changes -r290:313 into audiodb-debian branch. (+ new debian/changelog)
author mas01cr
date Fri, 14 Dec 2007 14:41:37 +0000
parents b83f0fd53a2c
children abfb26e08d9c
comparison
equal deleted inserted replaced
226:b83f0fd53a2c 243:15b8ff55ea5b
13 #include <float.h> 13 #include <float.h>
14 #include <signal.h> 14 #include <signal.h>
15 15
16 // includes for web services 16 // includes for web services
17 #include "soapH.h" 17 #include "soapH.h"
18 #include "adb.nsmap"
19 #include "cmdline.h" 18 #include "cmdline.h"
20 19
21 #define MAXSTR 512 20 #define MAXSTR 512
22 21
23 // Databse PRIMARY commands 22 // Databse PRIMARY commands
54 53
55 #define O2_DEFAULT_POINTNN (10U) 54 #define O2_DEFAULT_POINTNN (10U)
56 #define O2_DEFAULT_TRACKNN (10U) 55 #define O2_DEFAULT_TRACKNN (10U)
57 56
58 #define O2_DEFAULTDBSIZE (2000000000) // 2GB table size 57 #define O2_DEFAULTDBSIZE (2000000000) // 2GB table size
59 //#define O2_DEFAULTDBSIZE (1000000000U) // 1GB table size 58
60 59 #define O2_MAXFILES (20000U)
61 //#define O2_MAXFILES (1000000)
62 #define O2_MAXFILES (20000U) // 10,000 files
63 #define O2_MAXFILESTR (256U) 60 #define O2_MAXFILESTR (256U)
64 #define O2_FILETABLESIZE (O2_MAXFILESTR) 61 #define O2_FILETABLESIZE (O2_MAXFILESTR)
65 #define O2_TRACKTABLESIZE (sizeof(unsigned)) 62 #define O2_TRACKTABLESIZE (sizeof(unsigned))
66 #define O2_HEADERSIZE (sizeof(dbTableHeaderT)) 63 #define O2_HEADERSIZE (sizeof(dbTableHeaderT))
67 #define O2_MEANNUMVECTORS (1000U) 64 #define O2_MEANNUMVECTORS (1000U)
91 #define ALIGN_PAGE_UP(x) ((x) + (getpagesize()-1) & ~(getpagesize()-1)) 88 #define ALIGN_PAGE_UP(x) ((x) + (getpagesize()-1) & ~(getpagesize()-1))
92 #define ALIGN_PAGE_DOWN(x) ((x) & ~(getpagesize()-1)) 89 #define ALIGN_PAGE_DOWN(x) ((x) & ~(getpagesize()-1))
93 90
94 #define ENSURE_STRING(x) ((x) ? (x) : "") 91 #define ENSURE_STRING(x) ((x) ? (x) : "")
95 92
96 using namespace std; 93 #define CHECKED_MMAP(type, var, start, length) \
94 { void *tmp = mmap(0, length, (PROT_READ | (forWrite ? PROT_WRITE : 0)), MAP_SHARED, dbfid, (start)); \
95 if(tmp == (void *) -1) { \
96 error("mmap error for db table", #var, "mmap"); \
97 } \
98 var = (type) tmp; \
99 }
100
101 #define VERB_LOG(vv, ...) \
102 if(verbosity > vv) { \
103 fprintf(stderr, __VA_ARGS__); \
104 fflush(stderr); \
105 }
97 106
98 typedef struct dbTableHeader { 107 typedef struct dbTableHeader {
99 uint32_t magic; 108 uint32_t magic;
100 uint32_t version; 109 uint32_t version;
101 uint32_t numFiles; 110 uint32_t numFiles;
110 off_t timesTableOffset; 119 off_t timesTableOffset;
111 off_t powerTableOffset; 120 off_t powerTableOffset;
112 off_t dbSize; 121 off_t dbSize;
113 } dbTableHeaderT, *dbTableHeaderPtr; 122 } dbTableHeaderT, *dbTableHeaderPtr;
114 123
124 class Reporter;
115 125
116 class audioDB{ 126 class audioDB{
117 127
118 private: 128 private:
119 gengetopt_args_info args_info; 129 gengetopt_args_info args_info;
121 const char *dbName; 131 const char *dbName;
122 const char *inFile; 132 const char *inFile;
123 const char *hostport; 133 const char *hostport;
124 const char *key; 134 const char *key;
125 const char* trackFileName; 135 const char* trackFileName;
126 ifstream *trackFile; 136 std::ifstream *trackFile;
127 const char *command; 137 const char *command;
128 const char *output; 138 const char *output;
129 const char *timesFileName; 139 const char *timesFileName;
130 ifstream *timesFile; 140 std::ifstream *timesFile;
131 const char *powerFileName; 141 const char *powerFileName;
132 ifstream *powerFile; 142 std::ifstream *powerFile;
133 int powerfd; 143 int powerfd;
134 144
135 int dbfid; 145 int dbfid;
136 bool forWrite; 146 bool forWrite;
137 int infid; 147 int infid;
143 char *fileTable; 153 char *fileTable;
144 unsigned* trackTable; 154 unsigned* trackTable;
145 double* dataBuf; 155 double* dataBuf;
146 double* inBuf; 156 double* inBuf;
147 double* l2normTable; 157 double* l2normTable;
148 double* qNorm;
149 double* sNorm;
150 double* timesTable; 158 double* timesTable;
151 double* powerTable; 159 double* powerTable;
152 160
153 size_t fileTableLength; 161 size_t fileTableLength;
154 size_t trackTableLength; 162 size_t trackTableLength;
163 unsigned queryType; // point queries default 171 unsigned queryType; // point queries default
164 unsigned pointNN; // how many point NNs ? 172 unsigned pointNN; // how many point NNs ?
165 unsigned trackNN; // how many track NNs ? 173 unsigned trackNN; // how many track NNs ?
166 unsigned sequenceLength; 174 unsigned sequenceLength;
167 unsigned sequenceHop; 175 unsigned sequenceHop;
176 bool normalizedDistance;
168 unsigned queryPoint; 177 unsigned queryPoint;
169 unsigned usingQueryPoint; 178 unsigned usingQueryPoint;
170 unsigned usingTimes; 179 unsigned usingTimes;
171 unsigned usingPower; 180 unsigned usingPower;
172 unsigned isClient; 181 unsigned isClient;
185 struct timeval tv1; 194 struct timeval tv1;
186 struct timeval tv2; 195 struct timeval tv2;
187 196
188 // private methods 197 // private methods
189 void error(const char* a, const char* b = "", const char *sysFunc = 0); 198 void error(const char* a, const char* b = "", const char *sysFunc = 0);
190 void pointQuery(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse=0);
191 void trackPointQuery(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse=0);
192 void sequence_sum(double *buffer, int length, int seqlen); 199 void sequence_sum(double *buffer, int length, int seqlen);
193 void sequence_sqrt(double *buffer, int length, int seqlen); 200 void sequence_sqrt(double *buffer, int length, int seqlen);
194 void sequence_average(double *buffer, int length, int seqlen); 201 void sequence_average(double *buffer, int length, int seqlen);
195 202
196 void trackSequenceQueryNN(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse=0); 203 void initialize_arrays(int track, unsigned int numVectors, double *query, double *data_buffer, double **D, double **DD);
197 void trackSequenceQueryRad(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse=0); 204 void delete_arrays(int track, unsigned int numVectors, double **D, double **DD);
205 void read_data(int track, double **data_buffer_p, size_t *data_buffer_size_p);
206 void set_up_query(double **qp, double **vqp, double **qnp, double **vqnp, double **qpp, double **vqpp, double *mqdp, unsigned int *nvp);
207 void set_up_db(double **snp, double **vsnp, double **spp, double **vspp, double **mddp, unsigned int *dvp);
208 void query_loop(const char* dbName, const char* inFile, Reporter *reporter);
198 209
199 void initDBHeader(const char *dbName); 210 void initDBHeader(const char *dbName);
200 void initInputFile(const char *inFile); 211 void initInputFile(const char *inFile);
201 void initTables(const char* dbName, const char* inFile); 212 void initTables(const char* dbName, const char* inFile);
202 void unitNorm(double* X, unsigned d, unsigned n, double* qNorm); 213 void unitNorm(double* X, unsigned d, unsigned n, double* qNorm);
203 void unitNormAndInsertL2(double* X, unsigned dim, unsigned n, unsigned append); 214 void unitNormAndInsertL2(double* X, unsigned dim, unsigned n, unsigned append);
204 void insertTimeStamps(unsigned n, ifstream* timesFile, double* timesdata); 215 void insertTimeStamps(unsigned n, std::ifstream* timesFile, double* timesdata);
205 void insertPowerData(unsigned n, int powerfd, double *powerdata); 216 void insertPowerData(unsigned n, int powerfd, double *powerdata);
206 unsigned getKeyPos(char* key); 217 unsigned getKeyPos(char* key);
207 public: 218 public:
208 219
209 audioDB(const unsigned argc, char* const argv[]); 220 audioDB(const unsigned argc, char* const argv[]);
256 dbH(0), \ 267 dbH(0), \
257 fileTable(0), \ 268 fileTable(0), \
258 trackTable(0), \ 269 trackTable(0), \
259 dataBuf(0), \ 270 dataBuf(0), \
260 l2normTable(0), \ 271 l2normTable(0), \
261 qNorm(0), \
262 timesTable(0), \ 272 timesTable(0), \
263 fileTableLength(0), \ 273 fileTableLength(0), \
264 trackTableLength(0), \ 274 trackTableLength(0), \
265 dataBufLength(0), \ 275 dataBufLength(0), \
266 timesTableLength(0), \ 276 timesTableLength(0), \
271 queryType(O2_POINT_QUERY), \ 281 queryType(O2_POINT_QUERY), \
272 pointNN(O2_DEFAULT_POINTNN), \ 282 pointNN(O2_DEFAULT_POINTNN), \
273 trackNN(O2_DEFAULT_TRACKNN), \ 283 trackNN(O2_DEFAULT_TRACKNN), \
274 sequenceLength(16), \ 284 sequenceLength(16), \
275 sequenceHop(1), \ 285 sequenceHop(1), \
286 normalizedDistance(true), \
276 queryPoint(0), \ 287 queryPoint(0), \
277 usingQueryPoint(0), \ 288 usingQueryPoint(0), \
278 usingTimes(0), \ 289 usingTimes(0), \
279 usingPower(0), \ 290 usingPower(0), \
280 isClient(0), \ 291 isClient(0), \