Changeset 1502 in Sophya for trunk/ArchTOIPipe/TestPipes


Ignore:
Timestamp:
May 18, 2001, 7:29:04 PM (24 years ago)
Author:
cmv
Message:

definition des flags pour TOI flagtoidef.h (added)
Un peu plus pour GenWindowTOIProcessor.
commit mais classe inutilisable en l'etat. cmv 18/5/2001

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ArchTOIPipe/TestPipes/tgenw.cc

    r1497 r1502  
    11/*   Test de GenWindowTOIProcessor (generic processor with window)
    2 
    32----------------   Exemple d'appel  ---------------------
    4 csh> time ./tgenw -intoi bolo -start 1 -end 50000 -wgen 128,1,256 \
    5            bols.fits xx.fits
    6 // CMV tester wgen 16,64,...
     3csh> time ./tgenw -intoi bolo -start 1 -end 50000 -wgen 16,1,64 -wlcr 0,0,0 \
     4           -dbg 0 toto.fits xx.fits
    75*/
    8 
    9 
    106
    117#include "machdefs.h"
     
    2723class TGenWProc : public GenWindowTOIProcessor {
    2824public:
    29   TGenWProc(int wsz, int step, int wt);
     25  TGenWProc(int ntoiout, int wsz, int step, int wt);
    3026  virtual void UserInit(int_8 kstart);
    3127  virtual void UserProc(int_8 ks);
    3228  virtual void UserEnd(int_8 kend);
    33 
     29protected:
     30  int_8 SNRunning;
    3431};
    3532
    36 TGenWProc::TGenWProc(int wsz, int step, int wt)
    37   : GenWindowTOIProcessor(1,1,wsz,step,wt)
    38 {
     33TGenWProc::TGenWProc(int ntoiout,int wsz, int step, int wt)
     34  : GenWindowTOIProcessor(1,ntoiout,wsz,step,wt)
     35{
     36  SNRunning = 1;
    3937}
    4038void TGenWProc::UserInit(int_8 kstart)
     
    4947void TGenWProc::UserProc(int_8 ks)
    5048{
    51   if ( (ks == StartSampleNum()) || (ks >= EndSampleNum()-1) || (ks%1000 == 0) )
    52     cout << "TGenWProc::UserProc(" << ks << ") CenterSample=" << GetCenterSample() << endl;
    53   if (GetWStep() > 1) {
     49  if( ks==StartSampleNum() || ks>=EndSampleNum()-1 || ks%1000==0 )
     50    cout<<"TGenWProc::UserProc("<<ks<<") CenterSample="<<GetWCenterSample()<<endl;
     51
     52  // Test pour fichier cmv toto.fits (sn=100000+i, bolo=i)
     53  r_8 * datatest = GetWDataPointer();
     54  for(int_4 i=0;i<WSize;i++) {
     55    int_8 k=ks-WSize/2+i;
     56    if(k<SNbegin || k>SNend) continue;
     57    if(datatest[i]!=k-100000) {cout<<"PROBLEME ks="<<ks<<endl; break;}
     58  }
     59
     60  if(!NbOutput) return;
     61
     62  if(GetWStep()==1) {
     63    // Cas ou on a un step de 1
     64    r_8 data;
     65    int_8 flag;
     66    GetData(ks,data,flag);
     67    PutWData(ks,data,flag);
     68
     69  } else if(GetWStep()<GetWSize()) {
     70    // Cas ou on a un step plus petit que la fenetre:
     71    // on peut donc reconstituer le TOI original en sortie
     72    // (ca marche aussi pour WStep==1 mais test different)
     73    // ATTENTION: l'ordre d'ecriture depend de la taille relative
     74    // de WSize et WStep.
     75    // Il faut en plus faire attention au premier echantillon et au dernier
     76    // Visiblement il faut ecrire autant de donnees en sortie que lues en entree (??)
     77    // ===> Conduit a une logique d'une simplicite extreme:
     78    // ATTENTION: dans certains cas ca bloque car il peut arriver que
     79    // SNend ne soit jamais atteint selon les valeurs de WSize/WStep !
     80    // et on ne peut donc pas ecrire autant de valeurs en sortie que lues en entree
    5481    TVector<r_8> data;
    5582    TVector<int_8> flag;
    56     data = GetWData()(Range(GetWSize()/2,0,GetWStep()));
    57     flag = GetWFlag()(Range(GetWSize()/2,0,GetWStep()));
    58     PutWData(GetCenterSample(), data, flag);
    59   }
    60   else {
    61     //    PutWData(GetCenterSample(), GetWData()(GetWSize()/2), GetWFlag()(GetWSize()/2));
    62     r_8 data;
    63     int_8 flag;
    64     GetData(GetCenterSample(), data, flag);
    65     PutWData(GetCenterSample(), data, flag);
    66   }
     83    int_4 ideb,ifin,isndeb;
     84    if(GetWStep()<=GetWSize()/2+1) {
     85      //  ------|------
     86      //      ------|------
     87      //        :   :
     88      //        WStep
     89      //        :  :
     90      //        d..f
     91      ideb = GetWCenterIndex();
     92      isndeb = GetWCenterSample();
     93      ifin = ideb + GetWStep()-1;
     94    } else {
     95      //  ------|------
     96      //             ------|------
     97      //        :          :
     98      //            WStep
     99      //  :         :
     100      //  d.........f
     101      ifin = GetWSize()-1;
     102      ideb = ifin - GetWStep()+1;
     103      isndeb = GetWStartSample() + ideb;
     104    }
     105    if(isndeb<StartSampleNum()) {
     106      cout<<"........ ideb="<<ideb<<" isndeb="<<isndeb<<endl;
     107      ideb = StartSampleNum() - GetWStartSample();
     108      isndeb = StartSampleNum();
     109    }
     110    if(GetWStartSample()+ifin>EndSampleNum()) {
     111      cout<<"........ ifin="<<ifin<<endl;
     112      ifin = EndSampleNum() - GetWStartSample();
     113    }
     114    cout<<".... ideb="<<ideb<<" ifin="<<ifin<<" isndeb="<<isndeb<<endl;
     115    data = GetWData()(Range(ideb,ifin));
     116    flag = GetWFlag()(Range(ideb,ifin));
     117    PutWData(isndeb,data,flag);
     118  } else {
     119    // Cas ou on ne peut reproduire le TOI initial
     120    // On renumerote les samples
     121    // ATTENTION: faut en mettre autant en sortie que lu en entree (???)
     122    // ATTENTION: dans certains cas ca bloque car il peut arriver que
     123    // SNend ne soit jamais atteint selon les valeurs de WSize/WStep !
     124    // et on ne peut donc pas ecrire autant de valeurs en sortie que lues en entree
     125    // CA NE MARCHE PAS DANS CE CAS
     126    TVector<r_8> data;
     127    TVector<int_8> flag;
     128    int_4 ideb=0, ifin=GetWSize()-1;
     129    int_8 ilen = EndSampleNum() - StartSampleNum() + 1;
     130    if(GetWStartSample()+ideb<StartSampleNum()) {
     131      cout<<"........ ideb="<<ideb<<endl;
     132      ideb = StartSampleNum() - GetWStartSample();
     133    }
     134    if(GetWStartSample()+ifin>EndSampleNum()) {
     135      cout<<"........ ifin="<<ifin<<endl;
     136      ifin = EndSampleNum() - GetWStartSample();
     137    }
     138    data = GetWData()(Range(ideb,ifin));
     139    flag = GetWFlag()(Range(ideb,ifin));
     140    cout<<".... ideb="<<ideb<<" ifin="<<ifin<<" SNRunning="<<SNRunning<<endl;
     141    PutWData(SNRunning,data,flag);
     142    SNRunning += ifin-ideb+1;
     143    if(SNRunning<=ilen && GetWStep()-GetWSize()>0) {
     144      for(int_4 i=0;i<GetWStep()-GetWSize() && SNRunning<=ilen;i++)
     145        {PutWData(SNRunning,0.,0); SNRunning++;}
     146      // De toute facon impossible a faire puisque
     147      // ce putwdata efface le vecteur du putwdata precedent
     148    }
     149    cout<<".................... SNRunning="<<SNRunning<<endl;
     150  }
     151  // Oh que voila une logique simple et utilisable par tout un chacun !!!
    67152}
    68153
     
    75160  }
    76161  else {
    77     cout << "\n Usage : tgenw [-dbg] [-start snb] [-end sne] [-intoi name] \n"
     162    cout << "\n Usage : tgenw [-prt] [-dbg dbg] [-start snb] [-end sne] [-intoi name] \n"
    78163         << "         [-wtoi sz] [-wgen sz,step,szt] inFitsName outFitsName \n"
    79          << "   -dbg : sets TOISeqBuffered debug level to 1 \n"
     164         << "   -prt : sets TOISeqBuffered debug level to 1 \n"
     165         << "   -dbg : debug level for GenWProc \n"
    80166         << "   -start snb : sets the start sample num \n"
    81167         << "   -end sne : sets the end sample num \n"
     
    83169         << "   -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
    84170         << "   -wgen sz,step,szt : sets GenWProc window size, step total size \n"
     171         << "   -wlcr szl,szc,szr : sets LCR Window \n"
    85172         << endl;
    86173    exit(0);
     
    96183  bool fgdbg = false;
    97184  bool fgsetstart = false;
     185  int dbglevel = 0;
    98186  int wtoi = 8192;
    99187  int wgen = 16;
    100188  int stepgen = 1;
     189  int wgl = 0, wgc = 0, wgr = 0;
    101190  int wtotgen = 0;
    102191  int istart = 0;
    103192  int iend = 0;
    104193  string infile;
    105   string outfile;
     194  string outfile = "";
    106195  string outppfname;
    107196  string intoi = "boloMuV_27";
    108197
    109   if (narg < 3) Usage(true);
     198  if (narg < 2) Usage(true);
    110199  int ko=1;
    111200  // decoding arguments
     
    128217      sscanf(arg[ia+1],"%d,%d,%d",&wgen,&stepgen,&wtotgen); ia++;
    129218    }   
     219    else if (strcmp(arg[ia],"-wlcr") == 0) {
     220      if (ia == narg-1) Usage(true); 
     221      sscanf(arg[ia+1],"%d,%d,%d",&wgl,&wgc,&wgr); ia++;
     222    }   
    130223    else if (strcmp(arg[ia],"-intoi") == 0) {
    131224      if (ia == narg-1) Usage(true); 
    132225      intoi = arg[ia+1]; ia++;
    133226    }   
    134     else if (strcmp(arg[ia],"-dbg") == 0)  fgdbg = true;
     227    else if (strcmp(arg[ia],"-dbg") == 0) {
     228      if (ia == narg-1) Usage(true); 
     229      sscanf(arg[ia+1],"%d",&dbglevel); ia++;
     230    }   
     231    else if (strcmp(arg[ia],"-prt") == 0)  fgdbg = true;
    135232
    136233    else { ko = ia; break; }  // Debut des noms
     
    138235
    139236  if (iend < istart) iend = istart+wtoi*10;
    140   if ((narg-ko) < 2)  Usage(true);
     237  if ((narg-ko) < 1)  Usage(true);
    141238  infile = arg[ko];
    142   outfile = arg[ko+1];
    143   //  outppfname = arg[ko+2];
     239  if(ko+1<narg) outfile = arg[ko+1];
     240  // outppfname = arg[ko+2];
    144241
    145242  cout << " Initializing SOPHYA ... " << endl;
     
    150247       << outfile << endl;
    151248  cout << ">>> Window Size WTOI= " << wtoi << " WGenSz= " << wgen
    152        << " StepGen=" << stepgen << " WTot=" << wtotgen << endl;
     249       << " StepGen=" << stepgen << " WTot=" << wtotgen
     250       << " Wglcr=" << wgl << "," << wgc <<  "," << wgr << endl;
    153251  cout << ">>>> InTOIName= " << intoi
    154252       << "  iStart= " << istart << " iEnd= " << iend << endl;
     
    159257    //  mgr->setRequestedSample(11680920,11710584);
    160258    //  mgr->setRequestedSample(104121000, 104946120);
    161     if (fgsetstart) 
     259    if (fgsetstart)
    162260      mgr->setRequestedSample(istart, iend);
    163261 
    164262    FITSTOIReader r(infile);
    165263    cout << "reader created" << endl;
    166     FITSTOIWriter w(outfile);
    167     cout << "fits writer created" << endl;
    168 
     264
     265    int ntoiout=0;
     266    FITSTOIWriter* w=NULL;
     267    if(outfile.size()>0) {
     268      ntoiout=1;
     269      w = new FITSTOIWriter(outfile);
     270      w->setOutFlags(true);
     271      cout << "fits writer created" << endl;
     272    }
    169273
    170274    TOISeqBuffered * toiin = new TOISeqBuffered("f2in", wtoi);
    171275    if (fgdbg) toiin->setDebugLevel(1);
    172      
     276
     277    TOISeqBuffered * toiout = NULL;
     278    if(w) {
     279      toiout = new TOISeqBuffered("genout", wtoi);
     280      if (fgdbg) toiout->setDebugLevel(1);
     281    }
     282
     283    TGenWProc tgenp(ntoiout, wgen, stepgen, wtotgen);
     284    tgenp.SetWSizeLCR(wgl,wgc,wgr);
     285    tgenp.SetDbgLevel(dbglevel);
     286
    173287    cout << " Connecting to FitsReader ... " << endl;
    174288    r.addOutput(intoi, toiin);
    175289
    176     TOISeqBuffered * toiout = new TOISeqBuffered("genout", wtoi);
    177     if (fgdbg) toiout->setDebugLevel(1);
    178     TGenWProc tgenp(wgen, stepgen, wtotgen);
     290    if(w && toiout) {
     291      cout << " Connecting to FitsWriter ... " << endl;
     292      w->addInput("genout",toiout);
     293    }
    179294
    180295    cout << " Connecting  TGenWProc ... " << endl;
    181296    tgenp.addInput("in0",toiin);
    182     tgenp.addOutput("out0",toiout);
    183    
    184     cout << tgenp;
    185 
    186     w.addInput("genout", toiout);
     297    if(toiout) tgenp.addOutput("out0",toiout);
     298    tgenp.PrintStatus(cout,1);
    187299
    188300    PrtTim("starting threads");
    189301    r.start();
    190302    tgenp.start();
    191     w.start();
    192 
     303    if(w) w->start();
    193304
    194305    /*       
    195306    for(int jj=0; jj<3; jj++) {
    196307      cout << *toiin;
    197       cout << *toiout;
     308      if(toiout) cout << *toiout;
    198309      sleep(1);
    199310    }
    200311    */
    201    
    202    
    203    
    204312
    205313    mgr->joinAll();
     
    209317    //    r.PrintStatus(cout); 
    210318    //    cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
    211     //    w.PrintStatus(cout); 
     319    //    w->PrintStatus(cout); 
    212320
    213321    cout << " ------ toiin, toiout Status information ------- " << endl;
    214322    cout << *toiin;
    215     cout << *toiout;
    216    
    217     cout << tgenp;
    218    
     323    if(toiout) cout << *toiout;
     324    tgenp.PrintStatus(cout);
     325
     326    // Fermeture du fitswriter
     327    if(w) delete w;;
     328
    219329  }
    220330  catch (PThrowable & exc) {
Note: See TracChangeset for help on using the changeset viewer.