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