Mercurial > hg > audiodb
comparison audioDB.cpp @ 146:c9c508be69b3 powertable
Define a power command-line option; use it to turn on the DB flag.
Also enforce strict ordering: only accept power files if the DB has the
flag set; error if they're provided and the DB doesn't have the flag.
author | mas01cr |
---|---|
date | Wed, 31 Oct 2007 10:20:09 +0000 |
parents | 7162a8e9ab12 |
children | a564e6d7a30c |
comparison
equal
deleted
inserted
replaced
145:7162a8e9ab12 | 146:c9c508be69b3 |
---|---|
70 status(dbName); | 70 status(dbName); |
71 | 71 |
72 else if(O2_ACTION(COM_L2NORM)) | 72 else if(O2_ACTION(COM_L2NORM)) |
73 l2norm(dbName); | 73 l2norm(dbName); |
74 | 74 |
75 else if(O2_ACTION(COM_POWER)) | |
76 power_flag(dbName); | |
77 | |
75 else if(O2_ACTION(COM_DUMP)) | 78 else if(O2_ACTION(COM_DUMP)) |
76 dump(dbName); | 79 dump(dbName); |
77 | 80 |
78 else | 81 else |
79 error("Unrecognized command",command); | 82 error("Unrecognized command",command); |
218 command=COM_L2NORM; | 221 command=COM_L2NORM; |
219 dbName=args_info.database_arg; | 222 dbName=args_info.database_arg; |
220 return 0; | 223 return 0; |
221 } | 224 } |
222 | 225 |
226 if(args_info.POWER_given){ | |
227 command=COM_POWER; | |
228 dbName=args_info.database_arg; | |
229 return 0; | |
230 } | |
231 | |
223 if(args_info.INSERT_given){ | 232 if(args_info.INSERT_given){ |
224 command=COM_INSERT; | 233 command=COM_INSERT; |
225 dbName=args_info.database_arg; | 234 dbName=args_info.database_arg; |
226 inFile=args_info.features_arg; | 235 inFile=args_info.features_arg; |
227 if(args_info.key_given) | 236 if(args_info.key_given) |
526 | 535 |
527 initTables(dbName, 1, inFile); | 536 initTables(dbName, 1, inFile); |
528 | 537 |
529 if(!usingTimes && (dbH->flags & O2_FLAG_TIMES)) | 538 if(!usingTimes && (dbH->flags & O2_FLAG_TIMES)) |
530 error("Must use timestamps with timestamped database","use --times"); | 539 error("Must use timestamps with timestamped database","use --times"); |
540 | |
541 if(!usingPower && (dbH->flags & O2_FLAG_POWER)) | |
542 error("Must use power with power-enabled database", dbName); | |
531 | 543 |
532 // Check that there is room for at least 1 more file | 544 // Check that there is room for at least 1 more file |
533 if((char*)timesTable<((char*)dataBuf+dbH->length+statbuf.st_size-sizeof(int))) | 545 if((char*)timesTable<((char*)dataBuf+dbH->length+statbuf.st_size-sizeof(int))) |
534 error("No more room in database","insert failed: reason database is full."); | 546 error("No more room in database","insert failed: reason database is full."); |
535 | 547 |
661 } | 673 } |
662 } | 674 } |
663 | 675 |
664 void audioDB::insertPowerData(unsigned numVectors, int powerfd, double *powerdata) { | 676 void audioDB::insertPowerData(unsigned numVectors, int powerfd, double *powerdata) { |
665 if (usingPower) { | 677 if (usingPower) { |
678 if (!(dbH->flags & O2_FLAG_POWER)) { | |
679 error("Cannot insert power data on non-power DB", dbName); | |
680 } | |
681 | |
666 int one; | 682 int one; |
667 unsigned int count; | 683 unsigned int count; |
668 | 684 |
669 count = read(powerfd, &one, sizeof(unsigned int)); | 685 count = read(powerfd, &one, sizeof(unsigned int)); |
670 if (count != sizeof(unsigned int)) { | 686 if (count != sizeof(unsigned int)) { |
700 if(!(keysIn = new ifstream(key))) | 716 if(!(keysIn = new ifstream(key))) |
701 error("Could not open batch key file",key); | 717 error("Could not open batch key file",key); |
702 | 718 |
703 if(!usingTimes && (dbH->flags & O2_FLAG_TIMES)) | 719 if(!usingTimes && (dbH->flags & O2_FLAG_TIMES)) |
704 error("Must use timestamps with timestamped database","use --times"); | 720 error("Must use timestamps with timestamped database","use --times"); |
721 | |
722 if(!usingPower && (dbH->flags & O2_FLAG_POWER)) | |
723 error("Must use power with power-enabled database", dbName); | |
705 | 724 |
706 unsigned totalVectors=0; | 725 unsigned totalVectors=0; |
707 char *thisKey = new char[MAXSTR]; | 726 char *thisKey = new char[MAXSTR]; |
708 char *thisFile = new char[MAXSTR]; | 727 char *thisFile = new char[MAXSTR]; |
709 char *thisTimesFileName = new char[MAXSTR]; | 728 char *thisTimesFileName = new char[MAXSTR]; |
1058 } | 1077 } |
1059 // Update database flags | 1078 // Update database flags |
1060 dbH->flags = dbH->flags|O2_FLAG_L2NORM; | 1079 dbH->flags = dbH->flags|O2_FLAG_L2NORM; |
1061 memcpy (db, dbH, O2_HEADERSIZE); | 1080 memcpy (db, dbH, O2_HEADERSIZE); |
1062 } | 1081 } |
1063 | 1082 |
1083 void audioDB::power_flag(const char *dbName) { | |
1084 initTables(dbName, true, 0); | |
1085 if (dbH->length > 0) { | |
1086 error("cannot turn on power storage for non-empty database", dbName); | |
1087 } | |
1088 dbH->flags |= O2_FLAG_POWER; | |
1089 memcpy(db, dbH, O2_HEADERSIZE); | |
1090 } | |
1064 | 1091 |
1065 | 1092 |
1066 void audioDB::query(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){ | 1093 void audioDB::query(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){ |
1067 switch(queryType){ | 1094 switch(queryType){ |
1068 case O2_POINT_QUERY: | 1095 case O2_POINT_QUERY: |