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