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