annotate create.cpp @ 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 4e68f7d4d524 f9d86b1db21c 282c651e2fbb
rev   line source
mas01cr@239 1 #include "audioDB.h"
mas01cr@239 2
mas01cr@239 3 /* Make a new database.
mas01cr@239 4
mas01mc@324 5 IF size(featuredata) < O2_LARGE_ADB_SIZE
mas01cr@239 6 The database consists of:
mas01cr@239 7
mas01cr@239 8 * a header (see dbTableHeader struct definition);
mas01cr@239 9 * keyTable: list of keys of tracks;
mas01cr@239 10 * trackTable: Maps implicit feature index to a feature vector
mas01cr@239 11 matrix (sizes of tracks)
mas01cr@239 12 * featureTable: Lots of doubles;
mas01cr@239 13 * timesTable: (start,end) time points for each feature vector;
mas01cr@239 14 * powerTable: associated power for each feature vector;
mas01cr@239 15 * l2normTable: squared l2norms for each feature vector.
mas01mc@324 16
mas01mc@324 17 ELSE the database consists of:
mas01mc@324 18
mas01mc@324 19 * a header (see dbTableHeader struct definition);
mas01mc@324 20 * keyTable: list of keys of tracks
mas01mc@324 21 * trackTable: sizes of tracks
mas01mc@324 22 * featureTable: list of feature file names
mas01mc@324 23 * timesTable: list of times file names
mas01mc@324 24 * powerTable: list of power file names
mas01mc@324 25
mas01cr@239 26 */
mas01cr@239 27
mas01cr@239 28 void audioDB::create(const char* dbName){
mas01cr@239 29 if ((dbfid = open (dbName, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0)
mas01cr@239 30 error("Can't create database file", dbName, "open");
mas01cr@239 31 get_lock(dbfid, 1);
mas01cr@239 32
mas01cr@239 33 VERB_LOG(0, "header size: %ju\n", (intmax_t) O2_HEADERSIZE);
mas01cr@239 34
mas01cr@239 35 dbH = new dbTableHeaderT();
mas01cr@239 36 assert(dbH);
mas01cr@239 37
mas01cr@256 38 //unsigned int maxfiles = (unsigned int) rint((double) O2_MAXFILES * (double) size / (double) O2_DEFAULTDBSIZE);
mas01cr@239 39
mas01cr@239 40 // Initialize header
mas01cr@239 41 dbH->magic = O2_MAGIC;
mas01cr@239 42 dbH->version = O2_FORMAT_VERSION;
mas01cr@239 43 dbH->numFiles = 0;
mas01cr@239 44 dbH->dim = 0;
mas01cr@239 45 dbH->flags = 0;
mas01cr@239 46 dbH->headerSize = O2_HEADERSIZE;
mas01cr@239 47 dbH->length = 0;
mas01cr@239 48 dbH->fileTableOffset = ALIGN_PAGE_UP(O2_HEADERSIZE);
mas01cr@256 49 dbH->trackTableOffset = ALIGN_PAGE_UP(dbH->fileTableOffset + O2_FILETABLE_ENTRY_SIZE*ntracks);
mas01cr@256 50 dbH->dataOffset = ALIGN_PAGE_UP(dbH->trackTableOffset + O2_TRACKTABLE_ENTRY_SIZE*ntracks);
mas01cr@256 51
mas01cr@256 52 off_t databytes = ((off_t) datasize) * 1024 * 1024;
mas01cr@256 53 off_t auxbytes = databytes / datadim;
mas01cr@256 54
mas01mc@324 55 // For backward-compatibility, Record the point-encoding parameter for LSH indexing in the adb header
mas01mc@324 56 // If this value is 0 then it will be set to 14
mas01mc@324 57
mas01mc@324 58 #if O2_LSH_N_POINT_BITS > 15
mas01mc@324 59 #error "AudioDB Compile ERROR: consistency check of O2_LSH_POINT_BITS failed (>15)"
mas01mc@324 60 #endif
mas01mc@324 61
mas01mc@324 62 dbH->flags |= LSH_N_POINT_BITS << 28;
mas01mc@324 63
mas01mc@324 64 // If database will fit in a single file the vectors are copied into the AudioDB instance
mas01mc@324 65 // Else all the vectors are left on the FileSystem and we use the dataOffset as storage
mas01mc@324 66 // for the location of the features, powers and times files (assuming that arbitrary keys are used for the fileTable)
mas01mc@324 67 if(ntracks<O2_LARGE_ADB_NTRACKS && datasize<O2_LARGE_ADB_SIZE){
mas01mc@324 68 dbH->timesTableOffset = ALIGN_PAGE_UP(dbH->dataOffset + databytes);
mas01mc@324 69 dbH->powerTableOffset = ALIGN_PAGE_UP(dbH->timesTableOffset + 2*auxbytes);
mas01mc@324 70 dbH->l2normTableOffset = ALIGN_PAGE_UP(dbH->powerTableOffset + auxbytes);
mas01mc@324 71 dbH->dbSize = ALIGN_PAGE_UP(dbH->l2normTableOffset + auxbytes);
mas01mc@324 72 }
mas01mc@324 73 else{ // Create LARGE_ADB, features and powers kept on filesystem
mas01mc@324 74 dbH->flags |= O2_FLAG_LARGE_ADB;
mas01mc@324 75 dbH->timesTableOffset = ALIGN_PAGE_UP(dbH->dataOffset + O2_FILETABLE_ENTRY_SIZE*ntracks);
mas01mc@324 76 dbH->powerTableOffset = ALIGN_PAGE_UP(dbH->timesTableOffset + O2_FILETABLE_ENTRY_SIZE*ntracks);
mas01mc@324 77 dbH->l2normTableOffset = ALIGN_PAGE_UP(dbH->powerTableOffset + O2_FILETABLE_ENTRY_SIZE*ntracks);
mas01mc@324 78 dbH->dbSize = dbH->l2normTableOffset;
mas01mc@324 79 }
mas01cr@239 80
mas01cr@366 81 CHECKED_WRITE(dbfid, dbH, O2_HEADERSIZE);
mas01cr@239 82
mas01cr@239 83 // go to the location corresponding to the last byte
mas01cr@256 84 if (lseek (dbfid, dbH->dbSize - 1, SEEK_SET) == -1)
mas01cr@239 85 error("lseek error in db file", "", "lseek");
mas01cr@239 86
mas01cr@239 87 // write a dummy byte at the last location
mas01cr@239 88 if (write (dbfid, "", 1) != 1)
mas01cr@239 89 error("write error", "", "write");
mas01cr@239 90
mas01cr@239 91 VERB_LOG(0, "%s %s\n", COM_CREATE, dbName);
mas01cr@239 92 }
mas01cr@239 93