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