[1462] | 1 | #include "array.h"
|
---|
[1437] | 2 | #include "rztoi.h"
|
---|
| 3 | #include "toimanager.h"
|
---|
| 4 | #include "pexceptions.h"
|
---|
| 5 | #include "fftpserver.h"
|
---|
[1442] | 6 | #include "ctimer.h"
|
---|
[1437] | 7 |
|
---|
| 8 | RzTOIProc::RzTOIProc(int w1, int w2, int nmax)
|
---|
| 9 | {
|
---|
| 10 | cout << "RzTOIProc::RzTOIProc() Width= " << w1 << "," << w2 << " NMax=" << nmax;
|
---|
| 11 | _width1 = w1;
|
---|
| 12 | _width2 = w2;
|
---|
| 13 | _nmax = nmax;
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | void RzTOIProc::init() {
|
---|
| 17 | cout << "RzTOIProc::init" << endl;
|
---|
[1442] | 18 | declareInput("in");
|
---|
| 19 | declareOutput("out");
|
---|
[1437] | 20 | name = "rzproc";
|
---|
| 21 | upExtra = 1;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | void RzTOIProc::run() {
|
---|
| 25 | // TOIManager* mgr = TOIManager::getManager();
|
---|
| 26 | int snb = getMinIn();
|
---|
| 27 | int sne = getMaxIn();
|
---|
| 28 |
|
---|
| 29 | int istart, iend;
|
---|
| 30 | int ilast;
|
---|
| 31 | ilast = istart = snb;
|
---|
| 32 | iend = sne;
|
---|
| 33 | int ii, jj;
|
---|
| 34 |
|
---|
| 35 | try {
|
---|
[1442] | 36 | Timer tm("RzTOIProc::run()");
|
---|
[1437] | 37 |
|
---|
| 38 | FFTPackServer ffts;
|
---|
| 39 |
|
---|
| 40 | bool fgppf = false;
|
---|
| 41 | int nkv = 0;
|
---|
[1438] | 42 | // int nkvmx = 8;
|
---|
| 43 | #define nkvmx 8
|
---|
[1437] | 44 | Vector vkin[nkvmx];
|
---|
| 45 | Vector vkout[nkvmx];
|
---|
| 46 | TVector< complex<r_8> > vkfft[nkvmx];
|
---|
| 47 | if (outppf.length() > 0) fgppf = true;
|
---|
| 48 |
|
---|
[1439] | 49 | Vector vin, vout, vsave(_width2);
|
---|
[1437] | 50 | TVector< complex<r_8> > vfft;
|
---|
[1439] | 51 | double vlast = 0.;
|
---|
[1437] | 52 |
|
---|
| 53 | for (int k=0; k<_nmax; k++) {
|
---|
[1439] | 54 | // istart = snb + k*_width1;
|
---|
| 55 | istart = snb + k*_width1 - k*_width2;
|
---|
[1437] | 56 | iend = istart +_width1;
|
---|
[1439] | 57 | cout << "---RzTOIProc::run() - Processing bloc k= " << k
|
---|
[1437] | 58 | << " istart= " << istart << " iend= " << iend << endl;
|
---|
| 59 | if (iend > sne) {
|
---|
| 60 | cout << " RzTOIProc::run() - iend > getMaxIn() -> break " << endl;
|
---|
| 61 | break;
|
---|
| 62 | }
|
---|
| 63 | // Vector vin = getData(0, istart, iend);
|
---|
| 64 | vin.ReSize(_width1);
|
---|
[1439] | 65 | if (k == 0) {
|
---|
| 66 | jj = 0;
|
---|
| 67 | for(ii=istart; ii<iend; ii++)
|
---|
| 68 | vin(jj++) = getData(0, ii);
|
---|
| 69 | }
|
---|
| 70 | else {
|
---|
| 71 | vin(Range(0,-1,_width2)) = vsave;
|
---|
| 72 | jj = _width2;
|
---|
| 73 | for(ii=istart+_width2; ii<iend; ii++)
|
---|
| 74 | vin(jj++) = getData(0, ii);
|
---|
| 75 | }
|
---|
[1437] | 76 |
|
---|
[1439] | 77 | vsave = vin(Range(_width1-_width2, -1,_width2));
|
---|
| 78 | cout << "> End of getData() for bloc " << k << endl;
|
---|
| 79 |
|
---|
[1437] | 80 | vout.ReSize(vin.Size());
|
---|
[1439] | 81 | // cout << " DBG : Bloc[" << k << "] FirstSN=" << istart
|
---|
| 82 | // << " LastSN= " << istart+vout.Size()-_width2-1 << endl;
|
---|
[1476] | 83 | int i;
|
---|
| 84 | for(i=0; i<vout.Size()-_width2; i++) {
|
---|
[1437] | 85 | vout(i) = vin(Range(i,-1,_width2)).Sum()/(r_8)_width2;
|
---|
| 86 | putData(0, i+istart, vout(i));
|
---|
| 87 | vlast = vout(i);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[1476] | 90 | for(i=vout.Size()-_width2; i<vout.Size(); i++) {
|
---|
[1437] | 91 | vout(i) = vlast;
|
---|
[1439] | 92 | // putData(0, i+istart, vout(i));
|
---|
[1437] | 93 | }
|
---|
| 94 |
|
---|
[1439] | 95 | cout << ">> End of putData() for bloc[" << k << "] FirstSN="
|
---|
| 96 | << istart << " LastSN= " << istart+vout.Size()-_width2-1
|
---|
| 97 | << " Mean vout= " << vout.Sum()/vout.Size() << endl;
|
---|
[1437] | 98 |
|
---|
| 99 | vin -= vout;
|
---|
| 100 |
|
---|
| 101 | TVector< complex<r_8> > vfft;
|
---|
| 102 | ffts.FFTForward(vin, vfft);
|
---|
| 103 | ilast = iend;
|
---|
| 104 | /*
|
---|
| 105 | if (fgppf) {
|
---|
| 106 | string nom;
|
---|
| 107 | nom = "in" + (string)MuTyV(k);
|
---|
| 108 | ppo->PutObject(vin, nom);
|
---|
| 109 | nom = "out" + (string)MuTyV(k);
|
---|
| 110 | ppo->PutObject(vout, nom);
|
---|
| 111 | nom = "fft" + (string)MuTyV(k);
|
---|
| 112 | ppo->PutObject(vfft, nom);
|
---|
| 113 | }
|
---|
| 114 | */
|
---|
| 115 | if (fgppf && (nkv < nkvmx) ) {
|
---|
| 116 | vkin[nkv] = vin;
|
---|
| 117 | vkout[nkv] = vout;
|
---|
| 118 | vkfft[nkv] = vfft;
|
---|
| 119 | nkv++;
|
---|
| 120 | }
|
---|
[1442] | 121 |
|
---|
| 122 | tm.Split("End of bloc");
|
---|
[1437] | 123 | }
|
---|
| 124 |
|
---|
| 125 | if (fgppf) {
|
---|
| 126 | cout << " Writing to Out PPF ... " << endl;
|
---|
| 127 | POutPersist ppo(outppf);
|
---|
| 128 | for(int kkk=0; kkk<nkv; kkk++) {
|
---|
| 129 | string nom;
|
---|
| 130 | nom = "in" + (string)MuTyV(kkk);
|
---|
| 131 | ppo.PutObject(vkin[kkk], nom);
|
---|
| 132 | nom = "out" + (string)MuTyV(kkk);
|
---|
| 133 | ppo.PutObject(vkout[kkk], nom);
|
---|
| 134 | nom = "fft" + (string)MuTyV(kkk);
|
---|
| 135 | ppo.PutObject(vkfft[kkk], nom);
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[1439] | 139 | cout << " Filling with flag!=0 : putData(0, ii, flag) ii: "
|
---|
[1437] | 140 | << iend << " .. " << sne << endl;
|
---|
[1439] | 141 | for(ii=iend-_width2; ii<iend; ii++) {
|
---|
| 142 | putData(0, ii, vlast, 1);
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[1437] | 145 | double xxx;
|
---|
| 146 | for(ii=iend; ii<sne; ii++) {
|
---|
| 147 | if ((ii-iend)%1000 == 0)
|
---|
| 148 | cout << " RzTOIProc::run() - Processing sample ii= " << ii
|
---|
| 149 | << endl;
|
---|
| 150 | xxx=getData(0,ii);
|
---|
[1439] | 151 | putData(0,ii,xxx,2);
|
---|
[1437] | 152 | }
|
---|
| 153 |
|
---|
| 154 | }
|
---|
| 155 | catch (PException & e) {
|
---|
[1442] | 156 | cout << "RzTOIProc: Catched exception " << (string)typeid(e).name()
|
---|
| 157 | << "\n Msg= " << e.Msg() << endl;
|
---|
[1437] | 158 | }
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 |
|
---|
[1442] | 163 | RzSimpleTOIProc::RzSimpleTOIProc(int wsz, double fact)
|
---|
[1437] | 164 | {
|
---|
[1442] | 165 | if (wsz < 4) wsz = 4;
|
---|
[1437] | 166 | cout << "RzSimpleTOIProc::RzSimpleTOIProc() factor= " << fact
|
---|
[1442] | 167 | << " WSize=" << wsz << endl;
|
---|
[1437] | 168 | _fact = fact;
|
---|
[1442] | 169 | _wsz = wsz;
|
---|
[1437] | 170 | }
|
---|
| 171 |
|
---|
| 172 | void RzSimpleTOIProc::init() {
|
---|
| 173 | cout << "RzSimpleTOIProc::init" << endl;
|
---|
[1442] | 174 | declareInput("in");
|
---|
| 175 | declareOutput("out");
|
---|
[1437] | 176 | name = "rzsimpleproc";
|
---|
| 177 | upExtra = 1;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | void RzSimpleTOIProc::run() {
|
---|
| 181 | // TOIManager* mgr = TOIManager::getManager();
|
---|
| 182 | int snb = getMinIn();
|
---|
| 183 | int sne = getMaxIn();
|
---|
| 184 |
|
---|
[1442] | 185 | int nstot = sne-snb;
|
---|
| 186 | int nbloc = nstot/_wsz;
|
---|
| 187 | cout << " RzSimpleTOIProc::run(): snb=" << snb << " sne="
|
---|
| 188 | << sne << " NBloc=" << nbloc << endl;
|
---|
[1437] | 189 |
|
---|
| 190 | double val;
|
---|
[1442] | 191 | int snlast = snb;
|
---|
| 192 | int istart,ii,kb;
|
---|
[1437] | 193 | try {
|
---|
[1442] | 194 | Timer tm("RzSimpleTOIProc::run()");
|
---|
| 195 | Vector vin(_wsz);
|
---|
| 196 | for (kb=0; kb<nbloc; kb++) {
|
---|
| 197 | istart = kb*_wsz+snb;
|
---|
| 198 | if (kb%2 == 0) { // On parcourt a l'envers
|
---|
| 199 | cout << " ... Processing bloc[" << kb << "] (Reverse) SampleNum="
|
---|
| 200 | << istart+_wsz << " ->" << istart << endl;
|
---|
| 201 | for(ii=_wsz-1; ii>=0; ii--)
|
---|
| 202 | vin(ii) = getData(0, ii+istart);
|
---|
| 203 | }
|
---|
| 204 | else { // On parcourt vers l'avant
|
---|
| 205 | cout << " ... Processing bloc[" << kb << "] SampleNum="
|
---|
| 206 | << istart << " ->" << istart+_wsz << endl;
|
---|
| 207 | for(ii=0; ii<_wsz; ii++)
|
---|
| 208 | vin(ii) = getData(0, ii+istart);
|
---|
| 209 | }
|
---|
| 210 | for(ii=0; ii<_wsz; ii++)
|
---|
| 211 | putData(0, ii+istart, vin(ii)*_fact);
|
---|
| 212 | snlast = istart+_wsz;
|
---|
[1437] | 213 | }
|
---|
[1442] | 214 | cout << " ... Processing remaining Samples - SN="
|
---|
| 215 | << snlast << " ->" << sne << endl;
|
---|
[1443] | 216 | for(ii=snlast; ii<=sne; ii++) {
|
---|
[1442] | 217 | val = getData(0, ii);
|
---|
| 218 | putData(0, ii, val*_fact);
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 |
|
---|
[1437] | 222 | }
|
---|
| 223 | catch (PException & e) {
|
---|
[1442] | 224 | cout << "RzSimpleTOIProc exception " << (string)typeid(e).name()
|
---|
| 225 | << "\n Msg= " << e.Msg() << endl;
|
---|
[1437] | 226 | }
|
---|
| 227 | }
|
---|