Changeset 3623 in Sophya


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.

Location:
trunk/AddOn/TAcq
Files:
13 edited

Legend:

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

    r3592 r3623  
    5555  case BR_FFTOneChan :
    5656  case BR_FFTTwoChan :
     57    // Byte swap (sur 8 octets) de l'entete
    5758    // ByteSwap 8 (4->8 Reza/firmware SGDMA) de l'enete
    5859    for(int ka=0; ka<BRHDRSIZE; ka+=8) {
     
    6364    }
    6465
     66    // on reoordonne les coeff FFT et on swappe en mem temps  (Byte-swap sur 8 octets)
    6567    if (fgswap == BR_FFTOneChan) ReorderFFTData(src+HeaderSize(), dst_+HeaderSize(), DataSize());
    6668    else if (fgswap == BR_FFTTwoChan) {
     
    6870      ReorderFFTData(src+HeaderSize()+DataSize()/2, dst_+HeaderSize()+DataSize()/2, DataSize()/2);
    6971    }
     72    // Byte swap (sur 8 octets) du trailer
    7073    for(int ka=HeaderSize()+DataSize(); ka<sz_; ka+=8) {
    7174      for(int kb=0; kb<4; kb++) {
     
    7881  case BR_FFTOneChan32 :
    7982  case BR_FFTTwoChan32 :
    80     // on swappe tout  en attendant le swap general sinon il faut encore créer une fonctiondifferente de ReorderFFT
    81     // swapp du header uniquement
     83    // swap du header uniquement : Echange de deux mots de 4 octets
    8284    for(int ka=0; ka<BRHDRSIZE/4; ka+=2) {
    8385      dst32[ka] = src32[ka+1];
     
    8587    }
    8688 
    87     // on reoordonne et on swappe en mem temps
     89    // on reoordonne et on swappe en mem temps (Echange de deux mots de 4 octets)
    8890    if (fgswap == BR_FFTOneChan32) ReorderFFTData32(src+HeaderSize(), dst_+HeaderSize(), DataSize());
    8991    else if (fgswap == BR_FFTTwoChan32) {
     
    9193      ReorderFFTData32(src+HeaderSize()+DataSize()/2, dst_+HeaderSize()+DataSize()/2, DataSize()/2);
    9294    }
    93     // swap du trailler uniquement
     95    // swap du trailler uniquement : Echange de deux mots de 4 octets
    9496    for(int ka=(HeaderSize()+DataSize())/4;ka < sz_/4; ka+=2) {
    9597      dst32[ka] = src32[ka+1];
     
    99101  case BR_FFTOneChanNoSwap :
    100102  case BR_FFTTwoChanNoSwap :
    101     // on a plus de swapdonc il faut copier dans dst
    102     memcpy(dst_, src, sz_);
    103     // on reoordonne et on swappe en mem temps
     103    // copie du header uniquement
     104    for(int ka=0; ka<BRHDRSIZE/4; ka++)  dst32[ka] = src32[ka];
     105
     106    //DEL  on a plus de swapdonc il faut copier dans dst
     107    //DEL    memcpy(dst_, src, sz_);
     108
     109    // on reoordonne les coeff FFT (pas de swap)
    104110    if (fgswap == BR_FFTOneChanNoSwap) ReorderFFTDataNoSwap(src+HeaderSize(), dst_+HeaderSize(), DataSize());
    105111    else if (fgswap == BR_FFTTwoChanNoSwap) {
     
    107113      ReorderFFTDataNoSwap(src+HeaderSize()+DataSize()/2, dst_+HeaderSize()+DataSize()/2, DataSize()/2);
    108114    }
    109    
     115    // copie du trailler uniquement :
     116     for(int ka=(HeaderSize()+DataSize())/4;ka < sz_/4; ka++)  dst32[ka] = src32[ka];
     117   
    110118    break;
    111119  }  // Fin switch
     
    143151{
    144152  UInt16 ModAq;
    145   printf("Mod Acq %x \n",ModeAcq());
     153//DEL  printf("Mod Acq %x \n",ModeAcq());
    146154  ModAq = ((ModeAcq() & 0x30)>> 4);
    147155  return(ModAq);
    148  
    149 }
    150 
    151 /* --Methode__ */
    152 void BRPaquet::Print(ostream & os, int nelt, bool prht)
     156}
     157
     158/* --Methode__ */
     159void BRPaquet::SetHDRMarker64(UInt64 htag)
     160{
     161  *((UInt64*)(dst_+OFFSET)) = htag;
     162  return;       
     163}
     164
     165/* --Methode__ */
     166void BRPaquet::SetTRLMarker64(UInt64 ttag)
     167{
     168  *((UInt64*)(dst_+(sz_-BRTRLSIZE+OFFSET+1))) = 0;     
     169  *((UInt64*)(dst_+(sz_-BRTRLSIZE+OFFSET))) = ttag;
     170  return;                                       
     171}
     172
     173/* --Methode__ */
     174void BRPaquet::SetFrameCounter(UInt32 fc)
     175{
     176  UInt32* wp =  (UInt32*)(dst_+(BRFRCPTOFF+OFFSET));
     177  *wp = (*wp & 0x0000FFFF) | ((fc<<16) & 0xFFFF0000);
     178  return;                               
     179}
     180
     181/* --Methode__ */
     182void BRPaquet::SetTimeTag(UInt64 timtag)
     183{
     184  UInt32* wp =  (UInt32*)(dst_+(BRFRCPTOFF+OFFSET));
     185  UInt32 fc = *wp;
     186  *((UInt64*)(dst_+(BRTMTAGOFF+OFFSET))) = timtag;
     187  *wp = (*wp & 0x0000FFFF) | (fc & 0xFFFF0000);
     188  return;               
     189}
     190
     191/* --Methode__ */
     192ostream& BRPaquet::Print(ostream & os, int nelt, bool prht)
    153193{
    154194  os << endl << "BRPaquet::Print() PaqSz=" << PaquetSize() << " DataSize=" << DataSize()
    155      << " dst_pointer=(hex)" << hex << (unsigned long)dst_ << dec << endl;
     195     << " dst_pointer=(hex)" << hex << (unsigned long)dst_ << dec << endl; 
    156196  if (dst_ == NULL) {
    157197    os << " ...NULL paquet " << endl;
    158     return;
     198    return os;
    159199  }
    160 
    161   os << endl << " BR AcqMode: " << ModeAcquisition() << " Channel: " << ChannelID()  << endl;
    162 
     200  os << " BR AcqMode: " << ModeAcquisition() << " Channel: " << ChannelID() 
     201     << " FrameCounter=" << FrameCounter() << " FrameDataLen=" << PaqLen() << endl;
    163202  if (TrailerSize() > 0)
    164203    os << " ...HDRMarker(hex)=" << hex <<  HDRMarker() << " TRLMarker=" << TRLMarker() << dec << endl;
     
    168207  tt2 = TimeTag1();
    169208  tt1 = TimeTag2();
    170   os << " ...TimeTag (hex)=" << hex << "TimeTag()" << " TT1= " << tt1 << " TT2=" << tt2 << dec << endl;
     209  os << " ...TimeTag (hex)=" << hex << " TT1= " << tt1 << " TT2=" << tt2
     210     << dec << " ->TimeTag()=" << TimeTag() << endl;
    171211  // os << " ...Position Chariot (hex)= " << hex << PositionChariot() << endl;
    172212  if (nelt > DataSize()/2) nelt = DataSize()/2;
     
    192232    }
    193233  }
     234  return os;
    194235}
    195236
     
    401442  lostframes = 0;
    402443  frclst = 0;
     444  DefineHDRTag();
     445  DefineTRLTag();
    403446}
    404447
     
    407450}
    408451
     452UInt64 BRPaqChecker::DefineHDRTag(UInt32 hdr1, UInt32 hdr2)
     453{
     454  hdrtag_ = (UInt64)hdr1 + ((UInt64)hdr2 << 32);
     455  return hdrtag_;
     456}
     457
     458UInt64 BRPaqChecker::DefineTRLTag(UInt32 trl1, UInt32 trl2)
     459{
     460  trltag_ = (UInt64)trl1 + ((UInt64)trl2 << 32);
     461  return trltag_;
     462}
     463
     464
     465static int cnt_pb = 0;
    409466bool BRPaqChecker::Check(BRPaquet& paq)
    410467{
    411468  totnframes++;
    412   if (paq.HDRMarker() != 0x76543210) return false;
     469  if (paq.HDRMarker64() != HDRTag()) return false;
     470  if (paq.TRLMarker64() != TRLTag()) return false;
     471  /*
     472  if (paq.TRLMarker64() != TRLTag()) {
     473    cnt_pb++;
     474    if (cnt_pb < 5) paq.Print();
     475    return false;
     476  }
     477  */
    413478  unsigned int curfc = paq.FrameCounter();
    414479  unsigned int delfc = 0;
     
    419484  }
    420485  nframeok++; frclst = curfc;
     486  if (cnt_pb<5) { cnt_pb++; paq.Print(); }
    421487  return true;
    422488}
     
    424490ostream& BRPaqChecker::Print(ostream& os)
    425491{
    426   os << "BRPaqChecker:  Tot.Nb.Frames.Proc=" << totnframes << " NbFrameOK=" << nframeok
     492  //  os << "BRPaqChecker:  HDRTag=" << hex << HDRTag() << " TRLTag=" << TRLTag() << dec << "\n"
     493  //     << " ... Tot.Nb.Frames.Proc=" << totnframes << " NbFrame HDR/TRL OK=" << nframeok
     494  os << "BRPaqChecker: Tot.Nb.Frames.Proc=" << totnframes << " NbFrame HDR/TRL OK=" << nframeok
    427495     << " LostFrames=" << lostframes
    428496     << " Loss=" << (double)lostframes*100./(double)totnframes << " %" << endl;
  • trunk/AddOn/TAcq/brpaqu.h

    r3592 r3623  
    1515using namespace std;
    1616
     17// ------------------------------------------------
     18// ----- Classe TwoByteComplex ------
    1719// On definit une classe TwoByteComplex() pour manipuler une paire de byte
    1820// representant partie relle et imaginaire d'un nombre complexe
     
    4446};
    4547
    46 // Actuellement apres test Nancay un mot de 4octects est mis avant le header
     48// ------------------------------------------------
     49
     50// OFFSET : au cas ou le firmware reception ajoute des mots avant le header
    4751#define OFFSET 0
    4852// Taille entete/trailer en octets
     
    101105class BRPaquet {
    102106 public:
     107// Cree d'un objet BRPaquet avec copie/swap depuis src -> dst (si src != NULL)
    103108  BRPaquet(Byte* src, Byte* dst, int paqsz=4096, BRDataFmtConv fgswap=BR_SwapAll);
     109// Cree d'un objet BRPaquet de taille paqsz sur la zone dst   
    104110  BRPaquet(Byte* srcdst, int paqsz=4096);
    105   //  ~BRPaquet();
     111//  ~BRPaquet();
    106112
    107113  // Acces diverses tailles
     
    112118
    113119  // Acces differentes zone memoire
    114   inline Byte* Data() { return dst_+BRHDRSIZE+OFFSET; }
     120  inline Byte* Begin() { return dst_+OFFSET; }
    115121  inline Byte* Data1() { return dst_+BRHDRSIZE+OFFSET; }
    116122  inline Byte* Data2() { return dst_+BRHDRSIZE+(DataSize()/2)+OFFSET; }
     
    120126  // Valeurs differentes zones HDR/TRL
    121127  inline UInt32 HDRMarker() {return *((UInt32*)(dst_+OFFSET));}
     128  inline UInt32 HDRMarker2() {return *((UInt32*)(dst_+OFFSET+1));}
     129  inline UInt64 HDRMarker64() {return *((UInt64*)(dst_+OFFSET));}
     130
    122131  inline UInt32 TRLMarker() {return *((UInt32*)(dst_+(sz_-BRTRLSIZE+OFFSET)));}
     132  inline UInt32 TRLMarker2() {return *((UInt32*)(dst_+(sz_-BRTRLSIZE+OFFSET+1)));}
     133  inline UInt64 TRLMarker64() {return *((UInt64*)(dst_+(sz_-BRTRLSIZE+OFFSET)));}
     134
     135// Informations diverses sur le paquet/mode d'acquisition
    123136  inline UInt16 ModeAcq()   {return *((UInt16*)(dst_+(BRMODACQOFF+OFFSET)));}
    124137  inline UInt16 ChanId()    {return (( *((UInt16*)(dst_+(BRCHANIDOFF+OFFSET))) & 0x1800)>> 12) ;}
    125138  inline UInt16 ChipId()    {return (( *((UInt16*)(dst_+(BRCHANIDOFF+OFFSET))) & 0xC00)>> 10) ;}
    126139
     140  inline UInt32 FrameCounter()   {return ((*((UInt32*)(dst_+(BRFRCPTOFF+OFFSET))) &0xFFFF0000) >> 16);}
    127141  inline UInt32 TimeTag1()   {return *((UInt32*)(dst_+(BRTMTAGOFF+OFFSET)));}
    128   inline UInt32 FrameCounter()   {return ((*((UInt32*)(dst_+(BRFRCPTOFF+OFFSET))) &0xFFFF0000) >> 16);}
    129142  inline UInt32 TimeTag2() {return (*((UInt32*)(dst_+(BRFRCPTOFF+OFFSET))) &0xFFFF);}
     143  inline UInt64 TimeTag() {return (*((UInt64*)(dst_+(BRTMTAGOFF+OFFSET))) &0x0000FFFFFFFFFFFFLL);}
    130144
    131145  inline UInt32 PaqId()     {return *((UInt32*)(dst_+(BRPKTIDOFF+OFFSET)));}
    132146  inline UInt16 PaqLen()    {return *((UInt16*)(dst_+(BRPKTLENOFF+OFFSET)));}
    133147
    134 
    135   // inline unsigned short PositionChariot() {return *((unsigned short*)(dst_+BRPCOFF+OFFSET));}
    136 
    137   // pour faire un print de la structure
    138   void Print(ostream & os, int nelt=8, bool prht=true);
    139148  UInt16  ChannelID();
    140149  UInt16  ModeAcquisition();
     150
     151  // inline unsigned short PositionChariot() {return *((unsigned short*)(dst_+BRPCOFF+OFFSET));}
     152  // Fonctions utiles pour remplir un objet BRPaquet
     153  void SetHDRMarker64(UInt64 htag);
     154  void SetTRLMarker64(UInt64 ttag);
     155  void SetFrameCounter(UInt32 fc); 
     156  void SetTimeTag(UInt64 timtag);
     157  inline void SetPaqLen(UInt16 len) { *((UInt16*)(dst_+(BRPKTLENOFF+OFFSET))) = len; }
     158
     159  // pour faire un print de la structure
     160  ostream& Print(ostream & os, int nelt=8, bool prht=true);
     161  inline ostream& Print(int nelt=8, bool prht=true)
     162    { return Print(cout, nelt, prht); }
    141163
    142164  // fonction appelee par le constructeur pour reordonner les donnees FFT
     
    159181  BRPaqChecker();
    160182  ~BRPaqChecker();
     183
     184  UInt64 DefineHDRTag(UInt32 hdr1=0x76543210, UInt32 hdr2=0xFEDCBA98);
     185  UInt64 DefineTRLTag(UInt32 trl1=0x55555555, UInt32 trl2=0xAAAAAAAA);
     186 
     187  inline UInt64 HDRTag() { return hdrtag_; }
     188  inline UInt64 TRLTag() { return trltag_; }
     189
    161190  // Verifie le paquet, renvoie true si OK
    162191  bool Check(BRPaquet& paq);
     
    168197  unsigned long long lostframes;    // Nombre totale de frames/paquets perdus
    169198  unsigned int frclst;         // derniere valeur du frame-counter
     199
     200  UInt64 hdrtag_;
     201  UInt64 trltag_;
    170202};
    171203
  • trunk/AddOn/TAcq/makefile

    r3592 r3623  
    11include $(SOPHYABASE)/include/sophyamake.inc
    22
    3 all : traidio  tmtfft tstminifits tpciew tbrpaq tmtacq tstrdfits mfits2spec tsok
     3# all : traidio  tmtfft tstminifits tbrpaq tpciew tmtacq tstrdfits mfits2spec tsok
     4all : traidio  tmtfft tstminifits tmtacq tstrdfits mfits2spec tsok
    45
    56clean :
    6         rm *.o traidio tmtfft tstminifits tpciew tbrpaq tmtacq tstrdfits
     7        rm *.o traidio tmtfft tstminifits tpciew tbrpaq tmtacq tstrdfits mfits2spec
    78        rm mfits2spec tsok *.ppf *.fits
    89
     
    1415
    1516tmtacq.o : tmtacq.cc racquproc.h racqurw.h racqumem.h
    16         $(CXXCOMPILE) -c -o tmtacq.o tmtacq.cc
     17        $(CXXCOMPILE) -c -DNOPCIECARD -o tmtacq.o tmtacq.cc
    1718
    1819racqumem.o : racqumem.cc racqumem.h
  • trunk/AddOn/TAcq/pciewrap.cc

    r3538 r3623  
    11#include "pciewrap.h"
     2#include "brpaqu.h"
     3
     4#include "racqumem.h"
    25
    36#include <stdlib.h>
    47#include <stdio.h>
    58#include <math.h>
    6 
    79#include <iostream>
    810
    9 PCIEWrapper::PCIEWrapper()
     11TestPCIWrapperNODMA::TestPCIWrapperNODMA(UInt32 sz)
     12  : PCIEWrapper() , size_(sz)
    1013{
    11 // Faire l'initialisation PCI-Express ici
     14  data_ = new Byte[size_];
     15  frame_counter_ = 0;
     16  timetag_ = 0;
     17  tottransfer_ = 0;     
    1218}
    1319
    14 PCIEWrapper::~PCIEWrapper()
     20TestPCIWrapperNODMA::~TestPCIWrapperNODMA()
    1521{
    16 // Faire le nettoyage (liberer memoire ...)
     22  delete[] data_;       
    1723}
    1824
    19 
    20 // Variables pour tests
    21 static uint_4 NBytes = 0;
    22 static uint_4 Choix = 0;
    23 
    24 uint_4  PCIEWrapper::NBytesToRead()
     25UInt32 TestPCIWrapperNODMA::TransferSize()
    2526{
    26 // Lire le registre indiquant le nombre de mots prets a etre lus
    27 // cad transfere en memoire du PC
    28 int choix = rand()%5;
    29 if (choix < 2) {
    30   Choix = choix;
    31   if (choix == 0)  NBytes = 4096;
    32   else NBytes = 5000;
    33 }
    34 else {
    35   NBytes = 0;
    36   Choix = 0;
    37 }
    38 return NBytes; 
     27  return size_;
    3928}
    4029
    41 uint_4  PCIEWrapper::Read(uint_1* buff, uint_4 nbytes)
     30UInt64 TestPCIWrapperNODMA::TotTransferBytes()
    4231{
    43   if (NBytes == 0)  throw PCIEWException("PCIEWrapper::Read()/Error NBytes==0");
    44   if (nbytes > NBytes)  nbytes = NBytes;
    45   double dx = (rand()%8+1)*0.05;
    46   for(int k=0; k<nbytes; k++)  buff[k] = (uint_1)((1.+sin(dx*k))*100.);
    47   if ((Choix == 1) && (nbytes>2000))
    48     for(int k=1600; k<1900; k++) buff[k] = (uint_1)(128);
    49   return nbytes;
     32  return tottransfer_;
    5033}
     34
     35Byte* TestPCIWrapperNODMA::DoTransferData(int numbuff)
     36{
     37  frame_counter_ ++;
     38  timetag_ = frame_counter_ * size_ / 2;
     39  BRPaquet paq(data_, size_);
     40  paq.SetHDRMarker64(pchk_.HDRTag());
     41  paq.SetTRLMarker64(pchk_.TRLTag());
     42  paq.SetFrameCounter(frame_counter_);
     43  paq.SetTimeTag(timetag_);
     44  paq.SetPaqLen((UInt16)((size_ - BRHDRSIZE - BRTRLSIZE)/4));
     45  Byte* bp = paq.Data1();
     46  for(UInt32 kk=0; kk<paq.DataSize(); kk++)
     47    bp[kk] = (Byte)(sin(0.0345*kk)*78.+127.5);
     48  tottransfer_ += size_;
     49  return data_;
     50}
     51
     52void TestPCIWrapperNODMA::PrintStatus(ostream& os)
     53{
     54  os << "TestPCIWrapperNODMA::Status, FrameCounter=" << frame_counter_
     55     << " TimeTag=" << timetag_ << endl;
     56}
  • trunk/AddOn/TAcq/pciewrap.h

    r3538 r3623  
    11#ifndef  PCIEWRAP_H_SEEN
    22#define  PCIEWRAP_H_SEEN
    3 
     3#include "brtypes.h"
    44#include "machdefs.h"
     5#include "racqumem.h"
     6#include "brpaqu.h"
    57#include <string>
    68
     
    1719  explicit PCIEWException(const char * m) { msg = m; }
    1820  explicit PCIEWException(const string& m) { msg = m; }
     21  virtual ~PCIEWException() { }
    1922  virtual string const& Msg() const  {return msg;}
    2023  virtual const char* what() {return msg.c_str(); }
     
    2427
    2528
     29// Classe definissant l'interface des operations transfert DMA/PCIExpress
    2630class PCIEWrapper {
    27 public:
    28 // Constructeur - fait l'initialisation
    29           PCIEWrapper();
    30 // destructeur - libere la memoire allouee
    31   virtual ~PCIEWrapper();
     31 public:
     32  // Constructeur - fait l'initialisation
     33  PCIEWrapper() { }
     34  // destructeur - libere la memoire allouee
     35  virtual ~PCIEWrapper() { }
    3236
    33 // Retourne le nombre d'octets a lire
    34   uint_4  NBytesToRead();
    35 
    36 // Lecture du buffer de la carte
    37   uint_4  Read(uint_1* buff, uint_4 nbytes);
     37  virtual UInt32 TransferSize() = 0;
     38  virtual Byte* DoTransferData(int numbuff=0) = 0;
     39  virtual UInt64 TotTransferBytes() = 0;   
     40  virtual void PrintStatus(ostream& os) = 0;
    3841};
    3942
     43// Classe de test Implementant l'interface PCIEWrapper sans DMA
     44class TestPCIWrapperNODMA : public PCIEWrapper {
     45public:
     46  TestPCIWrapperNODMA(UInt32 sz);
     47  virtual ~TestPCIWrapperNODMA();
     48
     49  virtual UInt32 TransferSize() ;
     50  virtual Byte* DoTransferData(int numbuff=0) ;
     51  virtual UInt64 TotTransferBytes() ;   
     52  virtual void PrintStatus(ostream& os) ;
     53 
     54protected:
     55  Byte* data_;
     56  UInt32 size_;
     57  UInt32 frame_counter_;
     58  UInt64 timetag_;     
     59  UInt64 tottransfer_;
     60  BRPaqChecker pchk_;
     61};
    4062
    4163#endif
  • trunk/AddOn/TAcq/racqumem.cc

    r3538 r3623  
    88
    99RAcqMemZoneMgr::RAcqMemZoneMgr(uint_4 nz, uint_4 np, uint_4 psz)
    10   :  mex(true), nzones(nz), npaq(np), paqsz(psz), stop_(false)
     10  : mex(true), nzones(nz), npaq(np), paqsz(psz), stop_(false)
    1111{
    1212  St_MemZ st;
     13
    1314  st.act = (uint_4)MemZA_None;
    1415  st.stat = (uint_8)MemZS_Free;
     
    1617  uint_8 mzsz = npaq*paqsz;
    1718
    18   for(int k=0; k<NbZones(); k++) {
    19         memzones.push_back(new Byte[mzsz] );
    20         states.push_back(st);
    21   }     
     19   for(int k=0; k<NbZones(); k++) {
     20     memzones.push_back(new Byte[mzsz] );
     21     states.push_back(st);
     22   }
     23 
    2224}
    2325
     
    3436  mex.lock();
    3537  while ((rid < 0)&&(!stop_)) {
    36     switch (act) {
    37           case MemZA_Fill:
    38             for(int k=0; k<NbZones(); k++) {
    39               if ((states[k].act == MemZA_None) &&
    40                   ((states[k].stat == MemZS_Free)||(states[k].stat & MemZS_Saved)) )
    41                     rid = k; break;
    42             }
    43             if (rid >= 0) { states[rid].act = MemZA_Fill; states[rid].stat = MemZS_Free; }
    44           break;
    45           case MemZA_Save:
    46             for(int k=0; k<NbZones(); k++) {
    47               if ((states[k].act == MemZA_None) && (states[k].stat & MemZS_Filled) &&
    48                   !(states[k].stat & MemZS_Saved) )  rid = k; break;
    49             }
    50             if (rid >= 0) states[rid].act = MemZA_Save;
    51           break;
    52           case MemZA_Proc:
    53             for(int k=0; k<NbZones(); k++) {
    54               if ((states[k].act == MemZA_None) && (states[k].stat & MemZS_Filled) &&
    55                   !(states[k].stat & MemZS_Proc) )  rid = k; break;
    56             }
    57             if (rid >= 0) states[rid].act = MemZA_Proc;                   
    58           break;
    59     }
    60     if (rid < 0) mex.wait();
     38    switch (act)
     39      {
     40      case MemZA_Fill:
     41        if (rid < 0) for(uint_4 k=0; k<NbZones(); k++) {
     42          if ((states[k].act == MemZA_None) &&
     43              ((states[k].stat == MemZS_Free)||(states[k].stat & MemZS_Saved)) )
     44            { rid = k; break; }
     45        }
     46        if (rid >= 0) { states[rid].act = MemZA_Fill; states[rid].stat = MemZS_Free; }
     47        break;
     48      case MemZA_Save:
     49        for(uint_4 k=0; k<NbZones(); k++) {
     50          if ((states[k].act == MemZA_None) && (states[k].stat & MemZS_Filled) &&
     51              !(states[k].stat & MemZS_Saved) ) { rid = k; break; }
     52        }
     53        if (rid >= 0) states[rid].act = MemZA_Save;
     54        break;
     55      case MemZA_Proc:
     56        for(uint_4 k=0; k<NbZones(); k++) {
     57          if ((states[k].act == MemZA_None) && (states[k].stat & MemZS_Filled) &&
     58              !(states[k].stat & MemZS_Proc) ) { rid = k; break; }
     59        }
     60        if (rid >= 0) states[rid].act = MemZA_Proc;               
     61        break;
     62      case MemZA_None:   // MTQ pour supprimer un warning
     63        break;
     64      }
     65    if (rid < 0)  mex.wait();
    6166  }
    6267  mex.unlock();
     
    6671int RAcqMemZoneMgr::FreeMemZone(int id, MemZStatus st)
    6772{
    68   if ((id < 0) || (id >= states.size()))  return 1;
     73  if ((id < 0) || (id >= (int)states.size()))  return 1;
    6974  int rc = 0;
    7075  mex.lock();
     
    114119  os << "RAcqMemZoneMgr::Print() NbZones=" << NbZones() << " PaqSize()=" << PaqSize()
    115120     << " NbPaquets()=" << NbPaquets() << " ZoneSize()=" << ZoneSize() << endl;
    116   for(int k=0; k<states.size(); k++)
     121  for(uint_4 k=0; k<states.size(); k++)
    117122    os << " [" << k << "] Act=" << states[k].act << " Stat=" << states[k].stat
    118123       << " NbAct[0..2]=" << states[k].nbact[0] << "," << states[k].nbact[1]
     
    123128void RAcqMemZoneMgr::Stop()
    124129{
     130  //  cout << "RAcqMemZoneMgr::Stop() ........ STOP                          BROADCAST" <<endl;
    125131  stop_ = true;
    126132  mex.broadcast();
  • trunk/AddOn/TAcq/racqumem.h

    r3538 r3623  
    1414#include "sopnamsp.h"
    1515#include "zthread.h"
    16 
     16// #include "dmamgrintf.h"
    1717#include "brtypes.h"
    18 
     18#include "pciewrap.h"
    1919using namespace std;
    2020
     
    3636class RAcqMemZoneMgr {
    3737public:
    38 // Constructeur, nz=Nb de zones, np=Nb de paquets/zone , psz=taille de paquet
     38// Constructeur, classe dma, nz=Nb de zones, np=Nb de paquets/zone , psz=taille de paquet
    3939  RAcqMemZoneMgr(uint_4 nz, uint_4 np=1000, uint_4 psz=4096);
    4040  ~RAcqMemZoneMgr();
     
    4949  inline uint_4 ZoneSize() { return npaq*paqsz; }
    5050 
     51
    5152  // Retourne un MemZone disponible pour une action specifique
    5253  int FindMemZoneId(MemZaction act);
     
    5556  // Retourne le pointeur de la zone numero k
    5657  inline Byte* GetMemZone(int id)  {
    57     if ((id < 0) || (id >= memzones.size()))  return NULL;
     58    if ((id < 0) || (id >=(int) memzones.size()))  return NULL;
    5859    return memzones[id]; 
    5960    }
     
    6667  ZMutex mex;   
    6768  uint_4 nzones, npaq, paqsz;
     69//  DMAMgrInterface &dma_;
    6870  vector< Byte* > memzones;
    6971  vector< St_MemZ > states;
  • 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}   
  • trunk/AddOn/TAcq/racquproc.h

    r3538 r3623  
    2020
    2121
    22 //-------------------------------------------------------
    23 // Classe thread de traitement
    24 //-------------------------------------------------------
     22//-------------------------------------------------------------------
     23// Classe thread de traitement avec 1 voie par frame (donnees brutes)
     24//-------------------------------------------------------------------
    2525class DataProc : public ZThread {
    2626public:
    27   DataProc(RAcqMemZoneMgr& mem, string& path, uint_4 nmean=1, uint_4 nmax=100);
     27  DataProc(RAcqMemZoneMgr& mem, string& path, uint_4 nmean=1, uint_4 step=1, uint_4 nmax=100);
    2828  virtual void run();
     29  void Stop();
     30  inline void STOP() { stop_ = true; } 
     31
     32protected:
     33  RAcqMemZoneMgr& memgr;
     34  bool stop_; 
     35  uint_4 nmax_;  // Nombre maxi de blocs MemZone traites
     36  uint_4 step_;  // 1/step_ frame traite ds chaque bloc
     37  uint_4 nmean_;  // Nombre de blocs pour le calcul des moyennes
     38  string path_; 
     39  struct sigaction act;
     40};
     41
     42//---------------------------------------------------------------------
     43// Classe thread de traitement avec 2 voies par frame (donnees brutes)
     44//---------------------------------------------------------------------
     45class DataProc2C : public ZThread {
     46public:
     47  DataProc2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean=1, uint_4 step=1, uint_4 nmax=100);
     48  virtual void run();
     49  void Stop();
    2950  inline void STOP() { stop_ = true; } 
    3051protected:
     
    3253  bool stop_; 
    3354  uint_4 nmax_;  // Nombre maxi de blocs MemZone traites
     55  uint_4 step_;  // 1/step_ frame traite ds chaque bloc
    3456  uint_4 nmean_;  // Nombre de blocs pour le calcul des moyennes
    3557  string path_; 
    3658};
    3759
     60//---------------------------------------------------------------------
     61// Classe thread de traitement donnees FFT avec 2 voies par frame
     62//---------------------------------------------------------------------
     63class DataProcFFT2C : public ZThread {
     64public:
     65  DataProcFFT2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean=1, uint_4 step=1, uint_4 nmax=100);
     66  virtual void run();
     67  void Stop();
     68  inline void STOP() { stop_ = true; } 
     69protected:
     70  RAcqMemZoneMgr& memgr;
     71  bool stop_; 
     72  uint_4 nmax_;  // Nombre maxi de blocs MemZone traites
     73  uint_4 step_;  // 1/step_ frame traite ds chaque bloc
     74  uint_4 nmean_;  // Nombre de blocs pour le calcul des moyennes
     75  string path_; 
     76};
    3877
    3978#endif
  • trunk/AddOn/TAcq/racqurw.cc

    r3538 r3623  
    1010#include <unistd.h>
    1111#include <fstream>
    12 
     12#include <signal.h>
    1313#include "pexceptions.h"
    1414#include "timestamp.h"
    15 
    1615
    1716#include "pciewrap.h"
     
    1918#include "minifits.h"
    2019
    21 
     20#include "resusage.h" // Pour mesure temps elapsed/CPU ...
     21#include "datatable.h" // Pour sauver les entetes de paquet
     22#include <sys/time.h>  // pour gettimeofday
    2223//-------------------------------------------------------
    2324// Classe thread de lecture PCI-Express
    2425//-------------------------------------------------------
    2526
    26 PCIEReader::PCIEReader(RAcqMemZoneMgr& mem, uint_4 nmax)
    27   :  memgr(mem)
    28 {
    29   nmax_ = nmax;         
    30   stop_ = false;       
     27PCIEReader::PCIEReader(PCIEWrapper &pciw,uint_4 sizeFrame,uint_4 packSize ,RAcqMemZoneMgr& mem,
     28                       uint_4 nmax, BRDataFmtConv swapall)
     29  :   memgr(mem) , pciw_ (pciw)
     30{
     31  nmax_ = nmax;
     32  swapall_ = swapall;   // select data swap/format conversion for BRPaquet
     33  stop_ = false;
     34  packSize_ = packSize;
     35  sizeFr_ =sizeFrame;
     36  // Pour la logique de gestion des paquets ds zone memoire
     37  mid_ = -2;
     38  targ_npaq_ = 0;
     39 
     40 max_targ_npaq = memgr.NbPaquets();
     41  mmbuf_ = NULL;
     42}
     43
     44bool PCIEReader::MZoneManage(bool fgclean)    // Retourne true si probleme
     45{
     46  /* Pour debug
     47  cout << " PCIEReader::MZoneManage() mid_=" << mid_ << " arg_npaq_= " << targ_npaq_ 
     48       << " max_targ_npaq=" << max_targ_npaq << endl;
     49  */
     50  if (mid_ >= 0)  memgr.FreeMemZone(mid_, MemZS_Filled);
     51  mmbuf_ = NULL;  targ_npaq_ = 0;  mid_ = -2;
     52  if (fgclean)  return false;
     53  mid_ = memgr.FindMemZoneId(MemZA_Fill);
     54  mmbuf_ = memgr.GetMemZone(mid_);
     55  if (mmbuf_==NULL) return true;
     56  return false;
    3157}
    3258
    3359void PCIEReader::run()
    3460{
    35   cout << " PCIEReader::run() - Starting , NMaxMemZones=" << nmax_ << endl;     
     61  struct sigaction act;
     62  struct sigaction old_act;
     63   //Precision insuffisante  ResourceUsage ru; ru.Update();  // Pour recuperer le temps passe
     64  struct timeval tv1, tv2;
     65  gettimeofday(&tv1, NULL);
     66 
     67  try{
     68  cout << " PCIEReader::run() - Starting , NMaxMemZones=" << nmax_
     69       << "memgr.NbPaquets()=" << memgr.NbPaquets() << endl;   
    3670  setRC(1);     
    37   PCIEWrapper pciw;     
     71
     72  uint_4 cpt=0;
     73  // sigaddset(&act.sa_mask,SIGINT);  // pour proteger le transfert DMA
     74  //sigaction(SIGINT,&act,NULL); 
     75       
    3876  uint_4 paqsz = memgr.PaqSize();
    39   for (uint_4 kmz=0; kmz<nmax_; kmz++) {
    40     int mid = memgr.FindMemZoneId(MemZA_Fill);
    41     Byte* buff = memgr.GetMemZone(mid);
    42     if (buff == NULL) {
    43       cout << " PCIEReader::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
    44       setRC(2);           
    45       return;   
    46     }
    47     for(uint_4 i=0; i<memgr.NbPaquets(); i++) {
    48       while(pciw.NBytesToRead() < 1)  usleep(5);
    49       pciw.Read(buff+i*paqsz,paqsz);   
    50     }
    51     memgr.FreeMemZone(mid, MemZS_Filled);
    52   }     
     77  uint_4 dmasz = pciw_.TransferSize();
     78
     79  Byte* Datas = NULL;
     80  Byte* tampon = new Byte[paqsz];
     81  Byte* nextpaq = NULL;
     82
     83  uint_4 off_acheval = 0;
     84 
     85  int nerrdma = 0;
     86  int maxerrdma = 10;
     87  bool fgarret = false;
     88 
     89  uint_4 npaqfait = 0;    //  Nb total de paquets traites (DMA + decode)
     90 
     91  ///  do{  si boucle infini
     92  //  for (uint_4 kmz=0; kmz<nmax_; kmz++)  {
     93  while (npaqfait < nmax_*memgr.NbPaquets()) {
     94    if (stop_) break;
     95    if (fgarret) break;
     96    // On pointe vers le debut de la zone a remplir aver le prochain DMA
     97      Datas=pciw_.DoTransferData();
     98      if (Datas == NULL) { // No data Read in DMA
     99        nerrdma ++;
     100        cout << "PCIEReaderChecker/Erreur Waiting for datas ..." << endl;
     101        pciw_.PrintStatus(cout);
     102        if (nerrdma>=maxerrdma) { fgarret = true; break; }
     103      }
     104      else {  // DMA reussi
     105        uint_4 curoff = 0;
     106        //1- On traite le paquet a cheval, rempli partiellement avec le DMA d'avant si necessaire
     107        if (off_acheval > 0) {
     108          if ((paqsz-off_acheval)< dmasz) {
     109            memcpy((void *)(tampon+off_acheval), (void *)Datas, paqsz-off_acheval);
     110            curoff = paqsz-off_acheval;  off_acheval = 0; 
     111           
     112            if ((nextpaq=NextPaqTarget()) == NULL) {
     113              cout << "2 PCIEReader::run()/Error NextPaqTarget() returned NULL ->STOP 9" << endl;
     114              setRC(9);  fgarret=true; break;
     115            }
     116            BRPaquet paq(tampon, nextpaq, paqsz, swapall_);
     117            npaqfait++;  // Ne pas oublier le compteur de paquets faits
     118          }
     119          else {
     120            memcpy((void *)(tampon+off_acheval), (void *)Datas, dmasz);
     121            curoff =dmasz;
     122            off_acheval = (dmasz+off_acheval);
     123          }
     124        }
     125        //2- On traite les paquets complet qui se trouvent dans la zone du DMA
     126        while((curoff+paqsz)<=dmasz) {
     127          //          BRPaquet paq((Byte*)(Datas)+((paqsz*j)), nextdma+j*paqsz, paqsz, swapall_);
     128          if ((nextpaq=NextPaqTarget()) == NULL) {
     129            cout << "3 PCIEReader::run()/Error NextPaqTarget() returned NULL ->STOP 9" << endl;
     130            setRC(9);  fgarret=true; break;
     131          }
     132          BRPaquet paq(Datas+curoff, nextpaq, paqsz, swapall_);
     133          curoff += paqsz;  // On avance l'index dans le buffer du DMA
     134          npaqfait++;  // Ne pas oublier le compteur de paquets faits
     135        }  // -- FIN traitement des paquets complets ds un DMA
     136        //3- On copie si besoin la fin du DMA dans la zone tampon
     137        if (curoff < dmasz) {
     138          if (fgarret) break;  // pour sortir si l'on est passe par un STOP 9
     139          off_acheval = dmasz-curoff;
     140          memcpy(tampon, (void*)(Datas+curoff), off_acheval);
     141          curoff += off_acheval;
     142        }
     143      }  //   Traitement d'un DMA OK
     144  }
     145//  }while(!stop_);     
     146 
     147 
     148  gettimeofday(&tv2, NULL);
     149  double tmelaps2 = (tv2.tv_sec-tv1.tv_sec)*1000.+(tv2.tv_usec-tv1.tv_usec)/1000.;
     150  if (tmelaps2<0.1) tmelaps2=0.1;
     151  cout << " ------------------ PCIEReader::run()-End summary -------------------" << endl;
     152  cout << " PCIEReader/Info TotTransfer=" << pciw_.TotTransferBytes()/1024
     153       << " kb , ElapsTime=" << tmelaps2 << " ms ->"
     154       << (double)pciw_.TotTransferBytes()/tmelaps2 << " kb/s" << endl;
     155  cout << " --------------------------------------------------------------------" << endl;
     156 
     157  MZoneManage(true);
     158  delete [] tampon;
     159 
     160  }catch (PException& exc) {
     161    cout << " PCIEREADER::run()/catched PException " << exc.Msg() << endl;
     162    setRC(3);   
     163    return;
     164  }
     165  catch(...) {
     166    cout << "  PCIEREADER::run()/catched unknown ... exception " << endl;
     167    setRC(4);   
     168    return;
     169  }
    53170  setRC(0);
     171 
    54172  return;
    55173}
    56174
     175
     176void PCIEReader::Stop()
     177{
     178  // cout << " PCIEReader::Stop() -------------> STOP" <<endl;
     179  stop_ = true;
     180  return;
     181}
    57182
    58183
     
    61186//-------------------------------------------------------
    62187
    63 DataSaver::DataSaver(RAcqMemZoneMgr& mem, string& path, uint_4 nmax)
     188DataSaver::DataSaver(RAcqMemZoneMgr& mem, string& path, uint_4 nfiles, uint_4 nblocperfile, bool savesig)
    64189  :  memgr(mem)
    65190{
    66   nmax_ = nmax;
     191  nfiles_ = nfiles;
     192  nblocperfile_ = nblocperfile;
     193  nmax_ = nblocperfile_*nfiles_;
     194  savesig_ = savesig;  // Si false, pas d'ecriture des fichiers FITS du signal 
    67195  stop_ = false;       
    68196  path_ = path;
    69197}
    70 
     198void DataSaver::Stop()
     199{
     200  // cout<< " DataSaver:Stop ........ " << endl;
     201  stop_=true;
     202
     203}
    71204void DataSaver::run()
    72205{
    73206  setRC(1);     
     207  BRPaqChecker pcheck;  // Verification/comptage des paquets
     208
    74209  try {
    75210    TimeStamp ts;
    76     cout << " DataSaver::run() - Starting " << ts << " NMaxMemZones=" << nmax_ << endl;
     211    cout << " DataSaver::run() - Starting " << ts << " NbFiles=" << nfiles_ << " NBloc/File="
     212         << nblocperfile_ << " NMaxMemZones=" << nmax_ << endl;
    77213    char fname[512];
     214
    78215    sprintf(fname,"%s/saver.log",path_.c_str());
    79216    ofstream filog(fname);
    80217    filog << " DataProc::run() - starting log file " << ts << endl;                   
    81 
     218    filog << " NbFiles=" << nfiles_ << " NBloc/File="  << nblocperfile_ << " NMaxMemZones=" << nmax_ << endl;
     219       
     220    DataTable dt;
     221    dt.AddLongColumn("TimeTag");
     222    dt.AddIntegerColumn("FrameCounter");
     223    dt.AddIntegerColumn("FrameLength");
     224    dt.AddIntegerColumn("Num");
     225    DataTableRow dtr = dt.EmptyRow();
     226    uint_8 timtag = 0;
     227    uint_4 numpaq = 0;
     228    bool dthead = false;  // Mettre a false pour ne pas remplir DataTable Headers
     229
     230
     231    uint_4 fnum=0;
    82232    uint_4 paqsz = memgr.PaqSize();
    83     for (uint_4 kmz=0; kmz<nmax_; kmz++) {
    84       int mid = memgr.FindMemZoneId(MemZA_Save);
    85       Byte* buff = memgr.GetMemZone(mid);
    86       if (buff == NULL) {
    87         cout << " DataSaver::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
    88         setRC(2);       
    89         return;
     233    for (uint_4 nbFile=0;nbFile<nfiles_ ;nbFile++) {
     234      if (stop_ )   break;
     235      sprintf(fname,"%s/HDRfits%d.txt",path_.c_str(),fnum);
     236      ofstream header(fname);
     237
     238      BRPaquet paq0(NULL, NULL, paqsz);
     239      uint_4 npaqperfile = memgr.NbPaquets()*nblocperfile_;  // Nombre de paquets ecrits dans un fichier
     240
     241      MiniFITSFile mff;
     242      if (savesig_) { //Reza - Ouverture conditionnel fichier
     243        sprintf(fname,"%s/signal%d.fits",path_.c_str(),(int)fnum++);
     244        mff.Open(fname,MF_Write);  //Reza - Ouverture conditionnel fichier
     245        mff.setDTypeNaxis(MF_Byte, paq0.DataSize()+paq0.HeaderSize(), npaqperfile);
    90246      }
    91       sprintf(fname,"%s/signal%d.fits",path_.c_str(),(int)kmz);
    92       MiniFITSFile mff(fname,MF_Write);
    93       BRPaquet paq0(NULL, buff, paqsz);
    94       mff.setDTypeNaxis(MF_Byte, paq0.DataSize(), memgr.NbPaquets());
    95       for(uint_4 i=0; i<memgr.NbPaquets(); i++) {
    96         BRPaquet paq(NULL, buff+i*paqsz, paqsz);
    97         mff.WriteB(paq.Data(), paq.DataSize());
     247      else sprintf(fname,"MemDataBloc[%d]-NoDataFile",(int)fnum++);
     248
     249      for (uint_4 kmz=0; kmz<nblocperfile_; kmz++) {
     250        if (stop_) break;
     251          //DBG cout << " DataSaver::run()- nbFile=" << nbFile << " kmz=" << kmz << endl;       
     252        int mid = memgr.FindMemZoneId(MemZA_Save); 
     253        Byte* buff = memgr.GetMemZone(mid);
     254        if (buff == NULL) {
     255          cout << " DataSaver::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
     256          setRC(2);     
     257          return;       
     258        }
     259        for(uint_4 i=0; i<memgr.NbPaquets(); i++) {
     260 
     261          BRPaquet paq(NULL, buff+i*paqsz, paqsz);
     262          pcheck.Check(paq);   // Verification du paquet / FrameCounter
     263
     264          header << hex << paq.HDRMarker() << " " << paq.TRLMarker() << " " << paq.TimeTag2()<< " "<< paq.TimeTag1()<< " " << paq.FrameCounter() << " " << paq.PaqLen()  << endl;
     265
     266          if (dthead) {  // Remplissage DataTable entetes paquets
     267            timtag = (uint_8)paq.TimeTag2()*0x100000000ULL+paq.TimeTag1();
     268            dtr[0] = timtag;
     269            dtr[1] = paq.FrameCounter();
     270            dtr[2] = paq.PaqLen();
     271            dtr[3] = numpaq++;
     272            dt.AddRow(dtr);
     273          }
     274
     275          if (savesig_) // Reza - Ecriture conditionnel fichier fits signal
     276          //  mff.WriteB(paq.Data1(), paq.DataSize());
     277            mff.WriteB(paq.Header(),paq.DataSize()+paq.HeaderSize()); // ecriture datas + header
     278        }
     279        memgr.FreeMemZone(mid, MemZS_Saved);
    98280      }
    99       filog << ts << " : created data file  " << fname << endl;               
    100       cout << " DataSaver::run() " << ts << " : created data file  " << fname << endl;
    101       memgr.FreeMemZone(mid, MemZS_Saved);
     281      ts.SetNow();
     282      filog << ts << " : OK data file  " << fname << endl;                     
     283      cout << " DataSaver::run() " << ts << " : OK data file  " << fname << endl;
    102284    }
     285    if (dthead) {
     286      cout << dt;
     287      char fname2[256];
     288      sprintf(fname2,"%s/headers.ppf",path_.c_str());
     289      POutPersist po(fname2);
     290      po << dt;
     291    }
     292    cout << " --------------------  DataSaver::run() -------------------- " << endl;
     293    pcheck.Print(cout);
     294    cout << " ---------------------------------------------------------- " << endl;
     295    ts.SetNow();
     296    pcheck.Print(filog);
     297    filog << " DataSaver::run() - End of processing/run() " << ts << endl;                     
     298
    103299  }
    104300  catch (MiniFITSException& exc) {
     
    117313
    118314
     315
     316
     317//----------------------------------------------------------------------------------------------------------
     318// Classe thread de lecture PCI-Express + Check pour tests de verification de debit/etc avec un seul thread
     319//----------------------------------------------------------------------------------------------------------
     320
     321PCIEReaderChecker::PCIEReaderChecker(PCIEWrapper &pciw,uint_4 sizeFrame,uint_4 packSize ,RAcqMemZoneMgr& mem,
     322                                     uint_4 nmax, BRDataFmtConv swapall)
     323  :   memgr(mem) , pciw_ (pciw)
     324{
     325  nmax_ = nmax;
     326  swapall_ = swapall;   // select data swap/format conversion for BRPaquet
     327  stop_ = false;
     328  packSize_ = packSize;
     329  sizeFr_ =sizeFrame;
     330}
     331void PCIEReaderChecker::run()
     332{
     333 
     334  struct timeval tv1, tv2;
     335  gettimeofday(&tv1, NULL);
     336 
     337  cout << " PCIEReaderChecker::run() - Starting , NMaxMemZones=" << nmax_
     338       << " memgr.NbPaquets()=" << memgr.NbPaquets() << endl;   
     339  setRC(1);     
     340  cout << " ... RAcqMemZoneMgr not used - using s fixed memory location for packets decoding ..." << endl;
     341
     342  uint_4 cpt=0;
     343  // sigaddset(&act.sa_mask,SIGINT);  // pour proteger le transfert DMA
     344  //sigaction(SIGINT,&act,NULL);       
     345  uint_4 paqsz = memgr.PaqSize();
     346  uint_4 dmasz = pciw_.TransferSize();
     347
     348  BRPaqChecker pcheck;  // Verification/comptage des paquets
     349
     350  Byte* Datas = NULL;
     351  Byte* locdata = new Byte[paqsz];
     352  Byte* tampon = new Byte[paqsz];
     353
     354  uint_4 off_acheval = 0;
     355
     356  int nerrdma = 0;
     357  int maxerrdma = 10;
     358  bool fgarret = false;
     359  for (uint_4 kmz=0; kmz<nmax_; kmz++)  {
     360    if (stop_) break;
     361    if (fgarret) break;
     362
     363    Byte* nextdma = locdata;
     364    uint_4 npaqfait = 0;     
     365    //      for (uint_4 i=0; i<memgr.NbPaquets(); i += pktInDMATr) {  // attention pktInDMATr paquets dans 1 seul DMA
     366    while (npaqfait < memgr.NbPaquets()) {
     367      if (fgarret) break;
     368      // On pointe vers le debut de la zone a remplir aver le prochain DMA
     369      //-- Zone memoire locale Byte* nextdma = buff+i*paqsz;
     370        Datas=pciw_.DoTransferData();
     371       
     372        if (Datas == NULL) { // No data Read in DMA
     373          nerrdma ++;
     374          cout << "PCIEReaderChecker/Erreur Waiting for datas ..." << endl;
     375          pciw_.PrintStatus(cout);
     376          if (nerrdma>=maxerrdma) { fgarret = true; break; }
     377        }
     378        else {
     379          uint_4 curoff = 0;
     380          //1- On traite le paquet a cheval, rempli partiellement avec le DMA d'avant si necessaire
     381          //      if (off_acheval > 0) { 
     382          //  memcpy((void *)(tampon+off_acheval), (void *)Datas, paqsz-off_acheval);
     383          //  curoff = paqsz-off_acheval;  off_acheval = 0; 
     384           
     385          // BRPaquet paq(tampon, locdata, paqsz, swapall_);
     386          //  npaqfait++;  // Ne pas oublier le compteur de paquets faits
     387          //  pcheck.Check(paq);   // Verification du paquet / FrameCounter
     388          //}
     389        if (off_acheval > 0) {
     390          if ((paqsz-off_acheval)< dmasz) {
     391            memcpy((void *)(tampon+off_acheval), (void *)Datas, paqsz-off_acheval);
     392            curoff = paqsz-off_acheval;  off_acheval = 0; 
     393           
     394            BRPaquet paq(tampon, locdata, paqsz, swapall_);
     395            npaqfait++;  // Ne pas oublier le compteur de paquets faits
     396            pcheck.Check(paq);   // Verification du paquet / FrameCounter
     397          }
     398          else {
     399            memcpy((void *)(tampon+off_acheval), (void *)Datas, dmasz);
     400            curoff =dmasz;
     401            off_acheval = (dmasz+off_acheval);
     402          }
     403        }
     404          //2- On traite les paquets complet qui se trouvent dans la zone du DMA
     405          while((curoff+paqsz)<=dmasz) {
     406            //        BRPaquet paq((Byte*)(Datas)+((paqsz*j)), nextdma+j*paqsz, paqsz, swapall_);
     407            BRPaquet paq(Datas+curoff, locdata, paqsz, swapall_);
     408            curoff += paqsz;  // On avance l'index dans le buffer du DMA
     409            npaqfait++;  // Ne pas oublier le compteur de paquets faits
     410            pcheck.Check(paq);   // Verification du paquet / FrameCounter
     411          }  // -- FIN traitement des paquets complets ds un DMA
     412          //3- On copie si besoin la fin du DMA dans la zone tampon
     413          if (curoff < dmasz) {
     414            off_acheval = dmasz-curoff;
     415            memcpy(tampon, (void*)(Datas+curoff), off_acheval);
     416            curoff += off_acheval;
     417          }
     418        }  //   Traitement d'un DMA OK
     419       
     420    }  // Fin boucle de remplissage d'une zone memoire
     421  } //  Fin boucle sur les zones
     422 
     423  setRC(0);
     424  gettimeofday(&tv2, NULL);
     425  double tmelaps2 = (tv2.tv_sec-tv1.tv_sec)*1000.+(tv2.tv_usec-tv1.tv_usec)/1000.;
     426  if (tmelaps2<0.1) tmelaps2=0.1;
     427  cout << " ------------------ PCIEReaderChecker::run()-End summary -------------------" << endl;
     428  cout << " PCIEReaderChecker/Info TotTransfer=" << pciw_.TotTransferBytes()/1024
     429       << " kb , ElapsTime=" << tmelaps2 << " ms ->"
     430       << (double)pciw_.TotTransferBytes()/tmelaps2 << " kb/s" << endl;
     431  pcheck.Print(cout);
     432  cout << " --------------------------------------------------------------------" << endl;
     433
     434  delete [] locdata;
     435  delete [] tampon;
     436
     437  return;
     438}
     439void PCIEReaderChecker::Stop()
     440{
     441  // cout << " PCIEReaderChecker::stop()  ........ STOP" <<endl;
     442  stop_ = true;
     443
     444}
  • trunk/AddOn/TAcq/racqurw.h

    r3538 r3623  
    1414#include "sopnamsp.h"
    1515#include "zthread.h"
     16#include "pciewrap.h"
    1617
    1718#include "brtypes.h"
     19#include "brpaqu.h"
    1820
    1921using namespace std;
     
    2729class PCIEReader : public ZThread {
    2830public:
    29   PCIEReader(RAcqMemZoneMgr& mem, uint_4 nmax=100);     
     31  PCIEReader( PCIEWrapper &pciw , uint_4 sizeFrame,uint_4 paqSize ,RAcqMemZoneMgr& mem,
     32              uint_4 nmax=100, BRDataFmtConv swapall=BR_SwapAll);       
    3033  virtual void run();
     34   void Stop();
    3135  inline void STOP() { stop_ = true; } 
     36   
    3237protected:
     38  // Pour recuperer un pointeur sur la prochaine zone memoire devant recevoir un paquet
     39  inline Byte* NextPaqTarget()  {
     40    if ((mmbuf_ == NULL )||(targ_npaq_ >= max_targ_npaq))
     41      if (MZoneManage()) return NULL;
     42    Byte* rb=mmbuf_+targ_npaq_*packSize_;
     43    targ_npaq_++;
     44    return rb;
     45  }
     46  bool MZoneManage(bool clean=false);  // Renvoie true si probleme
     47
    3348  RAcqMemZoneMgr& memgr;
    3449  uint_4 nmax_;  // Nombre maxi de blocs MemZone traites
     50  BRDataFmtConv swapall_;  // select data swap/format conversion for BRPaquet
    3551  bool stop_; 
     52  unsigned int sizeFr_ ;
     53  PCIEWrapper& pciw_;
     54  uint_4 packSize_;
     55  // Variables pour gerer la logique de  NextPaqTarget() qui cache l'acces a RAcqMemZoneMgr
     56  int mid_;  // Identificateur zone memoire
     57  uint_4 targ_npaq_;  // Numero de paquet dans une seule zone memoire
     58  uint_4 max_targ_npaq; // =  mmgr.NbPaquets() = Max de targ_npaq_
     59  Byte* mmbuf_;  // Pointeur zone memoire rendu par RAcqMemZoneMgr
    3660};
    3761
     
    4266class DataSaver : public ZThread {
    4367public:
    44   DataSaver(RAcqMemZoneMgr& mem, string& path, uint_4 nmax=100);
     68  DataSaver(RAcqMemZoneMgr& mem, string& path, uint_4 nfiles=100, uint_4 nblocperfile=1, bool savesig=true);
     69
    4570  virtual void run();
     71  void Stop();
     72  inline void STOP() { stop_ = true; } 
     73protected:
     74  RAcqMemZoneMgr& memgr;
     75  uint_4 nfiles_;  // Nombre maxi de fichiers cree
     76  uint_4 nblocperfile_;  // Nombre de bloc (zone memoire) mis dans un fichier
     77  uint_4 nmax_;  // Nombre maxi de blocs MemZone traites = nfiles * nblocperfile_
     78  bool savesig_; // Si false, pas d'ecriture des fichiers FITS du signal
     79  bool stop_; 
     80  string path_; 
     81  struct sigaction act;
     82 
     83};
     84
     85//-------------------------------------------------------
     86// Classe thread de lecture PCI-Express + Check
     87//-------------------------------------------------------
     88
     89class PCIEReaderChecker : public ZThread {
     90public:
     91  PCIEReaderChecker( PCIEWrapper &pciw , uint_4 sizeFrame,uint_4 paqSize ,RAcqMemZoneMgr& mem,
     92                     uint_4 nmax=100, BRDataFmtConv swapall=BR_SwapAll); 
     93  virtual void run();
     94   void Stop();
    4695  inline void STOP() { stop_ = true; } 
    4796protected:
    4897  RAcqMemZoneMgr& memgr;
    4998  uint_4 nmax_;  // Nombre maxi de blocs MemZone traites
     99  BRDataFmtConv swapall_;  // select data swap/format conversion for BRPaquet
    50100  bool stop_; 
    51   string path_; 
     101  unsigned int sizeFr_ ;
     102  PCIEWrapper& pciw_;
     103  uint_4 packSize_;
    52104};
    53105
    54 
    55106#endif
  • trunk/AddOn/TAcq/tmtacq.cc

    r3538 r3623  
    11#include <iostream>
    22
     3#include "tmtacq.h"
    34#include "racqumem.h"
    45#include "racqurw.h"
     6#ifndef NOPCIECARD
     7#include "racquwbin.h"
     8#endif
    59#include "racquproc.h"
     10
    611
    712#include "pciewrap.h"
     
    1823using namespace std;
    1924using namespace SOPHYA;
    20 
     25       
     26static DataSaver *pDs;
     27static PCIEReaderChecker *pPcierc;
     28static PCIEReader *pPcier;
     29static DataProcFFT2C *pPrfft;
     30static DataProc2C *pPr;
     31static RAcqMemZoneMgr *pMmgr;
    2132//--------------------------------------------------------
    22 // Programme test acquisition BAORadio multi-thread
     33// Programme test acquisition BAORadio multi-thread 
    2334//  LAL -   R. Ansari Juillet -  2008
    2435//--------------------------------------------------------
     36void Stop(int s)
     37{
     38  printf("............. MAIN ... receive signal %d \n",s);
     39  if (pPcierc != NULL) pPcierc->Stop();
     40  if (pPcier != NULL) pPcier->Stop();
     41  if (pPr !=NULL) pPr->Stop();
     42  if (pPrfft !=NULL) pPrfft->Stop();
     43  if (pDs != NULL) pDs->Stop();
     44  if (pMmgr !=NULL) pMmgr->Stop();
     45 
     46}
    2547
    2648int main(int narg, char* arg[])
    27 {
     49{
     50 
     51 struct sigaction act;
    2852 
    2953  int rc = 0;
     54 cout << " ===============================================================" << endl;
     55  cout << " =========  " <<BAOR_ACQ_VER_STR <<BAOR_ACQ_VER <<"                  ===========" << endl;
     56  cout << " ===============================================================" << endl;
     57 
     58 if (narg < 8) {
     59   cout << "\n Usage: tmtacq CardNum PaquetSize NFrameDMA NFiles NBlocPerFile NMaxProc DataDirPath [AcqMode] [NPaqMemZone][HardCtlC]" << endl;
     60   cout << " - CardNum : PCI-Express card number (=1,2)" << endl;
     61   cout << " - PaquetSize or FrameSize (=DATA+HDR+TRL_Size)  " << endl;
     62   cout << " - NFrameDMA = DMASize= NFrameDMA*1024 , 4KO<=MaxDMASize<=64 ko " << endl;
     63   cout << " - NFiles = Number of data files produced " << endl;
     64   cout << " - NBlocPerFile = Number of memory data bloc in one file " << endl;
     65   cout << " - NMaxProc = Max number of memory data blocs processed (FFT ...) " << endl;
     66   cout << "      NMaxProc=0 -> No Processing " << endl;
     67   cout << " - DataDirPath : Subdirectory of /Raid " << endl;
     68   cout << "   Pour la version du firmware qui ne swappe pas les paquets" << endl;
     69   cout << " - AcqMode: = swapall , fft1c , fft2c, swh , nof , mxs , mono , monosw (default=std)" << endl;
     70   cout << "    swapall -> SwapAll+SaveData , swh->swap header only " << endl;
     71   cout << "    fft1c , ff2c -> reorder data for 1 channel/2channel FFT " << endl;
     72   cout << "    fft1cnof , ff2cnof -> reorder FFT data, but DONT write files " << endl;
     73   cout << endl;
     74   cout << "   Pour la version du firmware qui swappe partiellement " << endl;
     75   cout << "  -AcqMode : swap32 ,fft1c32 , fft2c32,fft1cnof32 , fft2cnof32 " <<endl;
     76   cout << "    fft1c32 , fft2c32 -> reorder data for 1 channel/2channel FFT " << endl;
     77   cout << "    fft1cnof32 , ff2cnof32 -> reorder FFT data, but DONT write files " << endl << endl;
     78 cout << endl;
     79   cout << "   Pour la version du firmware qui ne swappe plus " << endl;
     80   cout << "  -AcqMode :  nosw,fft1cnosw , fft2cnosw" <<endl;
     81   cout << "    fft1cnosw , fft2cnosw -> reorder data for 1 channel/2channel FFT " << endl;
     82   cout << "    fft1cnofnosw , ff2cnofnosw -> reorder FFT data, but DONT write files " << endl << endl;
     83
     84
     85   cout << "   Option pour debug ou test performance swapp initial (std)" << endl ;
     86   cout << "    nof->Don't write signal fits files , mxs->swh+nof: swap header only + no fits " << endl;
     87   cout << "    mono->Test with a single thread PCIEReaderChecker " << endl;
     88   cout << "   monosw->Test with a single thread PCIEReaderChecker, But swap all packet " << endl;
     89   cout << endl;
     90   cout << "   mononsw->Test with a single thread PCIEReaderChecker, But no swap paquet " << endl;
     91   cout << endl;
     92   cout << " - NPaqMemZone : Number of paquets in one memory data bloc (Default=128) " << endl;
     93   cout << " -HardCtlC : Y y (direct interrpution by CtrlC ) default (no) " << endl;
     94  return 1;
     95  }
     96
    3097  InitTim();
    3198 
     
    33100  TArrayInitiator _arri;
    34101  FitsIOServerInitiator _fiosi;
    35  
    36102  Timer tm("tmtacq");
    37   string dir = "ExA";
    38   cout << "tmtacq[1] - starting acq program " << endl;
    39  
     103 
     104  string acqmode = "std";
     105  if (narg > 8)  acqmode = arg[8];
     106  bool savesigfits = true;
     107  // BRDataFmtConv swapall = BR_SwapAll;
     108  BRDataFmtConv swapall = BR_Copy;
     109  bool monothr = false;
     110  if (acqmode == "swapall")  swapall = BR_SwapAll;
     111  if (acqmode == "fft1c")  swapall = BR_FFTOneChan;
     112  if (acqmode == "fft2c")  swapall = BR_FFTTwoChan;
     113  if (acqmode == "fft1cnof")  { swapall = BR_FFTOneChan;  savesigfits = false; }
     114  if (acqmode == "fft2cnof")  { swapall = BR_FFTTwoChan;  savesigfits = false; }
     115  if ((acqmode == "swh") || (acqmode == "mxs") || (acqmode == "mono") )  swapall = BR_SwapHDR;
     116  if ((acqmode == "nof") || (acqmode == "mxs") || (acqmode == "mono"))  savesigfits = false;
     117  if (acqmode == "mono")  { monothr = true;   swapall = BR_SwapHDR;; }
     118  if (acqmode == "monosw")  { monothr = true;   swapall = BR_SwapAll; }
     119  if (acqmode == "mononsw")  { monothr = true;   swapall = BR_Copy; }
     120
     121  if (acqmode == "swap32")   swapall = BR_Swap32 ;
     122  if (acqmode == "fft1c32")  swapall = BR_FFTOneChan32;
     123  if (acqmode == "fft2c32")  swapall = BR_FFTTwoChan32;
     124  if (acqmode == "fft1cnof32")  { swapall = BR_FFTOneChan32;  savesigfits = false; }
     125  if (acqmode == "fft2cnof32")  { swapall = BR_FFTTwoChan32;  savesigfits = false; }
     126
     127  if (acqmode == "nosw")   swapall = BR_Copy ;
     128  if (acqmode == "fft1cnosw")  swapall = BR_FFTOneChanNoSwap;
     129  if (acqmode == "fft2cnosw")  swapall = BR_FFTTwoChanNoSwap;
     130  if (acqmode == "fft1cnofnosw")  { swapall = BR_FFTOneChanNoSwap;  savesigfits = false; }
     131  if (acqmode == "fft2cnofnosw")  { swapall = BR_FFTTwoChanNoSwap;  savesigfits = false; }
     132
     133#ifdef NOPCIECARD
     134  string dir = string(arg[7])+"/";
     135#else 
     136  string dir =string("/Raid/")+arg[7]+"/";
     137#endif
     138  cout << "  DataDirpath=" << dir << " SwapMode=" << BRPaquet::FmtConvToString(swapall)
     139       << "  DataSaveMode=" << ((savesigfits)?"Yes/FitsFile":"NO") << endl;
     140 
     141  char cmd[192];
     142  sprintf(cmd,"mkdir %s",dir.c_str());
     143  if (system(cmd) < 0) {
     144    cout << "tmtacq/Error: Can not create  subdirectory " << dir << " -> exit" << endl;
     145    return 2;
     146  }
     147  int card = atoi(arg[1]);
     148  unsigned int sizeFrame = atoi(arg[2]);
     149  unsigned int nbFrameDMA = atoi(arg[3]);
     150  int NbFiles = atoi(arg[4]);
     151  int NBlocPerFile = atoi(arg[5]);
     152  int NMaxProc = atoi(arg[6]);  // Nombre de blocs traites par le thread de calcul
     153  cout << "tmtacq[1] - starting acq program under card " << card <<  " FrameSize= " << sizeFrame << endl;
     154
     155  uint_4 nZones = 10;  // Nombre de zones memoires
     156  uint_4 nPaqZone = 128;  // 128 Paquets / zone memoire - valeur par defaut
     157  if (narg > 9)    // pour traiter eventuellement un arret brutal par CtlC mettre le 9eme arg a Y
     158    { string val = arg[9];
     159      if ( ( val == "Y")||( val == "y")) ;
     160      else {
     161        act.sa_handler=Stop;
     162        sigaction(SIGINT,&act,NULL);   
     163        if ( atoi(arg[9]) > 0)  nPaqZone=atoi(arg[9]);
     164      }
     165    }
     166  else {
     167    act.sa_handler=Stop;
     168    sigaction(SIGINT,&act,NULL);       
     169  }
     170  uint_4 PaqSZ =sizeFrame;  // Taille de paquets
     171  // uint_4 dmaSize  = nbFrameDMA*PaqSZ ;  // plantage
     172  uint_4 dmaSize  = nbFrameDMA*1024 ;
     173  uint_4 patternSZ=0x400;  // pas utilise avec la fibre
     174  uint_4 NMaxBloc = NbFiles*NBlocPerFile;
     175  cout << "tmtacq[0] - PaqSize = " << PaqSZ << " NbPaq/Zone=" << nPaqZone << " NZones=" << nZones << endl;
     176  cout << " NbFiles=" << NbFiles << " NBloc/File=" << NBlocPerFile << " -> NMaxBloc=" << NMaxBloc << endl;
     177  cout << "tmtacq[1] NbFrameDMA=" << nbFrameDMA << "  DMASize=" << dmaSize << " bytes" << endl;
     178  cout << "tmtacq[1] NMaxProc=" << NMaxProc << endl;
    40179  try {
    41     RAcqMemZoneMgr mmgr(3,100,4096);
    42     PCIEReader pcir(mmgr, 10);
    43     DataSaver ds(mmgr, dir, 10);
    44     DataProc pr(mmgr, dir, 1, 10);
     180
     181#ifdef NOPCIECARD
     182    TestPCIWrapperNODMA pciw(PaqSZ);
     183#else
     184    DMAMgr dma1(card,patternSZ,dmaSize );
     185    if (! dma1.StatusFibre() ) {
     186      cout << " tmtacq[0] - fibre non accrochee -> exit " << endl;
     187      throw PCIEWException(" Fibre non accrochee ");
     188    }
     189    else cout << " tmtacq[0] - fibre accrochee OK " << endl;
     190#endif   
     191    RAcqMemZoneMgr mmgr(nZones, nPaqZone, PaqSZ);
     192    pMmgr =&mmgr;
     193
     194    if (monothr) {
     195      cout << "tmtacq[1] single thread PCIE test PCIEReaderChecker ... ";
     196      PCIEReaderChecker pcirc(pciw,dmaSize,PaqSZ ,mmgr, NMaxBloc, swapall);
     197      pPcierc=&pcirc;
     198      pcirc.start();
     199      sleep(1);
     200      pcirc.join();
     201      cout << "tmtacq[2] - single thread PCIEReaderChecker finished " << endl;
     202      tm.Split("Single Thread Finished"); 
     203      mmgr.Print(cout);
     204      return 0;
     205    }
     206    PCIEReader pcir(pciw,dmaSize,PaqSZ ,mmgr, NMaxBloc, swapall);
     207    pPcier= &pcir;
     208     DataSaver ds(mmgr, dir, NbFiles, NBlocPerFile, savesigfits);
     209     pDs= &ds;
     210     //DataBinSaver ds(mmgr, dir, NbFiles ,NBlocPerFile);
     211     //     DataProc1C pr(mmgr, dir, nmean, stepproc, 100);     Pour processer un canal
     212     int stepproc = 2;
     213     int nmean = nPaqZone*NBlocPerFile/stepproc;
     214     DataProc2C pr(mmgr, dir, nmean, stepproc, NMaxProc);
     215     DataProcFFT2C prfft(mmgr, dir, nmean, stepproc, NMaxProc);
    45216    tm.Split("Threads created"); 
    46217    cout << "tmtacq[2] - starting 3 threads pcir, ds, pr ... " << endl;
     218    /*
     219    char test[100];
     220    cout << " <CR> to continue, x to exit ..." << endl;
     221    gets(test); if (test[0] == 'x')  return 9;
     222    */
    47223    pcir.start();
    48224    ds.start();
    49     pr.start();
     225    if (NMaxProc>0) { // On ne demarre que si au moins NMaxProc>0
     226      if (acqmode.substr(0,5)=="fft2c") { prfft.start(); pPrfft=&prfft;}
     227      else { pr.start();   pPr=&pr;}
     228    }
    50229    cout << "tmtacq[3] - waiting for threads to finish ... " << endl;
    51230    sleep(1);
     
    54233    sleep(1);
    55234    mmgr.Stop();
    56     pr.join();
     235   if (NMaxProc>0) if ( pPr != NULL) pr.join();
     236   if (NMaxProc>0) if ( pPrfft != NULL) prfft.join();
    57237    cout << "tmtacq[4] - threads finished " << endl;
    58238    tm.Split("Threads Finished"); 
     
    63243    cerr << " tmtacq.cc catched MiniFITSException " << exc.Msg() << endl;
    64244    rc = 77;
     245  }
     246  catch (PCIEWException& exc) {
     247    cerr << "\7  tmtacq.cc catched MiniFITSException " << exc.Msg() << endl;
     248    rc = 75;
    65249  } 
    66250  catch (PThrowable& exc) {
     
    75259  }
    76260  catch (...) {
    77         cerr << " tmtacq.cc : Catched ... exception " << endl;
     261        cerr << "  tmtacq.cc : Catched ... exception " << endl;
    78262        rc = 79;
    79263  }
     
    81265  return rc;
    82266}
     267
  • trunk/AddOn/TAcq/tmtfft.cc

    r3538 r3623  
    2727#include "tarrinit.h"
    2828
    29 #include "stsrand.h"
     29#include "randfmt.h"
    3030#include "fftpserver.h"
    3131#include "fftwserver.h"
     
    7979  cout << "MTDoFFT::run() - Nom= " << nom_ << " vv.Size()= " << vv_.Size()
    8080       << " PaqSz=" << paqsz_ << " NbFFT= " << nbfft_ << endl;
    81   RandomGenerator rgen;
     81  FMTRandGen rgen;
    8282  TVector<r_4> vx(paqsz_);
    8383  fftwf_plan plan = fftwf_plan_dft_r2c_1d(paqsz_, vx.Data(),
     
    111111  Timer tm("f3_tmtfft");
    112112  vector<MTDoFFT *> vth;
    113   RandomGenerator rg;
     113  FMTRandGen rg;
    114114  TVector<r_4> DATA(VSZ);
    115115  for(sa_size_t i=0; i<VSZ; i++)
Note: See TracChangeset for help on using the changeset viewer.