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