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@316
|
295 NNresult rk;
|
mas01mc@264
|
296
|
mas01mc@248
|
297 if(adbQueryResponse==0) {
|
mas01mc@248
|
298 for(rit = v.rbegin(); rit < v.rend(); rit++) {
|
mas01mc@248
|
299 r = *rit;
|
mas01mc@292
|
300 if(fileTable)
|
mas01mc@292
|
301 std::cout << fileTable + r.trackID*O2_FILETABLE_ENTRY_SIZE << " ";
|
mas01mc@292
|
302 else
|
mas01mc@292
|
303 std::cout << r.trackID << " ";
|
mas01mc@292
|
304 std::cout << r.dist << std::endl;
|
mas01mc@264
|
305 unsigned int qsize = point_queues[r.trackID].size();
|
mas01mc@264
|
306 // Reverse the order of the points stored in point_queues
|
mas01mc@264
|
307 for(unsigned int k=0; k < qsize; k++){
|
mas01mc@264
|
308 point_queue.push( point_queues[r.trackID].top() );
|
mas01mc@264
|
309 point_queues[r.trackID].pop();
|
mas01mc@264
|
310 }
|
mas01mc@264
|
311
|
mas01mc@264
|
312 for(unsigned int k = 0; k < qsize; k++) {
|
mas01mc@316
|
313 rk = point_queue.top();
|
mas01mc@248
|
314 std::cout << rk.dist << " " << rk.qpos << " " << rk.spos << std::endl;
|
mas01mc@264
|
315 point_queue.pop();
|
mas01mc@248
|
316 }
|
mas01mc@248
|
317 }
|
mas01mc@248
|
318 } else {
|
mas01mc@316
|
319 ((adb__queryResponse*)adbQueryResponse)->result.__sizeRlist=size*pointNN;
|
mas01mc@316
|
320 ((adb__queryResponse*)adbQueryResponse)->result.__sizeDist=size*pointNN;
|
mas01mc@316
|
321 ((adb__queryResponse*)adbQueryResponse)->result.__sizeQpos=size*pointNN;
|
mas01mc@316
|
322 ((adb__queryResponse*)adbQueryResponse)->result.__sizeSpos=size*pointNN;
|
mas01mc@316
|
323 ((adb__queryResponse*)adbQueryResponse)->result.Rlist= new char*[size*pointNN];
|
mas01mc@316
|
324 ((adb__queryResponse*)adbQueryResponse)->result.Dist = new double[size*pointNN];
|
mas01mc@316
|
325 ((adb__queryResponse*)adbQueryResponse)->result.Qpos = new unsigned int[size*pointNN];
|
mas01mc@316
|
326 ((adb__queryResponse*)adbQueryResponse)->result.Spos = new unsigned int[size*pointNN];
|
mas01mc@248
|
327 unsigned int k = 0;
|
mas01mc@316
|
328 // Loop over returned tracks
|
mas01mc@316
|
329 for(rit = v.rbegin(); rit < v.rend(); rit++) {
|
mas01mc@248
|
330 r = *rit;
|
mas01mc@316
|
331 // Reverse the order of the points stored in point_queues
|
mas01mc@316
|
332 unsigned int qsize=point_queues[r.trackID].size();
|
mas01mc@316
|
333 while(qsize--){
|
mas01mc@316
|
334 point_queue.push(point_queues[r.trackID].top());
|
mas01mc@316
|
335 point_queues[r.trackID].pop();
|
mas01mc@316
|
336 }
|
mas01mc@316
|
337 qsize=point_queue.size();
|
mas01mc@316
|
338 unsigned int numReports = pointNN;
|
mas01mc@316
|
339 while(numReports--){ // pop the rest of the points
|
mas01mc@316
|
340 if(qsize)
|
mas01mc@316
|
341 rk = point_queue.top(); // Take one point from the top of the queue
|
mas01mc@316
|
342 else{
|
mas01mc@316
|
343 rk.dist = 1000000000.0;
|
mas01mc@316
|
344 rk.qpos = 0xFFFFFFFF;
|
mas01mc@316
|
345 rk.spos = 0xFFFFFFFF;
|
mas01mc@316
|
346 }
|
mas01mc@316
|
347
|
mas01mc@316
|
348 ((adb__queryResponse*)adbQueryResponse)->result.Rlist[k] = new char[O2_MAXFILESTR];
|
mas01mc@316
|
349 ((adb__queryResponse*)adbQueryResponse)->result.Dist[k] = rk.dist;
|
mas01mc@316
|
350 ((adb__queryResponse*)adbQueryResponse)->result.Qpos[k] = rk.qpos;
|
mas01mc@316
|
351 ((adb__queryResponse*)adbQueryResponse)->result.Spos[k] = rk.spos;
|
mas01mc@316
|
352 if(qsize){
|
mas01mc@316
|
353 if(fileTable)
|
mas01mc@316
|
354 snprintf(((adb__queryResponse*)adbQueryResponse)->result.Rlist[k], O2_MAXFILESTR, "%s", fileTable+r.trackID*O2_FILETABLE_ENTRY_SIZE);
|
mas01mc@316
|
355 else
|
mas01mc@316
|
356 snprintf(((adb__queryResponse*)adbQueryResponse)->result.Rlist[k], O2_MAXFILESTR, "%d", r.trackID);
|
mas01mc@316
|
357 point_queue.pop();
|
mas01mc@316
|
358 qsize--;
|
mas01mc@316
|
359 }
|
mas01mc@316
|
360 else
|
mas01mc@316
|
361 snprintf(((adb__queryResponse*)adbQueryResponse)->result.Rlist[k], O2_MAXFILESTR, "NULL");
|
mas01mc@316
|
362 k++;
|
mas01mc@316
|
363 }
|
mas01mc@248
|
364 }
|
mas01mc@248
|
365 }
|
mas01mc@248
|
366 // clean up
|
mas01mc@248
|
367 delete[] point_queues;
|
mas01mc@248
|
368 }
|
mas01mc@250
|
369
|
mas01mc@292
|
370 /********************** Radius Reporters **************************/
|
mas01mc@250
|
371
|
mas01mc@292
|
372 class triple{
|
mas01mc@292
|
373 public:
|
mas01mc@292
|
374 unsigned int a;
|
mas01mc@292
|
375 unsigned int b;
|
mas01mc@292
|
376 unsigned int c;
|
mas01mc@292
|
377
|
mas01mc@292
|
378 triple(void);
|
mas01mc@292
|
379 triple(unsigned int, unsigned int, unsigned int);
|
mas01mc@292
|
380 unsigned int first();
|
mas01mc@292
|
381 unsigned int second();
|
mas01mc@292
|
382 unsigned int third();
|
mas01mc@292
|
383 };
|
mas01mc@292
|
384
|
mas01mc@292
|
385 triple& make_triple(unsigned int, unsigned int, unsigned int);
|
mas01mc@292
|
386
|
mas01mc@292
|
387 triple::triple(unsigned int a, unsigned int b, unsigned int c):a(a),b(b),c(c){}
|
mas01mc@292
|
388
|
mas01mc@292
|
389 unsigned int triple::first(){return a;}
|
mas01mc@292
|
390 unsigned int triple::second(){return b;}
|
mas01mc@292
|
391 unsigned int triple::third(){return c;}
|
mas01mc@292
|
392
|
mas01mc@292
|
393 triple::triple():a(0),b(0),c(0){}
|
mas01mc@292
|
394
|
mas01mc@292
|
395 bool operator< (const triple &t1, const triple &t2) {
|
mas01mc@292
|
396 return ((t1.a < t2.a) ||
|
mas01mc@292
|
397 ((t1.a == t2.a) && ((t1.b < t2.b) ||
|
mas01mc@292
|
398 ((t1.b == t2.b) && (t1.c < t2.c)))));
|
mas01mc@292
|
399 }
|
mas01mc@292
|
400 bool operator== (const triple &t1, const triple &t2) {
|
mas01mc@292
|
401 return ((t1.a == t2.a) && (t1.b == t2.b) && (t1.c == t2.c));
|
mas01mc@292
|
402 }
|
mas01mc@292
|
403
|
mas01mc@292
|
404 triple& make_triple(unsigned int a, unsigned int b, unsigned int c){
|
mas01mc@292
|
405 triple* t = new triple(a,b,c);
|
mas01mc@292
|
406 return *t;
|
mas01mc@292
|
407 }
|
mas01mc@292
|
408
|
mas01mc@292
|
409 // track Sequence Query Radius Reporter
|
mas01mc@292
|
410 // only return tracks and retrieved point counts
|
mas01mc@292
|
411 class trackSequenceQueryRadReporter : public Reporter {
|
mas01mc@250
|
412 public:
|
mas01mc@292
|
413 trackSequenceQueryRadReporter(unsigned int trackNN, unsigned int numFiles);
|
mas01mc@292
|
414 ~trackSequenceQueryRadReporter();
|
mas01mc@250
|
415 void add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist);
|
mas01mc@292
|
416 void report(char *fileTable, void *adbQueryResponse);
|
mas01mc@250
|
417 protected:
|
mas01mc@250
|
418 unsigned int trackNN;
|
mas01mc@250
|
419 unsigned int numFiles;
|
mas01mc@292
|
420 std::set<std::pair<unsigned int, unsigned int> > *set;
|
mas01mc@292
|
421 std::set< triple > *set_triple;
|
mas01mc@250
|
422 unsigned int *count;
|
mas01mc@250
|
423 };
|
mas01mc@250
|
424
|
mas01mc@292
|
425 trackSequenceQueryRadReporter::trackSequenceQueryRadReporter(unsigned int trackNN, unsigned int numFiles):
|
mas01mc@292
|
426 trackNN(trackNN), numFiles(numFiles) {
|
mas01mc@292
|
427 set = new std::set<std::pair<unsigned int, unsigned int> >;
|
mas01mc@292
|
428 set_triple = new std::set<triple, std::less<triple> >;
|
mas01mc@250
|
429 count = new unsigned int[numFiles];
|
mas01mc@250
|
430 for (unsigned i = 0; i < numFiles; i++) {
|
mas01mc@250
|
431 count[i] = 0;
|
mas01mc@250
|
432 }
|
mas01mc@250
|
433 }
|
mas01mc@250
|
434
|
mas01mc@292
|
435 trackSequenceQueryRadReporter::~trackSequenceQueryRadReporter() {
|
mas01mc@250
|
436 delete set;
|
mas01mc@292
|
437 delete set_triple;
|
mas01mc@250
|
438 delete [] count;
|
mas01mc@250
|
439 }
|
mas01mc@250
|
440
|
mas01mc@292
|
441 void trackSequenceQueryRadReporter::add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist) {
|
mas01mc@292
|
442 std::set<std::pair<unsigned int, unsigned int> >::iterator it;
|
mas01mc@292
|
443 std::pair<unsigned int, unsigned int> pair = std::make_pair(trackID, qpos); // only count this once
|
mas01mc@292
|
444 std::set<triple>::iterator it2;
|
mas01mc@292
|
445 triple triple;
|
mas01mc@250
|
446
|
mas01mc@292
|
447 triple = make_triple(trackID, qpos, spos); // only count this once
|
mas01mc@292
|
448
|
mas01mc@292
|
449 // Record unique <trackID,qpos,spos> triples (record one collision from all hash tables)
|
mas01mc@292
|
450 it2 = set_triple->find(triple);
|
mas01mc@250
|
451
|
mas01mc@292
|
452 if(it2 == set_triple->end()){
|
mas01mc@292
|
453 set_triple->insert(triple);
|
mas01mc@292
|
454
|
mas01mc@292
|
455 it = set->find(pair);
|
mas01mc@292
|
456 if (it == set->end()) {
|
mas01mc@292
|
457 set->insert(pair);
|
mas01mc@292
|
458 count[trackID]++; // only count if <tackID,qpos> pair is unique
|
mas01mc@292
|
459 }
|
mas01mc@250
|
460 }
|
mas01mc@250
|
461 }
|
mas01mc@250
|
462
|
mas01mc@292
|
463 void trackSequenceQueryRadReporter::report(char *fileTable, void *adbQueryResponse) {
|
mas01mc@275
|
464 std::priority_queue < Radresult, std::vector<Radresult>, std::greater<Radresult> > result;
|
mas01mc@250
|
465 // KLUDGE: doing this backwards in an attempt to get the same
|
mas01mc@250
|
466 // tiebreak behaviour as before.
|
mas01mc@250
|
467 for (int i = numFiles-1; i >= 0; i--) {
|
mas01mc@250
|
468 Radresult r;
|
mas01mc@250
|
469 r.trackID = i;
|
mas01mc@250
|
470 r.count = count[i];
|
mas01mc@250
|
471 if(r.count > 0) {
|
mas01mc@250
|
472 result.push(r);
|
mas01mc@250
|
473 if (result.size() > trackNN) {
|
mas01mc@250
|
474 result.pop();
|
mas01mc@250
|
475 }
|
mas01mc@250
|
476 }
|
mas01mc@250
|
477 }
|
mas01mc@250
|
478
|
mas01mc@250
|
479 Radresult r;
|
mas01mc@250
|
480 std::vector<Radresult> v;
|
mas01mc@250
|
481 unsigned int size = result.size();
|
mas01mc@250
|
482 for(unsigned int k = 0; k < size; k++) {
|
mas01mc@250
|
483 r = result.top();
|
mas01mc@250
|
484 v.push_back(r);
|
mas01mc@250
|
485 result.pop();
|
mas01mc@250
|
486 }
|
mas01mc@292
|
487 std::vector<Radresult>::reverse_iterator rit;
|
mas01mc@292
|
488
|
mas01mc@292
|
489 if(adbQueryResponse==0) {
|
mas01mc@292
|
490 for(rit = v.rbegin(); rit < v.rend(); rit++) {
|
mas01mc@292
|
491 r = *rit;
|
mas01mc@292
|
492 if(fileTable)
|
mas01mc@292
|
493 std::cout << fileTable + r.trackID*O2_FILETABLE_ENTRY_SIZE << " ";
|
mas01mc@292
|
494 else
|
mas01mc@292
|
495 std::cout << r.trackID << " ";
|
mas01mc@292
|
496 std::cout << r.count << std::endl;
|
mas01mc@292
|
497 }
|
mas01mc@307
|
498 }
|
mas01mc@307
|
499 else {
|
mas01mc@307
|
500 ((adb__queryResponse*)adbQueryResponse)->result.__sizeRlist=size;
|
mas01mc@307
|
501 ((adb__queryResponse*)adbQueryResponse)->result.__sizeDist=size;
|
mas01mc@307
|
502 ((adb__queryResponse*)adbQueryResponse)->result.__sizeQpos=size;
|
mas01mc@307
|
503 ((adb__queryResponse*)adbQueryResponse)->result.__sizeSpos=size;
|
mas01mc@307
|
504 ((adb__queryResponse*)adbQueryResponse)->result.Rlist= new char*[size];
|
mas01mc@307
|
505 ((adb__queryResponse*)adbQueryResponse)->result.Dist = new double[size];
|
mas01mc@307
|
506 ((adb__queryResponse*)adbQueryResponse)->result.Qpos = new unsigned int[size];
|
mas01mc@307
|
507 ((adb__queryResponse*)adbQueryResponse)->result.Spos = new unsigned int[size];
|
mas01mc@307
|
508 unsigned int k = 0;
|
mas01mc@307
|
509 for(rit = v.rbegin(); rit < v.rend(); rit++, k++) {
|
mas01mc@307
|
510 r = *rit;
|
mas01mc@307
|
511 ((adb__queryResponse*)adbQueryResponse)->result.Rlist[k] = new char[O2_MAXFILESTR];
|
mas01mc@307
|
512 ((adb__queryResponse*)adbQueryResponse)->result.Dist[k] = 0;
|
mas01mc@307
|
513 ((adb__queryResponse*)adbQueryResponse)->result.Qpos[k] = 0;
|
mas01mc@307
|
514 ((adb__queryResponse*)adbQueryResponse)->result.Spos[k] = 0;
|
mas01mc@307
|
515 if(fileTable)
|
mas01mc@307
|
516 snprintf(((adb__queryResponse*)adbQueryResponse)->result.Rlist[k], O2_MAXFILESTR, "%s", fileTable+r.trackID*O2_FILETABLE_ENTRY_SIZE);
|
mas01mc@307
|
517 else
|
mas01mc@307
|
518 snprintf(((adb__queryResponse*)adbQueryResponse)->result.Rlist[k], O2_MAXFILESTR, "%d", r.trackID);
|
mas01mc@307
|
519 }
|
mas01mc@292
|
520 }
|
mas01mc@292
|
521 }
|
mas01mc@292
|
522
|
mas01mc@292
|
523 // track Sequence Query Radius NN Reporter
|
mas01mc@292
|
524 // retrieve tracks ordered by query-point matches (one per track per query point)
|
mas01mc@292
|
525 //
|
mas01mc@292
|
526 // as well as sorted n-NN points per retrieved track
|
mas01mc@292
|
527 class trackSequenceQueryRadNNReporter : public Reporter {
|
mas01mc@292
|
528 public:
|
mas01mc@292
|
529 trackSequenceQueryRadNNReporter(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles);
|
mas01mc@292
|
530 ~trackSequenceQueryRadNNReporter();
|
mas01mc@292
|
531 void add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist);
|
mas01mc@292
|
532 void report(char *fileTable, void *adbQueryResponse);
|
mas01mc@292
|
533 protected:
|
mas01mc@292
|
534 unsigned int pointNN;
|
mas01mc@292
|
535 unsigned int trackNN;
|
mas01mc@292
|
536 unsigned int numFiles;
|
mas01mc@292
|
537 std::set<std::pair<unsigned int, unsigned int> > *set;
|
mas01mc@292
|
538 std::set< triple > *set_triple;
|
mas01mc@292
|
539 std::priority_queue< NNresult, std::vector< NNresult>, std::less<NNresult> > *point_queues;
|
mas01mc@292
|
540 unsigned int *count;
|
mas01mc@292
|
541 };
|
mas01mc@292
|
542
|
mas01mc@292
|
543 trackSequenceQueryRadNNReporter::trackSequenceQueryRadNNReporter(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles):
|
mas01mc@292
|
544 pointNN(pointNN), trackNN(trackNN), numFiles(numFiles) {
|
mas01mc@292
|
545 // Where to count Radius track matches (one-to-one)
|
mas01mc@292
|
546 set = new std::set<std::pair<unsigned int, unsigned int> >;
|
mas01mc@292
|
547 set_triple = new std::set<triple, std::less<triple> >;
|
mas01mc@292
|
548 // Where to insert individual point matches (one-to-many)
|
mas01mc@292
|
549 point_queues = new std::priority_queue< NNresult, std::vector< NNresult>, std::less<NNresult> >[numFiles];
|
mas01mc@292
|
550
|
mas01mc@292
|
551 count = new unsigned int[numFiles];
|
mas01mc@292
|
552 for (unsigned i = 0; i < numFiles; i++) {
|
mas01mc@292
|
553 count[i] = 0;
|
mas01mc@292
|
554 }
|
mas01mc@292
|
555 }
|
mas01mc@292
|
556
|
mas01mc@292
|
557 trackSequenceQueryRadNNReporter::~trackSequenceQueryRadNNReporter() {
|
mas01mc@292
|
558 delete set;
|
mas01mc@292
|
559 delete set_triple;
|
mas01mc@292
|
560 delete [] count;
|
mas01mc@292
|
561 }
|
mas01mc@292
|
562
|
mas01mc@292
|
563 void trackSequenceQueryRadNNReporter::add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist) {
|
mas01mc@292
|
564 std::set<std::pair<unsigned int, unsigned int> >::iterator it;
|
mas01mc@292
|
565 std::set<triple>::iterator it2;
|
mas01mc@292
|
566 std::pair<unsigned int, unsigned int> pair;
|
mas01mc@292
|
567 triple triple;
|
mas01mc@292
|
568 NNresult r;
|
mas01mc@292
|
569
|
mas01mc@292
|
570 pair = std::make_pair(trackID, qpos); // only count this once
|
mas01mc@292
|
571 triple = make_triple(trackID, qpos, spos); // only count this once
|
mas01mc@292
|
572 // Record unique <trackID,qpos,spos> triples (record one collision from all hash tables)
|
mas01mc@292
|
573 it2 = set_triple->find(triple);
|
mas01mc@292
|
574 if(it2 == set_triple->end()){
|
mas01mc@292
|
575 set_triple->insert(triple);
|
mas01mc@292
|
576 // Record all matching points (within radius)
|
mas01mc@292
|
577 // Record counts of <trackID,qpos> pairs
|
mas01mc@292
|
578 it = set->find(pair);
|
mas01mc@292
|
579 if (it == set->end()) {
|
mas01mc@292
|
580 set->insert(pair);
|
mas01mc@292
|
581 count[trackID]++;
|
mas01mc@307
|
582 }
|
mas01mc@307
|
583 if (!isnan(dist)) {
|
mas01mc@307
|
584 r.trackID = trackID;
|
mas01mc@307
|
585 r.qpos = qpos;
|
mas01mc@307
|
586 r.dist = dist;
|
mas01mc@307
|
587 r.spos = spos;
|
mas01mc@307
|
588 point_queues[trackID].push(r);
|
mas01mc@307
|
589 if(point_queues[trackID].size() > pointNN)
|
mas01mc@307
|
590 point_queues[trackID].pop();
|
mas01mc@292
|
591 }
|
mas01mc@292
|
592 }
|
mas01mc@292
|
593 }
|
mas01mc@292
|
594
|
mas01mc@292
|
595 void trackSequenceQueryRadNNReporter::report(char *fileTable, void *adbQueryResponse) {
|
mas01mc@292
|
596 std::priority_queue < Radresult, std::vector<Radresult>, std::greater<Radresult> > result;
|
mas01mc@292
|
597 // KLUDGE: doing this backwards in an attempt to get the same
|
mas01mc@292
|
598 // tiebreak behaviour as before.
|
mas01mc@292
|
599 Radresult r;
|
mas01mc@292
|
600 NNresult rk;
|
mas01mc@307
|
601 std::vector<Radresult> v;
|
mas01mc@307
|
602 unsigned int size;
|
mas01mc@292
|
603
|
mas01mc@307
|
604 if(pointNN>1){
|
mas01mc@307
|
605 for (int i = numFiles-1; i >= 0; i--) {
|
mas01mc@307
|
606 r.trackID = i;
|
mas01mc@307
|
607 r.count = count[i];
|
mas01mc@307
|
608 if(r.count > 0) {
|
mas01mc@307
|
609 cout.flush();
|
mas01mc@307
|
610 result.push(r);
|
mas01mc@307
|
611 if (result.size() > trackNN) {
|
mas01mc@307
|
612 result.pop();
|
mas01mc@307
|
613 }
|
mas01mc@292
|
614 }
|
mas01mc@292
|
615 }
|
mas01mc@307
|
616
|
mas01mc@307
|
617 size = result.size();
|
mas01mc@307
|
618 for(unsigned int k = 0; k < size; k++) {
|
mas01mc@307
|
619 r = result.top();
|
mas01mc@307
|
620 v.push_back(r);
|
mas01mc@307
|
621 result.pop();
|
mas01mc@307
|
622 }
|
mas01mc@292
|
623 }
|
mas01mc@307
|
624 else{
|
mas01mc@307
|
625 // Instantiate a 1-NN trackAveragingNN reporter
|
mas01mc@307
|
626 trackSequenceQueryNNReporter<std::less <NNresult> >* rep = new trackSequenceQueryNNReporter<std::less <NNresult> >(1, trackNN, numFiles);
|
mas01mc@307
|
627 // Add all the points we've got to the reporter
|
mas01mc@307
|
628 for(unsigned int i=0; i<numFiles; i++){
|
mas01mc@307
|
629 int qsize = point_queues[i].size();
|
mas01mc@307
|
630 while(qsize--){
|
mas01mc@307
|
631 rk = point_queues[i].top();
|
mas01mc@307
|
632 rep->add_point(i, rk.qpos, rk.spos, rk.dist);
|
mas01mc@307
|
633 point_queues[i].pop();
|
mas01mc@307
|
634 }
|
mas01mc@307
|
635 }
|
mas01mc@307
|
636 // Report
|
mas01mc@307
|
637 rep->report(fileTable, adbQueryResponse);
|
mas01mc@307
|
638 // Exit
|
mas01mc@307
|
639 delete[] point_queues;
|
mas01mc@307
|
640 return;
|
mas01mc@292
|
641 }
|
mas01mc@264
|
642
|
mas01mc@264
|
643
|
mas01mc@264
|
644 // Traverse tracks in descending order of count cardinality
|
mas01mc@250
|
645 std::vector<Radresult>::reverse_iterator rit;
|
mas01mc@264
|
646 std::priority_queue< NNresult, std::vector< NNresult>, std::greater<NNresult> > point_queue;
|
mas01mc@264
|
647
|
mas01mc@250
|
648 if(adbQueryResponse==0) {
|
mas01mc@250
|
649 for(rit = v.rbegin(); rit < v.rend(); rit++) {
|
mas01mc@250
|
650 r = *rit;
|
mas01mc@292
|
651 if(fileTable)
|
mas01mc@292
|
652 std::cout << fileTable + r.trackID*O2_FILETABLE_ENTRY_SIZE << " ";
|
mas01mc@292
|
653 else
|
mas01mc@292
|
654 std::cout << r.trackID << " ";
|
mas01mc@292
|
655 std::cout << r.count << std::endl;
|
mas01mc@264
|
656
|
mas01mc@264
|
657 // Reverse the order of the points stored in point_queues
|
mas01mc@264
|
658 unsigned int qsize=point_queues[r.trackID].size();
|
mas01mc@264
|
659 for(unsigned int k=0; k < qsize; k++){
|
mas01mc@264
|
660 point_queue.push(point_queues[r.trackID].top());
|
mas01mc@264
|
661 point_queues[r.trackID].pop();
|
mas01mc@264
|
662 }
|
mas01mc@264
|
663 for(unsigned int k=0; k < qsize; k++){
|
mas01mc@292
|
664 rk = point_queue.top();
|
mas01mc@250
|
665 std::cout << rk.dist << " " << rk.qpos << " " << rk.spos << std::endl;
|
mas01mc@264
|
666 point_queue.pop();
|
mas01mc@250
|
667 }
|
mas01mc@250
|
668 }
|
mas01mc@250
|
669 }
|
mas01mc@307
|
670 else {
|
mas01mc@316
|
671 ((adb__queryResponse*)adbQueryResponse)->result.__sizeRlist=size*pointNN;
|
mas01mc@316
|
672 ((adb__queryResponse*)adbQueryResponse)->result.__sizeDist=size*pointNN;
|
mas01mc@316
|
673 ((adb__queryResponse*)adbQueryResponse)->result.__sizeQpos=size*pointNN;
|
mas01mc@316
|
674 ((adb__queryResponse*)adbQueryResponse)->result.__sizeSpos=size*pointNN;
|
mas01mc@316
|
675 ((adb__queryResponse*)adbQueryResponse)->result.Rlist= new char*[size*pointNN];
|
mas01mc@316
|
676 ((adb__queryResponse*)adbQueryResponse)->result.Dist = new double[size*pointNN];
|
mas01mc@316
|
677 ((adb__queryResponse*)adbQueryResponse)->result.Qpos = new unsigned int[size*pointNN];
|
mas01mc@316
|
678 ((adb__queryResponse*)adbQueryResponse)->result.Spos = new unsigned int[size*pointNN];
|
mas01mc@307
|
679 unsigned int k = 0;
|
mas01mc@307
|
680 // Loop over returned tracks
|
mas01mc@316
|
681 for(rit = v.rbegin(); rit < v.rend(); rit++) {
|
mas01mc@307
|
682 r = *rit;
|
mas01mc@307
|
683 // Reverse the order of the points stored in point_queues
|
mas01mc@307
|
684 unsigned int qsize=point_queues[r.trackID].size();
|
mas01mc@307
|
685 while(qsize--){
|
mas01mc@307
|
686 point_queue.push(point_queues[r.trackID].top());
|
mas01mc@307
|
687 point_queues[r.trackID].pop();
|
mas01mc@307
|
688 }
|
mas01mc@307
|
689 qsize=point_queue.size();
|
mas01mc@316
|
690 unsigned int numReports = pointNN;
|
mas01mc@316
|
691 while(numReports--){ // pop the rest of the points
|
mas01mc@316
|
692 if(qsize)
|
mas01mc@316
|
693 rk = point_queue.top(); // Take one point from the top of the queue
|
mas01mc@316
|
694 else{
|
mas01mc@316
|
695 rk.dist = 1000000000.0;
|
mas01mc@316
|
696 rk.qpos = 0xFFFFFFFF;
|
mas01mc@316
|
697 rk.spos = 0xFFFFFFFF;
|
mas01mc@316
|
698 }
|
mas01mc@316
|
699
|
mas01mc@316
|
700 ((adb__queryResponse*)adbQueryResponse)->result.Rlist[k] = new char[O2_MAXFILESTR];
|
mas01mc@316
|
701 ((adb__queryResponse*)adbQueryResponse)->result.Dist[k] = rk.dist;
|
mas01mc@316
|
702 ((adb__queryResponse*)adbQueryResponse)->result.Qpos[k] = rk.qpos;
|
mas01mc@316
|
703 ((adb__queryResponse*)adbQueryResponse)->result.Spos[k] = rk.spos;
|
mas01mc@316
|
704 if(qsize){
|
mas01mc@316
|
705 if(fileTable)
|
mas01mc@316
|
706 snprintf(((adb__queryResponse*)adbQueryResponse)->result.Rlist[k], O2_MAXFILESTR, "%s", fileTable+r.trackID*O2_FILETABLE_ENTRY_SIZE);
|
mas01mc@316
|
707 else
|
mas01mc@316
|
708 snprintf(((adb__queryResponse*)adbQueryResponse)->result.Rlist[k], O2_MAXFILESTR, "%d", r.trackID);
|
mas01mc@316
|
709 point_queue.pop();
|
mas01mc@316
|
710 qsize--;
|
mas01mc@316
|
711 }
|
mas01mc@316
|
712 else
|
mas01mc@316
|
713 snprintf(((adb__queryResponse*)adbQueryResponse)->result.Rlist[k], O2_MAXFILESTR, "NULL");
|
mas01mc@316
|
714 k++;
|
mas01mc@316
|
715 }
|
mas01mc@307
|
716 }
|
mas01mc@307
|
717 }
|
mas01mc@264
|
718 delete[] point_queues;
|
mas01mc@250
|
719 }
|
mas01mc@263
|
720
|
mas01mc@264
|
721 /********** ONE-TO-ONE REPORTERS *****************/
|
mas01mc@263
|
722
|
mas01mc@264
|
723 // track Sequence Query Radius NN Reporter One-to-One
|
mas01mc@264
|
724 // for each query point find the single best matching target point in all database
|
mas01mc@264
|
725 // report qpos, spos and trackID
|
mas01mc@263
|
726 class trackSequenceQueryRadNNReporterOneToOne : public Reporter {
|
mas01mc@263
|
727 public:
|
mas01mc@263
|
728 trackSequenceQueryRadNNReporterOneToOne(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles);
|
mas01mc@263
|
729 ~trackSequenceQueryRadNNReporterOneToOne();
|
mas01mc@263
|
730 void add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist);
|
mas01mc@292
|
731 void report(char *fileTable, void *adbQueryResponse);
|
mas01mc@263
|
732 protected:
|
mas01mc@263
|
733 unsigned int pointNN;
|
mas01mc@263
|
734 unsigned int trackNN;
|
mas01mc@263
|
735 unsigned int numFiles;
|
mas01mc@263
|
736 std::set< NNresult > *set;
|
mas01mc@263
|
737 std::vector< NNresult> *point_queue;
|
mas01mc@263
|
738 unsigned int *count;
|
mas01mc@263
|
739
|
mas01mc@263
|
740 };
|
mas01mc@263
|
741
|
mas01mc@263
|
742 trackSequenceQueryRadNNReporterOneToOne::trackSequenceQueryRadNNReporterOneToOne(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles):
|
mas01mc@263
|
743 pointNN(pointNN), trackNN(trackNN), numFiles(numFiles) {
|
mas01mc@263
|
744 // Where to count Radius track matches (one-to-one)
|
mas01mc@263
|
745 set = new std::set< NNresult >;
|
mas01mc@263
|
746 // Where to insert individual point matches (one-to-many)
|
mas01mc@263
|
747 point_queue = new std::vector< NNresult >;
|
mas01mc@263
|
748
|
mas01mc@263
|
749 count = new unsigned int[numFiles];
|
mas01mc@263
|
750 for (unsigned i = 0; i < numFiles; i++) {
|
mas01mc@263
|
751 count[i] = 0;
|
mas01mc@263
|
752 }
|
mas01mc@263
|
753 }
|
mas01mc@263
|
754
|
mas01mc@263
|
755 trackSequenceQueryRadNNReporterOneToOne::~trackSequenceQueryRadNNReporterOneToOne() {
|
mas01mc@263
|
756 delete set;
|
mas01mc@263
|
757 delete [] count;
|
mas01mc@263
|
758 }
|
mas01mc@263
|
759
|
mas01mc@263
|
760 void trackSequenceQueryRadNNReporterOneToOne::add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist) {
|
mas01mc@263
|
761 std::set< NNresult >::iterator it;
|
mas01mc@263
|
762 NNresult r;
|
mas01mc@264
|
763
|
mas01mc@263
|
764 r.qpos = qpos;
|
mas01mc@263
|
765 r.trackID = trackID;
|
mas01mc@263
|
766 r.spos = spos;
|
mas01mc@263
|
767 r.dist = dist;
|
mas01mc@263
|
768
|
mas01mc@263
|
769 if(point_queue->size() < r.qpos + 1){
|
mas01mc@263
|
770 point_queue->resize( r.qpos + 1 );
|
mas01mc@263
|
771 (*point_queue)[r.qpos].dist = 1e6;
|
mas01mc@263
|
772 }
|
mas01mc@263
|
773
|
mas01mc@263
|
774 if (r.dist < (*point_queue)[r.qpos].dist)
|
mas01mc@263
|
775 (*point_queue)[r.qpos] = r;
|
mas01mc@263
|
776
|
mas01mc@263
|
777 }
|
mas01mc@263
|
778
|
mas01mc@292
|
779 void trackSequenceQueryRadNNReporterOneToOne::report(char *fileTable, void *adbQueryResponse) {
|
mas01mc@263
|
780 if(adbQueryResponse==0) {
|
mas01mc@263
|
781 std::vector< NNresult >::iterator vit;
|
mas01mc@263
|
782 NNresult rk;
|
mas01mc@263
|
783 for( vit = point_queue->begin() ; vit < point_queue->end() ; vit++ ){
|
mas01mc@263
|
784 rk = *vit;
|
mas01mc@263
|
785 std::cout << rk.dist << " "
|
mas01mc@263
|
786 << rk.qpos << " "
|
mas01mc@292
|
787 << rk.spos << " ";
|
mas01mc@292
|
788 if(fileTable)
|
mas01mc@292
|
789 std::cout << fileTable + rk.trackID*O2_FILETABLE_ENTRY_SIZE << " ";
|
mas01mc@292
|
790 else
|
mas01mc@292
|
791 std::cout << rk.trackID << " ";
|
mas01mc@292
|
792 std::cout << std::endl;
|
mas01mc@263
|
793 }
|
mas01mc@263
|
794 } else {
|
mas01mc@263
|
795 // FIXME
|
mas01mc@263
|
796 }
|
mas01mc@263
|
797 }
|
mas01mc@292
|
798
|
mas01mc@292
|
799 #endif
|