1 | #include "toiprocessor.h"
|
---|
2 | #include "toiregwindow.h"
|
---|
3 | #include <pthread.h>
|
---|
4 |
|
---|
5 | #ifdef WITH_SOPHYA
|
---|
6 | #include "pexceptions.h"
|
---|
7 | #else
|
---|
8 | #include "apexceptions.h"
|
---|
9 | #endif
|
---|
10 |
|
---|
11 | #define CHKSYNC(ctx)
|
---|
12 | // if (((TOIRegularWindow*)this)->data.size() != ((TOIRegularWindow*)this)->flags.size()) \
|
---|
13 | // cout << ctx << ((TOIRegularWindow*)this)->data.size() << " " << \
|
---|
14 | // ((TOIRegularWindow*)this)->flags.size() << endl; \
|
---|
15 |
|
---|
16 | // ------------------------------------------------------------
|
---|
17 | // -------------------- TOIRegularWindow --------------------
|
---|
18 | // ------------------------------------------------------------
|
---|
19 |
|
---|
20 |
|
---|
21 | TOIRegularWindow::TOIRegularWindow() {
|
---|
22 | i0 = -1;
|
---|
23 | }
|
---|
24 |
|
---|
25 | TOIRegularWindow::TOIRegularWindow(string nm) {
|
---|
26 | i0 = -1;
|
---|
27 | setName(nm);
|
---|
28 | }
|
---|
29 |
|
---|
30 | TOIRegularWindow::~TOIRegularWindow() {
|
---|
31 | }
|
---|
32 |
|
---|
33 | TOI::DataStatus TOIRegularWindow::isDataAvailNL(int iStart, int iEnd) {
|
---|
34 | if (iEnd >= i0 + (long)data.size()) return DATA_NOT_YET;
|
---|
35 | if (iStart < i0) return DATA_DELETED;
|
---|
36 | return DATA_OK;
|
---|
37 | }
|
---|
38 |
|
---|
39 | TOI::DataStatus TOIRegularWindow::isDataAvailNL(int i) {
|
---|
40 | return TOI::isDataAvailNL(i);
|
---|
41 | }
|
---|
42 |
|
---|
43 |
|
---|
44 | void TOIRegularWindow::doWontNeedBefore(int i) {
|
---|
45 | if (i>= i0 + (long)data.size())
|
---|
46 | i = i0 + (long)data.size() - 1;
|
---|
47 | if (i>i0) { // don't empty list
|
---|
48 | int osz = data.size();
|
---|
49 | data.erase(data.begin(), data.begin()+(i-i0));
|
---|
50 | flags.erase(flags.begin(), flags.begin()+(i-i0));
|
---|
51 | i0 = i;
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 | #ifndef NO_SOPHYA
|
---|
58 | /* ----- l'interface va etre modifiee, NE PAS UTILISER
|
---|
59 | Array TOIRegularWindow::doGetData(int iStart, int iEnd) {
|
---|
60 | if (!isDataAvailNL(iStart, iEnd)) {
|
---|
61 | throw RangeCheckError("TOI::getData : data not available");
|
---|
62 | }
|
---|
63 | Array dat(iEnd - iStart + 1);
|
---|
64 | long j0 = iStart - i0;
|
---|
65 | for (int i=0; i<iEnd-iStart+1; i++) {
|
---|
66 | dat[i] = data[i+j0];
|
---|
67 | }
|
---|
68 | return dat;
|
---|
69 | }
|
---|
70 | TArray<int_4> TOIRegularWindow::doGetFlag(int iStart, int iEnd) {
|
---|
71 | if (isDataAvailNL(iStart, iEnd) != DATA_OK) throw RangeCheckError("TOI::getData : data not available");
|
---|
72 | TArray<int_4> dat(iEnd - iStart + 1);
|
---|
73 | long j0 = iStart - i0;
|
---|
74 | for (int i=0; i<iEnd-iStart+1; i++) {
|
---|
75 | dat[i] = flags[i+j0];
|
---|
76 | }
|
---|
77 | return dat;
|
---|
78 | }
|
---|
79 | l'interface va etre modifiee, NE PAS UTILISER ----- */
|
---|
80 | #endif
|
---|
81 |
|
---|
82 | void TOIRegularWindow::doGetData(int i, double & val, int_8 & flg) {
|
---|
83 | if (isDataAvailNL(i) != DATA_OK) {
|
---|
84 | cerr << "TOI::getData : data not available " << i << endl;
|
---|
85 | throw RangeCheckError("TOI::getData : data not available");
|
---|
86 | }
|
---|
87 |
|
---|
88 | val = data[i - i0];
|
---|
89 | flg = flags[i - i0];
|
---|
90 |
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | /*RZCMV
|
---|
95 | int_4 TOIRegularWindow::doGetFlag(int i) {
|
---|
96 | if (isDataAvailNL(i) != DATA_OK) {
|
---|
97 | cerr << "TOI::getFlag : data not available " << i << endl;
|
---|
98 | throw RangeCheckError("TOI::getFlag : data not available");
|
---|
99 | }
|
---|
100 | return flags[i - i0];
|
---|
101 | }
|
---|
102 | */
|
---|
103 |
|
---|
104 |
|
---|
105 |
|
---|
106 | void TOIRegularWindow::doPutData(int i, double value, int_8 flag) {
|
---|
107 | int_8 flgdef = 0;
|
---|
108 | if (i0 == -1) {
|
---|
109 | data.insert(data.begin(), 1, defaultValue);
|
---|
110 | flags.insert(flags.begin(), 1, flgdef);
|
---|
111 | i0 = i;
|
---|
112 | } else if (i<i0) {
|
---|
113 | data.insert(data.begin(), i0-i, defaultValue);
|
---|
114 | flags.insert(flags.begin(), i0-i, flgdef);
|
---|
115 | i0 = i;
|
---|
116 | } else if (i>=i0+(int)data.size()) {
|
---|
117 | data.insert(data.end(), (long) (i-(i0+data.size())+1), defaultValue);
|
---|
118 | flags.insert(flags.end(), (long) (i-(i0+flags.size())+1), flgdef);
|
---|
119 | }
|
---|
120 | data[i-i0] = value;
|
---|
121 | flags[i-i0] = flag;
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | bool TOIRegularWindow::hasSomeData() {
|
---|
126 | lock();
|
---|
127 | bool x = !data.empty();
|
---|
128 | unlock();
|
---|
129 | return x;
|
---|
130 | }
|
---|
131 |
|
---|
132 | int TOIRegularWindow::nextDataAvail(int iAfter) {
|
---|
133 | lock();
|
---|
134 | if (iAfter >= i0 + (long)data.size()) {unlock(); return -1;}
|
---|
135 | if (iAfter < i0) {unlock(); return i0;}
|
---|
136 | unlock();
|
---|
137 | return iAfter+1;
|
---|
138 | }
|
---|
139 |
|
---|
140 |
|
---|
141 | /* A faire, le nettoyage (heuristique selon demandes ?, guide ? ) */
|
---|
142 |
|
---|
143 |
|
---|