annotate audioDB.h @ 369:6564be3109c5 gcc-4.3-cleanups

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