| [1738] | 1 | // ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL
 | 
|---|
 | 2 | //                               Eric Aubourg
 | 
|---|
 | 3 | //                               Christophe Magneville
 | 
|---|
 | 4 | //                               Reza Ansari
 | 
|---|
| [1764] | 5 | // $Id: rztoi.cc,v 1.9 2001-11-14 14:10:13 aubourg Exp $
 | 
|---|
| [1738] | 6 | 
 | 
|---|
| [1764] | 7 | #include "config.h"
 | 
|---|
| [1462] | 8 | #include "array.h"
 | 
|---|
| [1437] | 9 | #include "rztoi.h"
 | 
|---|
 | 10 | #include "toimanager.h"
 | 
|---|
 | 11 | #include "pexceptions.h"
 | 
|---|
 | 12 | #include "fftpserver.h"
 | 
|---|
| [1442] | 13 | #include "ctimer.h"
 | 
|---|
| [1437] | 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;
 | 
|---|
| [1442] | 25 |   declareInput("in");
 | 
|---|
 | 26 |   declareOutput("out");
 | 
|---|
| [1437] | 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 {
 | 
|---|
| [1442] | 43 |     Timer tm("RzTOIProc::run()");
 | 
|---|
| [1437] | 44 | 
 | 
|---|
 | 45 |     FFTPackServer ffts;
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 |     bool fgppf = false;
 | 
|---|
 | 48 |     int nkv = 0;
 | 
|---|
| [1438] | 49 |     //    int nkvmx = 8;
 | 
|---|
 | 50 | #define nkvmx 8 
 | 
|---|
| [1437] | 51 |     Vector vkin[nkvmx];
 | 
|---|
 | 52 |     Vector vkout[nkvmx];
 | 
|---|
 | 53 |     TVector< complex<r_8> > vkfft[nkvmx];
 | 
|---|
 | 54 |     if (outppf.length() > 0)    fgppf = true;
 | 
|---|
 | 55 |     
 | 
|---|
| [1439] | 56 |     Vector vin, vout, vsave(_width2);
 | 
|---|
| [1437] | 57 |     TVector< complex<r_8> > vfft;
 | 
|---|
| [1439] | 58 |     double vlast = 0.;
 | 
|---|
| [1437] | 59 | 
 | 
|---|
 | 60 |     for (int k=0; k<_nmax; k++) {
 | 
|---|
| [1439] | 61 |       //      istart = snb + k*_width1;
 | 
|---|
 | 62 |       istart = snb + k*_width1 - k*_width2;
 | 
|---|
| [1437] | 63 |       iend = istart +_width1;
 | 
|---|
| [1439] | 64 |       cout << "---RzTOIProc::run() - Processing bloc k= " << k 
 | 
|---|
| [1437] | 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);
 | 
|---|
| [1439] | 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 |       }
 | 
|---|
| [1437] | 83 | 
 | 
|---|
| [1439] | 84 |       vsave = vin(Range(_width1-_width2, -1,_width2));
 | 
|---|
 | 85 |       cout << "> End of getData() for bloc " << k << endl;
 | 
|---|
 | 86 | 
 | 
|---|
| [1437] | 87 |       vout.ReSize(vin.Size());
 | 
|---|
| [1439] | 88 |       //      cout << " DBG : Bloc[" << k << "] FirstSN=" << istart
 | 
|---|
 | 89 |       //           << " LastSN= " << istart+vout.Size()-_width2-1 << endl;
 | 
|---|
| [1476] | 90 |       int i;
 | 
|---|
 | 91 |       for(i=0; i<vout.Size()-_width2; i++) {
 | 
|---|
| [1437] | 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 | 
 | 
|---|
| [1476] | 97 |       for(i=vout.Size()-_width2; i<vout.Size(); i++) {
 | 
|---|
| [1437] | 98 |         vout(i) = vlast;
 | 
|---|
| [1439] | 99 |         //      putData(0, i+istart, vout(i));
 | 
|---|
| [1437] | 100 |       }
 | 
|---|
 | 101 | 
 | 
|---|
| [1439] | 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;
 | 
|---|
| [1437] | 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 |       }
 | 
|---|
| [1442] | 128 | 
 | 
|---|
 | 129 |       tm.Split("End of bloc");
 | 
|---|
| [1437] | 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 | 
 | 
|---|
| [1439] | 146 |     cout << " Filling with flag!=0  : putData(0, ii, flag) ii: "
 | 
|---|
| [1437] | 147 |          << iend << " .. " << sne << endl;
 | 
|---|
| [1439] | 148 |     for(ii=iend-_width2; ii<iend; ii++) {
 | 
|---|
 | 149 |       putData(0, ii, vlast, 1);
 | 
|---|
 | 150 |     }
 | 
|---|
 | 151 | 
 | 
|---|
| [1437] | 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);
 | 
|---|
| [1439] | 158 |       putData(0,ii,xxx,2);
 | 
|---|
| [1437] | 159 |     }
 | 
|---|
 | 160 | 
 | 
|---|
 | 161 |   }
 | 
|---|
 | 162 |   catch (PException & e) {
 | 
|---|
| [1442] | 163 |     cout << "RzTOIProc: Catched exception " << (string)typeid(e).name()
 | 
|---|
 | 164 |          << "\n Msg= " << e.Msg() << endl;
 | 
|---|
| [1437] | 165 |   }
 | 
|---|
 | 166 | }
 | 
|---|
 | 167 | 
 | 
|---|
 | 168 | 
 | 
|---|
 | 169 | 
 | 
|---|
| [1442] | 170 | RzSimpleTOIProc::RzSimpleTOIProc(int wsz, double fact)
 | 
|---|
| [1437] | 171 | {
 | 
|---|
| [1442] | 172 |   if (wsz < 4) wsz = 4;
 | 
|---|
| [1437] | 173 |   cout << "RzSimpleTOIProc::RzSimpleTOIProc() factor= " << fact 
 | 
|---|
| [1442] | 174 |        << " WSize=" << wsz << endl; 
 | 
|---|
| [1437] | 175 |   _fact = fact;
 | 
|---|
| [1442] | 176 |   _wsz = wsz;
 | 
|---|
| [1437] | 177 | }
 | 
|---|
 | 178 | 
 | 
|---|
 | 179 | void RzSimpleTOIProc::init() {
 | 
|---|
 | 180 |   cout << "RzSimpleTOIProc::init" << endl;
 | 
|---|
| [1442] | 181 |   declareInput("in");
 | 
|---|
 | 182 |   declareOutput("out");
 | 
|---|
| [1437] | 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 | 
 | 
|---|
| [1442] | 192 |   int nstot = sne-snb;
 | 
|---|
 | 193 |   int nbloc = nstot/_wsz;
 | 
|---|
 | 194 |   cout << " RzSimpleTOIProc::run(): snb=" << snb << " sne=" 
 | 
|---|
 | 195 |        << sne << " NBloc=" << nbloc << endl;
 | 
|---|
| [1437] | 196 | 
 | 
|---|
 | 197 |   double val;
 | 
|---|
| [1442] | 198 |   int snlast = snb;
 | 
|---|
 | 199 |   int istart,ii,kb;
 | 
|---|
| [1437] | 200 |   try {
 | 
|---|
| [1442] | 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;
 | 
|---|
| [1437] | 220 |     }
 | 
|---|
| [1442] | 221 |     cout << " ... Processing remaining Samples - SN=" 
 | 
|---|
 | 222 |          << snlast << " ->" << sne << endl;
 | 
|---|
| [1443] | 223 |     for(ii=snlast; ii<=sne; ii++) {
 | 
|---|
| [1442] | 224 |       val = getData(0, ii);
 | 
|---|
 | 225 |       putData(0, ii, val*_fact);
 | 
|---|
 | 226 |     }
 | 
|---|
 | 227 |     
 | 
|---|
 | 228 |     
 | 
|---|
| [1437] | 229 |   }
 | 
|---|
 | 230 |   catch (PException & e) {
 | 
|---|
| [1442] | 231 |     cout << "RzSimpleTOIProc exception " << (string)typeid(e).name()
 | 
|---|
 | 232 |          << "\n  Msg= " << e.Msg() << endl;
 | 
|---|
| [1437] | 233 |   }
 | 
|---|
 | 234 | }
 | 
|---|