mas01mc@292
|
1 #ifndef __AUDIODB_H_
|
mas01mc@292
|
2 #define __AUDIODB_H_
|
mas01mc@292
|
3
|
mas01cr@0
|
4 #include <stdio.h>
|
mas01cr@0
|
5 #include <stdlib.h>
|
mas01cr@0
|
6 #include <sys/types.h>
|
mas01cr@0
|
7 #include <sys/stat.h>
|
mas01cr@0
|
8 #include <sys/mman.h>
|
mas01cr@0
|
9 #include <fcntl.h>
|
mas01cr@0
|
10 #include <string.h>
|
mas01cr@0
|
11 #include <iostream>
|
mas01cr@0
|
12 #include <fstream>
|
mas01cr@302
|
13 #include <set>
|
mas01cr@302
|
14 #include <string>
|
mas01cr@0
|
15 #include <math.h>
|
mas01cr@0
|
16 #include <sys/time.h>
|
mas01cr@0
|
17 #include <assert.h>
|
mas01cr@62
|
18 #include <float.h>
|
mas01cr@104
|
19 #include <signal.h>
|
mas01cr@280
|
20 #include <gsl/gsl_rng.h>
|
mas01cr@0
|
21
|
mas01mc@292
|
22 // includes for LSH indexing
|
mas01mc@292
|
23 #include "ReporterBase.h"
|
mas01mc@292
|
24 #include "lshlib.h"
|
mas01mc@292
|
25
|
mas01cr@0
|
26 // includes for web services
|
mas01cr@0
|
27 #include "soapH.h"
|
mas01cr@0
|
28 #include "cmdline.h"
|
mas01cr@0
|
29
|
mas01cr@0
|
30 #define MAXSTR 512
|
mas01cr@0
|
31
|
mas01cr@0
|
32 // Databse PRIMARY commands
|
mas01cr@0
|
33 #define COM_CREATE "--NEW"
|
mas01cr@0
|
34 #define COM_INSERT "--INSERT"
|
mas01cr@0
|
35 #define COM_BATCHINSERT "--BATCHINSERT"
|
mas01cr@0
|
36 #define COM_QUERY "--QUERY"
|
mas01cr@0
|
37 #define COM_STATUS "--STATUS"
|
mas01cr@0
|
38 #define COM_L2NORM "--L2NORM"
|
mas01cr@193
|
39 #define COM_POWER "--POWER"
|
mas01cr@0
|
40 #define COM_DUMP "--DUMP"
|
mas01cr@0
|
41 #define COM_SERVER "--SERVER"
|
mas01mc@292
|
42 #define COM_INDEX "--INDEX"
|
mas01cr@280
|
43 #define COM_SAMPLE "--SAMPLE"
|
mas01cr@0
|
44
|
mas01cr@0
|
45 // parameters
|
mas01cr@0
|
46 #define COM_CLIENT "--client"
|
mas01cr@0
|
47 #define COM_DATABASE "--database"
|
mas01cr@0
|
48 #define COM_QTYPE "--qtype"
|
mas01cr@0
|
49 #define COM_SEQLEN "--sequencelength"
|
mas01cr@0
|
50 #define COM_SEQHOP "--sequencehop"
|
mas01cr@0
|
51 #define COM_POINTNN "--pointnn"
|
mas01mc@307
|
52 #define COM_RADIUS "--radius"
|
mas01mc@18
|
53 #define COM_TRACKNN "--resultlength"
|
mas01cr@0
|
54 #define COM_QPOINT "--qpoint"
|
mas01cr@0
|
55 #define COM_FEATURES "--features"
|
mas01cr@0
|
56 #define COM_QUERYKEY "--key"
|
mas01cr@0
|
57 #define COM_KEYLIST "--keyList"
|
mas01cr@0
|
58 #define COM_TIMES "--times"
|
mas01cr@193
|
59 #define COM_QUERYPOWER "--power"
|
mas01cr@193
|
60 #define COM_RELATIVE_THRESH "--relative-threshold"
|
mas01cr@193
|
61 #define COM_ABSOLUTE_THRESH "--absolute-threshold"
|
mas01mc@310
|
62 #define COM_EXHAUSTIVE "--exhaustive"
|
mas01mc@310
|
63 #define COM_LSH_EXACT "--lsh_exact"
|
mas01cr@0
|
64
|
mas01mc@314
|
65 // Because LSH returns NN with P(1)<1 we want to return exact
|
mas01mc@314
|
66 // points above this boundary.
|
mas01mc@314
|
67 // Because we work in Radius^2 units,
|
mas01mc@314
|
68 // The sqrt of this number is the multiplier on the radius
|
mas01mc@314
|
69
|
mas01mc@314
|
70 #define O2_LSH_EXACT_MULT 9
|
mas01mc@314
|
71
|
mas01cr@108
|
72 #define O2_OLD_MAGIC ('O'|'2'<<8|'D'<<16|'B'<<24)
|
mas01cr@108
|
73 #define O2_MAGIC ('o'|'2'<<8|'d'<<16|'b'<<24)
|
mas01cr@210
|
74 #define O2_FORMAT_VERSION (4U)
|
mas01cr@0
|
75
|
mas01cr@0
|
76 #define O2_DEFAULT_POINTNN (10U)
|
mas01mc@18
|
77 #define O2_DEFAULT_TRACKNN (10U)
|
mas01cr@0
|
78
|
mas01mc@248
|
79 //#define O2_DEFAULTDBSIZE (4000000000) // 4GB table size
|
mas01mc@7
|
80 #define O2_DEFAULTDBSIZE (2000000000) // 2GB table size
|
mas01cr@0
|
81
|
mas01mc@295
|
82 // Bit masks for packing (trackID,pointID) into 32-bit unsigned int
|
mas01mc@319
|
83 // This can be controlled at compile time
|
mas01mc@319
|
84 #define O2_DEFAULT_LSH_N_POINT_BITS 14
|
mas01mc@319
|
85
|
mas01mc@319
|
86 // Override the default point bit width for large database support
|
mas01mc@319
|
87 #ifndef LSH_N_POINT_BITS
|
mas01mc@323
|
88 #define LSH_N_POINT_BITS O2_DEFAULT_LSH_N_POINT_BITS
|
mas01mc@319
|
89 #endif
|
mas01mc@295
|
90
|
mas01mc@295
|
91 // LIMIT PARAMETERS
|
mas01cr@256
|
92 #define O2_DEFAULT_DATASIZE (1355U) // in MB
|
mas01cr@256
|
93 #define O2_DEFAULT_NTRACKS (20000U)
|
mas01cr@256
|
94 #define O2_DEFAULT_DATADIM (9U)
|
mas01mc@292
|
95 #define O2_REALTYPE (double)
|
mas01mc@317
|
96 #define O2_MAXFILES (1000000U)
|
mas01cr@0
|
97 #define O2_MAXFILESTR (256U)
|
mas01cr@256
|
98 #define O2_FILETABLE_ENTRY_SIZE (O2_MAXFILESTR)
|
mas01cr@256
|
99 #define O2_TRACKTABLE_ENTRY_SIZE (sizeof(unsigned))
|
mas01cr@0
|
100 #define O2_HEADERSIZE (sizeof(dbTableHeaderT))
|
mas01cr@0
|
101 #define O2_MEANNUMVECTORS (1000U)
|
mas01mc@292
|
102 #define O2_MAXDIM (2000U)
|
mas01mc@263
|
103 #define O2_MAXNN (1000000U)
|
mas01mc@292
|
104 #define O2_MAXSEQLEN (8000U) // maximum feature vectors in a sequence
|
mas01mc@316
|
105 #define O2_MAXTRACKS (1000000U) // maximum number of tracks
|
mas01mc@319
|
106 #define O2_MAXTRACKLEN (1<<LSH_N_POINT_BITS) // maximum shingles in a track
|
mas01mc@292
|
107 #define O2_MAXDOTPRODUCTMEMORY (sizeof(O2_REALTYPE)*O2_MAXSEQLEN*O2_MAXSEQLEN) // 512MB
|
mas01mc@292
|
108 #define O2_DISTANCE_TOLERANCE (1e-6)
|
mas01mc@317
|
109 #define O2_SERIAL_MAX_TRACKBATCH (1000000)
|
mas01mc@320
|
110 #define O2_LARGE_ADB_SIZE (O2_DEFAULT_DATASIZE+1) // datasize at which features are kept externally (in Mbytes)
|
mas01mc@320
|
111 #define O2_LARGE_ADB_NTRACKS (O2_DEFAULT_NTRACKS+1) // ntracks at which features are kept externally
|
mas01mc@317
|
112 #define O2_MAX_VECTORS ( O2_MEANNUMVECTORS * O2_MAXTRACKS )
|
mas01cr@0
|
113
|
mas01cr@0
|
114 // Flags
|
mas01cr@0
|
115 #define O2_FLAG_L2NORM (0x1U)
|
mas01cr@0
|
116 #define O2_FLAG_MINMAX (0x2U)
|
mas01cr@193
|
117 #define O2_FLAG_POWER (0x4U)
|
mas01cr@0
|
118 #define O2_FLAG_TIMES (0x20U)
|
mas01mc@316
|
119 #define O2_FLAG_LARGE_ADB (0x40U)
|
mas01mc@301
|
120 #define DISPLAY_FLAG(x) (x?"on":"off")
|
mas01cr@0
|
121
|
mas01cr@105
|
122 // Query types
|
mas01cr@105
|
123 #define O2_POINT_QUERY (0x4U)
|
mas01cr@105
|
124 #define O2_SEQUENCE_QUERY (0x8U)
|
mas01cr@105
|
125 #define O2_TRACK_QUERY (0x10U)
|
mas01mc@248
|
126 #define O2_N_SEQUENCE_QUERY (0x20U)
|
mas01mc@263
|
127 #define O2_ONE_TO_ONE_N_SEQUENCE_QUERY (0x40U)
|
mas01mc@248
|
128
|
mas01cr@0
|
129 // Error Codes
|
mas01cr@0
|
130 #define O2_ERR_KEYNOTFOUND (0xFFFFFF00)
|
mas01cr@0
|
131
|
mas01cr@0
|
132 // Macros
|
mas01cr@0
|
133 #define O2_ACTION(a) (strcmp(command,a)==0)
|
mas01cr@0
|
134
|
mas01cr@108
|
135 #define ALIGN_UP(x,w) ((x) + ((1<<w)-1) & ~((1<<w)-1))
|
mas01cr@108
|
136 #define ALIGN_DOWN(x,w) ((x) & ~((1<<w)-1))
|
mas01cr@108
|
137
|
mas01cr@196
|
138 #define ALIGN_PAGE_UP(x) ((x) + (getpagesize()-1) & ~(getpagesize()-1))
|
mas01cr@196
|
139 #define ALIGN_PAGE_DOWN(x) ((x) & ~(getpagesize()-1))
|
mas01cr@196
|
140
|
mas01cr@166
|
141 #define ENSURE_STRING(x) ((x) ? (x) : "")
|
mas01cr@166
|
142
|
mas01cr@239
|
143 #define CHECKED_MMAP(type, var, start, length) \
|
mas01cr@239
|
144 { void *tmp = mmap(0, length, (PROT_READ | (forWrite ? PROT_WRITE : 0)), MAP_SHARED, dbfid, (start)); \
|
mas01cr@239
|
145 if(tmp == (void *) -1) { \
|
mas01cr@239
|
146 error("mmap error for db table", #var, "mmap"); \
|
mas01cr@239
|
147 } \
|
mas01cr@239
|
148 var = (type) tmp; \
|
mas01cr@239
|
149 }
|
mas01cr@239
|
150
|
mas01cr@239
|
151 #define VERB_LOG(vv, ...) \
|
mas01cr@239
|
152 if(verbosity > vv) { \
|
mas01cr@239
|
153 fprintf(stderr, __VA_ARGS__); \
|
mas01cr@239
|
154 fflush(stderr); \
|
mas01cr@239
|
155 }
|
mas01cr@0
|
156
|
mas01mc@316
|
157 // We will only use this in a 32-bit address space
|
mas01mc@316
|
158 // So map the off_t down to 32-bits first
|
mas01mc@321
|
159 #define INSERT_FILETABLE_STRING(TABLE, STR) \
|
mas01mc@321
|
160 strncpy(TABLE + dbH->numFiles*O2_FILETABLE_ENTRY_SIZE, STR, strlen(STR));
|
mas01mc@316
|
161
|
mas01mc@320
|
162 #define SAFE_DELETE(PTR) delete PTR; PTR=0;
|
mas01mc@320
|
163 #define SAFE_DELETE_ARRAY(PTR) delete[] PTR; PTR=0;
|
mas01mc@320
|
164
|
mas01mc@308
|
165 extern LSH* SERVER_LSH_INDEX_SINGLETON;
|
mas01mc@322
|
166 extern char* SERVER_ADB_ROOT;
|
mas01mc@322
|
167 extern char* SERVER_ADB_FEATURE_ROOT;
|
mas01mc@308
|
168
|
mas01cr@210
|
169 typedef struct dbTableHeader {
|
mas01cr@114
|
170 uint32_t magic;
|
mas01cr@114
|
171 uint32_t version;
|
mas01cr@114
|
172 uint32_t numFiles;
|
mas01cr@114
|
173 uint32_t dim;
|
mas01cr@114
|
174 uint32_t flags;
|
mas01cr@210
|
175 uint32_t headerSize;
|
mas01cr@196
|
176 off_t length;
|
mas01cr@196
|
177 off_t fileTableOffset;
|
mas01cr@196
|
178 off_t trackTableOffset;
|
mas01cr@196
|
179 off_t dataOffset;
|
mas01cr@196
|
180 off_t l2normTableOffset;
|
mas01cr@196
|
181 off_t timesTableOffset;
|
mas01cr@196
|
182 off_t powerTableOffset;
|
mas01cr@196
|
183 off_t dbSize;
|
mas01cr@0
|
184 } dbTableHeaderT, *dbTableHeaderPtr;
|
mas01cr@0
|
185
|
mas01mc@292
|
186
|
mas01mc@292
|
187 class PointPair{
|
mas01mc@292
|
188 public:
|
mas01mc@292
|
189 Uns32T trackID;
|
mas01mc@292
|
190 Uns32T qpos;
|
mas01mc@292
|
191 Uns32T spos;
|
mas01mc@292
|
192 PointPair(Uns32T a, Uns32T b, Uns32T c);
|
mas01mc@292
|
193 };
|
mas01mc@292
|
194
|
mas01mc@292
|
195 bool operator<(const PointPair& a, const PointPair& b);
|
mas01cr@0
|
196
|
mas01mc@308
|
197 class audioDB{
|
mas01cr@0
|
198 private:
|
mas01cr@0
|
199 gengetopt_args_info args_info;
|
mas01cr@0
|
200 unsigned dim;
|
mas01cr@0
|
201 const char *dbName;
|
mas01cr@0
|
202 const char *inFile;
|
mas01cr@0
|
203 const char *hostport;
|
mas01cr@0
|
204 const char *key;
|
mas01mc@18
|
205 const char* trackFileName;
|
mas01cr@239
|
206 std::ifstream *trackFile;
|
mas01cr@0
|
207 const char *command;
|
mas01cr@131
|
208 const char *output;
|
mas01cr@0
|
209 const char *timesFileName;
|
mas01cr@239
|
210 std::ifstream *timesFile;
|
mas01cr@193
|
211 const char *powerFileName;
|
mas01cr@239
|
212 std::ifstream *powerFile;
|
mas01mc@321
|
213 const char* adb_root;
|
mas01mc@321
|
214 const char* adb_feature_root;
|
mas01mc@321
|
215
|
mas01cr@193
|
216 int powerfd;
|
mas01cr@0
|
217 int dbfid;
|
mas01mc@292
|
218 int lshfid;
|
mas01cr@196
|
219 bool forWrite;
|
mas01cr@0
|
220 int infid;
|
mas01cr@0
|
221 char* db;
|
mas01cr@0
|
222 char* indata;
|
mas01cr@0
|
223 struct stat statbuf;
|
mas01cr@0
|
224 dbTableHeaderPtr dbH;
|
mas01cr@284
|
225
|
mas01cr@284
|
226 gsl_rng *rng;
|
mas01cr@0
|
227
|
mas01mc@316
|
228 char* fileTable;
|
mas01mc@18
|
229 unsigned* trackTable;
|
mas01mc@316
|
230 off_t* trackOffsetTable;
|
mas01cr@0
|
231 double* dataBuf;
|
mas01cr@0
|
232 double* inBuf;
|
mas01cr@0
|
233 double* l2normTable;
|
mas01cr@196
|
234 double* timesTable;
|
mas01cr@193
|
235 double* powerTable;
|
mas01cr@0
|
236
|
mas01mc@318
|
237 char* featureFileNameTable;
|
mas01mc@318
|
238 char* timesFileNameTable;
|
mas01mc@318
|
239 char* powerFileNameTable;
|
mas01mc@318
|
240
|
mas01cr@196
|
241 size_t fileTableLength;
|
mas01cr@196
|
242 size_t trackTableLength;
|
mas01cr@196
|
243 off_t dataBufLength;
|
mas01cr@196
|
244 size_t timesTableLength;
|
mas01cr@196
|
245 size_t powerTableLength;
|
mas01cr@196
|
246 size_t l2normTableLength;
|
mas01cr@196
|
247
|
mas01cr@0
|
248 // Flags and parameters
|
mas01cr@0
|
249 unsigned verbosity; // how much do we want to know?
|
mas01cr@256
|
250
|
mas01cr@280
|
251 unsigned nsamples;
|
mas01cr@280
|
252
|
mas01cr@256
|
253 //off_t size; // given size (for creation)
|
mas01cr@256
|
254 unsigned datasize; // size in MB
|
mas01cr@256
|
255 unsigned ntracks;
|
mas01cr@256
|
256 unsigned datadim;
|
mas01cr@256
|
257
|
mas01cr@0
|
258 unsigned queryType; // point queries default
|
mas01cr@0
|
259 unsigned pointNN; // how many point NNs ?
|
mas01mc@18
|
260 unsigned trackNN; // how many track NNs ?
|
mas01cr@0
|
261 unsigned sequenceLength;
|
mas01cr@0
|
262 unsigned sequenceHop;
|
mas01cr@239
|
263 bool normalizedDistance;
|
mas01mc@292
|
264 bool no_unit_norming;
|
mas01cr@0
|
265 unsigned queryPoint;
|
mas01cr@0
|
266 unsigned usingQueryPoint;
|
mas01cr@0
|
267 unsigned usingTimes;
|
mas01cr@193
|
268 unsigned usingPower;
|
mas01cr@0
|
269 unsigned isClient;
|
mas01cr@0
|
270 unsigned isServer;
|
mas01cr@0
|
271 unsigned port;
|
mas01cr@0
|
272 double timesTol;
|
mas01mc@17
|
273 double radius;
|
mas01mc@292
|
274 bool query_from_key;
|
mas01mc@292
|
275 Uns32T query_from_key_index;
|
mas01cr@193
|
276 bool use_absolute_threshold;
|
mas01cr@193
|
277 double absolute_threshold;
|
mas01cr@193
|
278 bool use_relative_threshold;
|
mas01cr@193
|
279 double relative_threshold;
|
mas01cr@193
|
280
|
mas01mc@292
|
281 ReporterBase* reporter; // track/point reporter
|
mas01mc@292
|
282 priority_queue<PointPair, std::vector<PointPair>, std::less<PointPair> >* exact_evaluation_queue;
|
mas01mc@292
|
283
|
mas01cr@0
|
284 // Timers
|
mas01cr@0
|
285 struct timeval tv1;
|
mas01cr@0
|
286 struct timeval tv2;
|
mas01cr@0
|
287
|
mas01cr@0
|
288 // private methods
|
mas01cr@32
|
289 void error(const char* a, const char* b = "", const char *sysFunc = 0);
|
mas01cr@193
|
290 void sequence_sum(double *buffer, int length, int seqlen);
|
mas01cr@193
|
291 void sequence_sqrt(double *buffer, int length, int seqlen);
|
mas01cr@193
|
292 void sequence_average(double *buffer, int length, int seqlen);
|
mas01cr@193
|
293
|
mas01cr@239
|
294 void initialize_arrays(int track, unsigned int numVectors, double *query, double *data_buffer, double **D, double **DD);
|
mas01cr@239
|
295 void delete_arrays(int track, unsigned int numVectors, double **D, double **DD);
|
mas01mc@319
|
296 void read_data(int trkfid, int track, double **data_buffer_p, size_t *data_buffer_size_p);
|
mas01cr@239
|
297 void set_up_query(double **qp, double **vqp, double **qnp, double **vqnp, double **qpp, double **vqpp, double *mqdp, unsigned int *nvp);
|
mas01mc@292
|
298 void set_up_query_from_key(double **qp, double **vqp, double **qnp, double **vqnp, double **qpp, double **vqpp, double *mqdp, unsigned *nvp, Uns32T queryIndex);
|
mas01cr@239
|
299 void set_up_db(double **snp, double **vsnp, double **spp, double **vspp, double **mddp, unsigned int *dvp);
|
mas01mc@292
|
300 void query_loop(const char* dbName, Uns32T queryIndex);
|
mas01mc@292
|
301 void query_loop_points(double* query, double* qnPtr, double* qpPtr, double meanQdur, Uns32T numVectors);
|
mas01mc@292
|
302 double dot_product_points(double* q, double* p, Uns32T L);
|
mas01cr@284
|
303 void initRNG();
|
mas01cr@196
|
304 void initDBHeader(const char *dbName);
|
mas01mc@316
|
305 void initInputFile(const char *inFile, bool loadData = true);
|
mas01mc@292
|
306 void initTables(const char* dbName, const char* inFile = 0);
|
mas01mc@292
|
307 void initTablesFromKey(const char* dbName, const Uns32T queryIndex);
|
mas01cr@0
|
308 void unitNorm(double* X, unsigned d, unsigned n, double* qNorm);
|
mas01cr@0
|
309 void unitNormAndInsertL2(double* X, unsigned dim, unsigned n, unsigned append);
|
mas01cr@239
|
310 void insertTimeStamps(unsigned n, std::ifstream* timesFile, double* timesdata);
|
mas01cr@193
|
311 void insertPowerData(unsigned n, int powerfd, double *powerdata);
|
mas01cr@0
|
312 unsigned getKeyPos(char* key);
|
mas01mc@321
|
313 void prefix_name(char** const name, const char* prefix);
|
mas01mc@321
|
314
|
mas01cr@0
|
315 public:
|
mas01cr@76
|
316 audioDB(const unsigned argc, char* const argv[]);
|
mas01cr@133
|
317 audioDB(const unsigned argc, char* const argv[], adb__queryResponse *adbQueryResponse);
|
mas01cr@133
|
318 audioDB(const unsigned argc, char* const argv[], adb__statusResponse *adbStatusResponse);
|
mas01cr@97
|
319 void cleanup();
|
mas01cr@0
|
320 ~audioDB();
|
mas01cr@0
|
321 int processArgs(const unsigned argc, char* const argv[]);
|
mas01cr@30
|
322 void get_lock(int fd, bool exclusive);
|
mas01cr@30
|
323 void release_lock(int fd);
|
mas01cr@0
|
324 void create(const char* dbName);
|
mas01cr@251
|
325 bool enough_per_file_space_free();
|
mas01cr@196
|
326 bool enough_data_space_free(off_t size);
|
mas01cr@196
|
327 void insert_data_vectors(off_t offset, void *buffer, size_t size);
|
mas01cr@0
|
328 void insert(const char* dbName, const char* inFile);
|
mas01cr@0
|
329 void batchinsert(const char* dbName, const char* inFile);
|
mas01mc@316
|
330 void batchinsert_large_adb(const char* dbName, const char* inFile);
|
mas01cr@133
|
331 void query(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse=0);
|
mas01cr@133
|
332 void status(const char* dbName, adb__statusResponse *adbStatusResponse=0);
|
mas01cr@284
|
333 unsigned random_track(unsigned *propTable, unsigned total);
|
mas01cr@280
|
334 void sample(const char *dbName);
|
mas01cr@0
|
335 void l2norm(const char* dbName);
|
mas01cr@193
|
336 void power_flag(const char *dbName);
|
mas01cr@193
|
337 bool powers_acceptable(double p1, double p2);
|
mas01cr@0
|
338 void dump(const char* dbName);
|
mas01cr@0
|
339
|
mas01mc@292
|
340 // LSH indexing parameters and data structures
|
mas01mc@292
|
341 LSH* lsh;
|
mas01mc@292
|
342 bool lsh_in_core; // load LSH tables for query into core (true) or keep on disk (false)
|
mas01mc@292
|
343 bool lsh_use_u_functions;
|
mas01mc@292
|
344 bool lsh_exact; // flag to indicate use exact evaluation of points returned by LSH
|
mas01mc@308
|
345 bool WS_load_index; // flag to indicate that we want to make a Web Services index memory resident
|
mas01mc@292
|
346 double lsh_param_w; // Width of LSH hash-function bins
|
mas01mc@292
|
347 Uns32T lsh_param_k; // Number of independent hash functions
|
mas01mc@292
|
348 Uns32T lsh_param_m; // Combinatorial parameter for m(m-1)/2 hash tables
|
mas01mc@292
|
349 Uns32T lsh_param_N; // Number of rows per hash table
|
mas01mc@292
|
350 Uns32T lsh_param_b; // Batch size, in number of tracks, per indexing iteration
|
mas01mc@292
|
351 Uns32T lsh_param_ncols; // Maximum number of collision in a hash-table row
|
mas01mc@319
|
352 Uns32T lsh_n_point_bits; // How many bits to use to encode point ID within a track
|
mas01mc@319
|
353
|
mas01mc@292
|
354
|
mas01mc@292
|
355 // LSH vector<> containers for one in-core copy of a set of feature vectors
|
mas01mc@292
|
356 vector<float>::iterator vi; // feature vector iterator
|
mas01mc@292
|
357 vector<vector<float> > *vv; // one-track's worth data
|
mas01mc@292
|
358
|
mas01mc@292
|
359 // LSH indexing and retrieval methods
|
mas01mc@292
|
360 void index_index_db(const char* dbName);
|
mas01mc@292
|
361 void index_initialize(double**,double**,double**,double**,unsigned int*);
|
mas01mc@292
|
362 void index_insert_tracks(Uns32T start_track, Uns32T end_track, double** fvpp, double** sNormpp,double** snPtrp, double** sPowerp, double** spPtrp);
|
mas01mc@292
|
363 int index_insert_track(Uns32T trackID, double** fvpp, double** snpp, double** sppp);
|
mas01mc@292
|
364 Uns32T index_insert_shingles(vector<vector<float> >*, Uns32T trackID, double* spp);
|
mas01mc@292
|
365 void index_make_shingle(vector<vector<float> >*, Uns32T idx, double* fvp, Uns32T dim, Uns32T seqLen);
|
mas01mc@292
|
366 int index_norm_shingles(vector<vector<float> >*, double* snp, double* spp);
|
mas01mc@292
|
367 int index_query_loop(const char* dbName, Uns32T queryIndex);
|
mas01mc@292
|
368 vector<vector<float> >* index_initialize_shingles(Uns32T sz);
|
mas01mc@292
|
369 int index_init_query(const char* dbName);
|
mas01mc@292
|
370 int index_exists(const char* dbName, double radius, Uns32T sequenceLength);
|
mas01mc@292
|
371 char* index_get_name(const char*dbName, double radius, Uns32T sequenceLength);
|
mas01mc@292
|
372 static void index_add_point_approximate(void* instance, Uns32T pointID, Uns32T qpos, float dist); // static point reporter callback method
|
mas01mc@292
|
373 static void index_add_point_exact(void* instance, Uns32T pointID, Uns32T qpos, float dist); // static point reporter callback method
|
mas01mc@319
|
374 static Uns32T index_to_trackID(Uns32T lshID, Uns32T nPntBits); // Convert lsh point index to audioDB trackID
|
mas01mc@319
|
375 static Uns32T index_to_trackPos(Uns32T lshID, Uns32T nPntBits); // Convert lsh point index to audioDB trackPos (spos)
|
mas01mc@319
|
376 static Uns32T index_from_trackInfo(Uns32T trackID, Uns32T pntID, Uns32T nPntBits); // Convert audioDB trackID and trackPos to an lsh point index
|
mas01mc@292
|
377 void initialize_exact_evalutation_queue();
|
mas01mc@292
|
378 void index_insert_exact_evaluation_queue(Uns32T trackID, Uns32T qpos, Uns32T spos);
|
mas01mc@308
|
379 LSH* index_allocate(char* indexName, bool load_hashTables);
|
mas01mc@319
|
380 void init_track_aux_data(Uns32T trackID, double* fvp, double** sNormpp,double** snPtrp, double** sPowerp, double** spPtrp);
|
mas01mc@319
|
381
|
mas01mc@292
|
382 // Web Services
|
mas01cr@0
|
383 void startServer();
|
mas01mc@308
|
384 void ws_status(const char*dbName, char* hostport);
|
mas01mc@308
|
385 void ws_query(const char*dbName, const char *featureFileName, const char* hostport);
|
mas01mc@308
|
386 void ws_query_by_key(const char*dbName, const char *trackKey, const char* hostport);
|
mas01cr@0
|
387
|
mas01cr@0
|
388 };
|
mas01mc@17
|
389
|
mas01mc@292
|
390 #define O2_AUDIODB_INITIALIZERS \
|
mas01mc@292
|
391 dim(0), \
|
mas01mc@292
|
392 dbName(0), \
|
mas01mc@292
|
393 inFile(0), \
|
mas01mc@292
|
394 key(0), \
|
mas01mc@292
|
395 trackFileName(0), \
|
mas01mc@292
|
396 trackFile(0), \
|
mas01mc@292
|
397 command(0), \
|
mas01mc@292
|
398 output(0), \
|
mas01mc@292
|
399 timesFileName(0), \
|
mas01mc@292
|
400 timesFile(0), \
|
mas01mc@292
|
401 powerFileName(0), \
|
mas01mc@292
|
402 powerFile(0), \
|
mas01mc@321
|
403 adb_root(0), \
|
mas01mc@321
|
404 adb_feature_root(0), \
|
mas01mc@321
|
405 powerfd(0), \
|
mas01mc@292
|
406 dbfid(0), \
|
mas01mc@292
|
407 lshfid(0), \
|
mas01mc@292
|
408 forWrite(false), \
|
mas01mc@292
|
409 infid(0), \
|
mas01mc@292
|
410 db(0), \
|
mas01mc@292
|
411 indata(0), \
|
mas01mc@292
|
412 dbH(0), \
|
mas01mc@292
|
413 rng(0), \
|
mas01mc@292
|
414 fileTable(0), \
|
mas01mc@292
|
415 trackTable(0), \
|
mas01mc@292
|
416 trackOffsetTable(0), \
|
mas01mc@292
|
417 dataBuf(0), \
|
mas01mc@292
|
418 l2normTable(0), \
|
mas01mc@292
|
419 timesTable(0), \
|
mas01mc@314
|
420 powerTable(0), \
|
mas01mc@318
|
421 featureFileNameTable(0), \
|
mas01mc@318
|
422 timesFileNameTable(0), \
|
mas01mc@318
|
423 powerFileNameTable(0), \
|
mas01mc@292
|
424 fileTableLength(0), \
|
mas01mc@292
|
425 trackTableLength(0), \
|
mas01mc@292
|
426 dataBufLength(0), \
|
mas01mc@292
|
427 timesTableLength(0), \
|
mas01mc@292
|
428 powerTableLength(0), \
|
mas01mc@292
|
429 l2normTableLength(0), \
|
mas01mc@292
|
430 verbosity(1), \
|
mas01mc@292
|
431 nsamples(2000), \
|
mas01mc@292
|
432 datasize(O2_DEFAULT_DATASIZE), \
|
mas01mc@292
|
433 ntracks(O2_DEFAULT_NTRACKS), \
|
mas01mc@292
|
434 datadim(O2_DEFAULT_DATADIM), \
|
mas01mc@292
|
435 queryType(O2_POINT_QUERY), \
|
mas01mc@292
|
436 pointNN(O2_DEFAULT_POINTNN), \
|
mas01mc@292
|
437 trackNN(O2_DEFAULT_TRACKNN), \
|
mas01mc@292
|
438 sequenceLength(16), \
|
mas01mc@292
|
439 sequenceHop(1), \
|
mas01mc@292
|
440 normalizedDistance(true), \
|
mas01mc@292
|
441 no_unit_norming(false), \
|
mas01mc@292
|
442 queryPoint(0), \
|
mas01mc@292
|
443 usingQueryPoint(0), \
|
mas01mc@292
|
444 usingTimes(0), \
|
mas01mc@292
|
445 usingPower(0), \
|
mas01mc@292
|
446 isClient(0), \
|
mas01mc@292
|
447 isServer(0), \
|
mas01mc@292
|
448 port(0), \
|
mas01mc@292
|
449 timesTol(0.1), \
|
mas01mc@292
|
450 radius(0), \
|
mas01mc@292
|
451 query_from_key(false), \
|
mas01mc@292
|
452 query_from_key_index(O2_ERR_KEYNOTFOUND), \
|
mas01mc@292
|
453 use_absolute_threshold(false), \
|
mas01mc@292
|
454 absolute_threshold(0.0), \
|
mas01mc@292
|
455 use_relative_threshold(false), \
|
mas01mc@292
|
456 relative_threshold(0.0), \
|
mas01mc@292
|
457 reporter(0), \
|
mas01mc@292
|
458 exact_evaluation_queue(0), \
|
mas01mc@292
|
459 lsh(0), \
|
mas01mc@292
|
460 lsh_in_core(false), \
|
mas01mc@292
|
461 lsh_use_u_functions(false), \
|
mas01mc@292
|
462 lsh_exact(false), \
|
mas01mc@308
|
463 WS_load_index(false), \
|
mas01mc@292
|
464 lsh_param_k(0), \
|
mas01mc@292
|
465 lsh_param_m(0), \
|
mas01mc@292
|
466 lsh_param_N(0), \
|
mas01mc@292
|
467 lsh_param_b(0), \
|
mas01mc@292
|
468 lsh_param_ncols(0), \
|
mas01mc@319
|
469 lsh_n_point_bits(0), \
|
mas01mc@292
|
470 vv(0)
|
mas01mc@292
|
471 #endif
|