annotate audioDB.h @ 437:9a065b8db769 api-inversion

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