comparison create.cpp @ 316:25572f1bd37f large_adb

Adding large_adb support (up to 1M tracks)
author mas01mc
date Tue, 19 Aug 2008 14:27:21 +0000
parents 896679d8cc39
children b9eff6896943
comparison
equal deleted inserted replaced
315:d2c56d4f841e 316:25572f1bd37f
1 #include "audioDB.h" 1 #include "audioDB.h"
2 2
3 /* Make a new database. 3 /* Make a new database.
4 4
5 IF size(featuredata) < O2_LARGE_ADB_SIZE
5 The database consists of: 6 The database consists of:
6 7
7 * a header (see dbTableHeader struct definition); 8 * a header (see dbTableHeader struct definition);
8 * keyTable: list of keys of tracks; 9 * keyTable: list of keys of tracks;
9 * trackTable: Maps implicit feature index to a feature vector 10 * trackTable: Maps implicit feature index to a feature vector
10 matrix (sizes of tracks) 11 matrix (sizes of tracks)
11 * featureTable: Lots of doubles; 12 * featureTable: Lots of doubles;
12 * timesTable: (start,end) time points for each feature vector; 13 * timesTable: (start,end) time points for each feature vector;
13 * powerTable: associated power for each feature vector; 14 * powerTable: associated power for each feature vector;
14 * l2normTable: squared l2norms for each feature vector. 15 * l2normTable: squared l2norms for each feature vector.
16
17 ELSE the database consists of:
18
19 * a header (see dbTableHeader struct definition);
20 * keyTable: list of keys of tracks
21 * trackTable: sizes of tracks
22 * featureTable: list of feature file names
23 * timesTable: list of times file names
24 * powerTable: list of power file names
25
15 */ 26 */
16 27
17 void audioDB::create(const char* dbName){ 28 void audioDB::create(const char* dbName){
18 if ((dbfid = open (dbName, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) 29 if ((dbfid = open (dbName, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0)
19 error("Can't create database file", dbName, "open"); 30 error("Can't create database file", dbName, "open");
39 dbH->dataOffset = ALIGN_PAGE_UP(dbH->trackTableOffset + O2_TRACKTABLE_ENTRY_SIZE*ntracks); 50 dbH->dataOffset = ALIGN_PAGE_UP(dbH->trackTableOffset + O2_TRACKTABLE_ENTRY_SIZE*ntracks);
40 51
41 off_t databytes = ((off_t) datasize) * 1024 * 1024; 52 off_t databytes = ((off_t) datasize) * 1024 * 1024;
42 off_t auxbytes = databytes / datadim; 53 off_t auxbytes = databytes / datadim;
43 54
44 dbH->timesTableOffset = ALIGN_PAGE_UP(dbH->dataOffset + databytes); 55 // If database will fit in a single file the vectors are copied into the AudioDB instance
45 dbH->powerTableOffset = ALIGN_PAGE_UP(dbH->timesTableOffset + 2*auxbytes); 56 // Else all the vectors are left on the FileSystem and we use the dataOffset as storage
46 dbH->l2normTableOffset = ALIGN_PAGE_UP(dbH->powerTableOffset + auxbytes); 57 // for the location of the features, powers and times files (assuming that arbitrary keys are used for the fileTable)
47 dbH->dbSize = ALIGN_PAGE_UP(dbH->l2normTableOffset + auxbytes); 58 if(datasize<O2_LARGE_ADB_SIZE){
59 dbH->timesTableOffset = ALIGN_PAGE_UP(dbH->dataOffset + databytes);
60 dbH->powerTableOffset = ALIGN_PAGE_UP(dbH->timesTableOffset + 2*auxbytes);
61 dbH->l2normTableOffset = ALIGN_PAGE_UP(dbH->powerTableOffset + auxbytes);
62 dbH->dbSize = ALIGN_PAGE_UP(dbH->l2normTableOffset + auxbytes);
63 }
64 else{
65 dbH->flags |= O2_FLAG_LARGE_ADB;
66 dbH->timesTableOffset = ALIGN_PAGE_UP(dbH->dataOffset + O2_FILETABLE_ENTRY_SIZE*ntracks);
67 dbH->powerTableOffset = ALIGN_PAGE_UP(dbH->timesTableOffset + O2_FILETABLE_ENTRY_SIZE*ntracks);
68 dbH->l2normTableOffset = ALIGN_PAGE_UP(dbH->powerTableOffset + O2_FILETABLE_ENTRY_SIZE*ntracks);
69 dbH->dbSize = dbH->l2normTableOffset;
70 }
48 71
49 write(dbfid, dbH, O2_HEADERSIZE); 72 write(dbfid, dbH, O2_HEADERSIZE);
50 73
51 // go to the location corresponding to the last byte 74 // go to the location corresponding to the last byte
52 if (lseek (dbfid, dbH->dbSize - 1, SEEK_SET) == -1) 75 if (lseek (dbfid, dbH->dbSize - 1, SEEK_SET) == -1)