Changeset 1496 in Sophya for trunk/ArchTOIPipe/ProcWSophya


Ignore:
Timestamp:
May 16, 2001, 4:26:28 PM (24 years ago)
Author:
ansari
Message:

2eme version de genwproc + programme de test rz+cmv 16/5/2001

Location:
trunk/ArchTOIPipe/ProcWSophya
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ArchTOIPipe/ProcWSophya/genwproc.cc

    r1495 r1496  
    66#include "ctimer.h"
    77
     8
     9// #define DEBUGGENW 1
     10
    811// -------------------------------------------------------------
    912//   Class GenWindowTOIProcessor : generic processor with window
     
    1922  if(wsz%2==0) wsz++;
    2023  if(wstep<1) wstep=1;
    21   if(wsztot<wsz) wsztot = 2*wsz;
     24  if(wsztot<wsz) wsztot = 2*wsz;  // CMV prise de decision wsztot / wstep
    2225
    2326  NbInput = nbinput;
     
    2730  WSizeTot = wsztot;
    2831
    29   SNdeb = SNend = StartSample = CurSnInd = -1;
     32  SNdeb = SNend = StartSample = CurWtIndex = -1;
    3033  TotNsCount = 0;
    3134
    32   TVector<r_8> vr8;
    33   TVector<int_8> vi8;
     35  SetDefaultValue();
     36
     37  TVector<r_8> vr8(1);     // CMV+RZ supprimer taille(1) apres correction de
     38  TVector<int_8> vi8(1);   // constructeur copie de TArray (taille nulle)
    3439 
    3540  int k;
     
    4449    WOutFlg.push_back(false);
    4550    WPutOutFlg.push_back(false);
     51    WPutOutOwnVector.push_back(false);
    4652    OutSample.push_back(0);
    4753  }
     
    7177    throw RangeCheckError("GenWindowTOIProcessor::GetWData : toi out of range !");
    7278  if(!WInFlg[numtoi])
    73     throw RangeCheckError("GenWindowTOIProcessor::GetWData : toi not connected!");
    74   return WDataIn[numtoi];
     79    throw ParmError("GenWindowTOIProcessor::GetWData : toi not connected!");
     80  return (WDataIn[numtoi])(Range(StartWtIndex(),0,WSize));
    7581}
    7682
     
    8086    throw RangeCheckError("GenWindowTOIProcessor::GetWFlag : toi out of range !");
    8187  if(!WInFlg[numtoi])
    82     throw RangeCheckError("GenWindowTOIProcessor::GetWFlag : toi not connected!");
    83   return WFlagIn[numtoi];
     88    throw ParmError("GenWindowTOIProcessor::GetWFlag : toi not connected!");
     89  return (WFlagIn[numtoi])(Range(StartWtIndex(),0,WSize));
     90}
     91
     92r_8 * GenWindowTOIProcessor::GetWDataPointer(int numtoi)
     93{
     94  if(numtoi<0 || numtoi>=NbInput)
     95    throw RangeCheckError("GenWindowTOIProcessor::GetWDataPointer : toi out of range !");
     96  if(!WInFlg[numtoi])
     97    throw ParmError("GenWindowTOIProcessor::GetWDataPointer : toi not connected!");
     98  return (WDataIn[numtoi].Data()+StartWtIndex());
     99
     100}
     101 
     102int_8 * GenWindowTOIProcessor::GetWFlagPointer(int numtoi)
     103{
     104  if(numtoi<0 || numtoi>=NbInput)
     105    throw RangeCheckError("GenWindowTOIProcessor::GetWFlagPointer : toi out of range !");
     106  if(!WInFlg[numtoi])
     107    throw ParmError("GenWindowTOIProcessor::GetWFlagPointer : toi not connected!");
     108  return (WFlagIn[numtoi].Data()+StartWtIndex());
     109}
     110
     111void GenWindowTOIProcessor::GetData(int numtoi, int_8 numsample, r_8 & data, int_8 & flag)
     112{
     113  if(numtoi<0 || numtoi>=NbInput)
     114    throw RangeCheckError("GenWindowTOIProcessor::GetData : toi out of range !");
     115  if(!WInFlg[numtoi])
     116    throw ParmError("GenWindowTOIProcessor::GetData : toi not connected!");
     117  int_8 k = numsample-GetStartSample();
     118  if ((k<0) || (k >= GetWSize()))
     119    throw RangeCheckError("GenWindowTOIProcessor::GetData : numsample out of window!");
     120  k += StartWtIndex();
     121  data = (WDataIn[numtoi])(k);
     122  flag = (WFlagIn[numtoi])(k);
    84123}
    85124
     
    91130    throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi out of range !");
    92131  if(!WOutFlg[numtoi])
    93     throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi not connected!");
     132    throw ParmError("GenWindowTOIProcessor::PutWFlag : toi not connected!");
    94133  if(data.Size()!=flag.Size())
    95134    throw ParmError("GenWindowTOIProcessor::PutWFlag : data.Size()!=flag.Size()!");
     135  if(data.Size() == 0)
     136    throw ParmError("GenWindowTOIProcessor::PutWFlag : data.Size()==0 !");
    96137  WDataOut[numtoi].Share(data);
    97138  WFlagOut[numtoi].Share(flag);
    98139  OutSample[numtoi] = numsample;
    99140  WPutOutFlg[numtoi] = true;
     141  WPutOutOwnVector[numtoi] = false;
    100142}
    101143
     
    106148    throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi out of range !");
    107149  if(!WOutFlg[numtoi])
    108     throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi not connected!");
    109   WDataOut[numtoi].Realloc(1,BaseArray::SameVectorType,true);
    110     (WDataOut[numtoi])(0) = data;
    111   WFlagOut[numtoi].Realloc(1,BaseArray::SameVectorType,true);
    112     (WFlagOut[numtoi])(0) = flag;
     150    throw ParmError("GenWindowTOIProcessor::PutWFlag : toi not connected!");
     151  if (!WPutOutOwnVector[numtoi]) {
     152    WDataOut[numtoi].Realloc(1,BaseArray::SameVectorType,true);
     153    WFlagOut[numtoi].Realloc(1,BaseArray::SameVectorType,true);
     154    WPutOutOwnVector[numtoi] = true;
     155  }
     156  (WDataOut[numtoi])(0) = data;
     157  (WFlagOut[numtoi])(0) = flag;
    113158  OutSample[numtoi] = numsample;
    114159  WPutOutFlg[numtoi] = true;
     
    116161
    117162////////////////////////////////////////////////////////////////
    118 void GenWindowTOIProcessor::UserInit()
     163void GenWindowTOIProcessor::UserInit(int_8 kstart)
    119164{
    120165  cout<<"GenWindowTOIProcessor::UserInit() Default implementation does nothing"<<endl;
    121166}
    122167
    123 void GenWindowTOIProcessor::UserProc()
     168void GenWindowTOIProcessor::UserProc(int_8 ks)
    124169{
    125170  cout<<"GenWindowTOIProcessor:UserProc() Default implementation does nothing"<<endl;
    126171}
    127172
    128 void GenWindowTOIProcessor::UserEnd()
     173void GenWindowTOIProcessor::UserEnd(int_8 kend)
    129174{
    130175  cout<<"GenWindowTOIProcessor::UserEnd() Default implementation does nothing"<<endl;
     
    152197{
    153198  //  TOIManager* mgr = TOIManager::getManager();
    154   int_8 SNdeb = getMinIn();
    155   int_8 SNend = getMaxIn();
     199  SNdeb = getMinIn();
     200  SNend = getMaxIn();
    156201  if(SNend-SNdeb<WSize)
    157     throw RangeCheckError("GenWindowTOIProcessor::run : sne-snb<WSize !");
     202    throw ParmError("GenWindowTOIProcessor::run : sne-snb<WSize !");
    158203
    159204  // Allocation des tailles pour les vecteurs
     
    169214    throw ParmError("GenWindowTOIProcessor::run() No input TOI connected!");
    170215  }
    171   for(kc=0;kc<NbOutput;kc++)
    172       WOutFlg[kc] = checkOutputTOIIndex(kc);
     216  for(kc=0;kc<NbOutput;kc++) WOutFlg[kc] = checkOutputTOIIndex(kc);
    173217
    174218  // Lecture des samples et remplissage des vecteurs
     
    176220  try {
    177221    Timer tm("GenWindowTOIProcessor::run()");
    178     int_8 ki = -1;
    179 
    180     for(int_8 ks=SNdeb;ks<=SNend;ks++) {
     222    for(int_8 ks=SNdeb;ks<=SNend;ks++) {  // CMV gerer le += step
    181223      Remplissage(ks);
     224      if (ks == SNdeb) {
     225        UserInit(ks);
     226        Ecriture();
     227      }
     228      if ((ks-SNdeb)%WStep == 0) {
     229        UserProc(ks);
     230        // Il faut traiter les ecritures en sortie
     231        Ecriture();
     232      }
    182233      TotNsCount++;
    183234    }
     235    UserEnd(SNend);
     236    Ecriture();
    184237    cout << " GenWindowTOIProcessor::run() - End of processing " << endl;
    185238
    186239  } catch(PException & exc) {
    187     cerr<<"GenWindowTOIProcessor: Catched Exception "<<(string)typeid(exc).name()
     240    cerr<<"GenWindowTOIProcessor::run Catched Exception "<<(string)typeid(exc).name()
    188241        <<"\n .... Msg= "<<exc.Msg()<<endl;
    189242  }
     
    196249//      samples :   sn-ws/2        sn          sn+ws/2
    197250//      fenetre :   0              ws/2+1      ws-1
    198 //   ki : index des vecteurs a remplir.
    199 //        C'est l'index ou on veut remplir la donnee
    200 //        dans un vecteur (fictif) de taille WSize.
    201 //        La routine gere le decalage dans le grand buffer WSizeTot.
    202 //  Si ki depasse la taille maximale permise on decale, sinon on ne fait rien
    203 // RETURN:
    204 //   numero du PROCHAIN index a remplir (ki+1 si pas decale !)
    205 {
    206 if(ks<SNdeb || ks>SNend)
     251{
     252#ifdef DEBUGGENW
     253 cout << "GenWindowTOIProcessor::Remplissage(" << ks << ") CurWtIndex=" << CurWtIndex << endl;
     254#endif
     255
     256if(ks<SNdeb || ks>SNend) {
     257  cerr << "GenWindowTOIProcessor::remplissage/Erreur : ks(=" << ks << ") <"
     258       << SNdeb << " || ks>" << SNend << endl;
    207259  throw RangeCheckError("GenWindowTOIProcessor::remplissage : ks<SNdeb || ks>SNend !");
    208 
     260 }
    209261int_8 wsz2=WSize/2;
    210262
     
    212264
    213265// Premier remplissage ???? Gestion de la borne inferieure
    214 if(CurSnInd<0) {
    215   CurSnInd = 0;
     266if(CurWtIndex<0) {
     267#ifdef DEBUGGENW
     268  cout << "GenWindowTOIProcessor::Remplissage 1ere fois" << endl;
     269#endif
     270  CurWtIndex = 0;
    216271  for(int_8 k=ks-wsz2; k<=ks+wsz2; k++) { // Lecture TOI
    217272    for(int kc=0; kc<NbInput; kc++) {
    218273      if(!WInFlg[kc]) continue;
    219274      if(k>=SNdeb && k<=SNend) {
    220         getData(kc,k,(WDataIn[kc])(CurSnInd), (WFlagIn[kc])(CurSnInd));
     275        getData(kc,k,(WDataIn[kc])(CurWtIndex), (WFlagIn[kc])(CurWtIndex));
    221276      } else {
    222         (WDataIn[kc])(CurSnInd) = (r_8) 0.;
    223         (WFlagIn[kc])(CurSnInd) = (int_8) 0;
     277        (WDataIn[kc])(CurWtIndex) = R8DefVal;
     278        (WFlagIn[kc])(CurWtIndex) = I8DefVal;
    224279      }
    225280    }
    226     CurSnInd++;
     281    CurWtIndex++;
    227282  }
    228283  return;
    229284}
    230285
     286// CMV gere decalage seulement si step < wsize sinon copie.
    231287// Faut-il decaler ????
    232 if(CurSnInd == WSizeTot) { // On decale
     288if(CurWtIndex == WSizeTot) { // On decale
     289#ifdef DEBUGGENW
     290  cout << "GenWindowTOIProcessor::Remplissage Decalage " << endl;
     291#endif
    233292  for(int kc=0; kc<NbInput; kc++) {
    234293    if(!WInFlg[kc]) continue;
     
    238297      }
    239298  }
    240   CurSnInd = WSize-1;
     299  CurWtIndex = WSize-1;
    241300}
    242301
    243302// Remplissage de ks+wsz2 (dernier element de la fenetre pour ks central)
    244303int_8 kse = ks+wsz2;
     304#ifdef DEBUGGENW
     305  cout << "GenWindowTOIProcessor::Normal fill " << endl;
     306#endif
    245307for(int kc=0; kc<NbInput; kc++) {
    246308  if(!WInFlg[kc]) continue;
    247309  if(kse>=SNdeb && kse<=SNend) {
    248     getData(kc,kse,(WDataIn[kc])(CurSnInd),(WFlagIn[kc])(CurSnInd));
     310    getData(kc,kse,(WDataIn[kc])(CurWtIndex),(WFlagIn[kc])(CurWtIndex));
    249311  } else {
    250     (WDataIn[kc])(CurSnInd) = (r_8) 0.;
    251     (WFlagIn[kc])(CurSnInd) = (int_8) 0;
    252   }
    253 }
    254 CurSnInd++;
     312    (WDataIn[kc])(CurWtIndex) = R8DefVal;
     313    (WFlagIn[kc])(CurWtIndex) = I8DefVal;
     314  }
     315}
     316CurWtIndex++;
    255317
    256318return;
    257319}
     320
     321void GenWindowTOIProcessor::Ecriture()
     322{
     323  int_8 maxlenout = 0;
     324  int kc;
     325  for(kc=0; kc<NbOutput; kc++)
     326    if(WOutFlg[kc] && WPutOutFlg[kc] && (WDataOut[kc].Size() > maxlenout) )
     327      maxlenout = WDataOut[kc].Size();
     328
     329  for(int_8 k=0; k<maxlenout; k++) {
     330    for(int kc=0; kc<NbOutput; kc++) {
     331      if(!WOutFlg[kc]) continue;
     332      if(!WPutOutFlg[kc]) continue;
     333      if(k>=WDataOut[kc].Size()) continue;
     334      putData(kc, k+OutSample[kc], (WDataOut[kc])(k), (WFlagOut[kc])(k));     
     335    }
     336  }
     337  for(kc=0; kc<NbOutput; kc++)  WPutOutFlg[kc] = false;
     338}
  • trunk/ArchTOIPipe/ProcWSophya/genwproc.h

    r1495 r1496  
    1313public:
    1414  GenWindowTOIProcessor(int nbinput,int nboutput,int wsz, int wstep=1, int wsztot=-1);
    15   ~GenWindowTOIProcessor();
     15  virtual ~GenWindowTOIProcessor();
    1616
    1717  inline int_8 GetWSize() const { return WSize; }
     
    2121  inline int_8 GetStartSample()  {return StartSample;}
    2222  inline int_8 GetCenterSample() {return StartSample + WSize/2;}
     23  inline int_8 StartSampleNum() { return SNdeb; }
     24  inline int_8 EndSampleNum() { return SNend; }
     25
     26  inline void SetDefaultValue(r_8 r8dval=0., int_8 i8dval=0)
     27                      {R8DefVal = r8dval; I8DefVal = i8dval;}
     28
    2329  TVector<r_8> GetWData(int numtoi=0);
    2430  TVector<int_8> GetWFlag(int numtoi=0);
     31  r_8 * GetWDataPointer(int numtoi=0);
     32  int_8 * GetWFlagPointer(int numtoi=0);
     33  void GetData(int numtoi, int_8 numsample, r_8 & data, int_8 & flag);
     34  inline void GetData(int_8 numsample, r_8 & data, int_8 & flag)
     35                      { GetData(0, numsample, data, flag); }
     36
    2537  void PutWData(int numtoi,int_8 numsample,TVector<r_8>& data,TVector<int_8>& flag);
    2638  void PutWData(int numtoi,int_8 numsample,r_8 data,int_8 flag);
     
    3244  virtual void PrintStatus(ostream & os);
    3345
    34   virtual void UserInit();
    35   virtual void UserProc();
    36   virtual void UserEnd();
     46  virtual void UserInit(int_8 kstart);
     47  virtual void UserProc(int_8 ks);
     48  virtual void UserEnd(int_8 kend);
    3749
    3850  virtual void  init(); 
     
    4153protected:
    4254  void Remplissage(int_8 ks);
    43   inline int_8 StartSnIndex()
    44          {if(CurSnInd<0) return -1; else return CurSnInd-WSize;}
    45   inline int_8 CenterSnIndex()
    46          {if(CurSnInd<0) return -1; else return CurSnInd-(WSize+1)/2;}
     55  void Ecriture();
     56  inline int_8 StartWtIndex()
     57         {if(CurWtIndex<0) return -1; else return CurWtIndex-WSize;}
     58  inline int_8 CenterWtIndex()
     59         {if(CurWtIndex<0) return -1; else return CurWtIndex-(WSize+1)/2;}
    4760
    4861  int NbInput,NbOutput;
    4962  int_8 WSizeTot,WSize,WStep;
    5063  int_8 SNdeb,SNend;
    51   int_8 StartSample,CurSnInd;
     64  int_8 StartSample,CurWtIndex;
    5265  int_8 TotNsCount;
     66  r_8 R8DefVal;
     67  int_8 I8DefVal;
    5368  vector< TVector<r_8>   > WDataIn;
    5469  vector< TVector<int_8> > WFlagIn;
     
    5873  vector< bool > WOutFlg;
    5974  vector< bool > WPutOutFlg;
     75  vector< bool > WPutOutOwnVector;
    6076  vector< int_8 > OutSample;
    6177};
Note: See TracChangeset for help on using the changeset viewer.