mas01mc@292
|
1 #ifndef __REPORTER_H
|
mas01mc@292
|
2 #define __REPORTER_H
|
mas01mc@292
|
3
|
mas01cr@239
|
4 #include <utility>
|
mas01cr@239
|
5 #include <queue>
|
mas01cr@239
|
6 #include <set>
|
mas01cr@239
|
7 #include <functional>
|
mas01mc@292
|
8 #include <iostream>
|
mas01mc@292
|
9 #include "ReporterBase.h"
|
mas01mc@292
|
10 #include "audioDB.h"
|
mas01cr@239
|
11
|
mas01cr@239
|
12 typedef struct nnresult {
|
mas01cr@239
|
13 unsigned int trackID;
|
mas01cr@239
|
14 double dist;
|
mas01cr@239
|
15 unsigned int qpos;
|
mas01cr@239
|
16 unsigned int spos;
|
mas01cr@239
|
17 } NNresult;
|
mas01cr@239
|
18
|
mas01cr@239
|
19 typedef struct radresult {
|
mas01cr@239
|
20 unsigned int trackID;
|
mas01cr@239
|
21 unsigned int count;
|
mas01cr@239
|
22 } Radresult;
|
mas01cr@239
|
23
|
mas01cr@239
|
24 bool operator< (const NNresult &a, const NNresult &b) {
|
mas01cr@239
|
25 return a.dist < b.dist;
|
mas01cr@239
|
26 }
|
mas01cr@239
|
27
|
mas01cr@239
|
28 bool operator> (const NNresult &a, const NNresult &b) {
|
mas01cr@239
|
29 return a.dist > b.dist;
|
mas01cr@239
|
30 }
|
mas01cr@239
|
31
|
mas01cr@239
|
32 bool operator< (const Radresult &a, const Radresult &b) {
|
mas01cr@239
|
33 return a.count < b.count;
|
mas01cr@239
|
34 }
|
mas01cr@239
|
35
|
mas01mc@275
|
36 bool operator> (const Radresult &a, const Radresult &b) {
|
mas01mc@275
|
37 return a.count > b.count;
|
mas01mc@275
|
38 }
|
mas01mc@275
|
39
|
mas01mc@292
|
40 class Reporter : public ReporterBase {
|
mas01cr@239
|
41 public:
|
mas01cr@239
|
42 virtual ~Reporter() {};
|
mas01cr@239
|
43 virtual void add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist) = 0;
|
mas01cr@239
|
44 // FIXME: this interface is a bit wacky: a relic of previous, more
|
mas01cr@239
|
45 // confused times. Really it might make sense to have separate
|
mas01cr@239
|
46 // reporter classes for WS and for stdout, rather than passing this
|
mas01cr@239
|
47 // adbQueryResponse thing everywhere; the fileTable argument is
|
mas01cr@239
|
48 // there solely for convertion trackIDs into names. -- CSR,
|
mas01cr@239
|
49 // 2007-12-10.
|
mas01mc@292
|
50 virtual void report(char *fileTable, void* adbQueryResponse) = 0;
|
mas01cr@239
|
51 };
|
mas01cr@239
|
52
|
mas01cr@239
|
53 template <class T> class pointQueryReporter : public Reporter {
|
mas01cr@239
|
54 public:
|
mas01cr@239
|
55 pointQueryReporter(unsigned int pointNN);
|
mas01cr@239
|
56 ~pointQueryReporter();
|
mas01cr@239
|
57 void add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist);
|
mas01mc@292
|
58 void report(char *fileTable, void* adbQueryResponse);
|
mas01cr@239
|
59 private:
|
mas01cr@239
|
60 unsigned int pointNN;
|
mas01cr@239
|
61 std::priority_queue< NNresult, std::vector< NNresult >, T> *queue;
|
mas01cr@239
|
62 };
|
mas01cr@239
|
63
|
mas01cr@239
|
64 template <class T> pointQueryReporter<T>::pointQueryReporter(unsigned int pointNN)
|
mas01cr@239
|
65 : pointNN(pointNN) {
|
mas01cr@239
|
66 queue = new std::priority_queue< NNresult, std::vector< NNresult >, T>;
|
mas01cr@239
|
67 }
|
mas01cr@239
|
68
|
mas01cr@239
|
69 template <class T> pointQueryReporter<T>::~pointQueryReporter() {
|
mas01cr@239
|
70 delete queue;
|
mas01cr@239
|
71 }
|
mas01cr@239
|
72
|
mas01cr@239
|
73 template <class T> void pointQueryReporter<T>::add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist) {
|
mas01cr@242
|
74 if (!isnan(dist)) {
|
mas01cr@242
|
75 NNresult r;
|
mas01cr@242
|
76 r.trackID = trackID;
|
mas01cr@242
|
77 r.qpos = qpos;
|
mas01cr@242
|
78 r.spos = spos;
|
mas01cr@242
|
79 r.dist = dist;
|
mas01cr@242
|
80 queue->push(r);
|
mas01cr@242
|
81 if(queue->size() > pointNN) {
|
mas01cr@242
|
82 queue->pop();
|
mas01cr@242
|
83 }
|
mas01cr@239
|
84 }
|
mas01cr@239
|
85 }
|
mas01cr@239
|
86
|
mas01mc@292
|
87 template <class T> void pointQueryReporter<T>::report(char *fileTable, void *adbQueryResponse) {
|
mas01cr@239
|
88 NNresult r;
|
mas01cr@239
|
89 std::vector<NNresult> v;
|
mas01cr@239
|
90 unsigned int size = queue->size();
|
mas01cr@239
|
91 for(unsigned int k = 0; k < size; k++) {
|
mas01cr@239
|
92 r = queue->top();
|
mas01cr@239
|
93 v.push_back(r);
|
mas01cr@239
|
94 queue->pop();
|
mas01cr@239
|
95 }
|
mas01cr@239
|
96 std::vector<NNresult>::reverse_iterator rit;
|
mas01cr@239
|
97
|
mas01cr@239
|
98 if(adbQueryResponse==0) {
|
mas01cr@239
|
99 for(rit = v.rbegin(); rit < v.rend(); rit++) {
|
mas01cr@239
|
100 r = *rit;
|
mas01mc@292
|
101 if(fileTable)
|
mas01mc@292
|
102 std::cout << fileTable + r.trackID*O2_FILETABLE_ENTRY_SIZE << " ";
|
mas01mc@292
|
103 else
|
mas01mc@292
|
104 std::cout << r.trackID << " ";
|
mas01cr@239
|
105 std::cout << r.dist << " " << r.qpos << " " << r.spos << std::endl;
|
mas01cr@239
|
106 }
|
mas01cr@239
|
107 } else {
|
mas01mc@292
|
108 ((adb__queryResponse*)adbQueryResponse)->result.__sizeRlist=size;
|
mas01mc@292
|
109 ((adb__queryResponse*)adbQueryResponse)->result.__sizeDist=size;
|
mas01mc@292
|
110 ((adb__queryResponse*)adbQueryResponse)->result.__sizeQpos=size;
|
mas01mc@292
|
111 ((adb__queryResponse*)adbQueryResponse)->result.__sizeSpos=size;
|
mas01mc@292
|
112 ((adb__queryResponse*)adbQueryResponse)->result.Rlist= new char*[size];
|
mas01mc@292
|
113 ((adb__queryResponse*)adbQueryResponse)->result.Dist = new double[size];
|
mas01mc@292
|
114 ((adb__queryResponse*)adbQueryResponse)->result.Qpos = new unsigned int[size];
|
mas01mc@292
|
115 ((adb__queryResponse*)adbQueryResponse)->result.Spos = new unsigned int[size];
|
mas01cr@239
|
116 unsigned int k = 0;
|
mas01cr@239
|
117 for(rit = v.rbegin(); rit < v.rend(); rit++, k++) {
|
mas01cr@239
|
118 r = *rit;
|
mas01mc@292
|
119 ((adb__queryResponse*)adbQueryResponse)->result.Rlist[k] = new char[O2_MAXFILESTR];
|
mas01mc@292
|
120 ((adb__queryResponse*)adbQueryResponse)->result.Dist[k] = r.dist;
|
mas01mc@292
|
121 ((adb__queryResponse*)adbQueryResponse)->result.Qpos[k] = r.qpos;
|
mas01mc@292
|
122 ((adb__queryResponse*)adbQueryResponse)->result.Spos[k] = r.spos;
|
mas01mc@292
|
123 if(fileTable)
|
mas01mc@292
|
124 snprintf(((adb__queryResponse*)adbQueryResponse)->result.Rlist[k], O2_MAXFILESTR, "%s", fileTable+r.trackID*O2_FILETABLE_ENTRY_SIZE);
|
mas01mc@292
|
125 else
|
mas01mc@292
|
126 snprintf(((adb__queryResponse*)adbQueryResponse)->result.Rlist[k], O2_MAXFILESTR, "%d", r.trackID);
|
mas01cr@239
|
127 }
|
mas01cr@239
|
128 }
|
mas01cr@239
|
129 }
|
mas01cr@239
|
130
|
mas01cr@239
|
131 template <class T> class trackAveragingReporter : public Reporter {
|
mas01cr@239
|
132 public:
|
mas01cr@239
|
133 trackAveragingReporter(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles);
|
mas01cr@239
|
134 ~trackAveragingReporter();
|
mas01cr@239
|
135 void add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist);
|
mas01mc@292
|
136 void report(char *fileTable, void *adbQueryResponse);
|
mas01mc@249
|
137 protected:
|
mas01cr@239
|
138 unsigned int pointNN;
|
mas01cr@239
|
139 unsigned int trackNN;
|
mas01cr@239
|
140 unsigned int numFiles;
|
mas01cr@239
|
141 std::priority_queue< NNresult, std::vector< NNresult>, T > *queues;
|
mas01cr@239
|
142 };
|
mas01cr@239
|
143
|
mas01cr@239
|
144 template <class T> trackAveragingReporter<T>::trackAveragingReporter(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles)
|
mas01cr@239
|
145 : pointNN(pointNN), trackNN(trackNN), numFiles(numFiles) {
|
mas01cr@239
|
146 queues = new std::priority_queue< NNresult, std::vector< NNresult>, T >[numFiles];
|
mas01cr@239
|
147 }
|
mas01cr@239
|
148
|
mas01cr@239
|
149 template <class T> trackAveragingReporter<T>::~trackAveragingReporter() {
|
mas01cr@239
|
150 delete [] queues;
|
mas01cr@239
|
151 }
|
mas01cr@239
|
152
|
mas01cr@239
|
153 template <class T> void trackAveragingReporter<T>::add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist) {
|
mas01cr@242
|
154 if (!isnan(dist)) {
|
mas01cr@242
|
155 NNresult r;
|
mas01cr@242
|
156 r.trackID = trackID;
|
mas01cr@242
|
157 r.qpos = qpos;
|
mas01cr@242
|
158 r.spos = spos;
|
mas01cr@242
|
159 r.dist = dist;
|
mas01cr@242
|
160 queues[trackID].push(r);
|
mas01cr@242
|
161 if(queues[trackID].size() > pointNN) {
|
mas01cr@242
|
162 queues[trackID].pop();
|
mas01cr@242
|
163 }
|
mas01cr@239
|
164 }
|
mas01cr@239
|
165 }
|
mas01cr@239
|
166
|
mas01mc@292
|
167 template <class T> void trackAveragingReporter<T>::report(char *fileTable, void *adbQueryResponse) {
|
mas01cr@239
|
168 std::priority_queue < NNresult, std::vector< NNresult>, T> result;
|
mas01cr@239
|
169 for (int i = numFiles-1; i >= 0; i--) {
|
mas01cr@239
|
170 unsigned int size = queues[i].size();
|
mas01cr@239
|
171 if (size > 0) {
|
mas01cr@239
|
172 NNresult r;
|
mas01cr@239
|
173 double dist = 0;
|
mas01cr@239
|
174 NNresult oldr = queues[i].top();
|
mas01cr@239
|
175 for (unsigned int j = 0; j < size; j++) {
|
mas01cr@239
|
176 r = queues[i].top();
|
mas01cr@239
|
177 dist += r.dist;
|
mas01cr@239
|
178 queues[i].pop();
|
mas01cr@239
|
179 if (r.dist == oldr.dist) {
|
mas01cr@239
|
180 r.qpos = oldr.qpos;
|
mas01cr@239
|
181 r.spos = oldr.spos;
|
mas01cr@239
|
182 } else {
|
mas01cr@239
|
183 oldr = r;
|
mas01cr@239
|
184 }
|
mas01cr@239
|
185 }
|
mas01cr@239
|
186 dist /= size;
|
mas01cr@239
|
187 r.dist = dist; // trackID, qpos and spos are magically right already.
|
mas01cr@239
|
188 result.push(r);
|
mas01cr@239
|
189 if (result.size() > trackNN) {
|
mas01cr@239
|
190 result.pop();
|
mas01cr@239
|
191 }
|
mas01cr@239
|
192 }
|
mas01cr@239
|
193 }
|
mas01cr@239
|
194
|
mas01cr@239
|
195 NNresult r;
|
mas01cr@239
|
196 std::vector<NNresult> v;
|
mas01cr@239
|
197 unsigned int size = result.size();
|
mas01cr@239
|
198 for(unsigned int k = 0; k < size; k++) {
|
mas01cr@239
|
199 r = result.top();
|
mas01cr@239
|
200 v.push_back(r);
|
mas01cr@239
|
201 result.pop();
|
mas01cr@239
|
202 }
|
mas01cr@239
|
203 std::vector<NNresult>::reverse_iterator rit;
|
mas01cr@239
|
204
|
mas01cr@239
|
205 if(adbQueryResponse==0) {
|
mas01cr@239
|
206 for(rit = v.rbegin(); rit < v.rend(); rit++) {
|
mas01cr@239
|
207 r = *rit;
|
mas01mc@292
|
208 if(fileTable)
|
mas01mc@292
|
209 std::cout << fileTable + r.trackID*O2_FILETABLE_ENTRY_SIZE << " ";
|
mas01mc@292
|
210 else
|
mas01mc@292
|
211 std::cout << r.trackID << " ";
|
mas01cr@239
|
212 std::cout << r.dist << " " << r.qpos << " " << r.spos << std::endl;
|
mas01cr@239
|
213 }
|
mas01cr@239
|
214 } else {
|
mas01mc@292
|
215 ((adb__queryResponse*)adbQueryResponse)->result.__sizeRlist=size;
|
mas01mc@292
|
216 ((adb__queryResponse*)adbQueryResponse)->result.__sizeDist=size;
|
mas01mc@292
|
217 ((adb__queryResponse*)adbQueryResponse)->result.__sizeQpos=size;
|
mas01mc@292
|
218 ((adb__queryResponse*)adbQueryResponse)->result.__sizeSpos=size;
|
mas01mc@292
|
219 ((adb__queryResponse*)adbQueryResponse)->result.Rlist= new char*[size];
|
mas01mc@292
|
220 ((adb__queryResponse*)adbQueryResponse)->result.Dist = new double[size];
|
mas01mc@292
|
221 ((adb__queryResponse*)adbQueryResponse)->result.Qpos = new unsigned int[size];
|
mas01mc@292
|
222 ((adb__queryResponse*)adbQueryResponse)->result.Spos = new unsigned int[size];
|
mas01cr@239
|
223 unsigned int k = 0;
|
mas01cr@239
|
224 for(rit = v.rbegin(); rit < v.rend(); rit++, k++) {
|
mas01cr@239
|
225 r = *rit;
|
mas01mc@292
|
226 ((adb__queryResponse*)adbQueryResponse)->result.Rlist[k] = new char[O2_MAXFILESTR];
|
mas01mc@292
|
227 ((adb__queryResponse*)adbQueryResponse)->result.Dist[k] = r.dist;
|
mas01mc@292
|
228 ((adb__queryResponse*)adbQueryResponse)->result.Qpos[k] = r.qpos;
|
mas01mc@292
|
229 ((adb__queryResponse*)adbQueryResponse)->result.Spos[k] = r.spos;
|
mas01mc@292
|
230 if(fileTable)
|
mas01mc@292
|
231 snprintf(((adb__queryResponse*)adbQueryResponse)->result.Rlist[k], O2_MAXFILESTR, "%s", fileTable+r.trackID*O2_FILETABLE_ENTRY_SIZE);
|
mas01mc@292
|
232 else
|
mas01mc@292
|
233 snprintf(((adb__queryResponse*)adbQueryResponse)->result.Rlist[k], O2_MAXFILESTR, "%d", r.trackID);
|
mas01cr@239
|
234 }
|
mas01cr@239
|
235 }
|
mas01cr@239
|
236 }
|
mas01cr@239
|
237
|
mas01mc@249
|
238 // Another type of trackAveragingReporter that reports all pointNN nearest neighbours
|
mas01mc@249
|
239 template <class T> class trackSequenceQueryNNReporter : public trackAveragingReporter<T> {
|
mas01mc@249
|
240 protected:
|
mas01mc@249
|
241 using trackAveragingReporter<T>::numFiles;
|
mas01mc@249
|
242 using trackAveragingReporter<T>::queues;
|
mas01mc@249
|
243 using trackAveragingReporter<T>::trackNN;
|
mas01mc@249
|
244 using trackAveragingReporter<T>::pointNN;
|
mas01mc@248
|
245 public:
|
mas01mc@248
|
246 trackSequenceQueryNNReporter(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles);
|
mas01mc@292
|
247 void report(char *fileTable, void *adbQueryResponse);
|
mas01mc@248
|
248 };
|
mas01mc@248
|
249
|
mas01mc@249
|
250 template <class T> trackSequenceQueryNNReporter<T>::trackSequenceQueryNNReporter(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles)
|
mas01mc@249
|
251 :trackAveragingReporter<T>(pointNN, trackNN, numFiles){}
|
mas01mc@248
|
252
|
mas01mc@292
|
253 template <class T> void trackSequenceQueryNNReporter<T>::report(char *fileTable, void *adbQueryResponse) {
|
mas01mc@248
|
254 std::priority_queue < NNresult, std::vector< NNresult>, T> result;
|
mas01mc@292
|
255 std::priority_queue< NNresult, std::vector< NNresult>, std::less<NNresult> > *point_queues
|
mas01mc@292
|
256 = new std::priority_queue< NNresult, std::vector< NNresult>, std::less<NNresult> >[numFiles];
|
mas01mc@249
|
257
|
mas01mc@248
|
258 for (int i = numFiles-1; i >= 0; i--) {
|
mas01mc@248
|
259 unsigned int size = queues[i].size();
|
mas01mc@248
|
260 if (size > 0) {
|
mas01mc@248
|
261 NNresult r;
|
mas01mc@248
|
262 double dist = 0;
|
mas01mc@248
|
263 NNresult oldr = queues[i].top();
|
mas01mc@248
|
264 for (unsigned int j = 0; j < size; j++) {
|
mas01mc@248
|
265 r = queues[i].top();
|
mas01mc@248
|
266 dist += r.dist;
|
mas01mc@248
|
267 point_queues[i].push(r);
|
mas01mc@249
|
268 queues[i].pop();
|
mas01mc@248
|
269 if (r.dist == oldr.dist) {
|
mas01mc@248
|
270 r.qpos = oldr.qpos;
|
mas01mc@248
|
271 r.spos = oldr.spos;
|
mas01mc@248
|
272 } else {
|
mas01mc@248
|
273 oldr = r;
|
mas01mc@248
|
274 }
|
mas01mc@248
|
275 }
|
mas01mc@248
|
276 dist /= size;
|
mas01mc@248
|
277 r.dist = dist; // trackID, qpos and spos are magically right already.
|
mas01mc@248
|
278 result.push(r);
|
mas01mc@248
|
279 if (result.size() > trackNN) {
|
mas01mc@248
|
280 result.pop();
|
mas01mc@248
|
281 }
|
mas01mc@248
|
282 }
|
mas01mc@248
|
283 }
|
mas01mc@248
|
284
|
mas01mc@248
|
285 NNresult r;
|
mas01mc@248
|
286 std::vector<NNresult> v;
|
mas01mc@248
|
287 unsigned int size = result.size();
|
mas01mc@248
|
288 for(unsigned int k = 0; k < size; k++) {
|
mas01mc@248
|
289 r = result.top();
|
mas01mc@248
|
290 v.push_back(r);
|
mas01mc@248
|
291 result.pop();
|
mas01mc@248
|
292 }
|
mas01mc@248
|
293 std::vector<NNresult>::reverse_iterator rit;
|
mas01mc@264
|
294 std::priority_queue< NNresult, std::vector< NNresult>, std::greater<NNresult> > point_queue;
|
mas01mc@264
|
295
|
mas01mc@248
|
296 if(adbQueryResponse==0) {
|
mas01mc@248
|
297 for(rit = v.rbegin(); rit < v.rend(); rit++) {
|
mas01mc@248
|
298 r = *rit;
|
mas01mc@292
|
299 if(fileTable)
|
mas01mc@292
|
300 std::cout << fileTable + r.trackID*O2_FILETABLE_ENTRY_SIZE << " ";
|
mas01mc@292
|
301 else
|
mas01mc@292
|
302 std::cout << r.trackID << " ";
|
mas01mc@292
|
303 std::cout << r.dist << std::endl;
|
mas01mc@264
|
304 unsigned int qsize = point_queues[r.trackID].size();
|
mas01mc@264
|
305 // Reverse the order of the points stored in point_queues
|
mas01mc@264
|
306 for(unsigned int k=0; k < qsize; k++){
|
mas01mc@264
|
307 point_queue.push( point_queues[r.trackID].top() );
|
mas01mc@264
|
308 point_queues[r.trackID].pop();
|
mas01mc@264
|
309 }
|
mas01mc@264
|
310
|
mas01mc@264
|
311 for(unsigned int k = 0; k < qsize; k++) {
|
mas01mc@264
|
312 NNresult rk = point_queue.top();
|
mas01mc@248
|
313 std::cout << rk.dist << " " << rk.qpos << " " << rk.spos << std::endl;
|
mas01mc@264
|
314 point_queue.pop();
|
mas01mc@248
|
315 }
|
mas01mc@248
|
316 }
|
mas01mc@248
|
317 } else {
|
mas01mc@292
|
318 ((adb__queryResponse*)adbQueryResponse)->result.__sizeRlist=size;
|
mas01mc@292
|
319 ((adb__queryResponse*)adbQueryResponse)->result.__sizeDist=size;
|
mas01mc@292
|
320 ((adb__queryResponse*)adbQueryResponse)->result.__sizeQpos=size;
|
mas01mc@292
|
321 ((adb__queryResponse*)adbQueryResponse)->result.__sizeSpos=size;
|
mas01mc@292
|
322 ((adb__queryResponse*)adbQueryResponse)->result.Rlist= new char*[size];
|
mas01mc@292
|
323 ((adb__queryResponse*)adbQueryResponse)->result.Dist = new double[size];
|
mas01mc@292
|
324 ((adb__queryResponse*)adbQueryResponse)->result.Qpos = new unsigned int[size];
|
mas01mc@292
|
325 ((adb__queryResponse*)adbQueryResponse)->result.Spos = new unsigned int[size];
|
mas01mc@248
|
326 unsigned int k = 0;
|
mas01mc@248
|
327 for(rit = v.rbegin(); rit < v.rend(); rit++, k++) {
|
mas01mc@248
|
328 r = *rit;
|
mas01mc@292
|
329 ((adb__queryResponse*)adbQueryResponse)->result.Rlist[k] = new char[O2_MAXFILESTR];
|
mas01mc@292
|
330 ((adb__queryResponse*)adbQueryResponse)->result.Dist[k] = r.dist;
|
mas01mc@292
|
331 ((adb__queryResponse*)adbQueryResponse)->result.Qpos[k] = r.qpos;
|
mas01mc@292
|
332 ((adb__queryResponse*)adbQueryResponse)->result.Spos[k] = r.spos;
|
mas01mc@292
|
333 if(fileTable)
|
mas01mc@292
|
334 snprintf(((adb__queryResponse*)adbQueryResponse)->result.Rlist[k], O2_MAXFILESTR, "%s", fileTable+r.trackID*O2_FILETABLE_ENTRY_SIZE);
|
mas01mc@292
|
335 else
|
mas01mc@292
|
336 snprintf(((adb__queryResponse*)adbQueryResponse)->result.Rlist[k], O2_MAXFILESTR, "%d", r.trackID);
|
mas01mc@248
|
337 }
|
mas01mc@248
|
338 }
|
mas01mc@248
|
339 // clean up
|
mas01mc@248
|
340 delete[] point_queues;
|
mas01mc@248
|
341 }
|
mas01mc@250
|
342
|
mas01mc@292
|
343 /********************** Radius Reporters **************************/
|
mas01mc@250
|
344
|
mas01mc@292
|
345 class triple{
|
mas01mc@292
|
346 public:
|
mas01mc@292
|
347 unsigned int a;
|
mas01mc@292
|
348 unsigned int b;
|
mas01mc@292
|
349 unsigned int c;
|
mas01mc@292
|
350
|
mas01mc@292
|
351 triple(void);
|
mas01mc@292
|
352 triple(unsigned int, unsigned int, unsigned int);
|
mas01mc@292
|
353 unsigned int first();
|
mas01mc@292
|
354 unsigned int second();
|
mas01mc@292
|
355 unsigned int third();
|
mas01mc@292
|
356 };
|
mas01mc@292
|
357
|
mas01mc@292
|
358 triple& make_triple(unsigned int, unsigned int, unsigned int);
|
mas01mc@292
|
359
|
mas01mc@292
|
360 triple::triple(unsigned int a, unsigned int b, unsigned int c):a(a),b(b),c(c){}
|
mas01mc@292
|
361
|
mas01mc@292
|
362 unsigned int triple::first(){return a;}
|
mas01mc@292
|
363 unsigned int triple::second(){return b;}
|
mas01mc@292
|
364 unsigned int triple::third(){return c;}
|
mas01mc@292
|
365
|
mas01mc@292
|
366 triple::triple():a(0),b(0),c(0){}
|
mas01mc@292
|
367
|
mas01mc@292
|
368 bool operator< (const triple &t1, const triple &t2) {
|
mas01mc@292
|
369 return ((t1.a < t2.a) ||
|
mas01mc@292
|
370 ((t1.a == t2.a) && ((t1.b < t2.b) ||
|
mas01mc@292
|
371 ((t1.b == t2.b) && (t1.c < t2.c)))));
|
mas01mc@292
|
372 }
|
mas01mc@292
|
373 bool operator== (const triple &t1, const triple &t2) {
|
mas01mc@292
|
374 return ((t1.a == t2.a) && (t1.b == t2.b) && (t1.c == t2.c));
|
mas01mc@292
|
375 }
|
mas01mc@292
|
376
|
mas01mc@292
|
377 triple& make_triple(unsigned int a, unsigned int b, unsigned int c){
|
mas01mc@292
|
378 triple* t = new triple(a,b,c);
|
mas01mc@292
|
379 return *t;
|
mas01mc@292
|
380 }
|
mas01mc@292
|
381
|
mas01mc@292
|
382
|
mas01mc@292
|
383 // track Sequence Query Radius Reporter
|
mas01mc@292
|
384 // only return tracks and retrieved point counts
|
mas01mc@292
|
385 class trackSequenceQueryRadReporter : public Reporter {
|
mas01mc@250
|
386 public:
|
mas01mc@292
|
387 trackSequenceQueryRadReporter(unsigned int trackNN, unsigned int numFiles);
|
mas01mc@292
|
388 ~trackSequenceQueryRadReporter();
|
mas01mc@250
|
389 void add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist);
|
mas01mc@292
|
390 void report(char *fileTable, void *adbQueryResponse);
|
mas01mc@250
|
391 protected:
|
mas01mc@250
|
392 unsigned int trackNN;
|
mas01mc@250
|
393 unsigned int numFiles;
|
mas01mc@292
|
394 std::set<std::pair<unsigned int, unsigned int> > *set;
|
mas01mc@292
|
395 std::set< triple > *set_triple;
|
mas01mc@250
|
396 unsigned int *count;
|
mas01mc@250
|
397 };
|
mas01mc@250
|
398
|
mas01mc@292
|
399 trackSequenceQueryRadReporter::trackSequenceQueryRadReporter(unsigned int trackNN, unsigned int numFiles):
|
mas01mc@292
|
400 trackNN(trackNN), numFiles(numFiles) {
|
mas01mc@292
|
401 set = new std::set<std::pair<unsigned int, unsigned int> >;
|
mas01mc@292
|
402 set_triple = new std::set<triple, std::less<triple> >;
|
mas01mc@250
|
403 count = new unsigned int[numFiles];
|
mas01mc@250
|
404 for (unsigned i = 0; i < numFiles; i++) {
|
mas01mc@250
|
405 count[i] = 0;
|
mas01mc@250
|
406 }
|
mas01mc@250
|
407 }
|
mas01mc@250
|
408
|
mas01mc@292
|
409 trackSequenceQueryRadReporter::~trackSequenceQueryRadReporter() {
|
mas01mc@250
|
410 delete set;
|
mas01mc@292
|
411 delete set_triple;
|
mas01mc@250
|
412 delete [] count;
|
mas01mc@250
|
413 }
|
mas01mc@250
|
414
|
mas01mc@292
|
415 void trackSequenceQueryRadReporter::add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist) {
|
mas01mc@292
|
416 std::set<std::pair<unsigned int, unsigned int> >::iterator it;
|
mas01mc@292
|
417 std::pair<unsigned int, unsigned int> pair = std::make_pair(trackID, qpos); // only count this once
|
mas01mc@292
|
418 std::set<triple>::iterator it2;
|
mas01mc@292
|
419 triple triple;
|
mas01mc@250
|
420
|
mas01mc@292
|
421 triple = make_triple(trackID, qpos, spos); // only count this once
|
mas01mc@292
|
422
|
mas01mc@292
|
423 // Record unique <trackID,qpos,spos> triples (record one collision from all hash tables)
|
mas01mc@292
|
424 it2 = set_triple->find(triple);
|
mas01mc@250
|
425
|
mas01mc@292
|
426 if(it2 == set_triple->end()){
|
mas01mc@292
|
427 set_triple->insert(triple);
|
mas01mc@292
|
428
|
mas01mc@292
|
429 it = set->find(pair);
|
mas01mc@292
|
430 if (it == set->end()) {
|
mas01mc@292
|
431 set->insert(pair);
|
mas01mc@292
|
432 count[trackID]++; // only count if <tackID,qpos> pair is unique
|
mas01mc@292
|
433 }
|
mas01mc@250
|
434 }
|
mas01mc@250
|
435 }
|
mas01mc@250
|
436
|
mas01mc@292
|
437 void trackSequenceQueryRadReporter::report(char *fileTable, void *adbQueryResponse) {
|
mas01mc@275
|
438 std::priority_queue < Radresult, std::vector<Radresult>, std::greater<Radresult> > result;
|
mas01mc@250
|
439 // KLUDGE: doing this backwards in an attempt to get the same
|
mas01mc@250
|
440 // tiebreak behaviour as before.
|
mas01mc@250
|
441 for (int i = numFiles-1; i >= 0; i--) {
|
mas01mc@250
|
442 Radresult r;
|
mas01mc@250
|
443 r.trackID = i;
|
mas01mc@250
|
444 r.count = count[i];
|
mas01mc@250
|
445 if(r.count > 0) {
|
mas01mc@250
|
446 result.push(r);
|
mas01mc@250
|
447 if (result.size() > trackNN) {
|
mas01mc@250
|
448 result.pop();
|
mas01mc@250
|
449 }
|
mas01mc@250
|
450 }
|
mas01mc@250
|
451 }
|
mas01mc@250
|
452
|
mas01mc@250
|
453 Radresult r;
|
mas01mc@250
|
454 std::vector<Radresult> v;
|
mas01mc@250
|
455 unsigned int size = result.size();
|
mas01mc@250
|
456 for(unsigned int k = 0; k < size; k++) {
|
mas01mc@250
|
457 r = result.top();
|
mas01mc@250
|
458 v.push_back(r);
|
mas01mc@250
|
459 result.pop();
|
mas01mc@250
|
460 }
|
mas01mc@292
|
461 std::vector<Radresult>::reverse_iterator rit;
|
mas01mc@292
|
462
|
mas01mc@292
|
463 if(adbQueryResponse==0) {
|
mas01mc@292
|
464 for(rit = v.rbegin(); rit < v.rend(); rit++) {
|
mas01mc@292
|
465 r = *rit;
|
mas01mc@292
|
466 if(fileTable)
|
mas01mc@292
|
467 std::cout << fileTable + r.trackID*O2_FILETABLE_ENTRY_SIZE << " ";
|
mas01mc@292
|
468 else
|
mas01mc@292
|
469 std::cout << r.trackID << " ";
|
mas01mc@292
|
470 std::cout << r.count << std::endl;
|
mas01mc@292
|
471 }
|
mas01mc@292
|
472 } else {
|
mas01mc@292
|
473 // FIXME
|
mas01mc@292
|
474 }
|
mas01mc@292
|
475 }
|
mas01mc@292
|
476
|
mas01mc@292
|
477 // track Sequence Query Radius NN Reporter
|
mas01mc@292
|
478 // retrieve tracks ordered by query-point matches (one per track per query point)
|
mas01mc@292
|
479 //
|
mas01mc@292
|
480 // as well as sorted n-NN points per retrieved track
|
mas01mc@292
|
481 class trackSequenceQueryRadNNReporter : public Reporter {
|
mas01mc@292
|
482 public:
|
mas01mc@292
|
483 trackSequenceQueryRadNNReporter(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles);
|
mas01mc@292
|
484 ~trackSequenceQueryRadNNReporter();
|
mas01mc@292
|
485 void add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist);
|
mas01mc@292
|
486 void report(char *fileTable, void *adbQueryResponse);
|
mas01mc@292
|
487 protected:
|
mas01mc@292
|
488 unsigned int pointNN;
|
mas01mc@292
|
489 unsigned int trackNN;
|
mas01mc@292
|
490 unsigned int numFiles;
|
mas01mc@292
|
491 std::set<std::pair<unsigned int, unsigned int> > *set;
|
mas01mc@292
|
492 std::set< triple > *set_triple;
|
mas01mc@292
|
493 std::priority_queue< NNresult, std::vector< NNresult>, std::less<NNresult> > *point_queues;
|
mas01mc@292
|
494 unsigned int *count;
|
mas01mc@292
|
495 };
|
mas01mc@292
|
496
|
mas01mc@292
|
497 trackSequenceQueryRadNNReporter::trackSequenceQueryRadNNReporter(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles):
|
mas01mc@292
|
498 pointNN(pointNN), trackNN(trackNN), numFiles(numFiles) {
|
mas01mc@292
|
499 // Where to count Radius track matches (one-to-one)
|
mas01mc@292
|
500 set = new std::set<std::pair<unsigned int, unsigned int> >;
|
mas01mc@292
|
501 set_triple = new std::set<triple, std::less<triple> >;
|
mas01mc@292
|
502 // Where to insert individual point matches (one-to-many)
|
mas01mc@292
|
503 point_queues = new std::priority_queue< NNresult, std::vector< NNresult>, std::less<NNresult> >[numFiles];
|
mas01mc@292
|
504
|
mas01mc@292
|
505 count = new unsigned int[numFiles];
|
mas01mc@292
|
506 for (unsigned i = 0; i < numFiles; i++) {
|
mas01mc@292
|
507 count[i] = 0;
|
mas01mc@292
|
508 }
|
mas01mc@292
|
509 }
|
mas01mc@292
|
510
|
mas01mc@292
|
511 trackSequenceQueryRadNNReporter::~trackSequenceQueryRadNNReporter() {
|
mas01mc@292
|
512 delete set;
|
mas01mc@292
|
513 delete set_triple;
|
mas01mc@292
|
514 delete [] count;
|
mas01mc@292
|
515 }
|
mas01mc@292
|
516
|
mas01mc@292
|
517 void trackSequenceQueryRadNNReporter::add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist) {
|
mas01mc@292
|
518 std::set<std::pair<unsigned int, unsigned int> >::iterator it;
|
mas01mc@292
|
519 std::set<triple>::iterator it2;
|
mas01mc@292
|
520 std::pair<unsigned int, unsigned int> pair;
|
mas01mc@292
|
521 triple triple;
|
mas01mc@292
|
522 NNresult r;
|
mas01mc@292
|
523
|
mas01mc@292
|
524 pair = std::make_pair(trackID, qpos); // only count this once
|
mas01mc@292
|
525 triple = make_triple(trackID, qpos, spos); // only count this once
|
mas01mc@292
|
526 // Record unique <trackID,qpos,spos> triples (record one collision from all hash tables)
|
mas01mc@292
|
527 it2 = set_triple->find(triple);
|
mas01mc@292
|
528 if(it2 == set_triple->end()){
|
mas01mc@292
|
529 set_triple->insert(triple);
|
mas01mc@292
|
530 // Record all matching points (within radius)
|
mas01mc@292
|
531 // Record counts of <trackID,qpos> pairs
|
mas01mc@292
|
532 it = set->find(pair);
|
mas01mc@292
|
533 if (it == set->end()) {
|
mas01mc@292
|
534 set->insert(pair);
|
mas01mc@292
|
535 count[trackID]++;
|
mas01mc@292
|
536 if (!isnan(dist)) {
|
mas01mc@292
|
537 r.trackID = trackID;
|
mas01mc@292
|
538 r.qpos = qpos;
|
mas01mc@292
|
539 r.dist = dist;
|
mas01mc@292
|
540 r.spos = spos;
|
mas01mc@292
|
541 point_queues[trackID].push(r);
|
mas01mc@292
|
542 if(point_queues[trackID].size() > pointNN)
|
mas01mc@292
|
543 point_queues[trackID].pop();
|
mas01mc@292
|
544 }
|
mas01mc@292
|
545 }
|
mas01mc@292
|
546 }
|
mas01mc@292
|
547 }
|
mas01mc@292
|
548
|
mas01mc@292
|
549 void trackSequenceQueryRadNNReporter::report(char *fileTable, void *adbQueryResponse) {
|
mas01mc@292
|
550 std::priority_queue < Radresult, std::vector<Radresult>, std::greater<Radresult> > result;
|
mas01mc@292
|
551 // KLUDGE: doing this backwards in an attempt to get the same
|
mas01mc@292
|
552 // tiebreak behaviour as before.
|
mas01mc@292
|
553 Radresult r;
|
mas01mc@292
|
554 NNresult rk;
|
mas01mc@292
|
555
|
mas01mc@292
|
556 for (int i = numFiles-1; i >= 0; i--) {
|
mas01mc@292
|
557 r.trackID = i;
|
mas01mc@292
|
558 r.count = count[i];
|
mas01mc@292
|
559 if(r.count > 0) {
|
mas01mc@292
|
560 cout.flush();
|
mas01mc@292
|
561 result.push(r);
|
mas01mc@292
|
562 if (result.size() > trackNN) {
|
mas01mc@292
|
563 result.pop();
|
mas01mc@292
|
564 }
|
mas01mc@292
|
565 }
|
mas01mc@292
|
566 }
|
mas01mc@292
|
567
|
mas01mc@292
|
568 std::vector<Radresult> v;
|
mas01mc@292
|
569 unsigned int size = result.size();
|
mas01mc@292
|
570 for(unsigned int k = 0; k < size; k++) {
|
mas01mc@292
|
571 r = result.top();
|
mas01mc@292
|
572 v.push_back(r);
|
mas01mc@292
|
573 result.pop();
|
mas01mc@292
|
574 }
|
mas01mc@264
|
575
|
mas01mc@264
|
576
|
mas01mc@264
|
577 // Traverse tracks in descending order of count cardinality
|
mas01mc@250
|
578 std::vector<Radresult>::reverse_iterator rit;
|
mas01mc@264
|
579 std::priority_queue< NNresult, std::vector< NNresult>, std::greater<NNresult> > point_queue;
|
mas01mc@264
|
580
|
mas01mc@250
|
581 if(adbQueryResponse==0) {
|
mas01mc@250
|
582 for(rit = v.rbegin(); rit < v.rend(); rit++) {
|
mas01mc@250
|
583 r = *rit;
|
mas01mc@292
|
584 if(fileTable)
|
mas01mc@292
|
585 std::cout << fileTable + r.trackID*O2_FILETABLE_ENTRY_SIZE << " ";
|
mas01mc@292
|
586 else
|
mas01mc@292
|
587 std::cout << r.trackID << " ";
|
mas01mc@292
|
588 std::cout << r.count << std::endl;
|
mas01mc@264
|
589
|
mas01mc@264
|
590 // Reverse the order of the points stored in point_queues
|
mas01mc@264
|
591 unsigned int qsize=point_queues[r.trackID].size();
|
mas01mc@264
|
592 for(unsigned int k=0; k < qsize; k++){
|
mas01mc@264
|
593 point_queue.push(point_queues[r.trackID].top());
|
mas01mc@264
|
594 point_queues[r.trackID].pop();
|
mas01mc@264
|
595 }
|
mas01mc@264
|
596 for(unsigned int k=0; k < qsize; k++){
|
mas01mc@292
|
597 rk = point_queue.top();
|
mas01mc@250
|
598 std::cout << rk.dist << " " << rk.qpos << " " << rk.spos << std::endl;
|
mas01mc@264
|
599 point_queue.pop();
|
mas01mc@250
|
600 }
|
mas01mc@250
|
601 }
|
mas01mc@250
|
602 } else {
|
mas01mc@250
|
603 // FIXME
|
mas01mc@250
|
604 }
|
mas01mc@264
|
605 delete[] point_queues;
|
mas01mc@250
|
606 }
|
mas01mc@263
|
607
|
mas01mc@264
|
608 /********** ONE-TO-ONE REPORTERS *****************/
|
mas01mc@263
|
609
|
mas01mc@264
|
610 // track Sequence Query Radius NN Reporter One-to-One
|
mas01mc@264
|
611 // for each query point find the single best matching target point in all database
|
mas01mc@264
|
612 // report qpos, spos and trackID
|
mas01mc@263
|
613 class trackSequenceQueryRadNNReporterOneToOne : public Reporter {
|
mas01mc@263
|
614 public:
|
mas01mc@263
|
615 trackSequenceQueryRadNNReporterOneToOne(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles);
|
mas01mc@263
|
616 ~trackSequenceQueryRadNNReporterOneToOne();
|
mas01mc@263
|
617 void add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist);
|
mas01mc@292
|
618 void report(char *fileTable, void *adbQueryResponse);
|
mas01mc@263
|
619 protected:
|
mas01mc@263
|
620 unsigned int pointNN;
|
mas01mc@263
|
621 unsigned int trackNN;
|
mas01mc@263
|
622 unsigned int numFiles;
|
mas01mc@263
|
623 std::set< NNresult > *set;
|
mas01mc@263
|
624 std::vector< NNresult> *point_queue;
|
mas01mc@263
|
625 unsigned int *count;
|
mas01mc@263
|
626
|
mas01mc@263
|
627 };
|
mas01mc@263
|
628
|
mas01mc@263
|
629 trackSequenceQueryRadNNReporterOneToOne::trackSequenceQueryRadNNReporterOneToOne(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles):
|
mas01mc@263
|
630 pointNN(pointNN), trackNN(trackNN), numFiles(numFiles) {
|
mas01mc@263
|
631 // Where to count Radius track matches (one-to-one)
|
mas01mc@263
|
632 set = new std::set< NNresult >;
|
mas01mc@263
|
633 // Where to insert individual point matches (one-to-many)
|
mas01mc@263
|
634 point_queue = new std::vector< NNresult >;
|
mas01mc@263
|
635
|
mas01mc@263
|
636 count = new unsigned int[numFiles];
|
mas01mc@263
|
637 for (unsigned i = 0; i < numFiles; i++) {
|
mas01mc@263
|
638 count[i] = 0;
|
mas01mc@263
|
639 }
|
mas01mc@263
|
640 }
|
mas01mc@263
|
641
|
mas01mc@263
|
642 trackSequenceQueryRadNNReporterOneToOne::~trackSequenceQueryRadNNReporterOneToOne() {
|
mas01mc@263
|
643 delete set;
|
mas01mc@263
|
644 delete [] count;
|
mas01mc@263
|
645 }
|
mas01mc@263
|
646
|
mas01mc@263
|
647 void trackSequenceQueryRadNNReporterOneToOne::add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist) {
|
mas01mc@263
|
648 std::set< NNresult >::iterator it;
|
mas01mc@263
|
649 NNresult r;
|
mas01mc@264
|
650
|
mas01mc@263
|
651 r.qpos = qpos;
|
mas01mc@263
|
652 r.trackID = trackID;
|
mas01mc@263
|
653 r.spos = spos;
|
mas01mc@263
|
654 r.dist = dist;
|
mas01mc@263
|
655
|
mas01mc@263
|
656 if(point_queue->size() < r.qpos + 1){
|
mas01mc@263
|
657 point_queue->resize( r.qpos + 1 );
|
mas01mc@263
|
658 (*point_queue)[r.qpos].dist = 1e6;
|
mas01mc@263
|
659 }
|
mas01mc@263
|
660
|
mas01mc@263
|
661 if (r.dist < (*point_queue)[r.qpos].dist)
|
mas01mc@263
|
662 (*point_queue)[r.qpos] = r;
|
mas01mc@263
|
663
|
mas01mc@263
|
664 }
|
mas01mc@263
|
665
|
mas01mc@292
|
666 void trackSequenceQueryRadNNReporterOneToOne::report(char *fileTable, void *adbQueryResponse) {
|
mas01mc@263
|
667 if(adbQueryResponse==0) {
|
mas01mc@263
|
668 std::vector< NNresult >::iterator vit;
|
mas01mc@263
|
669 NNresult rk;
|
mas01mc@263
|
670 for( vit = point_queue->begin() ; vit < point_queue->end() ; vit++ ){
|
mas01mc@263
|
671 rk = *vit;
|
mas01mc@263
|
672 std::cout << rk.dist << " "
|
mas01mc@263
|
673 << rk.qpos << " "
|
mas01mc@292
|
674 << rk.spos << " ";
|
mas01mc@292
|
675 if(fileTable)
|
mas01mc@292
|
676 std::cout << fileTable + rk.trackID*O2_FILETABLE_ENTRY_SIZE << " ";
|
mas01mc@292
|
677 else
|
mas01mc@292
|
678 std::cout << rk.trackID << " ";
|
mas01mc@292
|
679 std::cout << std::endl;
|
mas01mc@263
|
680 }
|
mas01mc@263
|
681 } else {
|
mas01mc@263
|
682 // FIXME
|
mas01mc@263
|
683 }
|
mas01mc@263
|
684 }
|
mas01mc@292
|
685
|
mas01mc@292
|
686 #endif
|