comparison create.cpp @ 239:2cc06e5b05a5

Merge refactoring branch. Bug fixes: * 64-bit powertable bug; * -inf - -inf bug; * use new times information; * plus short track, O2_MAXFILES and structure padding ABI fixes (already backported) Major code changes: * split source into functional units, known as 'files'; * Reporter class for accumulating and reporting on query results; * much OAOOization, mostly from above: net 800 LOC (25%) shorter.
author mas01cr
date Thu, 13 Dec 2007 14:23:32 +0000
parents
children 4dcb09f5fe85
comparison
equal deleted inserted replaced
224:3a81da6fb1d7 239:2cc06e5b05a5
1 #include "audioDB.h"
2
3 /* Make a new database.
4
5 The database consists of:
6
7 * a header (see dbTableHeader struct definition);
8 * keyTable: list of keys of tracks;
9 * trackTable: Maps implicit feature index to a feature vector
10 matrix (sizes of tracks)
11 * featureTable: Lots of doubles;
12 * timesTable: (start,end) time points for each feature vector;
13 * powerTable: associated power for each feature vector;
14 * l2normTable: squared l2norms for each feature vector.
15 */
16
17 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)
19 error("Can't create database file", dbName, "open");
20 get_lock(dbfid, 1);
21
22 VERB_LOG(0, "header size: %ju\n", (intmax_t) O2_HEADERSIZE);
23
24 dbH = new dbTableHeaderT();
25 assert(dbH);
26
27 unsigned int maxfiles = (unsigned int) rint((double) O2_MAXFILES * (double) size / (double) O2_DEFAULTDBSIZE);
28
29 // Initialize header
30 dbH->magic = O2_MAGIC;
31 dbH->version = O2_FORMAT_VERSION;
32 dbH->numFiles = 0;
33 dbH->dim = 0;
34 dbH->flags = 0;
35 dbH->headerSize = O2_HEADERSIZE;
36 dbH->length = 0;
37 dbH->fileTableOffset = ALIGN_PAGE_UP(O2_HEADERSIZE);
38 dbH->trackTableOffset = ALIGN_PAGE_UP(dbH->fileTableOffset + O2_FILETABLESIZE*maxfiles);
39 dbH->dataOffset = ALIGN_PAGE_UP(dbH->trackTableOffset + O2_TRACKTABLESIZE*maxfiles);
40 dbH->l2normTableOffset = ALIGN_PAGE_DOWN(size - maxfiles*O2_MEANNUMVECTORS*sizeof(double));
41 dbH->powerTableOffset = ALIGN_PAGE_DOWN(dbH->l2normTableOffset - maxfiles*O2_MEANNUMVECTORS*sizeof(double));
42 dbH->timesTableOffset = ALIGN_PAGE_DOWN(dbH->powerTableOffset - 2*maxfiles*O2_MEANNUMVECTORS*sizeof(double));
43 dbH->dbSize = size;
44
45 write(dbfid, dbH, O2_HEADERSIZE);
46
47 // go to the location corresponding to the last byte
48 if (lseek (dbfid, size - 1, SEEK_SET) == -1)
49 error("lseek error in db file", "", "lseek");
50
51 // write a dummy byte at the last location
52 if (write (dbfid, "", 1) != 1)
53 error("write error", "", "write");
54
55 VERB_LOG(0, "%s %s\n", COM_CREATE, dbName);
56 }
57
58 void audioDB::drop(){
59 // FIXME: drop something? Should we even allow this?
60 }
61