Mercurial > hg > audiodb
comparison audioDB.cpp @ 292:d9a88cfd4ab6
Completed merge of lshlib back to current version of the trunk.
author | mas01mc |
---|---|
date | Tue, 29 Jul 2008 22:01:17 +0000 |
parents | cacad987d785 |
children | f922c234462f |
comparison
equal
deleted
inserted
replaced
291:63ae0dfc1767 | 292:d9a88cfd4ab6 |
---|---|
1 #include "audioDB.h" | 1 #include "audioDB.h" |
2 | |
3 PointPair::PointPair(Uns32T a, Uns32T b, Uns32T c):trackID(a),qpos(b),spos(c){}; | |
4 | |
5 bool operator<(const PointPair& a, const PointPair& b){ | |
6 return ( (a.qpos<b.qpos) || | |
7 ((a.qpos==b.qpos) && | |
8 ( (a.trackID<b.trackID)) || ((a.trackID==b.trackID)&&(a.spos<b.spos)) ) ); | |
9 } | |
10 | |
11 bool operator>(const PointPair& a, const PointPair& b){ | |
12 return ( (a.qpos>b.qpos) || | |
13 ((a.qpos==b.qpos) && | |
14 ( (a.trackID>b.trackID)) || ((a.trackID==b.trackID)&&(a.spos>b.spos)) ) ); | |
15 } | |
16 | |
17 bool operator==(const PointPair& a, const PointPair& b){ | |
18 return ( (a.trackID==b.trackID) && (a.qpos==b.qpos) && (a.spos==b.spos) ); | |
19 } | |
2 | 20 |
3 audioDB::audioDB(const unsigned argc, char* const argv[]): O2_AUDIODB_INITIALIZERS | 21 audioDB::audioDB(const unsigned argc, char* const argv[]): O2_AUDIODB_INITIALIZERS |
4 { | 22 { |
5 if(processArgs(argc, argv)<0){ | 23 if(processArgs(argc, argv)<0){ |
6 printf("No command found.\n"); | 24 printf("No command found.\n"); |
47 else if(O2_ACTION(COM_POWER)) | 65 else if(O2_ACTION(COM_POWER)) |
48 power_flag(dbName); | 66 power_flag(dbName); |
49 | 67 |
50 else if(O2_ACTION(COM_DUMP)) | 68 else if(O2_ACTION(COM_DUMP)) |
51 dump(dbName); | 69 dump(dbName); |
70 | |
71 else if(O2_ACTION(COM_INDEX)) | |
72 index_index_db(dbName); | |
52 | 73 |
53 else | 74 else |
54 error("Unrecognized command",command); | 75 error("Unrecognized command",command); |
55 } | 76 } |
56 | 77 |
94 munmap(dataBuf, dataBufLength); | 115 munmap(dataBuf, dataBufLength); |
95 if(timesTable) | 116 if(timesTable) |
96 munmap(timesTable, timesTableLength); | 117 munmap(timesTable, timesTableLength); |
97 if(l2normTable) | 118 if(l2normTable) |
98 munmap(l2normTable, l2normTableLength); | 119 munmap(l2normTable, l2normTableLength); |
99 | 120 if(trackOffsetTable) |
121 delete trackOffsetTable; | |
122 if(reporter) | |
123 delete reporter; | |
124 if(exact_evaluation_queue) | |
125 delete exact_evaluation_queue; | |
100 if(rng) | 126 if(rng) |
101 gsl_rng_free(rng); | 127 gsl_rng_free(rng); |
102 | 128 if(vv) |
129 delete vv; | |
103 if(dbfid>0) | 130 if(dbfid>0) |
104 close(dbfid); | 131 close(dbfid); |
105 if(infid>0) | 132 if(infid>0) |
106 close(infid); | 133 close(infid); |
107 if(dbH) | 134 if(dbH) |
177 } else { | 204 } else { |
178 VERB_LOG(3, "Setting radius to %f\n", radius); | 205 VERB_LOG(3, "Setting radius to %f\n", radius); |
179 } | 206 } |
180 } | 207 } |
181 | 208 |
209 sequenceLength = args_info.sequencelength_arg; | |
210 if(sequenceLength < 1 || sequenceLength > 1000) { | |
211 error("seqlen out of range: 1 <= seqlen <= 1000"); | |
212 } | |
213 sequenceHop = args_info.sequencehop_arg; | |
214 if(sequenceHop < 1 || sequenceHop > 1000) { | |
215 error("seqhop out of range: 1 <= seqhop <= 1000"); | |
216 } | |
217 | |
218 if (args_info.absolute_threshold_given) { | |
219 if (args_info.absolute_threshold_arg >= 0) { | |
220 error("absolute threshold out of range: should be negative"); | |
221 } | |
222 use_absolute_threshold = true; | |
223 absolute_threshold = args_info.absolute_threshold_arg; | |
224 } | |
225 if (args_info.relative_threshold_given) { | |
226 use_relative_threshold = true; | |
227 relative_threshold = args_info.relative_threshold_arg; | |
228 } | |
229 | |
182 if(args_info.SERVER_given){ | 230 if(args_info.SERVER_given){ |
183 command=COM_SERVER; | 231 command=COM_SERVER; |
184 port=args_info.SERVER_arg; | 232 port=args_info.SERVER_arg; |
185 if(port<100 || port > 100000) | 233 if(port<100 || port > 100000) |
186 error("port out of range"); | 234 error("port out of range"); |
249 if(args_info.INSERT_given){ | 297 if(args_info.INSERT_given){ |
250 command=COM_INSERT; | 298 command=COM_INSERT; |
251 dbName=args_info.database_arg; | 299 dbName=args_info.database_arg; |
252 inFile=args_info.features_arg; | 300 inFile=args_info.features_arg; |
253 if(args_info.key_given) | 301 if(args_info.key_given) |
254 key=args_info.key_arg; | 302 if(!args_info.features_given) |
303 error("INSERT: '-k key' argument depends on '-f features'"); | |
304 else | |
305 key=args_info.key_arg; | |
255 if(args_info.times_given){ | 306 if(args_info.times_given){ |
256 timesFileName=args_info.times_arg; | 307 timesFileName=args_info.times_arg; |
257 if(strlen(timesFileName)>0){ | 308 if(strlen(timesFileName)>0){ |
258 if(!(timesFile = new std::ifstream(timesFileName,std::ios::in))) | 309 if(!(timesFile = new std::ifstream(timesFileName,std::ios::in))) |
259 error("Could not open times file for reading", timesFileName); | 310 error("Could not open times file for reading", timesFileName); |
275 if(args_info.BATCHINSERT_given){ | 326 if(args_info.BATCHINSERT_given){ |
276 command=COM_BATCHINSERT; | 327 command=COM_BATCHINSERT; |
277 dbName=args_info.database_arg; | 328 dbName=args_info.database_arg; |
278 inFile=args_info.featureList_arg; | 329 inFile=args_info.featureList_arg; |
279 if(args_info.keyList_given) | 330 if(args_info.keyList_given) |
280 key=args_info.keyList_arg; // INCONSISTENT NO CHECK | 331 if(!args_info.features_given) |
332 error("INSERT: '-k key' argument depends on '-f features'"); | |
333 else | |
334 key=args_info.key_arg; // INCONSISTENT NO CHECK | |
281 | 335 |
282 /* TO DO: REPLACE WITH | 336 /* TO DO: REPLACE WITH |
283 if(args_info.keyList_given){ | 337 if(args_info.keyList_given){ |
284 trackFileName=args_info.keyList_arg; | 338 trackFileName=args_info.keyList_arg; |
285 if(strlen(trackFileName)>0 && !(trackFile = new std::ifstream(trackFileName,std::ios::in))) | 339 if(strlen(trackFileName)>0 && !(trackFile = new std::ifstream(trackFileName,std::ios::in))) |
304 usingPower=1; | 358 usingPower=1; |
305 } | 359 } |
306 } | 360 } |
307 return 0; | 361 return 0; |
308 } | 362 } |
309 | 363 |
364 // Set no_unit_norm flag | |
365 no_unit_norming = args_info.no_unit_norming_flag; | |
366 lsh_use_u_functions = args_info.lsh_use_u_functions_flag; | |
367 | |
368 // LSH Index Command | |
369 if(args_info.INDEX_given){ | |
370 if(radius <= 0 ) | |
371 error("INDEXing requires a Radius argument"); | |
372 if(!(sequenceLength>0 && sequenceLength <= O2_MAXSEQLEN)) | |
373 error("INDEXing requires 1 <= sequenceLength <= 1000"); | |
374 command=COM_INDEX; | |
375 dbName=args_info.database_arg; | |
376 | |
377 // Whether to store LSH hash tables for query in core (FORMAT2) | |
378 lsh_in_core = args_info.lsh_inCore_flag; | |
379 | |
380 lsh_param_w = args_info.lsh_w_arg; | |
381 if(!(lsh_param_w>0 && lsh_param_w<=O2_SERIAL_MAX_BINWIDTH)) | |
382 error("Indexing parameter w out of range (0.0 < w <= 100.0)"); | |
383 | |
384 lsh_param_k = args_info.lsh_k_arg; | |
385 if(!(lsh_param_k>0 && lsh_param_k<=O2_SERIAL_MAX_FUNS)) | |
386 error("Indexing parameter k out of range (1 <= k <= 100)"); | |
387 | |
388 lsh_param_m = args_info.lsh_m_arg; | |
389 if(!(lsh_param_m>0 && lsh_param_m<= (1 + (sqrt(1 + O2_SERIAL_MAX_TABLES*8.0)))/2.0)) | |
390 error("Indexing parameter m out of range (1 <= m <= 20)"); | |
391 | |
392 lsh_param_N = args_info.lsh_N_arg; | |
393 if(!(lsh_param_N>0 && lsh_param_N<=O2_SERIAL_MAX_ROWS)) | |
394 error("Indexing parameter N out of range (1 <= N <= 1000000)"); | |
395 | |
396 lsh_param_b = args_info.lsh_b_arg; | |
397 if(!(lsh_param_b>0 && lsh_param_b<=O2_SERIAL_MAX_TRACKBATCH)) | |
398 error("Indexing parameter b out of range (1 <= b <= 10000)"); | |
399 | |
400 lsh_param_ncols = args_info.lsh_ncols_arg; | |
401 if( !(lsh_param_ncols>0 && lsh_param_ncols<=O2_SERIAL_MAX_COLS)) | |
402 error("Indexing parameter ncols out of range (1 <= ncols <= 1000"); | |
403 | |
404 return 0; | |
405 } | |
406 | |
310 // Query command and arguments | 407 // Query command and arguments |
311 if(args_info.QUERY_given){ | 408 if(args_info.QUERY_given){ |
312 command=COM_QUERY; | 409 command=COM_QUERY; |
313 dbName=args_info.database_arg; | 410 dbName=args_info.database_arg; |
314 inFile=args_info.features_arg; | 411 // XOR features and key search |
315 | 412 if(!args_info.features_given && !args_info.key_given || (args_info.features_given && args_info.key_given)) |
413 error("QUERY requires exactly one of either -f features or -k key"); | |
414 if(args_info.features_given) | |
415 inFile=args_info.features_arg; // query from file | |
416 else{ | |
417 query_from_key = true; | |
418 key=args_info.key_arg; // query from key | |
419 } | |
420 | |
316 if(args_info.keyList_given){ | 421 if(args_info.keyList_given){ |
317 trackFileName=args_info.keyList_arg; | 422 trackFileName=args_info.keyList_arg; |
318 if(strlen(trackFileName)>0 && !(trackFile = new std::ifstream(trackFileName,std::ios::in))) | 423 if(strlen(trackFileName)>0 && !(trackFile = new std::ifstream(trackFileName,std::ios::in))) |
319 error("Could not open keyList file for reading",trackFileName); | 424 error("Could not open keyList file for reading",trackFileName); |
320 } | 425 } |
356 queryPoint = args_info.qpoint_arg; | 461 queryPoint = args_info.qpoint_arg; |
357 usingQueryPoint=1; | 462 usingQueryPoint=1; |
358 if(queryPoint<0 || queryPoint >10000) | 463 if(queryPoint<0 || queryPoint >10000) |
359 error("queryPoint out of range: 0 <= queryPoint <= 10000"); | 464 error("queryPoint out of range: 0 <= queryPoint <= 10000"); |
360 } | 465 } |
361 | 466 |
467 // Whether to pre-load LSH hash tables for query | |
468 lsh_in_core = args_info.lsh_inCore_flag; | |
469 | |
470 // Whether to perform exact evaluation of points returned by LSH | |
471 lsh_exact = args_info.lsh_exact_flag; | |
472 | |
362 pointNN = args_info.pointnn_arg; | 473 pointNN = args_info.pointnn_arg; |
363 if(pointNN < 1 || pointNN > O2_MAXNN) { | 474 if(pointNN < 1 || pointNN > O2_MAXNN) { |
364 error("pointNN out of range: 1 <= pointNN <= 1000000"); | 475 error("pointNN out of range: 1 <= pointNN <= 1000000"); |
365 } | 476 } |
366 trackNN = args_info.resultlength_arg; | 477 trackNN = args_info.resultlength_arg; |
367 if(trackNN < 1 || trackNN > O2_MAXNN) { | 478 if(trackNN < 1 || trackNN > O2_MAXNN) { |
368 error("resultlength out of range: 1 <= resultlength <= 1000000"); | 479 error("resultlength out of range: 1 <= resultlength <= 1000000"); |
369 } | |
370 sequenceLength = args_info.sequencelength_arg; | |
371 if(sequenceLength < 1 || sequenceLength > 1000) { | |
372 error("seqlen out of range: 1 <= seqlen <= 1000"); | |
373 } | |
374 sequenceHop = args_info.sequencehop_arg; | |
375 if(sequenceHop < 1 || sequenceHop > 1000) { | |
376 error("seqhop out of range: 1 <= seqhop <= 1000"); | |
377 } | |
378 | |
379 if (args_info.absolute_threshold_given) { | |
380 if (args_info.absolute_threshold_arg >= 0) { | |
381 error("absolute threshold out of range: should be negative"); | |
382 } | |
383 use_absolute_threshold = true; | |
384 absolute_threshold = args_info.absolute_threshold_arg; | |
385 } | |
386 if (args_info.relative_threshold_given) { | |
387 use_relative_threshold = true; | |
388 relative_threshold = args_info.relative_threshold_arg; | |
389 } | 480 } |
390 return 0; | 481 return 0; |
391 } | 482 } |
392 return -1; // no command found | 483 return -1; // no command found |
393 } | 484 } |