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