[1462] | 1 | #include "array.h"
|
---|
[1442] | 2 | #include "simtoipr.h"
|
---|
[1454] | 3 | #include <math.h>
|
---|
[1442] | 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;
|
---|
[1454] | 20 | totnscount = glnscount = glcount = out_range_nscount = 0;
|
---|
[1443] | 21 | deglitchdone = false;
|
---|
[1454] | 22 | SetRange(-9.e39, 9.e39);
|
---|
[1442] | 23 | }
|
---|
| 24 |
|
---|
| 25 | SimpleDeglitcher::~SimpleDeglitcher()
|
---|
| 26 | {
|
---|
| 27 | }
|
---|
| 28 |
|
---|
[1454] | 29 |
|
---|
[1443] | 30 | void SimpleDeglitcher::PrintStatus(ostream & os)
|
---|
| 31 | {
|
---|
| 32 | os << "\n ------------------------------------------------------ \n"
|
---|
| 33 | << " SimpleDeglitcher::PrintStatus() - WindowSize=" << WSize()
|
---|
| 34 | << " NbSigmas=" << NbSigmas() << " MaxPoints=" << MaxPoints() << endl;
|
---|
[1454] | 35 | os << " Range_Min= " << range_min << " Range_Max= " << range_max << endl;
|
---|
[1443] | 36 | TOIProcessor::PrintStatus(os);
|
---|
| 37 | if (deglitchdone) os << " Deglitching performed " << endl;
|
---|
| 38 | else os << " NO deglitching done " << endl;
|
---|
[1454] | 39 | double nst = (ProcessedSampleCount() > 0) ? ProcessedSampleCount() : 1.;
|
---|
| 40 | os << " ProcessedSampleCount=" << ProcessedSampleCount()
|
---|
| 41 | << " OutOfRangeSampleCount=" << OutOfRangeSampleCount() << endl;
|
---|
| 42 | os << " GlitchCount= " << GlitchCount()
|
---|
| 43 | << " GlitchSampleCount=" << GlitchSampleCount()
|
---|
[1443] | 44 | << "( " << (double)GlitchSampleCount()*100./nst << " % )" << endl;
|
---|
| 45 | os << " ------------------------------------------------------ " << endl;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[1442] | 48 | void SimpleDeglitcher::init() {
|
---|
| 49 | cout << "SimpleDeglitcher::init" << endl;
|
---|
| 50 | declareInput("in");
|
---|
| 51 | declareOutput("out");
|
---|
| 52 | declareOutput("mean");
|
---|
| 53 | declareOutput("sigma");
|
---|
[1443] | 54 | declareOutput("incopie");
|
---|
[1442] | 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);
|
---|
[1443] | 68 | bool fgincopie = checkOutputTOIIndex(3);
|
---|
[1442] | 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 | }
|
---|
[1443] | 75 | if (!fgout && !fgmean && !fgsigma &&!fgincopie) {
|
---|
[1442] | 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 |
|
---|
[1443] | 86 | cout << " SimpleDeglitcher::run() SNRange=" << snb << " - " << sne << endl;
|
---|
[1442] | 87 | try {
|
---|
[1443] | 88 | Timer tm("SimpleDeglitcher::run()");
|
---|
[1442] | 89 | Vector vin(wsize);
|
---|
[1467] | 90 |
|
---|
| 91 | int wrec = maxpoints*2;
|
---|
| 92 | Vector vrec(wrec);
|
---|
| 93 |
|
---|
[1454] | 94 | TVector<int_8> vfg(wsize);
|
---|
[1467] | 95 | int wsz2 = wsize/2;
|
---|
| 96 | // Le debut
|
---|
[1442] | 97 | int k;
|
---|
[1467] | 98 | for(k=0; k<wsz2; k++)
|
---|
[1464] | 99 | getData(0, k+snb, vin(k), vfg(k));
|
---|
| 100 |
|
---|
[1467] | 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++;
|
---|
[1454] | 112 | }
|
---|
[1467] | 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 | }
|
---|
[1454] | 121 |
|
---|
[1467] | 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 |
|
---|
[1442] | 129 | int kgl = -1;
|
---|
| 130 | int ii,lastput;
|
---|
| 131 | bool fgglitch = false;
|
---|
| 132 | double valcur,valsub,valadd;
|
---|
[1467] | 133 | double lastvalok = mean;
|
---|
[1454] | 134 | uint_8 fgcur;
|
---|
[1467] | 135 | bool fgokcur=false;
|
---|
[1454] | 136 | // Boucle sur les sampleNum
|
---|
| 137 |
|
---|
[1467] | 138 | int knext;
|
---|
| 139 | int kfin = sne-snb;
|
---|
| 140 | for(k=0;k<=kfin;k++) {
|
---|
[1442] | 141 | totnscount++;
|
---|
[1443] | 142 | // if (k%10000 == 0) cout << " DBG: K=" << k << endl;
|
---|
[1467] | 143 | knext = k+wsz2;
|
---|
[1442] | 144 | // Calcul mean-sigma
|
---|
[1467] | 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) ) {
|
---|
[1454] | 150 | valadd = mean;
|
---|
[1467] | 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 | }
|
---|
[1442] | 176 | }
|
---|
| 177 |
|
---|
[1467] | 178 |
|
---|
[1442] | 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);
|
---|
[1454] | 184 | if (fgincopie)
|
---|
| 185 | putData(3, k+snb, vin(k%wsize), vfg(k%wsize));
|
---|
[1442] | 186 |
|
---|
[1454] | 187 | if ( (valcur < range_min) || (valcur > range_max) ) {
|
---|
| 188 | vin(k%wsize) = valcur = mean;
|
---|
| 189 | vfg(k%wsize) |= 2;
|
---|
| 190 | out_range_nscount++;
|
---|
| 191 | }
|
---|
[1467] | 192 | valcur = vin(k%wsize);
|
---|
| 193 | fgcur = vfg(k%wsize);
|
---|
[1443] | 194 |
|
---|
[1442] | 195 | if (!fgout) continue; // Pas de sortie out (deglitche)
|
---|
| 196 |
|
---|
[1443] | 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 | // }
|
---|
[1442] | 205 |
|
---|
[1467] | 206 | double curnsig = nsig;
|
---|
| 207 | if (fgglitch) curnsig /= 2.;
|
---|
| 208 |
|
---|
| 209 | if (valcur < mean+curnsig*sigma) { // inferieur au seuil
|
---|
[1442] | 210 | if (fgglitch) {
|
---|
| 211 | if (k-kgl < maxpoints) { // On vient de detecter un glitch
|
---|
| 212 | glcount++;
|
---|
[1467] | 213 | double recval = vrec.Sum()/wrec;
|
---|
[1442] | 214 | for(ii=kgl; ii<k; ii++) {
|
---|
[1467] | 215 | putData(0, ii+snb, recval, vfg(ii%wsize)|5);
|
---|
[1442] | 216 | glnscount++;
|
---|
| 217 | }
|
---|
| 218 | lastput = snb+k-1;
|
---|
| 219 | }
|
---|
| 220 | else {
|
---|
| 221 | for(ii=kgl; ii<k; ii++) {
|
---|
[1454] | 222 | putData(0, ii+snb, vin(ii%wsize), vfg(ii%wsize));
|
---|
[1442] | 223 | }
|
---|
| 224 | lastput = snb+k-1;
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 | putData(0, k+snb, valcur, 0);
|
---|
| 228 | lastput = snb+k;
|
---|
| 229 | kgl = -1; fgglitch = false;
|
---|
[1467] | 230 | vrec(k%wrec) = lastvalok = valcur;
|
---|
[1442] | 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
|
---|
[1454] | 236 | putData(0, ii+snb, vin(ii%wsize), vfg(ii%wsize));
|
---|
[1442] | 237 | lastput = snb+k;
|
---|
| 238 | fgglitch = false;
|
---|
[1467] | 239 | vrec(k%wrec) = lastvalok = valcur;
|
---|
[1442] | 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
|
---|
[1454] | 247 | putData(0, k+snb, valcur, fgcur);
|
---|
[1442] | 248 | lastput = snb+k;
|
---|
| 249 | }
|
---|
[1467] | 250 | vrec(k%wrec) = lastvalok;
|
---|
[1442] | 251 | }
|
---|
| 252 | }
|
---|
| 253 |
|
---|
[1443] | 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 "
|
---|
[1454] | 263 | << " ProcessedSampleCount=" << ProcessedSampleCount()
|
---|
[1443] | 264 | << " GlitchCount= " << GlitchCount() << endl;
|
---|
| 265 | if (fgout) deglitchdone = true;
|
---|
[1442] | 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 |
|
---|
[1454] | 274 | // -------------------------------------------------------------------
|
---|
| 275 | // Classe SimpleFilter : Filtre simple ds le domaine temporel
|
---|
| 276 | // -------------------------------------------------------------------
|
---|
[1442] | 277 |
|
---|
[1454] | 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 |
|
---|
[1442] | 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
|
---|
[1454] | 308 | << " FilterKind=" << FilterKind2String(fk) << endl;
|
---|
[1442] | 309 | wsize = wsz;
|
---|
| 310 | totnscount = 0;
|
---|
| 311 | coef = new double[wsz];
|
---|
[1467] | 312 | for(int k=0; k<wsz; k++) coef[k] = 0.;
|
---|
[1476] | 313 | int kk;
|
---|
[1454] | 314 | switch (fk) {
|
---|
| 315 | case UserFilter :
|
---|
| 316 | throw ParmError("SimpleFilter: Error in filter Kind (UserFilter)!");
|
---|
[1467] | 317 | // break;
|
---|
[1454] | 318 | case MeanFilter :
|
---|
[1476] | 319 | for(kk=0; kk<wsz; kk++)
|
---|
[1454] | 320 | coef[kk] = a/wsize;
|
---|
| 321 | break;
|
---|
| 322 | case SumFilter :
|
---|
[1476] | 323 | for(kk=0; kk<wsz; kk++)
|
---|
[1454] | 324 | coef[kk] = a;
|
---|
| 325 | break;
|
---|
| 326 | case GaussFilter :
|
---|
[1476] | 327 | for(kk=-(wsz/2); kk<=(wsz/2); kk++)
|
---|
[1467] | 328 | coef[kk+(wsz/2)] = a*exp(-(double)(kk*kk)/(s*s));
|
---|
[1454] | 329 | break;
|
---|
| 330 | case DiffFilter :
|
---|
[1476] | 331 | for(kk=0; kk<wsz; kk++)
|
---|
[1454] | 332 | coef[kk] = -a/wsize;
|
---|
| 333 | coef[wsz/2+1] += 1.;
|
---|
| 334 | break;
|
---|
| 335 | default :
|
---|
| 336 | throw ParmError("SimpleFilter: Error in filter Kind (UnknownFilter)!");
|
---|
[1467] | 337 | // break;
|
---|
[1454] | 338 | }
|
---|
[1442] | 339 | }
|
---|
| 340 |
|
---|
[1454] | 341 | SimpleFilter::SimpleFilter(Vector const & vc)
|
---|
| 342 | {
|
---|
| 343 | int wsz = vc.Size();
|
---|
| 344 | if (wsz < 3) wsz = 3;
|
---|
| 345 | if (wsz%2 == 0) wsz++;
|
---|
| 346 | FilterKind fk = UserFilter;
|
---|
| 347 | cout << "SimpleFilter::SimpleFilter(Vector & vc) vc.Size()= "
|
---|
| 348 | << vc.Size() << " WSize=" << wsz
|
---|
| 349 | << " FilterKind=" << FilterKind2String(fk) << endl;
|
---|
| 350 | wsize = wsz;
|
---|
| 351 | totnscount = 0;
|
---|
| 352 | coef = new double[wsz];
|
---|
[1476] | 353 | int kk;
|
---|
| 354 | for(kk=0; kk<vc.Size(); kk++)
|
---|
[1454] | 355 | coef[kk] = vc(kk);
|
---|
[1476] | 356 | for(kk=vc.Size(); kk<wsz; kk++)
|
---|
[1454] | 357 | coef[kk] = 0.;
|
---|
| 358 | }
|
---|
| 359 |
|
---|
[1442] | 360 | SimpleFilter::~SimpleFilter()
|
---|
| 361 | {
|
---|
| 362 | delete[] coef;
|
---|
| 363 | }
|
---|
| 364 |
|
---|
[1443] | 365 | void SimpleFilter::PrintStatus(ostream & os)
|
---|
| 366 | {
|
---|
| 367 | os << "\n ------------------------------------------------------ \n"
|
---|
| 368 | << " SimpleFilter::PrintStatus() - WindowSize=" << WSize()
|
---|
| 369 | << " FilterKind= " << Type() << endl;
|
---|
| 370 | TOIProcessor::PrintStatus(os);
|
---|
| 371 | os << " Coeff= " ;
|
---|
| 372 | for(int k=0; k<wsize; k++) os << coef[k] << " " ;
|
---|
| 373 | os << endl;
|
---|
[1454] | 374 | os << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
|
---|
[1443] | 375 | os << " ------------------------------------------------------ " << endl;
|
---|
| 376 | }
|
---|
| 377 |
|
---|
[1442] | 378 | void SimpleFilter::init() {
|
---|
| 379 | cout << "SimpleFilter::init" << endl;
|
---|
| 380 | declareInput("in");
|
---|
| 381 | declareOutput("out");
|
---|
[1443] | 382 | declareOutput("incopie");
|
---|
[1442] | 383 | name = "SimpleFilter";
|
---|
| 384 | // upExtra = 1;
|
---|
| 385 | }
|
---|
| 386 |
|
---|
| 387 | void SimpleFilter::run() {
|
---|
| 388 | // TOIManager* mgr = TOIManager::getManager();
|
---|
| 389 | int snb = getMinIn();
|
---|
| 390 | int sne = getMaxIn();
|
---|
| 391 |
|
---|
| 392 | bool fgout = checkOutputTOIIndex(0);
|
---|
[1443] | 393 | bool fgincopie = checkOutputTOIIndex(1);
|
---|
[1442] | 394 |
|
---|
| 395 | if (!checkInputTOIIndex(0)) {
|
---|
| 396 | cerr << " SimpleFilter::run() - Input TOI (in) not connected! "
|
---|
| 397 | << endl;
|
---|
| 398 | throw ParmError("SimpleFilter::run() Input TOI (in) not connected!");
|
---|
| 399 | }
|
---|
| 400 | if (!fgout) {
|
---|
| 401 | cerr << " SimpleFilter::run() - No Output TOI connected! "
|
---|
| 402 | << endl;
|
---|
| 403 | throw ParmError("SimpleFilter::run() No output TOI connected!");
|
---|
| 404 | }
|
---|
[1443] | 405 |
|
---|
| 406 | cout << " SimpleFilter::run() SNRange=" << snb << " - " << sne << endl;
|
---|
[1442] | 407 |
|
---|
| 408 |
|
---|
| 409 | try {
|
---|
[1443] | 410 | Timer tm("SimpleFilter::run()");
|
---|
[1442] | 411 | // Le debut
|
---|
| 412 | int wsz2 = wsize/2;
|
---|
| 413 | Vector vin(wsize);
|
---|
[1454] | 414 | TVector<int_8> vfg(wsize);
|
---|
[1442] | 415 | int k;
|
---|
[1464] | 416 | for(k=0; k<wsize; k++)
|
---|
| 417 | getData(0, k+snb, vin(k%wsize), vfg(k%wsize));
|
---|
| 418 |
|
---|
[1442] | 419 | double mean = vin.Sum()/wsize;
|
---|
[1454] | 420 | for(k=wsz2+1; k<wsize; k++) {
|
---|
| 421 | vin(k) = mean;
|
---|
| 422 | vfg(k) = 0;
|
---|
| 423 | }
|
---|
| 424 | int knext;
|
---|
| 425 | bool fgfin = false;
|
---|
| 426 | // Boucle sur les sampleNum
|
---|
[1443] | 427 | for(k=0;k<=sne-snb;k++) {
|
---|
[1442] | 428 | double sortie = 0;
|
---|
[1467] | 429 | for(int ii=-wsz2; ii<=wsz2; ii++) {
|
---|
| 430 | sortie += vin((ii+k+wsize)%wsize)*coef[ii+wsz2];
|
---|
[1442] | 431 | }
|
---|
[1454] | 432 | putData(0,k+snb,sortie,vfg(k%wsize));
|
---|
| 433 | if (fgincopie)
|
---|
| 434 | putData(1, k+snb, vin(k%wsize), vfg(k%wsize));
|
---|
| 435 | knext = k+wsz2+1;
|
---|
[1464] | 436 | if (knext<=(sne-snb))
|
---|
| 437 | getData(0, knext+snb, vin(knext%wsize), vfg(knext%wsize));
|
---|
| 438 |
|
---|
[1454] | 439 | else {
|
---|
| 440 | if (!fgfin) {
|
---|
| 441 | mean = vin.Sum()/wsize;
|
---|
| 442 | fgfin = true;
|
---|
| 443 | }
|
---|
| 444 | vin(knext%wsize) = mean;
|
---|
| 445 | vfg(knext%wsize) = 0;
|
---|
| 446 | }
|
---|
| 447 | totnscount++;
|
---|
[1442] | 448 | } // Boucle sur les num-sample
|
---|
[1443] | 449 | cout << " SimpleFilter::run() - End of processing " << endl;
|
---|
[1442] | 450 | } // Bloc try
|
---|
| 451 |
|
---|
| 452 | catch (PException & exc) {
|
---|
| 453 | cerr << "SimpleFilter: Catched Exception " << (string)typeid(exc).name()
|
---|
| 454 | << "\n .... Msg= " << exc.Msg() << endl;
|
---|
| 455 | }
|
---|
[1454] | 456 | }
|
---|
[1442] | 457 |
|
---|
[1454] | 458 | // ---------------------------------------------------------------
|
---|
| 459 | // -------------------- Classe SimpleAdder -----------------------
|
---|
| 460 | // ---------------------------------------------------------------
|
---|
[1442] | 461 |
|
---|
[1454] | 462 | SimpleAdder::SimpleAdder(int nbinput)
|
---|
| 463 | : gains(nbinput)
|
---|
| 464 | {
|
---|
| 465 | if (nbinput < 1)
|
---|
| 466 | throw ParmError("SimpleAdder::SimpleAdder() NbInput < 1 !");
|
---|
| 467 | nb_input = nbinput;
|
---|
| 468 | for(int k=0; k<nb_input; k++) gains(k) = 1.;
|
---|
| 469 | totnscount = 0;
|
---|
[1442] | 470 | }
|
---|
[1454] | 471 |
|
---|
| 472 | SimpleAdder::~SimpleAdder()
|
---|
| 473 | {
|
---|
| 474 | }
|
---|
| 475 |
|
---|
| 476 | void SimpleAdder::SetGain(int num, double g)
|
---|
| 477 | {
|
---|
| 478 | if ((num < 0) || (num >= nb_input))
|
---|
| 479 | throw RangeCheckError("SimpleAdder::SetGain() Out of range input number!");
|
---|
| 480 | gains(num) = g;
|
---|
| 481 | return;
|
---|
| 482 | }
|
---|
| 483 |
|
---|
| 484 | double SimpleAdder::Gain(int num)
|
---|
| 485 | {
|
---|
| 486 | if ((num < 0) || (num >= nb_input))
|
---|
| 487 | throw RangeCheckError("SimpleAdder::Gain() Out of range input number!");
|
---|
| 488 | return gains(num);
|
---|
| 489 | }
|
---|
| 490 |
|
---|
| 491 | void SimpleAdder::PrintStatus(ostream & os)
|
---|
| 492 | {
|
---|
| 493 | os << "\n ------------------------------------------------------ \n"
|
---|
| 494 | << " SimpleAdder::PrintStatus() - NbInput=" << NbInput() << endl;
|
---|
| 495 | TOIProcessor::PrintStatus(os);
|
---|
| 496 | os << " Gains= " ;
|
---|
| 497 | for(int k=0; k<nb_input; k++) os << gains(k) << " " ;
|
---|
| 498 | os << endl;
|
---|
| 499 | os << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
|
---|
| 500 | os << " ------------------------------------------------------ " << endl;
|
---|
| 501 | }
|
---|
| 502 |
|
---|
| 503 | void SimpleAdder::init() {
|
---|
| 504 | cout << "SimpleAdder::init NbInput=" << nb_input << endl;
|
---|
| 505 | char buff[32];
|
---|
| 506 | for(int k=0; k<nb_input; k++) {
|
---|
| 507 | sprintf(buff,"in%d", k);
|
---|
| 508 | declareInput(buff);
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | declareOutput("out");
|
---|
| 512 | name = "SimpleAdder";
|
---|
| 513 | // upExtra = 1;
|
---|
| 514 | }
|
---|
| 515 |
|
---|
| 516 | void SimpleAdder::run() {
|
---|
| 517 | // TOIManager* mgr = TOIManager::getManager();
|
---|
| 518 | int snb = getMinIn();
|
---|
| 519 | int sne = getMaxIn();
|
---|
| 520 |
|
---|
| 521 | bool fgout = checkOutputTOIIndex(0);
|
---|
| 522 | string msg_err;
|
---|
| 523 | for(int ki=0;ki<nb_input;ki++) {
|
---|
| 524 | if (!checkInputTOIIndex(ki)) {
|
---|
| 525 | msg_err = "SimpleAdder::run() - Input TOI (" + getInName(ki) +
|
---|
| 526 | " not connected!";
|
---|
| 527 | cerr << msg_err << endl;
|
---|
| 528 | throw ParmError(msg_err);
|
---|
| 529 | }
|
---|
| 530 | }
|
---|
| 531 | if (!fgout) {
|
---|
| 532 | cerr << " SimpleAdder::run() - No Output TOI connected! "
|
---|
| 533 | << endl;
|
---|
| 534 | throw ParmError("SimpleAdder::run() No output TOI connected!");
|
---|
| 535 | }
|
---|
| 536 |
|
---|
| 537 | cout << " SimpleAdder::run() SNRange=" << snb << " - " << sne << endl;
|
---|
| 538 |
|
---|
| 539 |
|
---|
| 540 | try {
|
---|
| 541 | Timer tm("SimpleAdder::run()");
|
---|
| 542 | int k,i;
|
---|
| 543 | double out = 0.;
|
---|
[1464] | 544 | double valin = 0.;
|
---|
| 545 | int_8 fgin = 0;
|
---|
| 546 | int_8 fgout = 0;
|
---|
[1454] | 547 | for(k=snb;k<=sne;k++) {
|
---|
| 548 | out = 0;
|
---|
| 549 | fgout = 0;
|
---|
| 550 | for(i=0; i<nb_input; i++) {
|
---|
[1464] | 551 | getData(i, k, valin, fgin);
|
---|
| 552 | out += gains(i)*valin;
|
---|
| 553 | fgout = fgout | fgin;
|
---|
[1454] | 554 | }
|
---|
| 555 | putData(0,k,out,fgout);
|
---|
| 556 | totnscount++;
|
---|
| 557 | } // Boucle sur les num-sample
|
---|
| 558 | cout << " SimpleAdder::run() - End of processing " << endl;
|
---|
| 559 | } // Bloc try
|
---|
| 560 |
|
---|
| 561 | catch (PException & exc) {
|
---|
| 562 | cerr << "SimpleAdder: Catched Exception " << (string)typeid(exc).name()
|
---|
| 563 | << "\n .... Msg= " << exc.Msg() << endl;
|
---|
| 564 | }
|
---|
| 565 | }
|
---|
| 566 |
|
---|
| 567 |
|
---|
[1467] | 568 | // ---------------------------------------------------------------
|
---|
| 569 | // -------------------- Classe SimpleFanOut -----------------------
|
---|
| 570 | // ---------------------------------------------------------------
|
---|
[1454] | 571 |
|
---|
[1467] | 572 | SimpleFanOut::SimpleFanOut(int nbinput, int mfanout)
|
---|
| 573 | {
|
---|
| 574 | if (nbinput < 1)
|
---|
| 575 | throw ParmError("SimpleFanOut::SimpleFanOut() NbInput < 1 !");
|
---|
| 576 | if (mfanout < 1)
|
---|
| 577 | throw ParmError("SimpleFanOut::SimpleFanOut() M_FanOut < 1 !");
|
---|
| 578 |
|
---|
| 579 | nb_input = nbinput;
|
---|
| 580 | m_fanout = mfanout;
|
---|
| 581 | totnscount = 0;
|
---|
| 582 | }
|
---|
| 583 |
|
---|
| 584 | SimpleFanOut::~SimpleFanOut()
|
---|
| 585 | {
|
---|
| 586 | }
|
---|
| 587 |
|
---|
| 588 |
|
---|
| 589 | void SimpleFanOut::PrintStatus(ostream & os)
|
---|
| 590 | {
|
---|
| 591 | os << "\n ------------------------------------------------------ \n"
|
---|
| 592 | << " SimpleFanOut::PrintStatus() - NbInput=" << NbInput()
|
---|
| 593 | << " M_FanOut=" << MFanOut() << endl;
|
---|
| 594 | TOIProcessor::PrintStatus(os);
|
---|
| 595 | os << endl;
|
---|
| 596 | os << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
|
---|
| 597 | os << " ------------------------------------------------------ " << endl;
|
---|
| 598 | }
|
---|
| 599 |
|
---|
| 600 | void SimpleFanOut::init() {
|
---|
| 601 | cout << "SimpleFanOut::init NbInput=" << nb_input << endl;
|
---|
| 602 | char buff[64];
|
---|
| 603 | for(int k=0; k<nb_input; k++) {
|
---|
| 604 | sprintf(buff,"in%d", k);
|
---|
| 605 | declareInput(buff);
|
---|
| 606 | for(int j=0; j<m_fanout; j++) {
|
---|
| 607 | sprintf(buff,"out%d_%d", k, j);
|
---|
| 608 | declareOutput(buff);
|
---|
| 609 | }
|
---|
| 610 | }
|
---|
| 611 |
|
---|
| 612 | name = "SimpleFanOut";
|
---|
| 613 | // upExtra = 1;
|
---|
| 614 | }
|
---|
| 615 |
|
---|
| 616 | void SimpleFanOut::run() {
|
---|
| 617 | // TOIManager* mgr = TOIManager::getManager();
|
---|
| 618 | int snb = getMinIn();
|
---|
| 619 | int sne = getMaxIn();
|
---|
| 620 |
|
---|
| 621 | TVector<int_4> in_index(nb_input);
|
---|
| 622 | TMatrix<int_4> out_index(nb_input, m_fanout);
|
---|
| 623 | in_index = -1;
|
---|
| 624 | out_index = -1;
|
---|
| 625 | int nbconin = 0;
|
---|
| 626 | bool fggin = false;
|
---|
| 627 | char buff[64];
|
---|
| 628 | for(int ki=0;ki<nb_input;ki++) {
|
---|
| 629 | sprintf(buff,"in%d", ki);
|
---|
| 630 | int idx = getInputTOIIndex(buff);
|
---|
| 631 | if (!checkInputTOIIndex(idx)) continue;
|
---|
| 632 | nbconin++;
|
---|
| 633 | in_index(ki) = idx;
|
---|
| 634 | bool fgout = false;
|
---|
| 635 | for(int jo=0; jo<m_fanout; jo++) {
|
---|
| 636 | sprintf(buff,"out%d_%d", ki, jo);
|
---|
| 637 | int odx = getOutputTOIIndex(buff);
|
---|
| 638 | if (checkOutputTOIIndex(odx)) {
|
---|
| 639 | out_index(ki, jo) = odx;
|
---|
| 640 | fgout = true;
|
---|
| 641 | }
|
---|
| 642 | }
|
---|
| 643 | if (!fgout) {
|
---|
| 644 | string msg_err =
|
---|
| 645 | "SimpleFanOut::run() - No connected Output for Input TOI ("
|
---|
| 646 | + getInName(ki) + ") !";
|
---|
| 647 | cerr << msg_err << endl;
|
---|
| 648 | throw ParmError(msg_err);
|
---|
| 649 | }
|
---|
| 650 | }
|
---|
| 651 | if (nbconin == 0) {
|
---|
| 652 | cerr << " SimpleFanOut::run() - No Input TOI connected! "
|
---|
| 653 | << endl;
|
---|
| 654 | throw ParmError("SimpleFanOut::run() No Inout TOI connected!");
|
---|
| 655 | }
|
---|
| 656 |
|
---|
| 657 | /*
|
---|
| 658 | for(int ki=0;ki<nb_input;ki++) {
|
---|
| 659 | cout << " SimpleFanOut::run() In(" << ki << ") Index=" << in_index(ki)
|
---|
| 660 | << " Name=" << getInName(in_index(ki)) << endl;
|
---|
| 661 | for(int jo=0; jo<m_fanout; jo++)
|
---|
| 662 | cout << " .... Out(" << ki << "," << jo << ") Index=" << out_index(ki, jo)
|
---|
| 663 | << " Name=" << getOutName(out_index(ki, jo)) << endl;
|
---|
| 664 | }
|
---|
| 665 | */
|
---|
| 666 | cout << " SimpleFanOut::run() SNRange=" << snb << " - " << sne << endl;
|
---|
| 667 |
|
---|
| 668 |
|
---|
| 669 | try {
|
---|
| 670 | Timer tm("SimpleFanOut::run()");
|
---|
| 671 | double valin = 0.;
|
---|
| 672 | int_8 fgin = 0;
|
---|
| 673 | for(int k=snb;k<=sne;k++) {
|
---|
| 674 | for(int i=0;i<nb_input;i++) {
|
---|
| 675 | if (in_index(i) < 0) continue;
|
---|
| 676 | valin = 0;
|
---|
| 677 | fgin = 0;
|
---|
| 678 | getData(in_index(i), k, valin, fgin);
|
---|
| 679 | for(int j=0; j<m_fanout; j++) {
|
---|
| 680 | if (out_index(i, j) < 0) continue;
|
---|
| 681 | putData(out_index(i, j), k, valin, fgin);
|
---|
| 682 | }
|
---|
| 683 | }
|
---|
| 684 | totnscount++;
|
---|
| 685 | } // Boucle sur les num-sample
|
---|
| 686 | cout << " SimpleFanOut::run() - End of processing "
|
---|
| 687 | << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
|
---|
| 688 | } // Bloc try
|
---|
| 689 |
|
---|
| 690 | catch (PException & exc) {
|
---|
| 691 | cerr << "SimpleFanOut: Catched Exception " << (string)typeid(exc).name()
|
---|
| 692 | << "\n .... Msg= " << exc.Msg() << endl;
|
---|
| 693 | }
|
---|
| 694 | }
|
---|
| 695 |
|
---|
| 696 |
|
---|
| 697 |
|
---|