[1738] | 1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
| 2 | // Eric Aubourg
|
---|
| 3 | // Christophe Magneville
|
---|
| 4 | // Reza Ansari
|
---|
[1999] | 5 | // $Id: simtoipr.cc,v 1.18 2002-05-13 15:50:50 ansari Exp $
|
---|
[1738] | 6 |
|
---|
[1764] | 7 | #include "config.h"
|
---|
| 8 |
|
---|
[1462] | 9 | #include "array.h"
|
---|
[1442] | 10 | #include "simtoipr.h"
|
---|
[1454] | 11 | #include <math.h>
|
---|
[1442] | 12 | #include "toimanager.h"
|
---|
| 13 | #include "pexceptions.h"
|
---|
| 14 | #include "ctimer.h"
|
---|
[1479] | 15 | #include "fftpserver.h"
|
---|
[1442] | 16 |
|
---|
[1999] | 17 | #include "flagtoidef.h"
|
---|
| 18 |
|
---|
[1479] | 19 | SimpleDeglitcher::SimpleDeglitcher(int wsz, double ns, int maxnpt, int minnpt)
|
---|
[1442] | 20 | {
|
---|
[1478] | 21 | SetWSize(wsz);
|
---|
[1479] | 22 | SetDetectionParam(ns, ns/2., maxnpt, minnpt);
|
---|
[1478] | 23 | SetRange(-9.e39, 9.e39);
|
---|
| 24 | RepBadSamples(true, true);
|
---|
[1442] | 25 |
|
---|
[1478] | 26 | totnscount = glnscount = glcount = out_range_nscount = 0;
|
---|
| 27 | deglitchdone = false;
|
---|
| 28 |
|
---|
[1442] | 29 | cout << "SimpleDeglitcher::SimpleDeglitcher() WSize= " << wsz
|
---|
| 30 | << " nSig=" << ns << " maxNPt=" << maxnpt << endl;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | SimpleDeglitcher::~SimpleDeglitcher()
|
---|
| 34 | {
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[1479] | 37 | void SimpleDeglitcher::SetDetectionParam(double ns, double ns2, int maxnpt,
|
---|
| 38 | int minnpt, int wszrec)
|
---|
[1478] | 39 | {
|
---|
| 40 | nsig = (ns > 0.01) ? ns : 1.;
|
---|
| 41 | nsig2 = (ns2 > 0.01) ? ns2 : nsig/2.;
|
---|
| 42 | maxpoints = ((maxnpt > 0) && (maxnpt <= wsize)) ? maxnpt : 5;
|
---|
[1479] | 43 | minpoints = ((minnpt > 0) && (minnpt <= maxpoints)) ? minnpt : maxpoints/2;
|
---|
[1478] | 44 | wrecsize = ((wszrec > 0) && (wszrec <= wsize)) ? wszrec : 2*maxpoints;
|
---|
| 45 | }
|
---|
[1454] | 46 |
|
---|
[1478] | 47 | inline char * _Bool2YesNo(bool fg)
|
---|
| 48 | {
|
---|
| 49 | if (fg) return "YES" ;
|
---|
| 50 | else return "NO" ;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[1762] | 53 | void SimpleDeglitcher::PrintStatus(::ostream & os)
|
---|
[1443] | 54 | {
|
---|
| 55 | os << "\n ------------------------------------------------------ \n"
|
---|
| 56 | << " SimpleDeglitcher::PrintStatus() - WindowSize=" << WSize()
|
---|
[1479] | 57 | << " MaxPoints=" << MaxPoints() << " MinPoints=" << MinPoints() << endl;
|
---|
| 58 | os << " NbSigmas=" << NbSigmas()
|
---|
| 59 | << " NbSigmas2=" << NbSigmas2() << " WRecSize= " << WRecSize()
|
---|
[1478] | 60 | << " Range_Min= " << range_min << " Range_Max= " << range_max << endl;
|
---|
| 61 | os << " RepOutOfRangeSamples: " << _Bool2YesNo(rec_out_range_samples)
|
---|
| 62 | << " RepGlitchSamples: " << _Bool2YesNo(rec_gl_samples)
|
---|
| 63 | << " UseWRec: " << _Bool2YesNo(rec_use_wrec) << endl;
|
---|
[1443] | 64 | TOIProcessor::PrintStatus(os);
|
---|
| 65 | if (deglitchdone) os << " Deglitching performed " << endl;
|
---|
| 66 | else os << " NO deglitching done " << endl;
|
---|
[1454] | 67 | double nst = (ProcessedSampleCount() > 0) ? ProcessedSampleCount() : 1.;
|
---|
| 68 | os << " ProcessedSampleCount=" << ProcessedSampleCount()
|
---|
| 69 | << " OutOfRangeSampleCount=" << OutOfRangeSampleCount() << endl;
|
---|
| 70 | os << " GlitchCount= " << GlitchCount()
|
---|
| 71 | << " GlitchSampleCount=" << GlitchSampleCount()
|
---|
[1443] | 72 | << "( " << (double)GlitchSampleCount()*100./nst << " % )" << endl;
|
---|
| 73 | os << " ------------------------------------------------------ " << endl;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[1442] | 76 | void SimpleDeglitcher::init() {
|
---|
| 77 | cout << "SimpleDeglitcher::init" << endl;
|
---|
| 78 | declareInput("in");
|
---|
| 79 | declareOutput("out");
|
---|
| 80 | declareOutput("mean");
|
---|
| 81 | declareOutput("sigma");
|
---|
[1443] | 82 | declareOutput("incopie");
|
---|
[1442] | 83 | name = "SimpleDeglitcher";
|
---|
| 84 | // upExtra = 1; A quoi ca sert ?
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[1478] | 87 |
|
---|
[1442] | 88 | void SimpleDeglitcher::run() {
|
---|
| 89 |
|
---|
| 90 | // TOIManager* mgr = TOIManager::getManager();
|
---|
| 91 | int snb = getMinIn();
|
---|
| 92 | int sne = getMaxIn();
|
---|
| 93 |
|
---|
| 94 | bool fgout = checkOutputTOIIndex(0);
|
---|
| 95 | bool fgmean = checkOutputTOIIndex(1);
|
---|
| 96 | bool fgsigma = checkOutputTOIIndex(2);
|
---|
[1443] | 97 | bool fgincopie = checkOutputTOIIndex(3);
|
---|
[1442] | 98 |
|
---|
| 99 | if (!checkInputTOIIndex(0)) {
|
---|
| 100 | cerr << " SimpleDeglitcher::run() - Input TOI (in) not connected! "
|
---|
| 101 | << endl;
|
---|
| 102 | throw ParmError("SimpleDeglitcher::run() Input TOI (in) not connected!");
|
---|
| 103 | }
|
---|
[1443] | 104 | if (!fgout && !fgmean && !fgsigma &&!fgincopie) {
|
---|
[1442] | 105 | cerr << " SimpleDeglitcher::run() - No Output TOI connected! "
|
---|
| 106 | << endl;
|
---|
| 107 | throw ParmError("SimpleDeglitcher::run() No output TOI connected!");
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | if (!fgout) {
|
---|
| 111 | cout << "Warning: SimpleDeglitcher::run() - No TOI connected to out \n"
|
---|
| 112 | << " No deglitching would be performed !" << endl;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[1443] | 115 | cout << " SimpleDeglitcher::run() SNRange=" << snb << " - " << sne << endl;
|
---|
[1442] | 116 | try {
|
---|
[1443] | 117 | Timer tm("SimpleDeglitcher::run()");
|
---|
[1442] | 118 | Vector vin(wsize);
|
---|
[1478] | 119 | Vector vas(wsize);
|
---|
[1467] | 120 |
|
---|
[1478] | 121 | int wrecsize = maxpoints*2;
|
---|
| 122 | Vector vrec(wrecsize);
|
---|
[1467] | 123 |
|
---|
[1532] | 124 | TVector<uint_8> vfg(wsize);
|
---|
[1467] | 125 | int wsz2 = wsize/2;
|
---|
| 126 | // Le debut
|
---|
[1442] | 127 | int k;
|
---|
[1467] | 128 | for(k=0; k<wsz2; k++)
|
---|
[1464] | 129 | getData(0, k+snb, vin(k), vfg(k));
|
---|
| 130 |
|
---|
[1479] | 131 | int nokdebut = 0;
|
---|
[1467] | 132 | double s = 0.;
|
---|
| 133 | double mean = 0.;
|
---|
| 134 | double s2 = 0.;
|
---|
| 135 | double sigma = 0.;
|
---|
| 136 | for(k=0; k<wsz2; k++) {
|
---|
| 137 | if ( vfg(k) != 0) continue;
|
---|
| 138 | if ( (vin(k) < range_min) || (vin(k) > range_max) ) continue;
|
---|
| 139 | s += vin(k);
|
---|
| 140 | s2 += vin(k)*vin(k);
|
---|
| 141 | nokdebut++;
|
---|
[1454] | 142 | }
|
---|
[1467] | 143 | if (nokdebut > 0) {
|
---|
| 144 | mean = s/nokdebut;
|
---|
| 145 | if (nokdebut > 1) sigma = sqrt(s2/nokdebut-mean*mean);
|
---|
| 146 | }
|
---|
| 147 | for(k=wsz2; k<wsize; k++) {
|
---|
| 148 | vin(k) = mean;
|
---|
| 149 | vfg(k) = 0;
|
---|
| 150 | }
|
---|
[1478] | 151 | for(k=0; k<wsize; k++) {
|
---|
| 152 | vas(k) = mean;
|
---|
| 153 | if ( vfg(k) != 0) continue;
|
---|
| 154 | if ( (vin(k) < range_min) || (vin(k) > range_max) ) continue;
|
---|
| 155 | vas(k) = vin(k);
|
---|
| 156 | }
|
---|
[1454] | 157 |
|
---|
[1478] | 158 | for(k=0; k<wrecsize; k++) {
|
---|
[1467] | 159 | if ( (vin(k) < range_min) || (vin(k) > range_max) ) vrec(k)=mean;
|
---|
| 160 | else vrec(k)=vin(k);
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | bool fgokdebut = false;
|
---|
| 164 |
|
---|
[1442] | 165 | int kgl = -1;
|
---|
| 166 | int ii,lastput;
|
---|
| 167 | bool fgglitch = false;
|
---|
| 168 | double valcur,valsub,valadd;
|
---|
[1467] | 169 | double lastvalok = mean;
|
---|
[1454] | 170 | uint_8 fgcur;
|
---|
[1467] | 171 | bool fgokcur=false;
|
---|
[1484] | 172 |
|
---|
| 173 | int sx_refresh_count = 0;
|
---|
| 174 | int sx_refresh_count_max = 16*wsize;
|
---|
| 175 |
|
---|
[1454] | 176 | // Boucle sur les sampleNum
|
---|
[1467] | 177 | int knext;
|
---|
| 178 | int kfin = sne-snb;
|
---|
| 179 | for(k=0;k<=kfin;k++) {
|
---|
[1442] | 180 | totnscount++;
|
---|
[1443] | 181 | // if (k%10000 == 0) cout << " DBG: K=" << k << endl;
|
---|
[1467] | 182 | knext = k+wsz2;
|
---|
[1442] | 183 | // Calcul mean-sigma
|
---|
[1467] | 184 | if (knext<=kfin) {
|
---|
[1478] | 185 | valsub = vas(knext%wsize);
|
---|
[1467] | 186 | getData(0, knext+snb, vin(knext%wsize), vfg(knext%wsize));
|
---|
| 187 | valadd = vin(knext%wsize);
|
---|
[1478] | 188 | if ( vfg(knext%wsize) ||
|
---|
| 189 | (valadd < range_min) || (valadd > range_max) ) {
|
---|
| 190 | vas(knext%wsize) = valadd = mean;
|
---|
[1467] | 191 | fgokcur = false;
|
---|
| 192 | }
|
---|
[1478] | 193 | else {
|
---|
| 194 | vas(knext%wsize) = valadd = vin(knext%wsize);
|
---|
| 195 | fgokcur = true;
|
---|
| 196 | }
|
---|
[1467] | 197 | if (!fgokdebut && fgokcur) {
|
---|
| 198 | s += valadd;
|
---|
| 199 | s2 += valadd*valadd;
|
---|
| 200 | nokdebut++;
|
---|
| 201 | mean = s/nokdebut;
|
---|
| 202 | if (nokdebut > 1) sigma = sqrt(s2/nokdebut-mean*mean);
|
---|
| 203 | if (nokdebut >= wsize) {
|
---|
| 204 | fgokdebut = true;
|
---|
| 205 | cout << " SimpleDeglitcher::DebugInfo - nokdebut=" << nokdebut
|
---|
| 206 | << " k=" << k << " knext=" << knext
|
---|
| 207 | << "\n ...DebugInfo mean=" << mean
|
---|
| 208 | << " sigma=" << sigma << " s=" << s << " s2=" << s2 << endl;
|
---|
| 209 | }
|
---|
| 210 | }
|
---|
| 211 | else {
|
---|
[1484] | 212 | if (sx_refresh_count >= sx_refresh_count_max) {
|
---|
| 213 | // On recalcule la somme
|
---|
| 214 | s = vas.Sum();
|
---|
| 215 | s2 = vas.SumX2();
|
---|
| 216 | sx_refresh_count = 0;
|
---|
| 217 | }
|
---|
| 218 | else {
|
---|
| 219 | s += (valadd-valsub);
|
---|
| 220 | s2 += (valadd*valadd-valsub*valsub);
|
---|
| 221 | sx_refresh_count++;
|
---|
| 222 | }
|
---|
[1467] | 223 | mean = s/wsize;
|
---|
| 224 | sigma = sqrt(s2/wsize-mean*mean);
|
---|
| 225 | }
|
---|
[1442] | 226 | }
|
---|
| 227 |
|
---|
[1467] | 228 |
|
---|
[1442] | 229 | // On gere les sorties Mean et Sigma
|
---|
| 230 | if (fgmean)
|
---|
| 231 | putData(1, k+snb, mean, 0);
|
---|
| 232 | if (fgsigma)
|
---|
| 233 | putData(2, k+snb, sigma, 0);
|
---|
[1454] | 234 | if (fgincopie)
|
---|
| 235 | putData(3, k+snb, vin(k%wsize), vfg(k%wsize));
|
---|
[1442] | 236 |
|
---|
[1478] | 237 | valcur = vin(k%wsize);
|
---|
[1454] | 238 | if ( (valcur < range_min) || (valcur > range_max) ) {
|
---|
[1478] | 239 | valcur = (rec_use_wrec) ? vrec.Sum()/wrecsize : mean;
|
---|
| 240 | if (rec_out_range_samples) vin(k%wsize) = valcur;
|
---|
[1999] | 241 | vfg(k%wsize) |= FlgToiOut;
|
---|
[1454] | 242 | out_range_nscount++;
|
---|
| 243 | }
|
---|
[1467] | 244 | valcur = vin(k%wsize);
|
---|
| 245 | fgcur = vfg(k%wsize);
|
---|
[1443] | 246 |
|
---|
[1442] | 247 | if (!fgout) continue; // Pas de sortie out (deglitche)
|
---|
| 248 |
|
---|
[1443] | 249 |
|
---|
| 250 | // if (k<100) {
|
---|
| 251 | // cout << "DBG-A-Deglitch[" << k << "] mean="
|
---|
| 252 | // << mean << " sigma=" << sigma << " valcur="
|
---|
| 253 | // << valcur << " Kgl=" << kgl ;
|
---|
| 254 | // if (fgglitch) cout << " In Glitch" ;
|
---|
| 255 | // cout << endl;
|
---|
| 256 | // }
|
---|
[1442] | 257 |
|
---|
[1478] | 258 | double curnsig = (fgglitch) ? nsig2 : nsig;
|
---|
[1467] | 259 |
|
---|
| 260 | if (valcur < mean+curnsig*sigma) { // inferieur au seuil
|
---|
[1442] | 261 | if (fgglitch) {
|
---|
[1479] | 262 | if ( (k-kgl <= maxpoints) && (k-kgl >= minpoints) ) {
|
---|
| 263 | // On vient de detecter un glitch
|
---|
[1442] | 264 | glcount++;
|
---|
[1478] | 265 | if (rec_gl_samples) { // On change la valeur des samples
|
---|
| 266 | double recval = (rec_use_wrec) ? vrec.Sum()/wrecsize : mean;
|
---|
| 267 | for(ii=kgl; ii<k; ii++) {
|
---|
[1999] | 268 | putData(0, ii+snb, recval, vfg(ii%wsize)|FlgToiSpike);
|
---|
[1478] | 269 | glnscount++;
|
---|
| 270 | }
|
---|
[1442] | 271 | }
|
---|
[1478] | 272 | else { // On ne fait que flagger les echantillons
|
---|
| 273 | for(ii=kgl; ii<k; ii++) {
|
---|
[1999] | 274 | putData(0, ii+snb, vin(ii%wsize), vfg(ii%wsize)|FlgToiSpike);
|
---|
[1478] | 275 | glnscount++;
|
---|
| 276 | }
|
---|
| 277 | }
|
---|
[1442] | 278 | lastput = snb+k-1;
|
---|
[1478] | 279 | } // - Fin de detection de glitch
|
---|
[1479] | 280 | else { // Trop long ou trop court - ce n'est pas un glitch ...
|
---|
[1442] | 281 | for(ii=kgl; ii<k; ii++) {
|
---|
[1999] | 282 | if (k-kgl > maxpoints) // Si trop long
|
---|
| 283 | putData(0, ii+snb, vin(ii%wsize), vfg(ii%wsize)|FlgToiSource);
|
---|
| 284 | else // Trop court
|
---|
| 285 | putData(0, ii+snb, vin(ii%wsize), vfg(ii%wsize));
|
---|
[1442] | 286 | }
|
---|
| 287 | lastput = snb+k-1;
|
---|
| 288 | }
|
---|
| 289 | }
|
---|
[1478] | 290 | putData(0, k+snb, vin(k%wsize), vfg(k%wsize));
|
---|
[1442] | 291 | lastput = snb+k;
|
---|
| 292 | kgl = -1; fgglitch = false;
|
---|
[1478] | 293 | vrec(k%wrecsize) = lastvalok = valcur;
|
---|
[1442] | 294 | }
|
---|
| 295 | else { // Superieur au seuil
|
---|
| 296 | if (fgglitch) {
|
---|
[1479] | 297 | if (k-kgl+1 > maxpoints) { // serie de points > seuil
|
---|
[1442] | 298 | for(ii=kgl; ii<=k; ii++) // -> Donc pas glitch
|
---|
[1454] | 299 | putData(0, ii+snb, vin(ii%wsize), vfg(ii%wsize));
|
---|
[1442] | 300 | lastput = snb+k;
|
---|
| 301 | fgglitch = false;
|
---|
[1478] | 302 | vrec(k%wrecsize) = lastvalok = valcur;
|
---|
[1442] | 303 | }
|
---|
| 304 | }
|
---|
| 305 | else {
|
---|
| 306 | if (kgl < 0) { // debut possible de glitch
|
---|
| 307 | fgglitch = true; kgl = k;
|
---|
| 308 | }
|
---|
| 309 | else { // On est toujours dans une serie > seuil
|
---|
[1478] | 310 | putData(0, k+snb, vin(k%wsize), vfg(k%wsize));
|
---|
| 311 | lastput = snb+k; lastvalok = valcur;
|
---|
[1442] | 312 | }
|
---|
[1478] | 313 | vrec(k%wrecsize) = lastvalok;
|
---|
[1442] | 314 | }
|
---|
| 315 | }
|
---|
| 316 |
|
---|
[1443] | 317 | // if (k%5000 == 0) cout << " ---DBG2: K=" << k << " glcount="
|
---|
| 318 | // << glcount << " LastPut= " << lastput << endl;
|
---|
| 319 | } // Fin de Boucle sur les num-sample
|
---|
| 320 |
|
---|
| 321 | //DBG cout << " La fin lastput=" << lastput << " SNE=" << sne;
|
---|
| 322 | //DBG for(k=lastput-snb+1; k<sne-snb; k++)
|
---|
| 323 | //DBG putData(0, k+snb, vin(k%wsize), 0);
|
---|
| 324 | // cout << " DBG3- OUT of try bloc ! " << endl;
|
---|
| 325 | cout << " SimpleDeglitcher::run() - End of processing "
|
---|
[1454] | 326 | << " ProcessedSampleCount=" << ProcessedSampleCount()
|
---|
[1443] | 327 | << " GlitchCount= " << GlitchCount() << endl;
|
---|
| 328 | if (fgout) deglitchdone = true;
|
---|
[1442] | 329 | } // Bloc try
|
---|
| 330 | catch (PException & exc) {
|
---|
| 331 | cerr << "SimpleDeglitcher: Catched Exception " << (string)typeid(exc).name()
|
---|
| 332 | << "\n .... Msg= " << exc.Msg() << endl;
|
---|
| 333 | }
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 |
|
---|
[1454] | 337 | // -------------------------------------------------------------------
|
---|
| 338 | // Classe SimpleFilter : Filtre simple ds le domaine temporel
|
---|
| 339 | // -------------------------------------------------------------------
|
---|
[1442] | 340 |
|
---|
[1454] | 341 | string SimpleFilter::FilterKind2String(FilterKind fk)
|
---|
| 342 | {
|
---|
| 343 | switch (fk) {
|
---|
| 344 | case UserFilter :
|
---|
| 345 | return ("UserFilter");
|
---|
| 346 | break;
|
---|
| 347 | case MeanFilter :
|
---|
| 348 | return ("MeanFilter");
|
---|
| 349 | break;
|
---|
| 350 | case SumFilter :
|
---|
| 351 | return ("SumFilter");
|
---|
| 352 | break;
|
---|
| 353 | case GaussFilter :
|
---|
| 354 | return ("GaussFilter");
|
---|
| 355 | break;
|
---|
| 356 | case DiffFilter :
|
---|
| 357 | return ("DiffFilter");
|
---|
| 358 | break;
|
---|
| 359 | default :
|
---|
| 360 | return ("ErrorFilterKind");
|
---|
| 361 | break;
|
---|
| 362 | }
|
---|
| 363 | return("");
|
---|
| 364 | }
|
---|
| 365 |
|
---|
[1442] | 366 | SimpleFilter::SimpleFilter(int wsz, FilterKind fk, double a, double s)
|
---|
| 367 | {
|
---|
| 368 | if (wsz < 3) wsz = 3;
|
---|
| 369 | if (wsz%2 == 0) wsz++;
|
---|
| 370 | cout << "SimpleFilter::SimpleFilter() wsz= " << wsz
|
---|
[1454] | 371 | << " FilterKind=" << FilterKind2String(fk) << endl;
|
---|
[1442] | 372 | wsize = wsz;
|
---|
| 373 | totnscount = 0;
|
---|
| 374 | coef = new double[wsz];
|
---|
[1467] | 375 | for(int k=0; k<wsz; k++) coef[k] = 0.;
|
---|
[1476] | 376 | int kk;
|
---|
[1454] | 377 | switch (fk) {
|
---|
| 378 | case UserFilter :
|
---|
| 379 | throw ParmError("SimpleFilter: Error in filter Kind (UserFilter)!");
|
---|
[1467] | 380 | // break;
|
---|
[1454] | 381 | case MeanFilter :
|
---|
[1476] | 382 | for(kk=0; kk<wsz; kk++)
|
---|
[1454] | 383 | coef[kk] = a/wsize;
|
---|
| 384 | break;
|
---|
| 385 | case SumFilter :
|
---|
[1476] | 386 | for(kk=0; kk<wsz; kk++)
|
---|
[1454] | 387 | coef[kk] = a;
|
---|
| 388 | break;
|
---|
| 389 | case GaussFilter :
|
---|
[1476] | 390 | for(kk=-(wsz/2); kk<=(wsz/2); kk++)
|
---|
[1531] | 391 | coef[kk+(wsz/2)] = a*exp(-(double)(kk*kk)/(2*s*s));
|
---|
[1454] | 392 | break;
|
---|
| 393 | case DiffFilter :
|
---|
[1476] | 394 | for(kk=0; kk<wsz; kk++)
|
---|
[1454] | 395 | coef[kk] = -a/wsize;
|
---|
| 396 | coef[wsz/2+1] += 1.;
|
---|
| 397 | break;
|
---|
| 398 | default :
|
---|
| 399 | throw ParmError("SimpleFilter: Error in filter Kind (UnknownFilter)!");
|
---|
[1467] | 400 | // break;
|
---|
[1454] | 401 | }
|
---|
[1442] | 402 | }
|
---|
| 403 |
|
---|
[1454] | 404 | SimpleFilter::SimpleFilter(Vector const & vc)
|
---|
| 405 | {
|
---|
| 406 | int wsz = vc.Size();
|
---|
| 407 | if (wsz < 3) wsz = 3;
|
---|
| 408 | if (wsz%2 == 0) wsz++;
|
---|
| 409 | FilterKind fk = UserFilter;
|
---|
| 410 | cout << "SimpleFilter::SimpleFilter(Vector & vc) vc.Size()= "
|
---|
| 411 | << vc.Size() << " WSize=" << wsz
|
---|
| 412 | << " FilterKind=" << FilterKind2String(fk) << endl;
|
---|
| 413 | wsize = wsz;
|
---|
| 414 | totnscount = 0;
|
---|
| 415 | coef = new double[wsz];
|
---|
[1476] | 416 | int kk;
|
---|
| 417 | for(kk=0; kk<vc.Size(); kk++)
|
---|
[1454] | 418 | coef[kk] = vc(kk);
|
---|
[1476] | 419 | for(kk=vc.Size(); kk<wsz; kk++)
|
---|
[1454] | 420 | coef[kk] = 0.;
|
---|
| 421 | }
|
---|
| 422 |
|
---|
[1442] | 423 | SimpleFilter::~SimpleFilter()
|
---|
| 424 | {
|
---|
| 425 | delete[] coef;
|
---|
| 426 | }
|
---|
| 427 |
|
---|
[1762] | 428 | void SimpleFilter::PrintStatus(::ostream & os)
|
---|
[1443] | 429 | {
|
---|
| 430 | os << "\n ------------------------------------------------------ \n"
|
---|
| 431 | << " SimpleFilter::PrintStatus() - WindowSize=" << WSize()
|
---|
| 432 | << " FilterKind= " << Type() << endl;
|
---|
| 433 | TOIProcessor::PrintStatus(os);
|
---|
| 434 | os << " Coeff= " ;
|
---|
| 435 | for(int k=0; k<wsize; k++) os << coef[k] << " " ;
|
---|
| 436 | os << endl;
|
---|
[1454] | 437 | os << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
|
---|
[1443] | 438 | os << " ------------------------------------------------------ " << endl;
|
---|
| 439 | }
|
---|
| 440 |
|
---|
[1442] | 441 | void SimpleFilter::init() {
|
---|
| 442 | cout << "SimpleFilter::init" << endl;
|
---|
| 443 | declareInput("in");
|
---|
| 444 | declareOutput("out");
|
---|
[1443] | 445 | declareOutput("incopie");
|
---|
[1442] | 446 | name = "SimpleFilter";
|
---|
| 447 | // upExtra = 1;
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 | void SimpleFilter::run() {
|
---|
| 451 | // TOIManager* mgr = TOIManager::getManager();
|
---|
| 452 | int snb = getMinIn();
|
---|
| 453 | int sne = getMaxIn();
|
---|
| 454 |
|
---|
| 455 | bool fgout = checkOutputTOIIndex(0);
|
---|
[1443] | 456 | bool fgincopie = checkOutputTOIIndex(1);
|
---|
[1442] | 457 |
|
---|
| 458 | if (!checkInputTOIIndex(0)) {
|
---|
| 459 | cerr << " SimpleFilter::run() - Input TOI (in) not connected! "
|
---|
| 460 | << endl;
|
---|
| 461 | throw ParmError("SimpleFilter::run() Input TOI (in) not connected!");
|
---|
| 462 | }
|
---|
| 463 | if (!fgout) {
|
---|
| 464 | cerr << " SimpleFilter::run() - No Output TOI connected! "
|
---|
| 465 | << endl;
|
---|
| 466 | throw ParmError("SimpleFilter::run() No output TOI connected!");
|
---|
| 467 | }
|
---|
[1443] | 468 |
|
---|
| 469 | cout << " SimpleFilter::run() SNRange=" << snb << " - " << sne << endl;
|
---|
[1442] | 470 |
|
---|
| 471 |
|
---|
| 472 | try {
|
---|
[1443] | 473 | Timer tm("SimpleFilter::run()");
|
---|
[1442] | 474 | // Le debut
|
---|
| 475 | int wsz2 = wsize/2;
|
---|
| 476 | Vector vin(wsize);
|
---|
[1532] | 477 | TVector<uint_8> vfg(wsize);
|
---|
[1442] | 478 | int k;
|
---|
[1464] | 479 | for(k=0; k<wsize; k++)
|
---|
| 480 | getData(0, k+snb, vin(k%wsize), vfg(k%wsize));
|
---|
| 481 |
|
---|
[1442] | 482 | double mean = vin.Sum()/wsize;
|
---|
[1454] | 483 | for(k=wsz2+1; k<wsize; k++) {
|
---|
| 484 | vin(k) = mean;
|
---|
| 485 | vfg(k) = 0;
|
---|
| 486 | }
|
---|
| 487 | int knext;
|
---|
| 488 | bool fgfin = false;
|
---|
| 489 | // Boucle sur les sampleNum
|
---|
[1443] | 490 | for(k=0;k<=sne-snb;k++) {
|
---|
[1442] | 491 | double sortie = 0;
|
---|
[1467] | 492 | for(int ii=-wsz2; ii<=wsz2; ii++) {
|
---|
| 493 | sortie += vin((ii+k+wsize)%wsize)*coef[ii+wsz2];
|
---|
[1442] | 494 | }
|
---|
[1454] | 495 | putData(0,k+snb,sortie,vfg(k%wsize));
|
---|
| 496 | if (fgincopie)
|
---|
| 497 | putData(1, k+snb, vin(k%wsize), vfg(k%wsize));
|
---|
| 498 | knext = k+wsz2+1;
|
---|
[1464] | 499 | if (knext<=(sne-snb))
|
---|
| 500 | getData(0, knext+snb, vin(knext%wsize), vfg(knext%wsize));
|
---|
| 501 |
|
---|
[1454] | 502 | else {
|
---|
| 503 | if (!fgfin) {
|
---|
| 504 | mean = vin.Sum()/wsize;
|
---|
| 505 | fgfin = true;
|
---|
| 506 | }
|
---|
| 507 | vin(knext%wsize) = mean;
|
---|
| 508 | vfg(knext%wsize) = 0;
|
---|
| 509 | }
|
---|
| 510 | totnscount++;
|
---|
[1442] | 511 | } // Boucle sur les num-sample
|
---|
[1443] | 512 | cout << " SimpleFilter::run() - End of processing " << endl;
|
---|
[1442] | 513 | } // Bloc try
|
---|
| 514 |
|
---|
| 515 | catch (PException & exc) {
|
---|
| 516 | cerr << "SimpleFilter: Catched Exception " << (string)typeid(exc).name()
|
---|
| 517 | << "\n .... Msg= " << exc.Msg() << endl;
|
---|
| 518 | }
|
---|
[1454] | 519 | }
|
---|
[1442] | 520 |
|
---|
[1454] | 521 | // ---------------------------------------------------------------
|
---|
| 522 | // -------------------- Classe SimpleAdder -----------------------
|
---|
| 523 | // ---------------------------------------------------------------
|
---|
[1442] | 524 |
|
---|
[1454] | 525 | SimpleAdder::SimpleAdder(int nbinput)
|
---|
| 526 | : gains(nbinput)
|
---|
| 527 | {
|
---|
| 528 | if (nbinput < 1)
|
---|
| 529 | throw ParmError("SimpleAdder::SimpleAdder() NbInput < 1 !");
|
---|
| 530 | nb_input = nbinput;
|
---|
| 531 | for(int k=0; k<nb_input; k++) gains(k) = 1.;
|
---|
| 532 | totnscount = 0;
|
---|
[1442] | 533 | }
|
---|
[1454] | 534 |
|
---|
| 535 | SimpleAdder::~SimpleAdder()
|
---|
| 536 | {
|
---|
| 537 | }
|
---|
| 538 |
|
---|
| 539 | void SimpleAdder::SetGain(int num, double g)
|
---|
| 540 | {
|
---|
| 541 | if ((num < 0) || (num >= nb_input))
|
---|
| 542 | throw RangeCheckError("SimpleAdder::SetGain() Out of range input number!");
|
---|
| 543 | gains(num) = g;
|
---|
| 544 | return;
|
---|
| 545 | }
|
---|
| 546 |
|
---|
| 547 | double SimpleAdder::Gain(int num)
|
---|
| 548 | {
|
---|
| 549 | if ((num < 0) || (num >= nb_input))
|
---|
| 550 | throw RangeCheckError("SimpleAdder::Gain() Out of range input number!");
|
---|
| 551 | return gains(num);
|
---|
| 552 | }
|
---|
| 553 |
|
---|
[1762] | 554 | void SimpleAdder::PrintStatus(::ostream & os)
|
---|
[1454] | 555 | {
|
---|
| 556 | os << "\n ------------------------------------------------------ \n"
|
---|
| 557 | << " SimpleAdder::PrintStatus() - NbInput=" << NbInput() << endl;
|
---|
| 558 | TOIProcessor::PrintStatus(os);
|
---|
| 559 | os << " Gains= " ;
|
---|
| 560 | for(int k=0; k<nb_input; k++) os << gains(k) << " " ;
|
---|
| 561 | os << endl;
|
---|
| 562 | os << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
|
---|
| 563 | os << " ------------------------------------------------------ " << endl;
|
---|
| 564 | }
|
---|
| 565 |
|
---|
| 566 | void SimpleAdder::init() {
|
---|
| 567 | cout << "SimpleAdder::init NbInput=" << nb_input << endl;
|
---|
| 568 | char buff[32];
|
---|
| 569 | for(int k=0; k<nb_input; k++) {
|
---|
| 570 | sprintf(buff,"in%d", k);
|
---|
| 571 | declareInput(buff);
|
---|
| 572 | }
|
---|
| 573 |
|
---|
| 574 | declareOutput("out");
|
---|
| 575 | name = "SimpleAdder";
|
---|
| 576 | // upExtra = 1;
|
---|
| 577 | }
|
---|
| 578 |
|
---|
| 579 | void SimpleAdder::run() {
|
---|
| 580 | // TOIManager* mgr = TOIManager::getManager();
|
---|
| 581 | int snb = getMinIn();
|
---|
| 582 | int sne = getMaxIn();
|
---|
| 583 |
|
---|
| 584 | bool fgout = checkOutputTOIIndex(0);
|
---|
| 585 | string msg_err;
|
---|
| 586 | for(int ki=0;ki<nb_input;ki++) {
|
---|
| 587 | if (!checkInputTOIIndex(ki)) {
|
---|
| 588 | msg_err = "SimpleAdder::run() - Input TOI (" + getInName(ki) +
|
---|
| 589 | " not connected!";
|
---|
| 590 | cerr << msg_err << endl;
|
---|
| 591 | throw ParmError(msg_err);
|
---|
| 592 | }
|
---|
| 593 | }
|
---|
| 594 | if (!fgout) {
|
---|
| 595 | cerr << " SimpleAdder::run() - No Output TOI connected! "
|
---|
| 596 | << endl;
|
---|
| 597 | throw ParmError("SimpleAdder::run() No output TOI connected!");
|
---|
| 598 | }
|
---|
| 599 |
|
---|
| 600 | cout << " SimpleAdder::run() SNRange=" << snb << " - " << sne << endl;
|
---|
| 601 |
|
---|
| 602 |
|
---|
| 603 | try {
|
---|
| 604 | Timer tm("SimpleAdder::run()");
|
---|
| 605 | int k,i;
|
---|
| 606 | double out = 0.;
|
---|
[1464] | 607 | double valin = 0.;
|
---|
[1532] | 608 | uint_8 fgin = 0;
|
---|
| 609 | uint_8 fgout = 0;
|
---|
[1454] | 610 | for(k=snb;k<=sne;k++) {
|
---|
| 611 | out = 0;
|
---|
| 612 | fgout = 0;
|
---|
| 613 | for(i=0; i<nb_input; i++) {
|
---|
[1464] | 614 | getData(i, k, valin, fgin);
|
---|
| 615 | out += gains(i)*valin;
|
---|
| 616 | fgout = fgout | fgin;
|
---|
[1454] | 617 | }
|
---|
| 618 | putData(0,k,out,fgout);
|
---|
| 619 | totnscount++;
|
---|
| 620 | } // Boucle sur les num-sample
|
---|
| 621 | cout << " SimpleAdder::run() - End of processing " << endl;
|
---|
| 622 | } // Bloc try
|
---|
| 623 |
|
---|
| 624 | catch (PException & exc) {
|
---|
| 625 | cerr << "SimpleAdder: Catched Exception " << (string)typeid(exc).name()
|
---|
| 626 | << "\n .... Msg= " << exc.Msg() << endl;
|
---|
| 627 | }
|
---|
| 628 | }
|
---|
| 629 |
|
---|
[1479] | 630 | // ----------------------------------------------------------------------
|
---|
| 631 | // Classe SimpleFourierFilter : Filtre simple ds le domaine de Fourier
|
---|
| 632 | // ----------------------------------------------------------------------
|
---|
[1454] | 633 |
|
---|
[1479] | 634 | SimpleFourierFilter::SimpleFourierFilter(Vector const & vc)
|
---|
| 635 | {
|
---|
| 636 | ffcoef = vc;
|
---|
| 637 | wsize = (ffcoef.Size()-1)*2;
|
---|
| 638 | if (wsize < 16)
|
---|
| 639 | throw ParmError("SimpleFourierFilter::SimpleFourierFilter() WSize<16 !");
|
---|
[1483] | 640 | KeepSpectra("spectra.ppf", 0);
|
---|
[1484] | 641 | ComputeMeanSpectra(false);
|
---|
| 642 | totnscount = 0;
|
---|
| 643 | totnbblock = 0;
|
---|
[1479] | 644 | }
|
---|
| 645 |
|
---|
| 646 | SimpleFourierFilter::~SimpleFourierFilter()
|
---|
| 647 | {
|
---|
| 648 | }
|
---|
| 649 |
|
---|
| 650 |
|
---|
[1762] | 651 | void SimpleFourierFilter::PrintStatus(::ostream & os)
|
---|
[1479] | 652 | {
|
---|
| 653 | os << "\n ------------------------------------------------------ \n"
|
---|
| 654 | << " SimpleFourierFilter::PrintStatus() - WindowSize="
|
---|
| 655 | << WSize() << endl;
|
---|
| 656 | TOIProcessor::PrintStatus(os);
|
---|
[1484] | 657 | os << " Coeff (Size= " << ffcoef.Size() << "): " << endl;
|
---|
| 658 | for(int i=0; i<16; i++) {
|
---|
| 659 | os << ffcoef(i) << " " ;
|
---|
| 660 | if (i == 7) os << endl;
|
---|
| 661 | }
|
---|
| 662 | os << " .... " << endl;
|
---|
| 663 | os << " ProcessedSampleCount=" << ProcessedSampleCount()
|
---|
| 664 | << " NbFFTBlocks= " << totnbblock << endl;
|
---|
[1479] | 665 | os << " ------------------------------------------------------ " << endl;
|
---|
| 666 | }
|
---|
| 667 |
|
---|
| 668 | void SimpleFourierFilter::init() {
|
---|
| 669 | cout << "SimpleFourierFFilter::init" << endl;
|
---|
| 670 | declareInput("in");
|
---|
| 671 | declareOutput("out");
|
---|
| 672 | declareOutput("incopie");
|
---|
| 673 | name = "SimpleFourierFilter";
|
---|
| 674 | // upExtra = 1;
|
---|
| 675 | }
|
---|
| 676 |
|
---|
| 677 |
|
---|
| 678 | void SimpleFourierFilter::run() {
|
---|
| 679 | // TOIManager* mgr = TOIManager::getManager();
|
---|
| 680 | int snb = getMinIn();
|
---|
| 681 | int sne = getMaxIn();
|
---|
| 682 |
|
---|
| 683 | bool fgout = checkOutputTOIIndex(0);
|
---|
| 684 | bool fgincopie = checkOutputTOIIndex(1);
|
---|
| 685 |
|
---|
| 686 | if (!checkInputTOIIndex(0)) {
|
---|
| 687 | cerr << " SimpleFourierFilter::run() - Input TOI (in) not connected! "
|
---|
| 688 | << endl;
|
---|
| 689 | throw ParmError("SimpleFourierFilter::run() Input TOI (in) not connected!");
|
---|
| 690 | }
|
---|
| 691 |
|
---|
[1484] | 692 | // ---- On peut utiliser cette classe pour calculer un spectre de Fourier ----
|
---|
| 693 | // if (!fgout) {
|
---|
| 694 | // cerr << " SimpleFourierFilter::run() - No Output TOI connected! "
|
---|
| 695 | // << endl;
|
---|
| 696 | // throw ParmError("SimpleFourierFilter::run() No output TOI connected!");
|
---|
| 697 | // }
|
---|
| 698 |
|
---|
[1479] | 699 | cout << " SimpleFourierFilter::run() SNRange=" << snb << " - " << sne << endl;
|
---|
| 700 |
|
---|
| 701 |
|
---|
| 702 | try {
|
---|
| 703 | Timer tm("SimpleFourierFilter::run()");
|
---|
| 704 | // Le debut
|
---|
| 705 | Vector vin(wsize);
|
---|
| 706 | Vector vout(wsize);
|
---|
[1532] | 707 | TVector<uint_8> vfg(wsize);
|
---|
[1483] | 708 | TVector< complex<r_8> > vfft, vfftmean;
|
---|
[1484] | 709 | Vector meanpowerspectra;
|
---|
[1479] | 710 | TVector< complex<r_8> > zcoef(ffcoef.Size());
|
---|
| 711 | zcoef = ffcoef;
|
---|
| 712 |
|
---|
| 713 |
|
---|
| 714 | FFTPackServer ffts;
|
---|
| 715 | ffts.setNormalize(true);
|
---|
| 716 |
|
---|
[1483] | 717 | POutPersist pout(outppfname);
|
---|
| 718 |
|
---|
[1479] | 719 | int k,i,klast;
|
---|
| 720 | int nks = 0;
|
---|
| 721 | klast = snb-1;
|
---|
[1484] | 722 | totnbblock = 0;
|
---|
[1483] | 723 | // Boucle sur les sampleNum
|
---|
[1479] | 724 | // 1er partie, on traite par paquets de wsize
|
---|
| 725 | for(k=snb;k<=sne-wsize+1;k+=wsize) {
|
---|
| 726 | for(i=0; i<wsize; i++)
|
---|
| 727 | getData(0, k+i, vin(i), vfg(i));
|
---|
| 728 | ffts.FFTForward(vin, vfft);
|
---|
[1484] | 729 | if (c_meanspectra) { // Compute mean-spectra
|
---|
| 730 | if (totnbblock == 0) {
|
---|
| 731 | vfftmean = vfft;
|
---|
| 732 | meanpowerspectra.ReSize(vfft.Size());
|
---|
| 733 | for(i=0; i<meanpowerspectra.Size(); i++)
|
---|
| 734 | meanpowerspectra(i) = sqrt(vfft(i).real()*vfft(i).real() +
|
---|
| 735 | vfft(i).imag()*vfft(i).imag() );
|
---|
| 736 | }
|
---|
| 737 | else {
|
---|
| 738 | vfftmean += vfft;
|
---|
| 739 | for(i=0; i<meanpowerspectra.Size(); i++)
|
---|
| 740 | meanpowerspectra(i) += sqrt(vfft(i).real()*vfft(i).real() +
|
---|
| 741 | vfft(i).imag()*vfft(i).imag() );
|
---|
| 742 | }
|
---|
| 743 | }
|
---|
| 744 | totnbblock++;
|
---|
[1479] | 745 | if (nks < nb_keep) {
|
---|
[1483] | 746 | TVector< complex<r_8> > vfftcopie;
|
---|
| 747 | vfftcopie = vfft;
|
---|
[1484] | 748 | string nomvfft = "spectra" + (string)MuTyV(nks);
|
---|
[1483] | 749 | pout.PutObject(vfftcopie, nomvfft);
|
---|
[1479] | 750 | nks++;
|
---|
| 751 | }
|
---|
[1484] | 752 | if (fgout) {
|
---|
| 753 | vfft.MulElt(zcoef);
|
---|
| 754 | ffts.FFTBackward(vfft, vout);
|
---|
| 755 | }
|
---|
| 756 | for(i=0; i<wsize; i++) {
|
---|
| 757 | if (fgout)
|
---|
| 758 | putData(0,k+i,vout(i),vfg(i));
|
---|
| 759 | if (fgincopie)
|
---|
[1479] | 760 | putData(1, k+i, vin(i), vfg(i));
|
---|
[1484] | 761 | }
|
---|
[1479] | 762 | klast+=wsize;
|
---|
| 763 | totnscount+=wsize;
|
---|
| 764 | }
|
---|
| 765 |
|
---|
| 766 |
|
---|
| 767 | // 2eme partie, on traite la fin du bloc d'echantillons si necessaire
|
---|
| 768 | double inval;
|
---|
[1532] | 769 | uint_8 inflg;
|
---|
[1479] | 770 | if (klast < sne)
|
---|
| 771 | for(k=klast+1; k<=sne; k++) {
|
---|
| 772 | getData(0, k, inval, inflg);
|
---|
[1484] | 773 | if (fgout) putData(0, k, inval, inflg);
|
---|
[1479] | 774 | if (fgincopie)
|
---|
| 775 | putData(1, k, inval, inflg);
|
---|
| 776 | totnscount++;
|
---|
| 777 | }
|
---|
[1483] | 778 |
|
---|
[1484] | 779 | if (c_meanspectra) {
|
---|
| 780 | vfftmean /= complex<r_8>((r_8)totnbblock, 0.);
|
---|
| 781 | pout.PutObject(vfftmean, "meanspectra");
|
---|
| 782 | meanpowerspectra /= (r_8)totnbblock;
|
---|
| 783 | pout.PutObject(vfftmean, "meanpowerspectra");
|
---|
| 784 | }
|
---|
| 785 | pout.PutObject(ffcoef, "fourierfilter");
|
---|
[1483] | 786 |
|
---|
[1484] | 787 | cout << " SimpleFourierFilter::run() - End of processing "
|
---|
| 788 | << " NbFFTBlocks= " << totnbblock << endl;
|
---|
[1479] | 789 | } // Bloc try
|
---|
| 790 |
|
---|
| 791 | catch (PException & exc) {
|
---|
| 792 | cerr << "SimpleFourierFilter: Catched Exception " << (string)typeid(exc).name()
|
---|
| 793 | << "\n .... Msg= " << exc.Msg() << endl;
|
---|
| 794 | }
|
---|
| 795 | }
|
---|
| 796 |
|
---|
[1467] | 797 | // ---------------------------------------------------------------
|
---|
| 798 | // -------------------- Classe SimpleFanOut -----------------------
|
---|
| 799 | // ---------------------------------------------------------------
|
---|
[1454] | 800 |
|
---|
[1467] | 801 | SimpleFanOut::SimpleFanOut(int nbinput, int mfanout)
|
---|
| 802 | {
|
---|
| 803 | if (nbinput < 1)
|
---|
| 804 | throw ParmError("SimpleFanOut::SimpleFanOut() NbInput < 1 !");
|
---|
| 805 | if (mfanout < 1)
|
---|
| 806 | throw ParmError("SimpleFanOut::SimpleFanOut() M_FanOut < 1 !");
|
---|
| 807 |
|
---|
| 808 | nb_input = nbinput;
|
---|
| 809 | m_fanout = mfanout;
|
---|
| 810 | totnscount = 0;
|
---|
| 811 | }
|
---|
| 812 |
|
---|
| 813 | SimpleFanOut::~SimpleFanOut()
|
---|
| 814 | {
|
---|
| 815 | }
|
---|
| 816 |
|
---|
| 817 |
|
---|
[1762] | 818 | void SimpleFanOut::PrintStatus(::ostream & os)
|
---|
[1467] | 819 | {
|
---|
| 820 | os << "\n ------------------------------------------------------ \n"
|
---|
| 821 | << " SimpleFanOut::PrintStatus() - NbInput=" << NbInput()
|
---|
| 822 | << " M_FanOut=" << MFanOut() << endl;
|
---|
| 823 | TOIProcessor::PrintStatus(os);
|
---|
| 824 | os << endl;
|
---|
| 825 | os << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
|
---|
| 826 | os << " ------------------------------------------------------ " << endl;
|
---|
| 827 | }
|
---|
| 828 |
|
---|
| 829 | void SimpleFanOut::init() {
|
---|
| 830 | cout << "SimpleFanOut::init NbInput=" << nb_input << endl;
|
---|
| 831 | char buff[64];
|
---|
| 832 | for(int k=0; k<nb_input; k++) {
|
---|
| 833 | sprintf(buff,"in%d", k);
|
---|
| 834 | declareInput(buff);
|
---|
| 835 | for(int j=0; j<m_fanout; j++) {
|
---|
| 836 | sprintf(buff,"out%d_%d", k, j);
|
---|
| 837 | declareOutput(buff);
|
---|
| 838 | }
|
---|
| 839 | }
|
---|
| 840 |
|
---|
| 841 | name = "SimpleFanOut";
|
---|
| 842 | // upExtra = 1;
|
---|
| 843 | }
|
---|
| 844 |
|
---|
| 845 | void SimpleFanOut::run() {
|
---|
| 846 | // TOIManager* mgr = TOIManager::getManager();
|
---|
| 847 | int snb = getMinIn();
|
---|
| 848 | int sne = getMaxIn();
|
---|
| 849 |
|
---|
| 850 | TVector<int_4> in_index(nb_input);
|
---|
| 851 | TMatrix<int_4> out_index(nb_input, m_fanout);
|
---|
| 852 | in_index = -1;
|
---|
| 853 | out_index = -1;
|
---|
| 854 | int nbconin = 0;
|
---|
| 855 | char buff[64];
|
---|
| 856 | for(int ki=0;ki<nb_input;ki++) {
|
---|
| 857 | sprintf(buff,"in%d", ki);
|
---|
| 858 | int idx = getInputTOIIndex(buff);
|
---|
| 859 | if (!checkInputTOIIndex(idx)) continue;
|
---|
| 860 | nbconin++;
|
---|
| 861 | in_index(ki) = idx;
|
---|
| 862 | bool fgout = false;
|
---|
| 863 | for(int jo=0; jo<m_fanout; jo++) {
|
---|
| 864 | sprintf(buff,"out%d_%d", ki, jo);
|
---|
| 865 | int odx = getOutputTOIIndex(buff);
|
---|
| 866 | if (checkOutputTOIIndex(odx)) {
|
---|
| 867 | out_index(ki, jo) = odx;
|
---|
| 868 | fgout = true;
|
---|
| 869 | }
|
---|
| 870 | }
|
---|
| 871 | if (!fgout) {
|
---|
| 872 | string msg_err =
|
---|
| 873 | "SimpleFanOut::run() - No connected Output for Input TOI ("
|
---|
| 874 | + getInName(ki) + ") !";
|
---|
| 875 | cerr << msg_err << endl;
|
---|
| 876 | throw ParmError(msg_err);
|
---|
| 877 | }
|
---|
| 878 | }
|
---|
| 879 | if (nbconin == 0) {
|
---|
| 880 | cerr << " SimpleFanOut::run() - No Input TOI connected! "
|
---|
| 881 | << endl;
|
---|
| 882 | throw ParmError("SimpleFanOut::run() No Inout TOI connected!");
|
---|
| 883 | }
|
---|
| 884 |
|
---|
| 885 | /*
|
---|
| 886 | for(int ki=0;ki<nb_input;ki++) {
|
---|
| 887 | cout << " SimpleFanOut::run() In(" << ki << ") Index=" << in_index(ki)
|
---|
| 888 | << " Name=" << getInName(in_index(ki)) << endl;
|
---|
| 889 | for(int jo=0; jo<m_fanout; jo++)
|
---|
| 890 | cout << " .... Out(" << ki << "," << jo << ") Index=" << out_index(ki, jo)
|
---|
| 891 | << " Name=" << getOutName(out_index(ki, jo)) << endl;
|
---|
| 892 | }
|
---|
| 893 | */
|
---|
| 894 | cout << " SimpleFanOut::run() SNRange=" << snb << " - " << sne << endl;
|
---|
| 895 |
|
---|
| 896 |
|
---|
| 897 | try {
|
---|
| 898 | Timer tm("SimpleFanOut::run()");
|
---|
| 899 | double valin = 0.;
|
---|
[1532] | 900 | uint_8 fgin = 0;
|
---|
[1467] | 901 | for(int k=snb;k<=sne;k++) {
|
---|
| 902 | for(int i=0;i<nb_input;i++) {
|
---|
| 903 | if (in_index(i) < 0) continue;
|
---|
| 904 | valin = 0;
|
---|
| 905 | fgin = 0;
|
---|
| 906 | getData(in_index(i), k, valin, fgin);
|
---|
| 907 | for(int j=0; j<m_fanout; j++) {
|
---|
| 908 | if (out_index(i, j) < 0) continue;
|
---|
| 909 | putData(out_index(i, j), k, valin, fgin);
|
---|
| 910 | }
|
---|
| 911 | }
|
---|
| 912 | totnscount++;
|
---|
| 913 | } // Boucle sur les num-sample
|
---|
| 914 | cout << " SimpleFanOut::run() - End of processing "
|
---|
| 915 | << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
|
---|
| 916 | } // Bloc try
|
---|
| 917 |
|
---|
| 918 | catch (PException & exc) {
|
---|
| 919 | cerr << "SimpleFanOut: Catched Exception " << (string)typeid(exc).name()
|
---|
| 920 | << "\n .... Msg= " << exc.Msg() << endl;
|
---|
| 921 | }
|
---|
| 922 | }
|
---|
| 923 |
|
---|
| 924 |
|
---|
| 925 |
|
---|