comparison create.cpp @ 204:2ea1908707c7 refactoring

Filewise refactor. Break apart huge monolithic audioDB.cpp file into seven broadly independent portions: * SOAP * DB creation * insertion * query * dump * common functionality * constructor functions Remove the "using namespace std" from the header file, though that wasn't actually a problem: the problem in question is solved by including adb.nsmap in only soap.cpp. Makefile improvements.
author mas01cr
date Wed, 28 Nov 2007 15:10:28 +0000
parents
children acafe033b962
comparison
equal deleted inserted replaced
203:4b05c5bbf06d 204:2ea1908707c7
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 if(verbosity) {
23 std::cerr << "header size:" << O2_HEADERSIZE << std::endl;
24 }
25
26 dbH = new dbTableHeaderT();
27 assert(dbH);
28
29 unsigned int maxfiles = (unsigned int) rint((double) O2_MAXFILES * (double) size / (double) O2_DEFAULTDBSIZE);
30
31 // Initialize header
32 dbH->magic = O2_MAGIC;
33 dbH->version = O2_FORMAT_VERSION;
34 dbH->numFiles = 0;
35 dbH->dim = 0;
36 dbH->flags = 0;
37 dbH->length = 0;
38 dbH->fileTableOffset = ALIGN_PAGE_UP(O2_HEADERSIZE);
39 dbH->trackTableOffset = ALIGN_PAGE_UP(dbH->fileTableOffset + O2_FILETABLESIZE*maxfiles);
40 dbH->dataOffset = ALIGN_PAGE_UP(dbH->trackTableOffset + O2_TRACKTABLESIZE*maxfiles);
41 dbH->l2normTableOffset = ALIGN_PAGE_DOWN(size - maxfiles*O2_MEANNUMVECTORS*sizeof(double));
42 dbH->powerTableOffset = ALIGN_PAGE_DOWN(dbH->l2normTableOffset - maxfiles*O2_MEANNUMVECTORS*sizeof(double));
43 dbH->timesTableOffset = ALIGN_PAGE_DOWN(dbH->powerTableOffset - 2*maxfiles*O2_MEANNUMVECTORS*sizeof(double));
44 dbH->dbSize = size;
45
46 write(dbfid, dbH, O2_HEADERSIZE);
47
48 // go to the location corresponding to the last byte
49 if (lseek (dbfid, size - 1, SEEK_SET) == -1)
50 error("lseek error in db file", "", "lseek");
51
52 // write a dummy byte at the last location
53 if (write (dbfid, "", 1) != 1)
54 error("write error", "", "write");
55
56 if(verbosity) {
57 std::cerr << COM_CREATE << " " << dbName << std::endl;
58 }
59 }
60
61 void audioDB::drop(){
62 // FIXME: drop something? Should we even allow this?
63 }
64