comparison audioDB.h @ 0:9eab3e0f3068

Initial import
author mas01cr
date Fri, 20 Jul 2007 15:51:39 +0000
parents
children bd6bb994081b 69eb22e09772
comparison
equal deleted inserted replaced
-1:000000000000 0:9eab3e0f3068
1 /* audioDB.h
2
3 audioDB version 1.0
4
5 An efficient feature-vector database management system (FVDBMS) for
6 content-based multimedia search and retrieval.
7
8 Usage: audioDB [OPTIONS]...
9
10 --full-help Print help, including hidden options, and exit
11 -V, --version Print version and exit
12 -H, --help print help on audioDB usage and exit.
13
14 Database Setup:
15 These commands require a database argument.
16 -d, --database=filename database name to be used with database commands
17 -N, --new make a new database
18 -S, --status database information
19 -D, --dump list all segments: index key size
20
21 Database Insertion:
22 The following commands process a binary input feature file and optional
23 associated key.
24 -I, --insert add feature vectors to an existing database
25 -f, --features=filename binary series of vectors file
26 -t, --times=filename list of time points (ascii) for feature vectors
27 -k, --key=identifier unique identifier associated with features
28
29 Batch Commands:
30 These batch commands require a list of feature vector filenames in a text
31 file and optional list of keys in a text file.
32 -B, --batchinsert add feature vectors named in a featureList file
33 (with optional keys in a keyList file) to the
34 named database
35 -F, --featureList=filename text file containing list of binary feature
36 vector files to process
37 -T, --timesList=filename text file containing list of ascii time-point
38 files for each feature vector file named in
39 featureList
40 -K, --keyList=filename text file containing list of unique identifiers
41 to associate with list of feature files
42
43 Database Search:
44 Thse commands control the behaviour of retrieval from a named database.
45 -Q, --query perform a content-based search on the named
46 database using the named feature vector file
47 as a query
48 -q, --qtype=type the type of search (possible values="point",
49 "segment", "sequence" default=`sequence')
50 -p, --qpoint=position ordinal position of query vector (or start of
51 sequence) in feature vector input file
52 (default=`0')
53 -n, --pointnn=numpoints number of point nearest neighbours to use [per
54 segment in segment and sequence mode]
55 (default=`10')
56 -r, --resultlength=length maximum length of the result list
57 (default=`10')
58 -l, --sequencelength=length length of sequences for sequence search
59 (default=`16')
60 -h, --sequencehop=hop hop size of sequence window for sequence search
61 (default=`1')
62
63 Web Services:
64 These commands enable the database process to establish a connection via the
65 internet and operate as separate client and server processes.
66 -s, --server=port run as standalone web service on named port
67 (default=`80011')
68 -c, --client=hostname:port run as a client using named host service
69
70 */
71
72
73 #include <stdio.h>
74 #include <stdlib.h>
75 #include <sys/types.h>
76 #include <sys/stat.h>
77 #include <sys/mman.h>
78 #include <fcntl.h>
79 #include <string.h>
80 #include <iostream>
81 #include <fstream>
82 #include <math.h>
83 #include <sys/time.h>
84 #include <assert.h>
85
86 // includes for web services
87 #include "soapH.h"
88 #include "adb.nsmap"
89 #include "cmdline.h"
90
91 #define MAXSTR 512
92
93 // Databse PRIMARY commands
94 #define COM_CREATE "--NEW"
95 #define COM_INSERT "--INSERT"
96 #define COM_BATCHINSERT "--BATCHINSERT"
97 #define COM_QUERY "--QUERY"
98 #define COM_STATUS "--STATUS"
99 #define COM_L2NORM "--L2NORM"
100 #define COM_DUMP "--DUMP"
101 #define COM_SERVER "--SERVER"
102
103 // parameters
104 #define COM_CLIENT "--client"
105 #define COM_DATABASE "--database"
106 #define COM_QTYPE "--qtype"
107 #define COM_SEQLEN "--sequencelength"
108 #define COM_SEQHOP "--sequencehop"
109 #define COM_POINTNN "--pointnn"
110 #define COM_SEGNN "--resultlength"
111 #define COM_QPOINT "--qpoint"
112 #define COM_FEATURES "--features"
113 #define COM_QUERYKEY "--key"
114 #define COM_KEYLIST "--keyList"
115 #define COM_TIMES "--times"
116
117 #define O2_MAGIC 1111765583 // 'B'<<24|'D'<<16|'2'<<8|'O' reads O2DB in little endian order
118
119 #define O2_DEFAULT_POINTNN (10U)
120 #define O2_DEFAULT_SEGNN (10U)
121
122 //#define O2_DEFAULTDBSIZE (2000000000) // 2GB table size
123 #define O2_DEFAULTDBSIZE (1000000000U) // 1GB table size
124
125 //#define O2_MAXFILES (1000000)
126 #define O2_MAXFILES (10000U) // 10,000 files
127 #define O2_MAXFILESTR (256U)
128 #define O2_FILETABLESIZE (O2_MAXFILESTR)
129 #define O2_SEGTABLESIZE (sizeof(unsigned))
130 #define O2_HEADERSIZE (sizeof(dbTableHeaderT))
131 #define O2_MEANNUMVECTORS (1000U)
132 #define O2_MAXDIM (1000U)
133 #define O2_MAXNN (1000U)
134
135 // Flags
136 #define O2_FLAG_L2NORM (0x1U)
137 #define O2_FLAG_MINMAX (0x2U)
138 #define O2_FLAG_POINT_QUERY (0x4U)
139 #define O2_FLAG_SEQUENCE_QUERY (0x8U)
140 #define O2_FLAG_SEG_QUERY (0x10U)
141 #define O2_FLAG_TIMES (0x20U)
142
143 // Error Codes
144 #define O2_ERR_KEYNOTFOUND (0xFFFFFF00)
145
146 // Macros
147 #define O2_ACTION(a) (strcmp(command,a)==0)
148
149 using namespace std;
150
151 // 64 byte header
152 typedef struct dbTableHeader{
153 unsigned magic;
154 unsigned numFiles;
155 unsigned dim;
156 unsigned length;
157 unsigned flags;
158 } dbTableHeaderT, *dbTableHeaderPtr;
159
160
161 class audioDB{
162
163 private:
164 gengetopt_args_info args_info;
165 unsigned dim;
166 const char *dbName;
167 const char *inFile;
168 const char *hostport;
169 const char *key;
170 const char* segFileName;
171 ifstream *segFile;
172 const char *command;
173 const char *timesFileName;
174 ifstream *timesFile;
175
176 int dbfid;
177 int infid;
178 char* db;
179 char* indata;
180 struct stat statbuf;
181 dbTableHeaderPtr dbH;
182 size_t fileTableOffset;
183 size_t segTableOffset;
184 size_t dataoffset;
185 size_t l2normTableOffset;
186 size_t timesTableOffset;
187
188 char *fileTable;
189 unsigned* segTable;
190 double* dataBuf;
191 double* inBuf;
192 double* l2normTable;
193 double* qNorm;
194 double* sNorm;
195 double* timesTable;
196
197 // Flags and parameters
198 unsigned verbosity; // how much do we want to know?
199 unsigned queryType; // point queries default
200 unsigned pointNN; // how many point NNs ?
201 unsigned segNN; // how many seg NNs ?
202 unsigned sequenceLength;
203 unsigned sequenceHop;
204 unsigned queryPoint;
205 unsigned usingQueryPoint;
206 unsigned usingTimes;
207 unsigned isClient;
208 unsigned isServer;
209 unsigned port;
210 double timesTol;
211
212 // Timers
213 struct timeval tv1;
214 struct timeval tv2;
215
216
217
218
219 // private methods
220 void error(const char* a, const char* b = "");
221 void pointQuery(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult=0);
222 void sequenceQuery(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult=0);
223 void segPointQuery(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult=0);
224 void segSequenceQuery(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult=0);
225
226 void initTables(const char* dbName, const char* inFile);
227 void NBestMatchedFilter();
228 void unitNorm(double* X, unsigned d, unsigned n, double* qNorm);
229 void unitNormAndInsertL2(double* X, unsigned dim, unsigned n, unsigned append);
230 void normalize(double* X, int dim, int n);
231 void normalize(double* X, int dim, int n, double minval, double maxval);
232 void insertTimeStamps(unsigned n, ifstream* timesFile, double* timesdata);
233 unsigned getKeyPos(char* key);
234 public:
235
236 audioDB(const unsigned argc, char* const argv[], adb__queryResult *adbQueryResult=0);
237 ~audioDB();
238 int processArgs(const unsigned argc, char* const argv[]);
239 void create(const char* dbName);
240 void drop();
241 void insert(const char* dbName, const char* inFile);
242 void batchinsert(const char* dbName, const char* inFile);
243 void query(const char* dbName, const char* inFile, adb__queryResult *adbQueryResult=0);
244 void status(const char* dbName);
245 void ws_status(const char*dbName, char* hostport);
246 void ws_query(const char*dbName, const char *segKey, const char* hostport);
247 void l2norm(const char* dbName);
248 void dump(const char* dbName);
249 void deleteDB(const char* dbName, const char* inFile);
250
251 // web services
252 void startServer();
253
254 };