| 1 | // ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL | 
|---|
| 2 | //                               Eric Aubourg | 
|---|
| 3 | //                               Christophe Magneville | 
|---|
| 4 | //                               Reza Ansari | 
|---|
| 5 | // $Id: genwproc.cc,v 1.8 2001-11-13 16:22:46 aubourg Exp $ | 
|---|
| 6 |  | 
|---|
| 7 | #include "array.h" | 
|---|
| 8 | #include <math.h> | 
|---|
| 9 | #include "genwproc.h" | 
|---|
| 10 | #include "toimanager.h" | 
|---|
| 11 | #include "pexceptions.h" | 
|---|
| 12 | #include "ctimer.h" | 
|---|
| 13 |  | 
|---|
| 14 | // ------------------------------------------------------------- | 
|---|
| 15 | //   Class GenWindowTOIProcessor : generic processor with window | 
|---|
| 16 | // ------------------------------------------------------------- | 
|---|
| 17 |  | 
|---|
| 18 | //////////////////////////////////////////////////////////////// | 
|---|
| 19 | GenWindowTOIProcessor::GenWindowTOIProcessor(int_4 nbinput,int_4 nboutput | 
|---|
| 20 | ,int_4 wsz, int_4 wstep, int_4 wsztot) | 
|---|
| 21 | { | 
|---|
| 22 | if(nbinput<1) throw ParmError("GenWindowTOIProcessor::Creator nbinput<1 !"); | 
|---|
| 23 | if(nboutput<0) nboutput=0; | 
|---|
| 24 | if(wsz<2) throw ParmError("GenWindowTOIProcessor::Creator wsz<2 !"); | 
|---|
| 25 | if(wsz%2==0) {if(wsztot==wsz) wsztot++; wsz++;} | 
|---|
| 26 | if(wstep<1) wstep=1; | 
|---|
| 27 | if(wsztot<wsz) wsztot = 2*wsz; | 
|---|
| 28 | // cas sans intersection entre 2 samples successifs | 
|---|
| 29 | if(wstep>=wsz) wsztot = wsz; | 
|---|
| 30 |  | 
|---|
| 31 | NbInput = nbinput; | 
|---|
| 32 | NbOutput = nboutput; | 
|---|
| 33 | WSize = wsz; | 
|---|
| 34 | WStep = wstep; | 
|---|
| 35 | WSizeTot = wsztot; | 
|---|
| 36 |  | 
|---|
| 37 | CurWtIndex = -1; | 
|---|
| 38 | SNbegin = SNend = StartSample = LastFilledSn = -1; | 
|---|
| 39 | TotNsCount = TotDecalCount = 0; | 
|---|
| 40 |  | 
|---|
| 41 | SetDbgLevel(); | 
|---|
| 42 | SetWSizeLCR(); | 
|---|
| 43 | SetDefaultValue(); | 
|---|
| 44 |  | 
|---|
| 45 | TVector<r_8> vr8(1);     // CMV+RZ supprimer taille(1) apres correction de | 
|---|
| 46 | TVector<int_8> vi8(1);   // constructeur copie de TArray (taille nulle) | 
|---|
| 47 |  | 
|---|
| 48 | int_4 k; | 
|---|
| 49 | for(k=0;k<NbInput;k++) { | 
|---|
| 50 | WDataIn.push_back(vr8); | 
|---|
| 51 | WFlagIn.push_back(vi8); | 
|---|
| 52 | WInFlg.push_back(false); | 
|---|
| 53 | } | 
|---|
| 54 | if(NbOutput) | 
|---|
| 55 | for(k=0;k<NbOutput;k++) { | 
|---|
| 56 | WDataOut.push_back(vr8); | 
|---|
| 57 | WFlagOut.push_back(vi8); | 
|---|
| 58 | WOutFlg.push_back(false); | 
|---|
| 59 | WPutOutFlg.push_back(false); | 
|---|
| 60 | WPutOutOwnVector.push_back(false); | 
|---|
| 61 | OutSample.push_back(0); | 
|---|
| 62 | } | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|
| 65 | GenWindowTOIProcessor::~GenWindowTOIProcessor() | 
|---|
| 66 | { | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | //////////////////////////////////////////////////////////////// | 
|---|
| 70 | void GenWindowTOIProcessor::PrintStatus(::ostream & os) | 
|---|
| 71 | { | 
|---|
| 72 | os<<"\n ------------------------------------------------------ \n" | 
|---|
| 73 | <<" GenWindowTOIProcessor::PrintStatus() - ["<<NbInput<<","<<NbOutput<<"]"<<endl | 
|---|
| 74 | <<" WSizeTot="<<WSizeTot<<" WSize="<<GetWSize()<<" WStep= "<<GetWStep()<<endl; | 
|---|
| 75 | os<<" WindowLCR: " | 
|---|
| 76 | <<" L=("<<W0Left<<","<<GetWSize('l')<<")" | 
|---|
| 77 | <<" C=("<<W0Center<<","<<GetWSize('c')<<")" | 
|---|
| 78 | <<" R=("<<W0Right<<","<<GetWSize('r')<<")" | 
|---|
| 79 | <<endl; | 
|---|
| 80 |  | 
|---|
| 81 | TOIProcessor::PrintStatus(os); | 
|---|
| 82 | os<<"ProcessedSampleCount="<<ProcessedSampleCount()<<" NbDecal="<<TotDecalCount<<endl; | 
|---|
| 83 | os<<"------------------------------------------------------ "<<endl; | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | //////////////////////////////////////////////////////////////// | 
|---|
| 87 | TVector<r_8> GenWindowTOIProcessor::GetWData(int_4 numtoi) | 
|---|
| 88 | { | 
|---|
| 89 | if(numtoi<0 || numtoi>=NbInput) | 
|---|
| 90 | throw RangeCheckError("GenWindowTOIProcessor::GetWData : toi out of range !"); | 
|---|
| 91 | if(!WInFlg[numtoi]) | 
|---|
| 92 | throw ParmError("GenWindowTOIProcessor::GetWData : toi not connected!"); | 
|---|
| 93 | return (WDataIn[numtoi])(Range(StartWtIndex(),0,WSize)); | 
|---|
| 94 | } | 
|---|
| 95 |  | 
|---|
| 96 | TVector<uint_8> GenWindowTOIProcessor::GetWFlag(int_4 numtoi) | 
|---|
| 97 | { | 
|---|
| 98 | if(numtoi<0 || numtoi>=NbInput) | 
|---|
| 99 | throw RangeCheckError("GenWindowTOIProcessor::GetWFlag : toi out of range !"); | 
|---|
| 100 | if(!WInFlg[numtoi]) | 
|---|
| 101 | throw ParmError("GenWindowTOIProcessor::GetWFlag : toi not connected!"); | 
|---|
| 102 | return (WFlagIn[numtoi])(Range(StartWtIndex(),0,WSize)); | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | r_8 * GenWindowTOIProcessor::GetWDataPointer(int_4 numtoi) | 
|---|
| 106 | { | 
|---|
| 107 | if(numtoi<0 || numtoi>=NbInput) | 
|---|
| 108 | throw RangeCheckError("GenWindowTOIProcessor::GetWDataPointer : toi out of range !"); | 
|---|
| 109 | if(!WInFlg[numtoi]) | 
|---|
| 110 | throw ParmError("GenWindowTOIProcessor::GetWDataPointer : toi not connected!"); | 
|---|
| 111 | return (WDataIn[numtoi].Data()+StartWtIndex()); | 
|---|
| 112 |  | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 | uint_8 * GenWindowTOIProcessor::GetWFlagPointer(int_4 numtoi) | 
|---|
| 116 | { | 
|---|
| 117 | if(numtoi<0 || numtoi>=NbInput) | 
|---|
| 118 | throw RangeCheckError("GenWindowTOIProcessor::GetWFlagPointer : toi out of range !"); | 
|---|
| 119 | if(!WInFlg[numtoi]) | 
|---|
| 120 | throw ParmError("GenWindowTOIProcessor::GetWFlagPointer : toi not connected!"); | 
|---|
| 121 | return (WFlagIn[numtoi].Data()+StartWtIndex()); | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | void GenWindowTOIProcessor::GetData(int_4 numtoi, int_8 numsample, r_8 & data, uint_8 & flag) | 
|---|
| 125 | { | 
|---|
| 126 | if(numtoi<0 || numtoi>=NbInput) | 
|---|
| 127 | throw RangeCheckError("GenWindowTOIProcessor::GetData : toi out of range !"); | 
|---|
| 128 | if(!WInFlg[numtoi]) | 
|---|
| 129 | throw ParmError("GenWindowTOIProcessor::GetData : toi not connected!"); | 
|---|
| 130 | int_8 k = numsample-GetWStartSample(); | 
|---|
| 131 | if ((k<0) || (k >= GetWSize())) | 
|---|
| 132 | throw RangeCheckError("GenWindowTOIProcessor::GetData : numsample out of window!"); | 
|---|
| 133 | k += StartWtIndex(); | 
|---|
| 134 | data = (WDataIn[numtoi])(k); | 
|---|
| 135 | flag = (WFlagIn[numtoi])(k); | 
|---|
| 136 | } | 
|---|
| 137 |  | 
|---|
| 138 | //////////////////////////////////////////////////////////////// | 
|---|
| 139 | void GenWindowTOIProcessor::PutWData(int numtoi,int_8 numsample | 
|---|
| 140 | ,TVector<r_8>& data,TVector<uint_8>& flag) | 
|---|
| 141 | { | 
|---|
| 142 | if(numtoi<0 || numtoi>=NbOutput || NbOutput<=0) | 
|---|
| 143 | throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi out of range !"); | 
|---|
| 144 | if(!WOutFlg[numtoi]) | 
|---|
| 145 | throw ParmError("GenWindowTOIProcessor::PutWFlag : toi not connected!"); | 
|---|
| 146 | if(data.Size()!=flag.Size()) | 
|---|
| 147 | throw ParmError("GenWindowTOIProcessor::PutWFlag : data.Size()!=flag.Size()!"); | 
|---|
| 148 | if(data.Size() == 0) | 
|---|
| 149 | throw ParmError("GenWindowTOIProcessor::PutWFlag : data.Size()==0 !"); | 
|---|
| 150 | WDataOut[numtoi].Share(data); | 
|---|
| 151 | WFlagOut[numtoi].Share(flag); | 
|---|
| 152 | OutSample[numtoi] = numsample; | 
|---|
| 153 | WPutOutFlg[numtoi] = true; | 
|---|
| 154 | WPutOutOwnVector[numtoi] = false; | 
|---|
| 155 | } | 
|---|
| 156 |  | 
|---|
| 157 | void GenWindowTOIProcessor::PutWData(int numtoi,int_8 numsample | 
|---|
| 158 | , r_8 data, uint_8 flag) | 
|---|
| 159 | { | 
|---|
| 160 | if(numtoi<0 || numtoi>=NbOutput || NbOutput<=0) | 
|---|
| 161 | throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi out of range !"); | 
|---|
| 162 | if(!WOutFlg[numtoi]) | 
|---|
| 163 | throw ParmError("GenWindowTOIProcessor::PutWFlag : toi not connected!"); | 
|---|
| 164 | if (!WPutOutOwnVector[numtoi]) { | 
|---|
| 165 | WDataOut[numtoi].Realloc(1,BaseArray::SameVectorType,true); | 
|---|
| 166 | WFlagOut[numtoi].Realloc(1,BaseArray::SameVectorType,true); | 
|---|
| 167 | WPutOutOwnVector[numtoi] = true; | 
|---|
| 168 | } | 
|---|
| 169 | (WDataOut[numtoi])(0) = data; | 
|---|
| 170 | (WFlagOut[numtoi])(0) = flag; | 
|---|
| 171 | OutSample[numtoi] = numsample; | 
|---|
| 172 | WPutOutFlg[numtoi] = true; | 
|---|
| 173 | } | 
|---|
| 174 |  | 
|---|
| 175 | /******* cmv routines | 
|---|
| 176 | void GenWindowTOIProcessor::PutWData(int_4 numtoi,int_8 numsample | 
|---|
| 177 | ,TVector<r_8>& data,TVector<uint_8>& flag) | 
|---|
| 178 | { | 
|---|
| 179 | if(numtoi<0 || numtoi>=NbOutput || NbOutput<=0) | 
|---|
| 180 | throw RangeCheckError("GenWindowTOIProcessor::PutWData : toi out of range !"); | 
|---|
| 181 | if(!WOutFlg[numtoi]) | 
|---|
| 182 | throw ParmError("GenWindowTOIProcessor::PutWData : toi not connected!"); | 
|---|
| 183 | if(data.Size()!=flag.Size()) | 
|---|
| 184 | throw ParmError("GenWindowTOIProcessor::PutWData : data.Size()!=flag.Size()!"); | 
|---|
| 185 | if(data.Size() == 0) | 
|---|
| 186 | throw ParmError("GenWindowTOIProcessor::PutWData : data.Size()==0 !"); | 
|---|
| 187 |  | 
|---|
| 188 | for(int_4 k=0;k<data.Size(); k++) | 
|---|
| 189 | putData(numtoi,numsample+k,data(k),flag(k)); | 
|---|
| 190 | } | 
|---|
| 191 |  | 
|---|
| 192 | void GenWindowTOIProcessor::PutWData(int_4 numtoi,int_8 numsample | 
|---|
| 193 | ,r_8 data, uint_8 flag) | 
|---|
| 194 | { | 
|---|
| 195 | if(numtoi<0 || numtoi>=NbOutput || NbOutput<=0) | 
|---|
| 196 | throw RangeCheckError("GenWindowTOIProcessor::PutWData : toi out of range !"); | 
|---|
| 197 | if(!WOutFlg[numtoi]) | 
|---|
| 198 | throw ParmError("GenWindowTOIProcessor::PutWData : toi not connected!"); | 
|---|
| 199 |  | 
|---|
| 200 | putData(numtoi,numsample,data,flag); | 
|---|
| 201 | } | 
|---|
| 202 | *********/ | 
|---|
| 203 |  | 
|---|
| 204 | //////////////////////////////////////////////////////////////// | 
|---|
| 205 | void GenWindowTOIProcessor::SetWSizeLCR(int_4 wszl,int_4 wszc,int_4 wszr) | 
|---|
| 206 | // Fenetre a gauche, au centre et a droite du pixel central | 
|---|
| 207 | // Selon la logique: | 
|---|
| 208 | //----------------------------------------------- | 
|---|
| 209 | //                     | pixel central | 
|---|
| 210 | //                     | | 
|---|
| 211 | //                     | | 
|---|
| 212 | //          | wszl | wszc | wszr | | 
|---|
| 213 | //                     | | 
|---|
| 214 | //       |           WSize           | | 
|---|
| 215 | //----------------------------------------------- | 
|---|
| 216 | // wszc toujours impair SVP. | 
|---|
| 217 | // Default: 0,0,0 : WSize/2,1,WSize/2 | 
|---|
| 218 | { | 
|---|
| 219 | int_4 wsz2 = WSize/2; | 
|---|
| 220 | // Default | 
|---|
| 221 | if(wszl<=0 && wszc<=0 && wszr<=0) { | 
|---|
| 222 | WSizeLeft = WSizeRight = wsz2; WSizeCenter = 1; | 
|---|
| 223 | W0Left = 0; W0Center = wsz2;   W0Right = wsz2+1; | 
|---|
| 224 | return; | 
|---|
| 225 | } | 
|---|
| 226 |  | 
|---|
| 227 | // Fenetre centrale | 
|---|
| 228 | if(wszc<=0)    wszc = 1; | 
|---|
| 229 | if(wszc%2==0)  wszc++; | 
|---|
| 230 | if(wszc>WSize) wszc = WSize; | 
|---|
| 231 | WSizeCenter = wszc; | 
|---|
| 232 | W0Center = wsz2 - WSizeCenter/2; | 
|---|
| 233 |  | 
|---|
| 234 | // Fenetre de gauche | 
|---|
| 235 | if(wszl<=0) wszl = WSize; | 
|---|
| 236 | W0Left = W0Center - wszl; | 
|---|
| 237 | if(W0Left<0) W0Left = 0; | 
|---|
| 238 | WSizeLeft = W0Center - W0Left; | 
|---|
| 239 | if(WSizeLeft<=0) WSizeLeft = 1; | 
|---|
| 240 |  | 
|---|
| 241 | // Fenetre de droite | 
|---|
| 242 | if(wszr<=0) wszr = WSize; | 
|---|
| 243 | W0Right = W0Center + WSizeCenter; | 
|---|
| 244 | if(W0Right>=WSize) W0Right = WSize - 1; | 
|---|
| 245 | int_4 dum = W0Right + wszr; if(dum>WSize) dum = WSize; | 
|---|
| 246 | WSizeRight = dum - W0Right; | 
|---|
| 247 | if(WSizeRight<=0) WSizeRight = 1; | 
|---|
| 248 | } | 
|---|
| 249 |  | 
|---|
| 250 | TVector<r_8> GenWindowTOIProcessor::GetWData(char cw,int_4 numtoi) | 
|---|
| 251 | // cr='l' fenetre de gauche, 'c' du centre, 'r' de droite, autre = tout | 
|---|
| 252 | { | 
|---|
| 253 | if(numtoi<0 || numtoi>=NbInput) | 
|---|
| 254 | throw RangeCheckError("GenWindowTOIProcessor::GetWData(lcr) : toi out of range !"); | 
|---|
| 255 | if(!WInFlg[numtoi]) | 
|---|
| 256 | throw ParmError("GenWindowTOIProcessor::GetWData(lcr) : toi not connected!"); | 
|---|
| 257 | return (WDataIn[numtoi])(Range(StartWtIndex(cw),0,GetWSize(cw))); | 
|---|
| 258 | } | 
|---|
| 259 |  | 
|---|
| 260 | TVector<uint_8> GenWindowTOIProcessor::GetWFlag(char cw,int_4 numtoi) | 
|---|
| 261 | // cr='l' fenetre de gauche, 'c' du centre, 'r' de droite, autre = tout | 
|---|
| 262 | { | 
|---|
| 263 | if(numtoi<0 || numtoi>=NbInput) | 
|---|
| 264 | throw RangeCheckError("GenWindowTOIProcessor::GetWFlag(lcr) : toi out of range !"); | 
|---|
| 265 | if(!WInFlg[numtoi]) | 
|---|
| 266 | throw ParmError("GenWindowTOIProcessor::GetWFlag(lcr) : toi not connected!"); | 
|---|
| 267 | return (WFlagIn[numtoi])(Range(StartWtIndex(cw),0,GetWSize(cw))); | 
|---|
| 268 | } | 
|---|
| 269 |  | 
|---|
| 270 | r_8 * GenWindowTOIProcessor::GetWDataPointer(char cw,int_4 numtoi,int_4& n) | 
|---|
| 271 | // cr='l' fenetre de gauche, 'c' du centre, 'r' de droite, autre = tout | 
|---|
| 272 | { | 
|---|
| 273 | if(numtoi<0 || numtoi>=NbInput) | 
|---|
| 274 | throw RangeCheckError("GenWindowTOIProcessor::GetWDataPointe(lcr)r : toi out of range !"); | 
|---|
| 275 | if(!WInFlg[numtoi]) | 
|---|
| 276 | throw ParmError("GenWindowTOIProcessor::GetWDataPointer(lcr) : toi not connected!"); | 
|---|
| 277 | n = GetWSize(cw); | 
|---|
| 278 | return (WDataIn[numtoi].Data()+StartWtIndex(cw)); | 
|---|
| 279 |  | 
|---|
| 280 | } | 
|---|
| 281 |  | 
|---|
| 282 | uint_8 * GenWindowTOIProcessor::GetWFlagPointer(char cw,int_4 numtoi,int_4& n) | 
|---|
| 283 | // cr='l' fenetre de gauche, 'c' du centre, 'r' de droite, autre = tout | 
|---|
| 284 | { | 
|---|
| 285 | if(numtoi<0 || numtoi>=NbInput) | 
|---|
| 286 | throw RangeCheckError("GenWindowTOIProcessor::GetWFlagPointer(lcr) : toi out of range !"); | 
|---|
| 287 | if(!WInFlg[numtoi]) | 
|---|
| 288 | throw ParmError("GenWindowTOIProcessor::GetWFlagPointer(lcr) : toi not connected!"); | 
|---|
| 289 | n = GetWSize(cw); | 
|---|
| 290 | return (WFlagIn[numtoi].Data()+StartWtIndex(cw)); | 
|---|
| 291 | } | 
|---|
| 292 |  | 
|---|
| 293 | //////////////////////////////////////////////////////////////// | 
|---|
| 294 | void GenWindowTOIProcessor::UserInit(int_8 kstart) | 
|---|
| 295 | { | 
|---|
| 296 | cout<<"GenWindowTOIProcessor::UserInit() Default implementation does nothing"<<endl; | 
|---|
| 297 | } | 
|---|
| 298 |  | 
|---|
| 299 | void GenWindowTOIProcessor::UserProc(int_8 ks) | 
|---|
| 300 | { | 
|---|
| 301 | cout<<"GenWindowTOIProcessor:UserProc() Default implementation does nothing"<<endl; | 
|---|
| 302 | } | 
|---|
| 303 |  | 
|---|
| 304 | void GenWindowTOIProcessor::UserEnd(int_8 kend) | 
|---|
| 305 | { | 
|---|
| 306 | cout<<"GenWindowTOIProcessor::UserEnd() Default implementation does nothing"<<endl; | 
|---|
| 307 | } | 
|---|
| 308 |  | 
|---|
| 309 | //////////////////////////////////////////////////////////////// | 
|---|
| 310 | void GenWindowTOIProcessor::init() | 
|---|
| 311 | { | 
|---|
| 312 | cout << "GenWindowTOIProcessor::init" << endl; | 
|---|
| 313 | char buff[64]; | 
|---|
| 314 | int_4 k; | 
|---|
| 315 | for(k=0; k<NbInput; k++) { | 
|---|
| 316 | sprintf(buff,"in%d", k); | 
|---|
| 317 | declareInput(buff); | 
|---|
| 318 | } | 
|---|
| 319 | if(NbOutput) | 
|---|
| 320 | for(k=0; k<NbOutput; k++) { | 
|---|
| 321 | sprintf(buff,"out%d",k); | 
|---|
| 322 | declareOutput(buff); | 
|---|
| 323 | } | 
|---|
| 324 | name = "GenWindowTOIProcessor"; | 
|---|
| 325 | // upExtra = 1; $CHECK a quoi ca sert EA? | 
|---|
| 326 | } | 
|---|
| 327 |  | 
|---|
| 328 | void GenWindowTOIProcessor::run() | 
|---|
| 329 | { | 
|---|
| 330 | //  TOIManager* mgr = TOIManager::getManager(); | 
|---|
| 331 | SNbegin = getMinIn(); | 
|---|
| 332 | SNend   = getMaxIn(); | 
|---|
| 333 |  | 
|---|
| 334 | if(SNend-SNbegin<WSize) | 
|---|
| 335 | throw ParmError("GenWindowTOIProcessor::run : sne-snb<WSize !"); | 
|---|
| 336 |  | 
|---|
| 337 | // Allocation des tailles pour les vecteurs | 
|---|
| 338 | int_4 kc, nc=0; | 
|---|
| 339 | for(kc=0;kc<NbInput;kc++) { | 
|---|
| 340 | if( !(WInFlg[kc]=checkInputTOIIndex(kc)) ) continue; | 
|---|
| 341 | WDataIn[kc].ReSize(WSizeTot); | 
|---|
| 342 | WFlagIn[kc].ReSize(WSizeTot); | 
|---|
| 343 | nc++; | 
|---|
| 344 | } | 
|---|
| 345 | if(nc==0) { | 
|---|
| 346 | cerr<<" GenWindowTOIProcessor::run() - No input TOI connected!"<<endl; | 
|---|
| 347 | throw ParmError("GenWindowTOIProcessor::run() No input TOI connected!"); | 
|---|
| 348 | } | 
|---|
| 349 | if(NbOutput) | 
|---|
| 350 | for(kc=0;kc<NbOutput;kc++) WOutFlg[kc] = checkOutputTOIIndex(kc); | 
|---|
| 351 |  | 
|---|
| 352 | // Lecture des samples et remplissage des vecteurs | 
|---|
| 353 | cout<<"GenWindowTOIProcessor::run() SNRange="<<SNbegin<<" - "<<SNend<<endl; | 
|---|
| 354 | try { | 
|---|
| 355 | Timer tm("GenWindowTOIProcessor::run()"); | 
|---|
| 356 | int_4 wsz2=WSize/2; | 
|---|
| 357 | int_8 ksend = SNbegin; | 
|---|
| 358 | for(int_8 ks=SNbegin; ks<=SNend; ks+=WStep) { | 
|---|
| 359 |  | 
|---|
| 360 | Remplissage(ks); | 
|---|
| 361 | if(DbgLevel) test_avec_print(ks); | 
|---|
| 362 |  | 
|---|
| 363 | if(ks == SNbegin) {UserInit(ks); Ecriture();} | 
|---|
| 364 |  | 
|---|
| 365 | UserProc(ks); | 
|---|
| 366 | Ecriture(); | 
|---|
| 367 |  | 
|---|
| 368 | ksend = ks; | 
|---|
| 369 | TotNsCount++; | 
|---|
| 370 | } | 
|---|
| 371 | UserEnd(ksend); Ecriture(); | 
|---|
| 372 | cout << " GenWindowTOIProcessor::run() - End of processing " << endl; | 
|---|
| 373 |  | 
|---|
| 374 | } catch(PException & exc) { | 
|---|
| 375 | cerr<<"GenWindowTOIProcessor::run Catched Exception "<<(string)typeid(exc).name() | 
|---|
| 376 | <<"\n .... Msg= "<<exc.Msg()<<endl; | 
|---|
| 377 | } | 
|---|
| 378 | } | 
|---|
| 379 |  | 
|---|
| 380 | //////////////////////////////////////////////////////////////// | 
|---|
| 381 | void GenWindowTOIProcessor::Remplissage(int_8 ks) | 
|---|
| 382 | // INPUT: | 
|---|
| 383 | //   ks : numero du sample CENTRAL | 
|---|
| 384 | //      samples :   sn-ws/2        sn          sn+ws/2 | 
|---|
| 385 | //      fenetre :   0              ws/2+1      ws-1 | 
|---|
| 386 | // Cette routine doit etre utilisee dans une boucle: | 
|---|
| 387 | //      for(int k=???; k<???; k+=WStep) ..... | 
|---|
| 388 | // Dans le grand buffer WSizeTot il doit y avoir WSize samples | 
|---|
| 389 | //      entre ks1=ks-wsz2 et ks2=ks-wsz2  (ks1<=k<=ks2) | 
|---|
| 390 | // En ENTREE de cette routine : | 
|---|
| 391 | // - CurWtIndex = c'est l'index du tableau WSizeTot qui doit etre rempli | 
|---|
| 392 | //                (le dernier index qui a ete rempli par l'appel precedent | 
|---|
| 393 | //                 est donc CurWtIndex-1) | 
|---|
| 394 | // - LastFilledSn = c'est le dernier numero de sample qui a ete rempli | 
|---|
| 395 | //                  dans le tableau WSizeTot par l'appel precedent | 
|---|
| 396 | { | 
|---|
| 397 | int_4 wsz2=WSize/2; | 
|---|
| 398 |  | 
|---|
| 399 | // Numero de sample du premier element du tableau WSize | 
|---|
| 400 | //   (peut etre < SNbegin au debut) | 
|---|
| 401 | StartSample = ks - wsz2; | 
|---|
| 402 |  | 
|---|
| 403 | // on doit avoir les samples [ks1,ks2] dans le buffer | 
|---|
| 404 | // (mais selon le step, certain peuvent etre deja remplis) | 
|---|
| 405 | int_8 ks1 = ks-wsz2, ks2 = ks+wsz2; | 
|---|
| 406 |  | 
|---|
| 407 | if(DbgLevel>1) | 
|---|
| 408 | cout<<"DBG-GenWindowTOIProcessor::Remplissage("<<ks | 
|---|
| 409 | <<") ["<<ks1<<","<<ks2<<"]" | 
|---|
| 410 | <<" CurWtIndex="<<CurWtIndex<<" LastFilledSn="<<LastFilledSn<<endl; | 
|---|
| 411 |  | 
|---|
| 412 | //-------------------------------------------------------- | 
|---|
| 413 | // Premier remplissage ???? | 
|---|
| 414 | // Gestion de la borne inferieure pour le permier sample | 
|---|
| 415 | //-------------------------------------------------------- | 
|---|
| 416 | if(CurWtIndex<0) { | 
|---|
| 417 | if(DbgLevel>1) | 
|---|
| 418 | cout<<"DBG-GenWindowTOIProcessor::Remplissage 1ere fois"<<endl; | 
|---|
| 419 | for(int_4 ntoi=0; ntoi<NbInput; ntoi++) { | 
|---|
| 420 | if(!WInFlg[ntoi]) continue; | 
|---|
| 421 | for(int_8 k=ks1, j=0; k<=ks2; k++, j++) { | 
|---|
| 422 | if(k>=SNbegin && k<=SNend) { | 
|---|
| 423 | getData(ntoi,k,(WDataIn[ntoi])(j),(WFlagIn[ntoi])(j)); | 
|---|
| 424 | } else { | 
|---|
| 425 | (WDataIn[ntoi])(j) = R8DefVal; (WFlagIn[ntoi])(j) = I8DefVal; | 
|---|
| 426 | } | 
|---|
| 427 | } | 
|---|
| 428 | } | 
|---|
| 429 | CurWtIndex = ks2 - ks1 + 1; | 
|---|
| 430 | LastFilledSn = ks2; | 
|---|
| 431 | return; | 
|---|
| 432 | } | 
|---|
| 433 |  | 
|---|
| 434 | //-------------------------------------------------------- | 
|---|
| 435 | // Faut-il decaler ???? | 
|---|
| 436 | //-------------------------------------------------------- | 
|---|
| 437 | if(WStep>=WSize) { | 
|---|
| 438 | // On ne decale pas puisque entre 2 appels a la routine | 
|---|
| 439 | // il faut TOUT recharger (aucun sample deja charge n'est utile) | 
|---|
| 440 | CurWtIndex = 0; | 
|---|
| 441 | } else { | 
|---|
| 442 | // Certains samples deja charges sont utiles | 
|---|
| 443 | int_8 ifin = ks2 - LastFilledSn + CurWtIndex-1; | 
|---|
| 444 | if(ifin >= WSizeTot) { // On decale | 
|---|
| 445 | int_8 ideb = CurWtIndex-1 - LastFilledSn + ks1; | 
|---|
| 446 | if(DbgLevel>1) | 
|---|
| 447 | cout<<"DBG-GenWindowTOIProcessor::Remplissage ... Decalage ideb="<<ideb | 
|---|
| 448 | <<" ifin="<<ifin<< endl; | 
|---|
| 449 | for(int_4 ntoi=0; ntoi<NbInput; ntoi++) { | 
|---|
| 450 | if(!WInFlg[ntoi]) continue; | 
|---|
| 451 | for(int_4 i=ideb, j=0; i<CurWtIndex; i++, j++) { | 
|---|
| 452 | (WDataIn[ntoi])(j) = (WDataIn[ntoi])(i); | 
|---|
| 453 | (WFlagIn[ntoi])(j) = (WFlagIn[ntoi])(i); | 
|---|
| 454 | } | 
|---|
| 455 | } | 
|---|
| 456 | CurWtIndex = CurWtIndex-ideb; | 
|---|
| 457 | TotDecalCount++; | 
|---|
| 458 | } | 
|---|
| 459 | } | 
|---|
| 460 |  | 
|---|
| 461 | // Remplissage des samples utiles pour ks | 
|---|
| 462 | if(ks1<=LastFilledSn) ks1 = LastFilledSn+1; | 
|---|
| 463 | if(DbgLevel>1) | 
|---|
| 464 | cout<<"DBG-GenWindowTOIProcessor::Normal fill de ["<<ks1<<","<<ks2<<"]"<<endl; | 
|---|
| 465 | for(int_4 ntoi=0; ntoi<NbInput; ntoi++) { | 
|---|
| 466 | if(!WInFlg[ntoi]) continue; | 
|---|
| 467 | for(int_4 k=ks1, j=CurWtIndex; k<=ks2; k++, j++) { | 
|---|
| 468 | if(k>=SNbegin && k<=SNend) { | 
|---|
| 469 | getData(ntoi,k,(WDataIn[ntoi])(j),(WFlagIn[ntoi])(j)); | 
|---|
| 470 | } else { | 
|---|
| 471 | (WDataIn[ntoi])(j) = R8DefVal; (WFlagIn[ntoi])(j) = I8DefVal; | 
|---|
| 472 | } | 
|---|
| 473 | } | 
|---|
| 474 | } | 
|---|
| 475 | CurWtIndex += ks2 - ks1 + 1; | 
|---|
| 476 | LastFilledSn = ks2; | 
|---|
| 477 |  | 
|---|
| 478 | return; | 
|---|
| 479 | } | 
|---|
| 480 |  | 
|---|
| 481 | void GenWindowTOIProcessor::Ecriture() | 
|---|
| 482 | { | 
|---|
| 483 | int_8 maxlenout = 0; | 
|---|
| 484 | int kc; | 
|---|
| 485 | for(kc=0; kc<NbOutput; kc++) | 
|---|
| 486 | if(WOutFlg[kc] && WPutOutFlg[kc] && (WDataOut[kc].Size() > maxlenout) ) | 
|---|
| 487 | maxlenout = WDataOut[kc].Size(); | 
|---|
| 488 |  | 
|---|
| 489 | for(int_8 k=0; k<maxlenout; k++) { | 
|---|
| 490 | for(int kc=0; kc<NbOutput; kc++) { | 
|---|
| 491 | if(!WOutFlg[kc]) continue; | 
|---|
| 492 | if(!WPutOutFlg[kc]) continue; | 
|---|
| 493 | if(k>=WDataOut[kc].Size()) continue; | 
|---|
| 494 | putData(kc, k+OutSample[kc], (WDataOut[kc])(k), (WFlagOut[kc])(k)); | 
|---|
| 495 | } | 
|---|
| 496 | } | 
|---|
| 497 | for(kc=0; kc<NbOutput; kc++)  WPutOutFlg[kc] = false; | 
|---|
| 498 | } | 
|---|
| 499 |  | 
|---|
| 500 | //////////////////////////////////////////////////////////////// | 
|---|
| 501 | void  GenWindowTOIProcessor::test_avec_print(int_8 ks) | 
|---|
| 502 | { | 
|---|
| 503 | if(DbgLevel<=0) return; | 
|---|
| 504 |  | 
|---|
| 505 | int i,ii=0; | 
|---|
| 506 | r_8   * datatot = WDataIn[0].Data(); | 
|---|
| 507 | uint_8 * flagtot = WFlagIn[0].Data(); | 
|---|
| 508 | r_8   * data = GetWDataPointer(); | 
|---|
| 509 | uint_8 * flag = GetWFlagPointer(); | 
|---|
| 510 | int_4 nl,nc,nr; | 
|---|
| 511 | r_8   * datal = GetWDataPointer('l',nl); | 
|---|
| 512 | uint_8 * flagl = GetWFlagPointer('l',nl); | 
|---|
| 513 | r_8   * datac = GetWDataPointer('c',nc); | 
|---|
| 514 | uint_8 * flagc = GetWFlagPointer('c',nc); | 
|---|
| 515 | r_8   * datar = GetWDataPointer('r',nr); | 
|---|
| 516 | uint_8 * flagr = GetWFlagPointer('r',nr); | 
|---|
| 517 |  | 
|---|
| 518 | cout<<"-------- ks = "<<ks<<endl; | 
|---|
| 519 |  | 
|---|
| 520 | if(DbgLevel>2) { | 
|---|
| 521 | cout<<"datatot = "; | 
|---|
| 522 | for(i=0;i<WSizeTot;i++) {ii=0; cout<<" "<<datatot[i]; if(i%10==9) {cout<<endl; ii=1;}} | 
|---|
| 523 | if(ii==0) cout<<endl; | 
|---|
| 524 | cout<<"flagtot = "; | 
|---|
| 525 | for(i=0;i<WSizeTot;i++) {ii=0; cout<<" "<<flagtot[i]; if(i%10==9) {cout<<endl; ii=1;}} | 
|---|
| 526 | if(ii==0) cout<<endl; | 
|---|
| 527 | } | 
|---|
| 528 |  | 
|---|
| 529 | cout<<"data = "; | 
|---|
| 530 | for(i=0;i<GetWSize();i++) {ii=0; cout<<" "<<data[i]; if(i%10==9) {cout<<endl; ii=1;}} | 
|---|
| 531 | if(ii==0) cout<<endl; | 
|---|
| 532 | cout<<"flag = "; | 
|---|
| 533 | for(i=0;i<GetWSize();i++) {ii=0; cout<<" "<<flag[i]; if(i%10==9) {cout<<endl; ii=1;}} | 
|---|
| 534 | if(ii==0) cout<<endl; | 
|---|
| 535 |  | 
|---|
| 536 | if(DbgLevel>2) { | 
|---|
| 537 | cout<<"datal = "; | 
|---|
| 538 | for(i=0;i<nl;i++) {ii=0; cout<<" "<<datal[i]; if(i%10==9) {cout<<endl; ii=1;}} | 
|---|
| 539 | if(ii==0) cout<<endl; | 
|---|
| 540 | cout<<"flagl = "; | 
|---|
| 541 | for(i=0;i<nl;i++) {ii=0; cout<<" "<<flagl[i]; if(i%10==9) {cout<<endl; ii=1;}} | 
|---|
| 542 | if(ii==0) cout<<endl; | 
|---|
| 543 | cout<<"datac = "; | 
|---|
| 544 | for(i=0;i<nc;i++) {ii=0; cout<<" "<<datac[i]; if(i%10==9) {cout<<endl; ii=1;}} | 
|---|
| 545 | if(ii==0) cout<<endl; | 
|---|
| 546 | cout<<"flagc = "; | 
|---|
| 547 | for(i=0;i<nc;i++) {ii=0; cout<<" "<<flagc[i]; if(i%10==9) {cout<<endl; ii=1;}} | 
|---|
| 548 | if(ii==0) cout<<endl; | 
|---|
| 549 | cout<<"datar = "; | 
|---|
| 550 | for(i=0;i<nr;i++) {ii=0; cout<<" "<<datar[i]; if(i%10==9) {cout<<endl; ii=1;}} | 
|---|
| 551 | if(ii==0) cout<<endl; | 
|---|
| 552 | cout<<"flagr = "; | 
|---|
| 553 | for(i=0;i<nr;i++) {ii=0; cout<<" "<<flagr[i]; if(i%10==9) {cout<<endl; ii=1;}} | 
|---|
| 554 | if(ii==0) cout<<endl; | 
|---|
| 555 | } | 
|---|
| 556 | } | 
|---|