1 | #include "array.h"
|
---|
2 | #include "simtoipr.h"
|
---|
3 | #include <math.h>
|
---|
4 | #include "toimanager.h"
|
---|
5 | #include "pexceptions.h"
|
---|
6 | #include "ctimer.h"
|
---|
7 |
|
---|
8 | SimpleDeglitcher::SimpleDeglitcher(int wsz, double ns, int maxnpt)
|
---|
9 | {
|
---|
10 | SetWSize(wsz);
|
---|
11 | SetDetectionParam(ns, ns/2., maxnpt);
|
---|
12 | SetRange(-9.e39, 9.e39);
|
---|
13 | RepBadSamples(true, true);
|
---|
14 |
|
---|
15 | totnscount = glnscount = glcount = out_range_nscount = 0;
|
---|
16 | deglitchdone = false;
|
---|
17 |
|
---|
18 | cout << "SimpleDeglitcher::SimpleDeglitcher() WSize= " << wsz
|
---|
19 | << " nSig=" << ns << " maxNPt=" << maxnpt << endl;
|
---|
20 | }
|
---|
21 |
|
---|
22 | SimpleDeglitcher::~SimpleDeglitcher()
|
---|
23 | {
|
---|
24 | }
|
---|
25 |
|
---|
26 | void SimpleDeglitcher::SetDetectionParam(double ns, double ns2, int maxnpt, int wszrec)
|
---|
27 | {
|
---|
28 | nsig = (ns > 0.01) ? ns : 1.;
|
---|
29 | nsig2 = (ns2 > 0.01) ? ns2 : nsig/2.;
|
---|
30 | maxpoints = ((maxnpt > 0) && (maxnpt <= wsize)) ? maxnpt : 5;
|
---|
31 | wrecsize = ((wszrec > 0) && (wszrec <= wsize)) ? wszrec : 2*maxpoints;
|
---|
32 | }
|
---|
33 |
|
---|
34 | inline char * _Bool2YesNo(bool fg)
|
---|
35 | {
|
---|
36 | if (fg) return "YES" ;
|
---|
37 | else return "NO" ;
|
---|
38 | }
|
---|
39 |
|
---|
40 | void SimpleDeglitcher::PrintStatus(ostream & os)
|
---|
41 | {
|
---|
42 | os << "\n ------------------------------------------------------ \n"
|
---|
43 | << " SimpleDeglitcher::PrintStatus() - WindowSize=" << WSize()
|
---|
44 | << " NbSigmas=" << NbSigmas() << " MaxPoints=" << MaxPoints() << endl;
|
---|
45 | os << " NbSigmas2=" << NbSigmas2() << " WRecSize= " << WRecSize()
|
---|
46 | << " Range_Min= " << range_min << " Range_Max= " << range_max << endl;
|
---|
47 | os << " RepOutOfRangeSamples: " << _Bool2YesNo(rec_out_range_samples)
|
---|
48 | << " RepGlitchSamples: " << _Bool2YesNo(rec_gl_samples)
|
---|
49 | << " UseWRec: " << _Bool2YesNo(rec_use_wrec) << endl;
|
---|
50 | TOIProcessor::PrintStatus(os);
|
---|
51 | if (deglitchdone) os << " Deglitching performed " << endl;
|
---|
52 | else os << " NO deglitching done " << endl;
|
---|
53 | double nst = (ProcessedSampleCount() > 0) ? ProcessedSampleCount() : 1.;
|
---|
54 | os << " ProcessedSampleCount=" << ProcessedSampleCount()
|
---|
55 | << " OutOfRangeSampleCount=" << OutOfRangeSampleCount() << endl;
|
---|
56 | os << " GlitchCount= " << GlitchCount()
|
---|
57 | << " GlitchSampleCount=" << GlitchSampleCount()
|
---|
58 | << "( " << (double)GlitchSampleCount()*100./nst << " % )" << endl;
|
---|
59 | os << " ------------------------------------------------------ " << endl;
|
---|
60 | }
|
---|
61 |
|
---|
62 | void SimpleDeglitcher::init() {
|
---|
63 | cout << "SimpleDeglitcher::init" << endl;
|
---|
64 | declareInput("in");
|
---|
65 | declareOutput("out");
|
---|
66 | declareOutput("mean");
|
---|
67 | declareOutput("sigma");
|
---|
68 | declareOutput("incopie");
|
---|
69 | name = "SimpleDeglitcher";
|
---|
70 | // upExtra = 1; A quoi ca sert ?
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | #define FG_OUTOFRANGE 1
|
---|
75 | #define FG_GLITCH 2
|
---|
76 | void SimpleDeglitcher::run() {
|
---|
77 |
|
---|
78 | // TOIManager* mgr = TOIManager::getManager();
|
---|
79 | int snb = getMinIn();
|
---|
80 | int sne = getMaxIn();
|
---|
81 |
|
---|
82 | bool fgout = checkOutputTOIIndex(0);
|
---|
83 | bool fgmean = checkOutputTOIIndex(1);
|
---|
84 | bool fgsigma = checkOutputTOIIndex(2);
|
---|
85 | bool fgincopie = checkOutputTOIIndex(3);
|
---|
86 |
|
---|
87 | if (!checkInputTOIIndex(0)) {
|
---|
88 | cerr << " SimpleDeglitcher::run() - Input TOI (in) not connected! "
|
---|
89 | << endl;
|
---|
90 | throw ParmError("SimpleDeglitcher::run() Input TOI (in) not connected!");
|
---|
91 | }
|
---|
92 | if (!fgout && !fgmean && !fgsigma &&!fgincopie) {
|
---|
93 | cerr << " SimpleDeglitcher::run() - No Output TOI connected! "
|
---|
94 | << endl;
|
---|
95 | throw ParmError("SimpleDeglitcher::run() No output TOI connected!");
|
---|
96 | }
|
---|
97 |
|
---|
98 | if (!fgout) {
|
---|
99 | cout << "Warning: SimpleDeglitcher::run() - No TOI connected to out \n"
|
---|
100 | << " No deglitching would be performed !" << endl;
|
---|
101 | }
|
---|
102 |
|
---|
103 | cout << " SimpleDeglitcher::run() SNRange=" << snb << " - " << sne << endl;
|
---|
104 | try {
|
---|
105 | Timer tm("SimpleDeglitcher::run()");
|
---|
106 | Vector vin(wsize);
|
---|
107 | Vector vas(wsize);
|
---|
108 |
|
---|
109 | int wrecsize = maxpoints*2;
|
---|
110 | Vector vrec(wrecsize);
|
---|
111 |
|
---|
112 | TVector<int_8> vfg(wsize);
|
---|
113 | int wsz2 = wsize/2;
|
---|
114 | // Le debut
|
---|
115 | int k;
|
---|
116 | for(k=0; k<wsz2; k++)
|
---|
117 | getData(0, k+snb, vin(k), vfg(k));
|
---|
118 |
|
---|
119 | int nokdebut = 0.;
|
---|
120 | double s = 0.;
|
---|
121 | double mean = 0.;
|
---|
122 | double s2 = 0.;
|
---|
123 | double sigma = 0.;
|
---|
124 | for(k=0; k<wsz2; k++) {
|
---|
125 | if ( vfg(k) != 0) continue;
|
---|
126 | if ( (vin(k) < range_min) || (vin(k) > range_max) ) continue;
|
---|
127 | s += vin(k);
|
---|
128 | s2 += vin(k)*vin(k);
|
---|
129 | nokdebut++;
|
---|
130 | }
|
---|
131 | if (nokdebut > 0) {
|
---|
132 | mean = s/nokdebut;
|
---|
133 | if (nokdebut > 1) sigma = sqrt(s2/nokdebut-mean*mean);
|
---|
134 | }
|
---|
135 | for(k=wsz2; k<wsize; k++) {
|
---|
136 | vin(k) = mean;
|
---|
137 | vfg(k) = 0;
|
---|
138 | }
|
---|
139 | for(k=0; k<wsize; k++) {
|
---|
140 | vas(k) = mean;
|
---|
141 | if ( vfg(k) != 0) continue;
|
---|
142 | if ( (vin(k) < range_min) || (vin(k) > range_max) ) continue;
|
---|
143 | vas(k) = vin(k);
|
---|
144 | }
|
---|
145 |
|
---|
146 | for(k=0; k<wrecsize; k++) {
|
---|
147 | if ( (vin(k) < range_min) || (vin(k) > range_max) ) vrec(k)=mean;
|
---|
148 | else vrec(k)=vin(k);
|
---|
149 | }
|
---|
150 |
|
---|
151 | bool fgokdebut = false;
|
---|
152 |
|
---|
153 | int kgl = -1;
|
---|
154 | int ii,lastput;
|
---|
155 | bool fgglitch = false;
|
---|
156 | double valcur,valsub,valadd;
|
---|
157 | double lastvalok = mean;
|
---|
158 | uint_8 fgcur;
|
---|
159 | bool fgokcur=false;
|
---|
160 | // Boucle sur les sampleNum
|
---|
161 |
|
---|
162 | int knext;
|
---|
163 | int kfin = sne-snb;
|
---|
164 | for(k=0;k<=kfin;k++) {
|
---|
165 | totnscount++;
|
---|
166 | // if (k%10000 == 0) cout << " DBG: K=" << k << endl;
|
---|
167 | knext = k+wsz2;
|
---|
168 | // Calcul mean-sigma
|
---|
169 | if (knext<=kfin) {
|
---|
170 | valsub = vas(knext%wsize);
|
---|
171 | getData(0, knext+snb, vin(knext%wsize), vfg(knext%wsize));
|
---|
172 | valadd = vin(knext%wsize);
|
---|
173 | if ( vfg(knext%wsize) ||
|
---|
174 | (valadd < range_min) || (valadd > range_max) ) {
|
---|
175 | vas(knext%wsize) = valadd = mean;
|
---|
176 | fgokcur = false;
|
---|
177 | }
|
---|
178 | else {
|
---|
179 | vas(knext%wsize) = valadd = vin(knext%wsize);
|
---|
180 | fgokcur = true;
|
---|
181 | }
|
---|
182 | if (!fgokdebut && fgokcur) {
|
---|
183 | s += valadd;
|
---|
184 | s2 += valadd*valadd;
|
---|
185 | nokdebut++;
|
---|
186 | mean = s/nokdebut;
|
---|
187 | if (nokdebut > 1) sigma = sqrt(s2/nokdebut-mean*mean);
|
---|
188 | if (nokdebut >= wsize) {
|
---|
189 | fgokdebut = true;
|
---|
190 | cout << " SimpleDeglitcher::DebugInfo - nokdebut=" << nokdebut
|
---|
191 | << " k=" << k << " knext=" << knext
|
---|
192 | << "\n ...DebugInfo mean=" << mean
|
---|
193 | << " sigma=" << sigma << " s=" << s << " s2=" << s2 << endl;
|
---|
194 | }
|
---|
195 | }
|
---|
196 | else {
|
---|
197 | s += (valadd-valsub);
|
---|
198 | s2 += (valadd*valadd-valsub*valsub);
|
---|
199 | mean = s/wsize;
|
---|
200 | sigma = sqrt(s2/wsize-mean*mean);
|
---|
201 | }
|
---|
202 | }
|
---|
203 |
|
---|
204 |
|
---|
205 | // On gere les sorties Mean et Sigma
|
---|
206 | if (fgmean)
|
---|
207 | putData(1, k+snb, mean, 0);
|
---|
208 | if (fgsigma)
|
---|
209 | putData(2, k+snb, sigma, 0);
|
---|
210 | if (fgincopie)
|
---|
211 | putData(3, k+snb, vin(k%wsize), vfg(k%wsize));
|
---|
212 |
|
---|
213 | valcur = vin(k%wsize);
|
---|
214 | if ( (valcur < range_min) || (valcur > range_max) ) {
|
---|
215 | valcur = (rec_use_wrec) ? vrec.Sum()/wrecsize : mean;
|
---|
216 | if (rec_out_range_samples) vin(k%wsize) = valcur;
|
---|
217 | vfg(k%wsize) |= FG_OUTOFRANGE;
|
---|
218 | out_range_nscount++;
|
---|
219 | }
|
---|
220 | valcur = vin(k%wsize);
|
---|
221 | fgcur = vfg(k%wsize);
|
---|
222 |
|
---|
223 | if (!fgout) continue; // Pas de sortie out (deglitche)
|
---|
224 |
|
---|
225 |
|
---|
226 | // if (k<100) {
|
---|
227 | // cout << "DBG-A-Deglitch[" << k << "] mean="
|
---|
228 | // << mean << " sigma=" << sigma << " valcur="
|
---|
229 | // << valcur << " Kgl=" << kgl ;
|
---|
230 | // if (fgglitch) cout << " In Glitch" ;
|
---|
231 | // cout << endl;
|
---|
232 | // }
|
---|
233 |
|
---|
234 | double curnsig = (fgglitch) ? nsig2 : nsig;
|
---|
235 |
|
---|
236 | if (valcur < mean+curnsig*sigma) { // inferieur au seuil
|
---|
237 | if (fgglitch) {
|
---|
238 | if (k-kgl < maxpoints) { // On vient de detecter un glitch
|
---|
239 | glcount++;
|
---|
240 | if (rec_gl_samples) { // On change la valeur des samples
|
---|
241 | double recval = (rec_use_wrec) ? vrec.Sum()/wrecsize : mean;
|
---|
242 | for(ii=kgl; ii<k; ii++) {
|
---|
243 | putData(0, ii+snb, recval, vfg(ii%wsize)|FG_GLITCH);
|
---|
244 | glnscount++;
|
---|
245 | }
|
---|
246 | }
|
---|
247 | else { // On ne fait que flagger les echantillons
|
---|
248 | for(ii=kgl; ii<k; ii++) {
|
---|
249 | putData(0, ii+snb, vin(ii%wsize), vfg(ii%wsize)|FG_GLITCH);
|
---|
250 | glnscount++;
|
---|
251 | }
|
---|
252 | }
|
---|
253 | lastput = snb+k-1;
|
---|
254 | } // - Fin de detection de glitch
|
---|
255 | else { // Trop long - ce n'est pas un glitch ...
|
---|
256 | for(ii=kgl; ii<k; ii++) {
|
---|
257 | putData(0, ii+snb, vin(ii%wsize), vfg(ii%wsize));
|
---|
258 | }
|
---|
259 | lastput = snb+k-1;
|
---|
260 | }
|
---|
261 | }
|
---|
262 | putData(0, k+snb, vin(k%wsize), vfg(k%wsize));
|
---|
263 | lastput = snb+k;
|
---|
264 | kgl = -1; fgglitch = false;
|
---|
265 | vrec(k%wrecsize) = lastvalok = valcur;
|
---|
266 | }
|
---|
267 | else { // Superieur au seuil
|
---|
268 | if (fgglitch) {
|
---|
269 | if (k-kgl+1 >= maxpoints) { // serie de points > seuil
|
---|
270 | for(ii=kgl; ii<=k; ii++) // -> Donc pas glitch
|
---|
271 | putData(0, ii+snb, vin(ii%wsize), vfg(ii%wsize));
|
---|
272 | lastput = snb+k;
|
---|
273 | fgglitch = false;
|
---|
274 | vrec(k%wrecsize) = lastvalok = valcur;
|
---|
275 | }
|
---|
276 | }
|
---|
277 | else {
|
---|
278 | if (kgl < 0) { // debut possible de glitch
|
---|
279 | fgglitch = true; kgl = k;
|
---|
280 | }
|
---|
281 | else { // On est toujours dans une serie > seuil
|
---|
282 | putData(0, k+snb, vin(k%wsize), vfg(k%wsize));
|
---|
283 | lastput = snb+k; lastvalok = valcur;
|
---|
284 | }
|
---|
285 | vrec(k%wrecsize) = lastvalok;
|
---|
286 | }
|
---|
287 | }
|
---|
288 |
|
---|
289 | // if (k%5000 == 0) cout << " ---DBG2: K=" << k << " glcount="
|
---|
290 | // << glcount << " LastPut= " << lastput << endl;
|
---|
291 | } // Fin de Boucle sur les num-sample
|
---|
292 |
|
---|
293 | //DBG cout << " La fin lastput=" << lastput << " SNE=" << sne;
|
---|
294 | //DBG for(k=lastput-snb+1; k<sne-snb; k++)
|
---|
295 | //DBG putData(0, k+snb, vin(k%wsize), 0);
|
---|
296 | // cout << " DBG3- OUT of try bloc ! " << endl;
|
---|
297 | cout << " SimpleDeglitcher::run() - End of processing "
|
---|
298 | << " ProcessedSampleCount=" << ProcessedSampleCount()
|
---|
299 | << " GlitchCount= " << GlitchCount() << endl;
|
---|
300 | if (fgout) deglitchdone = true;
|
---|
301 | } // Bloc try
|
---|
302 | catch (PException & exc) {
|
---|
303 | cerr << "SimpleDeglitcher: Catched Exception " << (string)typeid(exc).name()
|
---|
304 | << "\n .... Msg= " << exc.Msg() << endl;
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 |
|
---|
309 | // -------------------------------------------------------------------
|
---|
310 | // Classe SimpleFilter : Filtre simple ds le domaine temporel
|
---|
311 | // -------------------------------------------------------------------
|
---|
312 |
|
---|
313 | string SimpleFilter::FilterKind2String(FilterKind fk)
|
---|
314 | {
|
---|
315 | switch (fk) {
|
---|
316 | case UserFilter :
|
---|
317 | return ("UserFilter");
|
---|
318 | break;
|
---|
319 | case MeanFilter :
|
---|
320 | return ("MeanFilter");
|
---|
321 | break;
|
---|
322 | case SumFilter :
|
---|
323 | return ("SumFilter");
|
---|
324 | break;
|
---|
325 | case GaussFilter :
|
---|
326 | return ("GaussFilter");
|
---|
327 | break;
|
---|
328 | case DiffFilter :
|
---|
329 | return ("DiffFilter");
|
---|
330 | break;
|
---|
331 | default :
|
---|
332 | return ("ErrorFilterKind");
|
---|
333 | break;
|
---|
334 | }
|
---|
335 | return("");
|
---|
336 | }
|
---|
337 |
|
---|
338 | SimpleFilter::SimpleFilter(int wsz, FilterKind fk, double a, double s)
|
---|
339 | {
|
---|
340 | if (wsz < 3) wsz = 3;
|
---|
341 | if (wsz%2 == 0) wsz++;
|
---|
342 | cout << "SimpleFilter::SimpleFilter() wsz= " << wsz
|
---|
343 | << " FilterKind=" << FilterKind2String(fk) << endl;
|
---|
344 | wsize = wsz;
|
---|
345 | totnscount = 0;
|
---|
346 | coef = new double[wsz];
|
---|
347 | for(int k=0; k<wsz; k++) coef[k] = 0.;
|
---|
348 | int kk;
|
---|
349 | switch (fk) {
|
---|
350 | case UserFilter :
|
---|
351 | throw ParmError("SimpleFilter: Error in filter Kind (UserFilter)!");
|
---|
352 | // break;
|
---|
353 | case MeanFilter :
|
---|
354 | for(kk=0; kk<wsz; kk++)
|
---|
355 | coef[kk] = a/wsize;
|
---|
356 | break;
|
---|
357 | case SumFilter :
|
---|
358 | for(kk=0; kk<wsz; kk++)
|
---|
359 | coef[kk] = a;
|
---|
360 | break;
|
---|
361 | case GaussFilter :
|
---|
362 | for(kk=-(wsz/2); kk<=(wsz/2); kk++)
|
---|
363 | coef[kk+(wsz/2)] = a*exp(-(double)(kk*kk)/(s*s));
|
---|
364 | break;
|
---|
365 | case DiffFilter :
|
---|
366 | for(kk=0; kk<wsz; kk++)
|
---|
367 | coef[kk] = -a/wsize;
|
---|
368 | coef[wsz/2+1] += 1.;
|
---|
369 | break;
|
---|
370 | default :
|
---|
371 | throw ParmError("SimpleFilter: Error in filter Kind (UnknownFilter)!");
|
---|
372 | // break;
|
---|
373 | }
|
---|
374 | }
|
---|
375 |
|
---|
376 | SimpleFilter::SimpleFilter(Vector const & vc)
|
---|
377 | {
|
---|
378 | int wsz = vc.Size();
|
---|
379 | if (wsz < 3) wsz = 3;
|
---|
380 | if (wsz%2 == 0) wsz++;
|
---|
381 | FilterKind fk = UserFilter;
|
---|
382 | cout << "SimpleFilter::SimpleFilter(Vector & vc) vc.Size()= "
|
---|
383 | << vc.Size() << " WSize=" << wsz
|
---|
384 | << " FilterKind=" << FilterKind2String(fk) << endl;
|
---|
385 | wsize = wsz;
|
---|
386 | totnscount = 0;
|
---|
387 | coef = new double[wsz];
|
---|
388 | int kk;
|
---|
389 | for(kk=0; kk<vc.Size(); kk++)
|
---|
390 | coef[kk] = vc(kk);
|
---|
391 | for(kk=vc.Size(); kk<wsz; kk++)
|
---|
392 | coef[kk] = 0.;
|
---|
393 | }
|
---|
394 |
|
---|
395 | SimpleFilter::~SimpleFilter()
|
---|
396 | {
|
---|
397 | delete[] coef;
|
---|
398 | }
|
---|
399 |
|
---|
400 | void SimpleFilter::PrintStatus(ostream & os)
|
---|
401 | {
|
---|
402 | os << "\n ------------------------------------------------------ \n"
|
---|
403 | << " SimpleFilter::PrintStatus() - WindowSize=" << WSize()
|
---|
404 | << " FilterKind= " << Type() << endl;
|
---|
405 | TOIProcessor::PrintStatus(os);
|
---|
406 | os << " Coeff= " ;
|
---|
407 | for(int k=0; k<wsize; k++) os << coef[k] << " " ;
|
---|
408 | os << endl;
|
---|
409 | os << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
|
---|
410 | os << " ------------------------------------------------------ " << endl;
|
---|
411 | }
|
---|
412 |
|
---|
413 | void SimpleFilter::init() {
|
---|
414 | cout << "SimpleFilter::init" << endl;
|
---|
415 | declareInput("in");
|
---|
416 | declareOutput("out");
|
---|
417 | declareOutput("incopie");
|
---|
418 | name = "SimpleFilter";
|
---|
419 | // upExtra = 1;
|
---|
420 | }
|
---|
421 |
|
---|
422 | void SimpleFilter::run() {
|
---|
423 | // TOIManager* mgr = TOIManager::getManager();
|
---|
424 | int snb = getMinIn();
|
---|
425 | int sne = getMaxIn();
|
---|
426 |
|
---|
427 | bool fgout = checkOutputTOIIndex(0);
|
---|
428 | bool fgincopie = checkOutputTOIIndex(1);
|
---|
429 |
|
---|
430 | if (!checkInputTOIIndex(0)) {
|
---|
431 | cerr << " SimpleFilter::run() - Input TOI (in) not connected! "
|
---|
432 | << endl;
|
---|
433 | throw ParmError("SimpleFilter::run() Input TOI (in) not connected!");
|
---|
434 | }
|
---|
435 | if (!fgout) {
|
---|
436 | cerr << " SimpleFilter::run() - No Output TOI connected! "
|
---|
437 | << endl;
|
---|
438 | throw ParmError("SimpleFilter::run() No output TOI connected!");
|
---|
439 | }
|
---|
440 |
|
---|
441 | cout << " SimpleFilter::run() SNRange=" << snb << " - " << sne << endl;
|
---|
442 |
|
---|
443 |
|
---|
444 | try {
|
---|
445 | Timer tm("SimpleFilter::run()");
|
---|
446 | // Le debut
|
---|
447 | int wsz2 = wsize/2;
|
---|
448 | Vector vin(wsize);
|
---|
449 | TVector<int_8> vfg(wsize);
|
---|
450 | int k;
|
---|
451 | for(k=0; k<wsize; k++)
|
---|
452 | getData(0, k+snb, vin(k%wsize), vfg(k%wsize));
|
---|
453 |
|
---|
454 | double mean = vin.Sum()/wsize;
|
---|
455 | for(k=wsz2+1; k<wsize; k++) {
|
---|
456 | vin(k) = mean;
|
---|
457 | vfg(k) = 0;
|
---|
458 | }
|
---|
459 | int knext;
|
---|
460 | bool fgfin = false;
|
---|
461 | // Boucle sur les sampleNum
|
---|
462 | for(k=0;k<=sne-snb;k++) {
|
---|
463 | double sortie = 0;
|
---|
464 | for(int ii=-wsz2; ii<=wsz2; ii++) {
|
---|
465 | sortie += vin((ii+k+wsize)%wsize)*coef[ii+wsz2];
|
---|
466 | }
|
---|
467 | putData(0,k+snb,sortie,vfg(k%wsize));
|
---|
468 | if (fgincopie)
|
---|
469 | putData(1, k+snb, vin(k%wsize), vfg(k%wsize));
|
---|
470 | knext = k+wsz2+1;
|
---|
471 | if (knext<=(sne-snb))
|
---|
472 | getData(0, knext+snb, vin(knext%wsize), vfg(knext%wsize));
|
---|
473 |
|
---|
474 | else {
|
---|
475 | if (!fgfin) {
|
---|
476 | mean = vin.Sum()/wsize;
|
---|
477 | fgfin = true;
|
---|
478 | }
|
---|
479 | vin(knext%wsize) = mean;
|
---|
480 | vfg(knext%wsize) = 0;
|
---|
481 | }
|
---|
482 | totnscount++;
|
---|
483 | } // Boucle sur les num-sample
|
---|
484 | cout << " SimpleFilter::run() - End of processing " << endl;
|
---|
485 | } // Bloc try
|
---|
486 |
|
---|
487 | catch (PException & exc) {
|
---|
488 | cerr << "SimpleFilter: Catched Exception " << (string)typeid(exc).name()
|
---|
489 | << "\n .... Msg= " << exc.Msg() << endl;
|
---|
490 | }
|
---|
491 | }
|
---|
492 |
|
---|
493 | // ---------------------------------------------------------------
|
---|
494 | // -------------------- Classe SimpleAdder -----------------------
|
---|
495 | // ---------------------------------------------------------------
|
---|
496 |
|
---|
497 | SimpleAdder::SimpleAdder(int nbinput)
|
---|
498 | : gains(nbinput)
|
---|
499 | {
|
---|
500 | if (nbinput < 1)
|
---|
501 | throw ParmError("SimpleAdder::SimpleAdder() NbInput < 1 !");
|
---|
502 | nb_input = nbinput;
|
---|
503 | for(int k=0; k<nb_input; k++) gains(k) = 1.;
|
---|
504 | totnscount = 0;
|
---|
505 | }
|
---|
506 |
|
---|
507 | SimpleAdder::~SimpleAdder()
|
---|
508 | {
|
---|
509 | }
|
---|
510 |
|
---|
511 | void SimpleAdder::SetGain(int num, double g)
|
---|
512 | {
|
---|
513 | if ((num < 0) || (num >= nb_input))
|
---|
514 | throw RangeCheckError("SimpleAdder::SetGain() Out of range input number!");
|
---|
515 | gains(num) = g;
|
---|
516 | return;
|
---|
517 | }
|
---|
518 |
|
---|
519 | double SimpleAdder::Gain(int num)
|
---|
520 | {
|
---|
521 | if ((num < 0) || (num >= nb_input))
|
---|
522 | throw RangeCheckError("SimpleAdder::Gain() Out of range input number!");
|
---|
523 | return gains(num);
|
---|
524 | }
|
---|
525 |
|
---|
526 | void SimpleAdder::PrintStatus(ostream & os)
|
---|
527 | {
|
---|
528 | os << "\n ------------------------------------------------------ \n"
|
---|
529 | << " SimpleAdder::PrintStatus() - NbInput=" << NbInput() << endl;
|
---|
530 | TOIProcessor::PrintStatus(os);
|
---|
531 | os << " Gains= " ;
|
---|
532 | for(int k=0; k<nb_input; k++) os << gains(k) << " " ;
|
---|
533 | os << endl;
|
---|
534 | os << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
|
---|
535 | os << " ------------------------------------------------------ " << endl;
|
---|
536 | }
|
---|
537 |
|
---|
538 | void SimpleAdder::init() {
|
---|
539 | cout << "SimpleAdder::init NbInput=" << nb_input << endl;
|
---|
540 | char buff[32];
|
---|
541 | for(int k=0; k<nb_input; k++) {
|
---|
542 | sprintf(buff,"in%d", k);
|
---|
543 | declareInput(buff);
|
---|
544 | }
|
---|
545 |
|
---|
546 | declareOutput("out");
|
---|
547 | name = "SimpleAdder";
|
---|
548 | // upExtra = 1;
|
---|
549 | }
|
---|
550 |
|
---|
551 | void SimpleAdder::run() {
|
---|
552 | // TOIManager* mgr = TOIManager::getManager();
|
---|
553 | int snb = getMinIn();
|
---|
554 | int sne = getMaxIn();
|
---|
555 |
|
---|
556 | bool fgout = checkOutputTOIIndex(0);
|
---|
557 | string msg_err;
|
---|
558 | for(int ki=0;ki<nb_input;ki++) {
|
---|
559 | if (!checkInputTOIIndex(ki)) {
|
---|
560 | msg_err = "SimpleAdder::run() - Input TOI (" + getInName(ki) +
|
---|
561 | " not connected!";
|
---|
562 | cerr << msg_err << endl;
|
---|
563 | throw ParmError(msg_err);
|
---|
564 | }
|
---|
565 | }
|
---|
566 | if (!fgout) {
|
---|
567 | cerr << " SimpleAdder::run() - No Output TOI connected! "
|
---|
568 | << endl;
|
---|
569 | throw ParmError("SimpleAdder::run() No output TOI connected!");
|
---|
570 | }
|
---|
571 |
|
---|
572 | cout << " SimpleAdder::run() SNRange=" << snb << " - " << sne << endl;
|
---|
573 |
|
---|
574 |
|
---|
575 | try {
|
---|
576 | Timer tm("SimpleAdder::run()");
|
---|
577 | int k,i;
|
---|
578 | double out = 0.;
|
---|
579 | double valin = 0.;
|
---|
580 | int_8 fgin = 0;
|
---|
581 | int_8 fgout = 0;
|
---|
582 | for(k=snb;k<=sne;k++) {
|
---|
583 | out = 0;
|
---|
584 | fgout = 0;
|
---|
585 | for(i=0; i<nb_input; i++) {
|
---|
586 | getData(i, k, valin, fgin);
|
---|
587 | out += gains(i)*valin;
|
---|
588 | fgout = fgout | fgin;
|
---|
589 | }
|
---|
590 | putData(0,k,out,fgout);
|
---|
591 | totnscount++;
|
---|
592 | } // Boucle sur les num-sample
|
---|
593 | cout << " SimpleAdder::run() - End of processing " << endl;
|
---|
594 | } // Bloc try
|
---|
595 |
|
---|
596 | catch (PException & exc) {
|
---|
597 | cerr << "SimpleAdder: Catched Exception " << (string)typeid(exc).name()
|
---|
598 | << "\n .... Msg= " << exc.Msg() << endl;
|
---|
599 | }
|
---|
600 | }
|
---|
601 |
|
---|
602 |
|
---|
603 | // ---------------------------------------------------------------
|
---|
604 | // -------------------- Classe SimpleFanOut -----------------------
|
---|
605 | // ---------------------------------------------------------------
|
---|
606 |
|
---|
607 | SimpleFanOut::SimpleFanOut(int nbinput, int mfanout)
|
---|
608 | {
|
---|
609 | if (nbinput < 1)
|
---|
610 | throw ParmError("SimpleFanOut::SimpleFanOut() NbInput < 1 !");
|
---|
611 | if (mfanout < 1)
|
---|
612 | throw ParmError("SimpleFanOut::SimpleFanOut() M_FanOut < 1 !");
|
---|
613 |
|
---|
614 | nb_input = nbinput;
|
---|
615 | m_fanout = mfanout;
|
---|
616 | totnscount = 0;
|
---|
617 | }
|
---|
618 |
|
---|
619 | SimpleFanOut::~SimpleFanOut()
|
---|
620 | {
|
---|
621 | }
|
---|
622 |
|
---|
623 |
|
---|
624 | void SimpleFanOut::PrintStatus(ostream & os)
|
---|
625 | {
|
---|
626 | os << "\n ------------------------------------------------------ \n"
|
---|
627 | << " SimpleFanOut::PrintStatus() - NbInput=" << NbInput()
|
---|
628 | << " M_FanOut=" << MFanOut() << endl;
|
---|
629 | TOIProcessor::PrintStatus(os);
|
---|
630 | os << endl;
|
---|
631 | os << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
|
---|
632 | os << " ------------------------------------------------------ " << endl;
|
---|
633 | }
|
---|
634 |
|
---|
635 | void SimpleFanOut::init() {
|
---|
636 | cout << "SimpleFanOut::init NbInput=" << nb_input << endl;
|
---|
637 | char buff[64];
|
---|
638 | for(int k=0; k<nb_input; k++) {
|
---|
639 | sprintf(buff,"in%d", k);
|
---|
640 | declareInput(buff);
|
---|
641 | for(int j=0; j<m_fanout; j++) {
|
---|
642 | sprintf(buff,"out%d_%d", k, j);
|
---|
643 | declareOutput(buff);
|
---|
644 | }
|
---|
645 | }
|
---|
646 |
|
---|
647 | name = "SimpleFanOut";
|
---|
648 | // upExtra = 1;
|
---|
649 | }
|
---|
650 |
|
---|
651 | void SimpleFanOut::run() {
|
---|
652 | // TOIManager* mgr = TOIManager::getManager();
|
---|
653 | int snb = getMinIn();
|
---|
654 | int sne = getMaxIn();
|
---|
655 |
|
---|
656 | TVector<int_4> in_index(nb_input);
|
---|
657 | TMatrix<int_4> out_index(nb_input, m_fanout);
|
---|
658 | in_index = -1;
|
---|
659 | out_index = -1;
|
---|
660 | int nbconin = 0;
|
---|
661 | bool fggin = false;
|
---|
662 | char buff[64];
|
---|
663 | for(int ki=0;ki<nb_input;ki++) {
|
---|
664 | sprintf(buff,"in%d", ki);
|
---|
665 | int idx = getInputTOIIndex(buff);
|
---|
666 | if (!checkInputTOIIndex(idx)) continue;
|
---|
667 | nbconin++;
|
---|
668 | in_index(ki) = idx;
|
---|
669 | bool fgout = false;
|
---|
670 | for(int jo=0; jo<m_fanout; jo++) {
|
---|
671 | sprintf(buff,"out%d_%d", ki, jo);
|
---|
672 | int odx = getOutputTOIIndex(buff);
|
---|
673 | if (checkOutputTOIIndex(odx)) {
|
---|
674 | out_index(ki, jo) = odx;
|
---|
675 | fgout = true;
|
---|
676 | }
|
---|
677 | }
|
---|
678 | if (!fgout) {
|
---|
679 | string msg_err =
|
---|
680 | "SimpleFanOut::run() - No connected Output for Input TOI ("
|
---|
681 | + getInName(ki) + ") !";
|
---|
682 | cerr << msg_err << endl;
|
---|
683 | throw ParmError(msg_err);
|
---|
684 | }
|
---|
685 | }
|
---|
686 | if (nbconin == 0) {
|
---|
687 | cerr << " SimpleFanOut::run() - No Input TOI connected! "
|
---|
688 | << endl;
|
---|
689 | throw ParmError("SimpleFanOut::run() No Inout TOI connected!");
|
---|
690 | }
|
---|
691 |
|
---|
692 | /*
|
---|
693 | for(int ki=0;ki<nb_input;ki++) {
|
---|
694 | cout << " SimpleFanOut::run() In(" << ki << ") Index=" << in_index(ki)
|
---|
695 | << " Name=" << getInName(in_index(ki)) << endl;
|
---|
696 | for(int jo=0; jo<m_fanout; jo++)
|
---|
697 | cout << " .... Out(" << ki << "," << jo << ") Index=" << out_index(ki, jo)
|
---|
698 | << " Name=" << getOutName(out_index(ki, jo)) << endl;
|
---|
699 | }
|
---|
700 | */
|
---|
701 | cout << " SimpleFanOut::run() SNRange=" << snb << " - " << sne << endl;
|
---|
702 |
|
---|
703 |
|
---|
704 | try {
|
---|
705 | Timer tm("SimpleFanOut::run()");
|
---|
706 | double valin = 0.;
|
---|
707 | int_8 fgin = 0;
|
---|
708 | for(int k=snb;k<=sne;k++) {
|
---|
709 | for(int i=0;i<nb_input;i++) {
|
---|
710 | if (in_index(i) < 0) continue;
|
---|
711 | valin = 0;
|
---|
712 | fgin = 0;
|
---|
713 | getData(in_index(i), k, valin, fgin);
|
---|
714 | for(int j=0; j<m_fanout; j++) {
|
---|
715 | if (out_index(i, j) < 0) continue;
|
---|
716 | putData(out_index(i, j), k, valin, fgin);
|
---|
717 | }
|
---|
718 | }
|
---|
719 | totnscount++;
|
---|
720 | } // Boucle sur les num-sample
|
---|
721 | cout << " SimpleFanOut::run() - End of processing "
|
---|
722 | << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
|
---|
723 | } // Bloc try
|
---|
724 |
|
---|
725 | catch (PException & exc) {
|
---|
726 | cerr << "SimpleFanOut: Catched Exception " << (string)typeid(exc).name()
|
---|
727 | << "\n .... Msg= " << exc.Msg() << endl;
|
---|
728 | }
|
---|
729 | }
|
---|
730 |
|
---|
731 |
|
---|
732 |
|
---|