// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL // Eric Aubourg // Christophe Magneville // Reza Ansari // $Id: genwproc.cc,v 1.8 2001-11-13 16:22:46 aubourg Exp $ #include "array.h" #include #include "genwproc.h" #include "toimanager.h" #include "pexceptions.h" #include "ctimer.h" // ------------------------------------------------------------- // Class GenWindowTOIProcessor : generic processor with window // ------------------------------------------------------------- //////////////////////////////////////////////////////////////// GenWindowTOIProcessor::GenWindowTOIProcessor(int_4 nbinput,int_4 nboutput ,int_4 wsz, int_4 wstep, int_4 wsztot) { if(nbinput<1) throw ParmError("GenWindowTOIProcessor::Creator nbinput<1 !"); if(nboutput<0) nboutput=0; if(wsz<2) throw ParmError("GenWindowTOIProcessor::Creator wsz<2 !"); if(wsz%2==0) {if(wsztot==wsz) wsztot++; wsz++;} if(wstep<1) wstep=1; if(wsztot=wsz) wsztot = wsz; NbInput = nbinput; NbOutput = nboutput; WSize = wsz; WStep = wstep; WSizeTot = wsztot; CurWtIndex = -1; SNbegin = SNend = StartSample = LastFilledSn = -1; TotNsCount = TotDecalCount = 0; SetDbgLevel(); SetWSizeLCR(); SetDefaultValue(); TVector vr8(1); // CMV+RZ supprimer taille(1) apres correction de TVector vi8(1); // constructeur copie de TArray (taille nulle) int_4 k; for(k=0;k GenWindowTOIProcessor::GetWData(int_4 numtoi) { if(numtoi<0 || numtoi>=NbInput) throw RangeCheckError("GenWindowTOIProcessor::GetWData : toi out of range !"); if(!WInFlg[numtoi]) throw ParmError("GenWindowTOIProcessor::GetWData : toi not connected!"); return (WDataIn[numtoi])(Range(StartWtIndex(),0,WSize)); } TVector GenWindowTOIProcessor::GetWFlag(int_4 numtoi) { if(numtoi<0 || numtoi>=NbInput) throw RangeCheckError("GenWindowTOIProcessor::GetWFlag : toi out of range !"); if(!WInFlg[numtoi]) throw ParmError("GenWindowTOIProcessor::GetWFlag : toi not connected!"); return (WFlagIn[numtoi])(Range(StartWtIndex(),0,WSize)); } r_8 * GenWindowTOIProcessor::GetWDataPointer(int_4 numtoi) { if(numtoi<0 || numtoi>=NbInput) throw RangeCheckError("GenWindowTOIProcessor::GetWDataPointer : toi out of range !"); if(!WInFlg[numtoi]) throw ParmError("GenWindowTOIProcessor::GetWDataPointer : toi not connected!"); return (WDataIn[numtoi].Data()+StartWtIndex()); } uint_8 * GenWindowTOIProcessor::GetWFlagPointer(int_4 numtoi) { if(numtoi<0 || numtoi>=NbInput) throw RangeCheckError("GenWindowTOIProcessor::GetWFlagPointer : toi out of range !"); if(!WInFlg[numtoi]) throw ParmError("GenWindowTOIProcessor::GetWFlagPointer : toi not connected!"); return (WFlagIn[numtoi].Data()+StartWtIndex()); } void GenWindowTOIProcessor::GetData(int_4 numtoi, int_8 numsample, r_8 & data, uint_8 & flag) { if(numtoi<0 || numtoi>=NbInput) throw RangeCheckError("GenWindowTOIProcessor::GetData : toi out of range !"); if(!WInFlg[numtoi]) throw ParmError("GenWindowTOIProcessor::GetData : toi not connected!"); int_8 k = numsample-GetWStartSample(); if ((k<0) || (k >= GetWSize())) throw RangeCheckError("GenWindowTOIProcessor::GetData : numsample out of window!"); k += StartWtIndex(); data = (WDataIn[numtoi])(k); flag = (WFlagIn[numtoi])(k); } //////////////////////////////////////////////////////////////// void GenWindowTOIProcessor::PutWData(int numtoi,int_8 numsample ,TVector& data,TVector& flag) { if(numtoi<0 || numtoi>=NbOutput || NbOutput<=0) throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi out of range !"); if(!WOutFlg[numtoi]) throw ParmError("GenWindowTOIProcessor::PutWFlag : toi not connected!"); if(data.Size()!=flag.Size()) throw ParmError("GenWindowTOIProcessor::PutWFlag : data.Size()!=flag.Size()!"); if(data.Size() == 0) throw ParmError("GenWindowTOIProcessor::PutWFlag : data.Size()==0 !"); WDataOut[numtoi].Share(data); WFlagOut[numtoi].Share(flag); OutSample[numtoi] = numsample; WPutOutFlg[numtoi] = true; WPutOutOwnVector[numtoi] = false; } void GenWindowTOIProcessor::PutWData(int numtoi,int_8 numsample , r_8 data, uint_8 flag) { if(numtoi<0 || numtoi>=NbOutput || NbOutput<=0) throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi out of range !"); if(!WOutFlg[numtoi]) throw ParmError("GenWindowTOIProcessor::PutWFlag : toi not connected!"); if (!WPutOutOwnVector[numtoi]) { WDataOut[numtoi].Realloc(1,BaseArray::SameVectorType,true); WFlagOut[numtoi].Realloc(1,BaseArray::SameVectorType,true); WPutOutOwnVector[numtoi] = true; } (WDataOut[numtoi])(0) = data; (WFlagOut[numtoi])(0) = flag; OutSample[numtoi] = numsample; WPutOutFlg[numtoi] = true; } /******* cmv routines void GenWindowTOIProcessor::PutWData(int_4 numtoi,int_8 numsample ,TVector& data,TVector& flag) { if(numtoi<0 || numtoi>=NbOutput || NbOutput<=0) throw RangeCheckError("GenWindowTOIProcessor::PutWData : toi out of range !"); if(!WOutFlg[numtoi]) throw ParmError("GenWindowTOIProcessor::PutWData : toi not connected!"); if(data.Size()!=flag.Size()) throw ParmError("GenWindowTOIProcessor::PutWData : data.Size()!=flag.Size()!"); if(data.Size() == 0) throw ParmError("GenWindowTOIProcessor::PutWData : data.Size()==0 !"); for(int_4 k=0;k=NbOutput || NbOutput<=0) throw RangeCheckError("GenWindowTOIProcessor::PutWData : toi out of range !"); if(!WOutFlg[numtoi]) throw ParmError("GenWindowTOIProcessor::PutWData : toi not connected!"); putData(numtoi,numsample,data,flag); } *********/ //////////////////////////////////////////////////////////////// void GenWindowTOIProcessor::SetWSizeLCR(int_4 wszl,int_4 wszc,int_4 wszr) // Fenetre a gauche, au centre et a droite du pixel central // Selon la logique: //----------------------------------------------- // | pixel central // | // | // | wszl | wszc | wszr | // | // | WSize | //----------------------------------------------- // wszc toujours impair SVP. // Default: 0,0,0 : WSize/2,1,WSize/2 { int_4 wsz2 = WSize/2; // Default if(wszl<=0 && wszc<=0 && wszr<=0) { WSizeLeft = WSizeRight = wsz2; WSizeCenter = 1; W0Left = 0; W0Center = wsz2; W0Right = wsz2+1; return; } // Fenetre centrale if(wszc<=0) wszc = 1; if(wszc%2==0) wszc++; if(wszc>WSize) wszc = WSize; WSizeCenter = wszc; W0Center = wsz2 - WSizeCenter/2; // Fenetre de gauche if(wszl<=0) wszl = WSize; W0Left = W0Center - wszl; if(W0Left<0) W0Left = 0; WSizeLeft = W0Center - W0Left; if(WSizeLeft<=0) WSizeLeft = 1; // Fenetre de droite if(wszr<=0) wszr = WSize; W0Right = W0Center + WSizeCenter; if(W0Right>=WSize) W0Right = WSize - 1; int_4 dum = W0Right + wszr; if(dum>WSize) dum = WSize; WSizeRight = dum - W0Right; if(WSizeRight<=0) WSizeRight = 1; } TVector GenWindowTOIProcessor::GetWData(char cw,int_4 numtoi) // cr='l' fenetre de gauche, 'c' du centre, 'r' de droite, autre = tout { if(numtoi<0 || numtoi>=NbInput) throw RangeCheckError("GenWindowTOIProcessor::GetWData(lcr) : toi out of range !"); if(!WInFlg[numtoi]) throw ParmError("GenWindowTOIProcessor::GetWData(lcr) : toi not connected!"); return (WDataIn[numtoi])(Range(StartWtIndex(cw),0,GetWSize(cw))); } TVector GenWindowTOIProcessor::GetWFlag(char cw,int_4 numtoi) // cr='l' fenetre de gauche, 'c' du centre, 'r' de droite, autre = tout { if(numtoi<0 || numtoi>=NbInput) throw RangeCheckError("GenWindowTOIProcessor::GetWFlag(lcr) : toi out of range !"); if(!WInFlg[numtoi]) throw ParmError("GenWindowTOIProcessor::GetWFlag(lcr) : toi not connected!"); return (WFlagIn[numtoi])(Range(StartWtIndex(cw),0,GetWSize(cw))); } r_8 * GenWindowTOIProcessor::GetWDataPointer(char cw,int_4 numtoi,int_4& n) // cr='l' fenetre de gauche, 'c' du centre, 'r' de droite, autre = tout { if(numtoi<0 || numtoi>=NbInput) throw RangeCheckError("GenWindowTOIProcessor::GetWDataPointe(lcr)r : toi out of range !"); if(!WInFlg[numtoi]) throw ParmError("GenWindowTOIProcessor::GetWDataPointer(lcr) : toi not connected!"); n = GetWSize(cw); return (WDataIn[numtoi].Data()+StartWtIndex(cw)); } uint_8 * GenWindowTOIProcessor::GetWFlagPointer(char cw,int_4 numtoi,int_4& n) // cr='l' fenetre de gauche, 'c' du centre, 'r' de droite, autre = tout { if(numtoi<0 || numtoi>=NbInput) throw RangeCheckError("GenWindowTOIProcessor::GetWFlagPointer(lcr) : toi out of range !"); if(!WInFlg[numtoi]) throw ParmError("GenWindowTOIProcessor::GetWFlagPointer(lcr) : toi not connected!"); n = GetWSize(cw); return (WFlagIn[numtoi].Data()+StartWtIndex(cw)); } //////////////////////////////////////////////////////////////// void GenWindowTOIProcessor::UserInit(int_8 kstart) { cout<<"GenWindowTOIProcessor::UserInit() Default implementation does nothing"<=SNbegin && k<=SNend) { getData(ntoi,k,(WDataIn[ntoi])(j),(WFlagIn[ntoi])(j)); } else { (WDataIn[ntoi])(j) = R8DefVal; (WFlagIn[ntoi])(j) = I8DefVal; } } } CurWtIndex = ks2 - ks1 + 1; LastFilledSn = ks2; return; } //-------------------------------------------------------- // Faut-il decaler ???? //-------------------------------------------------------- if(WStep>=WSize) { // On ne decale pas puisque entre 2 appels a la routine // il faut TOUT recharger (aucun sample deja charge n'est utile) CurWtIndex = 0; } else { // Certains samples deja charges sont utiles int_8 ifin = ks2 - LastFilledSn + CurWtIndex-1; if(ifin >= WSizeTot) { // On decale int_8 ideb = CurWtIndex-1 - LastFilledSn + ks1; if(DbgLevel>1) cout<<"DBG-GenWindowTOIProcessor::Remplissage ... Decalage ideb="<=SNbegin && k<=SNend) { getData(ntoi,k,(WDataIn[ntoi])(j),(WFlagIn[ntoi])(j)); } else { (WDataIn[ntoi])(j) = R8DefVal; (WFlagIn[ntoi])(j) = I8DefVal; } } } CurWtIndex += ks2 - ks1 + 1; LastFilledSn = ks2; return; } void GenWindowTOIProcessor::Ecriture() { int_8 maxlenout = 0; int kc; for(kc=0; kc maxlenout) ) maxlenout = WDataOut[kc].Size(); for(int_8 k=0; k=WDataOut[kc].Size()) continue; putData(kc, k+OutSample[kc], (WDataOut[kc])(k), (WFlagOut[kc])(k)); } } for(kc=0; kc2) { cout<<"datal = "; for(i=0;i