Changeset 3623 in Sophya for trunk/AddOn/TAcq/racquproc.cc


Ignore:
Timestamp:
May 22, 2009, 9:59:38 AM (16 years ago)
Author:
ansari
Message:

Modifications et ameliorations diverses pour programme acquisition/traitement multifibres

Reza 22/05/2009

1- Extension/amelioration classe BRPaquet et BRPaqChecker
2- Correction BUG dans RAcqMemZoneMgr bloquant l'utilisation a une seule zone memoire
3- Classe PCIEWrapper devenue virtuelle pure et introduction de la classe TestPCIWrapperNODMA
pour les smulations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/AddOn/TAcq/racquproc.cc

    r3538 r3623  
    44#include <unistd.h>
    55#include <fstream>
     6#include <signal.h>
    67
    78#include "pexceptions.h"
     
    1819#include "brpaqu.h"
    1920#include "minifits.h"
    20 
     21struct sigaction act;
    2122
    2223//-------------------------------------------------------
    23 // Classe thread de traitement
     24// Classe thread de traitement  avec 1 voie par frame
    2425//-------------------------------------------------------
    2526
    26 DataProc::DataProc(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 nmax)
     27void DataProcSignal(int s)
     28{
     29  cout <<"............................................... receive CtrlC" << endl;
     30
     31}
     32
     33DataProc::DataProc(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
    2734  :  memgr(mem)
    2835{
    2936  nmax_ = nmax;
    3037  nmean_ = nmean;
     38  step_ = step;
    3139  stop_ = false;       
    3240  path_ = path;
     41  act.sa_handler=DataProcSignal;
    3342}
    3443
     
    3645{ return (z.real()*z.real()+z.imag()*z.imag()); }
    3746
     47void DataProc::Stop()
     48{
     49 stop_=true;
     50 //  cout <<" DataProc::Stop ... > STOP " << endl;
     51}
     52
    3853void DataProc::run()
    3954{
    40        
     55 
     56  // sigaddset(&act.sa_mask,SIGINT);  // pour proteger le transfert DMA
     57  // sigaction(SIGINT,&act,NULL);       
    4158  setRC(1);     
    4259  try {
    4360    TimeStamp ts;
    44     cout << " DataProc::run() - Starting " << ts << " NMaxMemZones=" << nmax_ << endl; 
     61    cout << " DataProc::run() - Starting " << ts << " NMaxMemZones=" << nmax_
     62         << " NMean=" << nmean_ << " Step=" << step_ << endl;   
    4563    char fname[512];
    4664    sprintf(fname,"%s/proc.log",path_.c_str());
    4765    ofstream filog(fname);
    4866    filog << " DataProc::run() - starting log file " << ts << endl;                   
     67    filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
    4968
    5069// Initialisation pour clcul FFT
     
    5978    spectre.ReSize(cfour.Size());
    6079   
    61     fftwf_plan plan = fftwf_plan_dft_r2c_1d(pq.DataSize(), vx.Data(),
    62                                        (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
     80    fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
     81                                       (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
    6382
    6483    uint_4 ifile = 0;                           
     84    uint_4 nzm = 0;
    6585    for (uint_4 kmz=0; kmz<nmax_; kmz++) {
     86      if (stop_) break;
    6687      int mid = memgr.FindMemZoneId(MemZA_Proc);
    6788      Byte* buff = memgr.GetMemZone(mid);
     
    7293      }
    7394      BRPaquet paq0(NULL, buff, paqsz);
    74       uint_4 nzm = 0;
    75       for(uint_4 i=0; i<memgr.NbPaquets(); i++) {
     95      for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
    7696        BRPaquet paq(NULL, buff+i*paqsz, paqsz);
    7797        Byte min = 255;
     
    7999           
    80100        for(sa_size_t j=0; j<vx.Size(); j++)
    81           vx(j) = (r_4)(*(paq.Data()+j));
     101          vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
    82102        fftwf_execute(plan);
    83         //    ffts_.FFTForward(vx, cfour_);
     103        //        ffts_.FFTForward(vx, cfour_);
    84104        for(sa_size_t j=0; j<spectre.Size(); j++)
    85105          spectre(j) += Zmod2(cfour(j));
    86106        nzm++;
    87107      }
    88       if (nzm >= nmean_) {
     108      if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
    89109        spectre /= (r_4)(nzm);
     110        spectre.Info()["NPaqMoy"] = nzm;
    90111        sprintf(fname,"%s/spectre%d.ppf",path_.c_str(),(int)ifile);
    91112        POutPersist po(fname);
     
    114135  return;
    115136}   
     137
     138//---------------------------------------------------------------
     139// Classe thread de traitement donnees ADC avec 2 voies par frame
     140//---------------------------------------------------------------
     141
     142DataProc2C::DataProc2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
     143  :  memgr(mem)
     144{
     145  nmax_ = nmax;
     146  nmean_ = nmean;
     147  step_ = step;
     148  stop_ = false;       
     149  path_ = path;
     150  act.sa_handler=DataProcSignal;
     151}
     152void DataProc2C::Stop()
     153{
     154 stop_=true;
     155 // cout <<" DataProc2C::Stop ... > STOP " << endl;
     156}
     157
     158void DataProc2C::run()
     159{
     160  //   sigaction(SIGINT,&act,NULL);     
     161  setRC(1);     
     162  try {
     163    TimeStamp ts;
     164    cout << " DataProc2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
     165         << " NMean=" << nmean_ << " Step=" << step_ << endl;   
     166    char fname[512];
     167    sprintf(fname,"%s/proc.log",path_.c_str());
     168    ofstream filog(fname);
     169    filog << " DataProc2C::run() - starting log file " << ts << endl;                 
     170    filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
     171
     172// Initialisation pour clcul FFT
     173    TVector< complex<r_4> > cfour;  // composant TF
     174    uint_4 paqsz = memgr.PaqSize();
     175    BRPaquet pq(NULL, NULL, paqsz);
     176    TVector<r_4> vx(pq.DataSize()/2);
     177    vx = (r_4)(0.);
     178    FFTPackServer ffts;
     179    ffts.FFTForward(vx, cfour);
     180    TVector<r_4> spectreV1, spectreV2;
     181    spectreV1.ReSize(cfour.Size());
     182    spectreV2.ReSize(cfour.Size());
     183   
     184    fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
     185                                       (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
     186
     187    uint_4 ifile = 0;                           
     188    uint_4 nzm = 0;
     189    for (uint_4 kmz=0; kmz<nmax_; kmz++) {
     190      if (stop_) break;
     191      int mid = memgr.FindMemZoneId(MemZA_Proc);
     192      Byte* buff = memgr.GetMemZone(mid);
     193      if (buff == NULL) {
     194        cout << " DataProc2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
     195        setRC(2);       
     196        return;
     197      }
     198      BRPaquet paq0(NULL, buff, paqsz);
     199      for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
     200        BRPaquet paq(NULL, buff+i*paqsz, paqsz);
     201        Byte min = 255;
     202        Byte max = 0;
     203           
     204        for(sa_size_t j=0; j<vx.Size(); j++)
     205          vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
     206        fftwf_execute(plan);
     207        //   ffts_.FFTForward(vx, cfour_);
     208        for(sa_size_t j=0; j<spectreV1.Size(); j++)
     209          spectreV1(j) += Zmod2(cfour(j));
     210 
     211        for(sa_size_t j=0; j<vx.Size(); j++)
     212          vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
     213        fftwf_execute(plan);
     214        //    ffts_.FFTForward(vx, cfour_);
     215        for(sa_size_t j=0; j<spectreV2.Size(); j++)
     216          spectreV2(j) += Zmod2(cfour(j));
     217
     218        nzm++;
     219      }
     220      if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
     221        spectreV1 /= (r_4)(nzm);
     222        spectreV2 /= (r_4)(nzm);
     223        spectreV1.Info()["NPaqMoy"] = nzm;
     224        spectreV2.Info()["NPaqMoy"] = nzm;
     225        {
     226        sprintf(fname,"%s/spectre2C_%d.ppf",path_.c_str(),(int)ifile);
     227        POutPersist po(fname);
     228        po << PPFNameTag("specV1") << spectreV1;
     229        po << PPFNameTag("specV2") << spectreV2;
     230        }
     231        spectreV1 = (r_4)(0.);
     232        spectreV2 = (r_4)(0.);
     233        nzm = 0;  ifile++;
     234        ts.SetNow();
     235        filog << ts << " :  proc file  " << fname << endl;                     
     236        cout << " DataProc2C::run() " << ts << " : created file  " << fname << endl;
     237      }
     238     
     239      memgr.FreeMemZone(mid, MemZS_Proc);
     240    }
     241  }
     242  catch (PException& exc) {
     243    cout << " DataProc2C::run()/catched PException " << exc.Msg() << endl;
     244    setRC(3);   
     245    return;
     246  }
     247  catch(...) {
     248    cout << " DataProc2C::run()/catched unknown ... exception " << endl;
     249    setRC(4);   
     250    return;
     251  }
     252  setRC(0);
     253  return;
     254}   
     255
     256
     257
     258
     259//---------------------------------------------------------------
     260// Classe thread de traitement donnees FFT avec 2 voies par frame
     261//---------------------------------------------------------------
     262
     263inline r_4 Zmod2TwoByte(TwoByteComplex z)
     264{ return (z.realD()*z.realD()+z.imagD()*z.imagD()); }
     265
     266DataProcFFT2C::DataProcFFT2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
     267  :  memgr(mem)
     268{
     269  nmax_ = nmax;
     270  nmean_ = nmean;
     271  step_ = step;
     272  stop_ = false;       
     273  path_ = path;
     274 act.sa_handler=DataProcSignal;
     275}
     276void DataProcFFT2C::Stop()
     277{
     278 stop_=true;
     279 // cout <<" DataProcFFT2C::Stop ... > STOP " << endl;
     280}
     281
     282void DataProcFFT2C::run()
     283{
     284  // sigaction(SIGINT,&act,NULL);       
     285  setRC(1);     
     286  try {
     287    TimeStamp ts;
     288    cout << " DataProcFFT2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
     289         << " NMean=" << nmean_ << " Step=" << step_ << endl;   
     290    char fname[512];
     291    sprintf(fname,"%s/proc.log",path_.c_str());
     292    ofstream filog(fname);
     293    filog << " DataProcFFT2C::run() - starting log file " << ts << endl;                       
     294    filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
     295
     296// Initialisation pour clcul FFT
     297    TVector< complex<r_4> > cfour;  // composant TF
     298    uint_4 paqsz = memgr.PaqSize();
     299    BRPaquet pq(NULL, NULL, paqsz);
     300 
     301    TVector<r_4> spectreV1(pq.DataSize()/4+1), spectreV2(pq.DataSize()/4+1);   
     302
     303    uint_4 ifile = 0;                           
     304    for (uint_4 kmz=0; kmz<nmax_; kmz++) {
     305      if (stop_ ) break;
     306      int mid = memgr.FindMemZoneId(MemZA_Proc);
     307      Byte* buff = memgr.GetMemZone(mid);
     308      if (buff == NULL) {
     309        cout << " DataProcFFT2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
     310        setRC(2);       
     311        return;
     312      }
     313      BRPaquet paq0(NULL, buff, paqsz);
     314      uint_4 nzm = 0;
     315      for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
     316        BRPaquet paq(NULL, buff+i*paqsz, paqsz);
     317        Byte min = 255;
     318        Byte max = 0;
     319               
     320        TwoByteComplex* zz;
     321        // Traitement Voie 1
     322        zz = (TwoByteComplex*)paq.Data1();
     323        spectreV1(0) += zz[0].realD()*zz[0].realD();  // Composante continue, partie reelle uniquement
     324        for(sa_size_t j=1; j<spectreV1.Size()-1; j++)  spectreV1(j) += Zmod2TwoByte(zz[j]);
     325
     326        spectreV1(spectreV1.Size()-1) += zz[0].imagD()*zz[0].imagD();  // Freq. Nyquist a N/2
     327
     328        // Traitement Voie 2
     329        zz = (TwoByteComplex*)paq.Data2();
     330        spectreV2(0) += zz[0].realD()*zz[0].realD();  // Composante continue, partie reelle uniquement
     331        for(sa_size_t j=1; j<spectreV2.Size()-1; j++)  spectreV2(j) += Zmod2TwoByte(zz[j]);
     332
     333        spectreV2(spectreV2.Size()-1) += zz[0].imagD()*zz[0].imagD();  // Freq. Nyquist a N/2
     334
     335        nzm++;
     336      }
     337      if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
     338        spectreV1 /= (r_4)(nzm);
     339        spectreV2 /= (r_4)(nzm);
     340        spectreV1.Info()["NPaqMoy"] = nzm;
     341        spectreV2.Info()["NPaqMoy"] = nzm;
     342        {
     343        sprintf(fname,"%s/spectreFFT2C_%d.ppf",path_.c_str(),(int)ifile);
     344        POutPersist po(fname);
     345        po << PPFNameTag("specV1") << spectreV1;
     346        po << PPFNameTag("specV2") << spectreV2;
     347        }
     348        spectreV1 = (r_4)(0.);
     349        spectreV2 = (r_4)(0.);
     350        nzm = 0;  ifile++;
     351        ts.SetNow();
     352        filog << ts << " :  proc file  " << fname << endl;                     
     353        cout << " DataProcFFT2C::run() " << ts << " : created file  " << fname << endl;
     354      }
     355     
     356      memgr.FreeMemZone(mid, MemZS_Proc);
     357    }
     358  }
     359  catch (PException& exc) {
     360    cout << " DataProcFFT2C::run()/catched PException " << exc.Msg() << endl;
     361    setRC(3);   
     362    return;
     363  }
     364  catch(...) {
     365    cout << " DataProcFFT2C::run()/catched unknown ... exception " << endl;
     366    setRC(4);   
     367    return;
     368  }
     369  setRC(0);
     370  return;
     371}   
Note: See TracChangeset for help on using the changeset viewer.