| [3537] | 1 | #ifndef  RACQURW_H_SEEN
 | 
|---|
 | 2 | #define  RACQURW_H_SEEN
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 | //----------------------------------------------------------------
 | 
|---|
 | 5 | // ---- classes de threads pour lecture (transfert DMA) 
 | 
|---|
 | 6 | //      et ecriture disque pour acquisition   BAORadio       -----
 | 
|---|
 | 7 | // LAL -      R. Ansari - Juin/Juillet 2008 
 | 
|---|
 | 8 | //----------------------------------------------------------------
 | 
|---|
 | 9 | 
 | 
|---|
 | 10 | #include "racqumem.h"
 | 
|---|
 | 11 | #include <string>
 | 
|---|
 | 12 | #include <vector>
 | 
|---|
 | 13 | #include <iostream>
 | 
|---|
 | 14 | #include "sopnamsp.h"
 | 
|---|
 | 15 | #include "zthread.h"
 | 
|---|
| [3623] | 16 | #include "pciewrap.h"
 | 
|---|
| [3537] | 17 | #include "brtypes.h"
 | 
|---|
| [3623] | 18 | #include "brpaqu.h"
 | 
|---|
| [3671] | 19 | #include "brparam.h"
 | 
|---|
 | 20 | #include "minifits.h"
 | 
|---|
| [3537] | 21 | 
 | 
|---|
 | 22 | using namespace std;
 | 
|---|
 | 23 | 
 | 
|---|
 | 24 | 
 | 
|---|
| [3658] | 25 | // Quelques definitions globales
 | 
|---|
 | 26 | // Nombre maximum de fibres geres par les classes MultiReader / MultiDiskWriter
 | 
|---|
| [3681] | 27 | #ifndef MAXNBFIB
 | 
|---|
| [3775] | 28 | #define MAXNBFIB  32   
 | 
|---|
| [3681] | 29 | #endif
 | 
|---|
| [3537] | 30 | 
 | 
|---|
 | 31 | //-------------------------------------------------------
 | 
|---|
 | 32 | // Classe thread de lecture PCI-Express
 | 
|---|
 | 33 | //-------------------------------------------------------
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | class PCIEReader : public ZThread {
 | 
|---|
 | 36 | public:
 | 
|---|
| [3628] | 37 |   PCIEReader( PCIEWrapperInterface &pciw , uint_4 sizeFrame,uint_4 paqSize ,RAcqMemZoneMgr& mem, 
 | 
|---|
| [3623] | 38 |               uint_4 nmax=100, BRDataFmtConv swapall=BR_SwapAll);       
 | 
|---|
| [3537] | 39 |   virtual void run(); 
 | 
|---|
| [3623] | 40 |    void Stop();
 | 
|---|
| [3537] | 41 |   inline void STOP() { stop_ = true; }  
 | 
|---|
| [3623] | 42 |     
 | 
|---|
| [3537] | 43 | protected:
 | 
|---|
| [3623] | 44 |   // Pour recuperer un pointeur sur la prochaine zone memoire devant recevoir un paquet
 | 
|---|
 | 45 |   inline Byte* NextPaqTarget()  {
 | 
|---|
 | 46 |     if ((mmbuf_ == NULL )||(targ_npaq_ >= max_targ_npaq)) 
 | 
|---|
 | 47 |       if (MZoneManage()) return NULL;
 | 
|---|
 | 48 |     Byte* rb=mmbuf_+targ_npaq_*packSize_;
 | 
|---|
 | 49 |     targ_npaq_++;
 | 
|---|
 | 50 |     return rb;
 | 
|---|
 | 51 |   }
 | 
|---|
 | 52 |   bool MZoneManage(bool clean=false);  // Renvoie true si probleme
 | 
|---|
 | 53 | 
 | 
|---|
| [3537] | 54 |   RAcqMemZoneMgr& memgr;
 | 
|---|
 | 55 |   uint_4 nmax_;  // Nombre maxi de blocs MemZone traites
 | 
|---|
| [3623] | 56 |   BRDataFmtConv swapall_;  // select data swap/format conversion for BRPaquet
 | 
|---|
| [3537] | 57 |   bool stop_;  
 | 
|---|
| [3623] | 58 |   unsigned int sizeFr_ ;
 | 
|---|
| [3628] | 59 |   PCIEWrapperInterface& pciw_;
 | 
|---|
| [3623] | 60 |   uint_4 packSize_;
 | 
|---|
 | 61 |   // Variables pour gerer la logique de  NextPaqTarget() qui cache l'acces a RAcqMemZoneMgr
 | 
|---|
 | 62 |   int mid_;  // Identificateur zone memoire
 | 
|---|
 | 63 |   uint_4 targ_npaq_;  // Numero de paquet dans une seule zone memoire 
 | 
|---|
 | 64 |   uint_4 max_targ_npaq; // =  mmgr.NbPaquets() = Max de targ_npaq_
 | 
|---|
 | 65 |   Byte* mmbuf_;  // Pointeur zone memoire rendu par RAcqMemZoneMgr 
 | 
|---|
| [3671] | 66 | 
 | 
|---|
| [3537] | 67 | };
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 | //-------------------------------------------------------
 | 
|---|
 | 70 | // Classe thread de sauvegarde sur fichiers
 | 
|---|
 | 71 | //-------------------------------------------------------
 | 
|---|
 | 72 | 
 | 
|---|
 | 73 | class DataSaver : public ZThread {
 | 
|---|
 | 74 | public: 
 | 
|---|
| [3623] | 75 |   DataSaver(RAcqMemZoneMgr& mem, string& path, uint_4 nfiles=100, uint_4 nblocperfile=1, bool savesig=true);
 | 
|---|
 | 76 | 
 | 
|---|
| [3537] | 77 |   virtual void run(); 
 | 
|---|
| [3623] | 78 |   void Stop(); 
 | 
|---|
| [3537] | 79 |   inline void STOP() { stop_ = true; }  
 | 
|---|
 | 80 | protected:
 | 
|---|
 | 81 |   RAcqMemZoneMgr& memgr;
 | 
|---|
| [3623] | 82 |   uint_4 nfiles_;  // Nombre maxi de fichiers cree
 | 
|---|
 | 83 |   uint_4 nblocperfile_;  // Nombre de bloc (zone memoire) mis dans un fichier
 | 
|---|
 | 84 |   uint_4 nmax_;  // Nombre maxi de blocs MemZone traites = nfiles * nblocperfile_
 | 
|---|
 | 85 |   bool savesig_; // Si false, pas d'ecriture des fichiers FITS du signal 
 | 
|---|
| [3537] | 86 |   bool stop_;  
 | 
|---|
 | 87 |   string path_;  
 | 
|---|
| [3623] | 88 |   struct sigaction act;
 | 
|---|
 | 89 |  
 | 
|---|
| [3537] | 90 | };
 | 
|---|
 | 91 | 
 | 
|---|
| [3623] | 92 | //-------------------------------------------------------
 | 
|---|
 | 93 | // Classe thread de lecture PCI-Express + Check 
 | 
|---|
 | 94 | //-------------------------------------------------------
 | 
|---|
| [3537] | 95 | 
 | 
|---|
| [3623] | 96 | class PCIEReaderChecker : public ZThread {
 | 
|---|
 | 97 | public:
 | 
|---|
| [3658] | 98 |   PCIEReaderChecker( PCIEWrapperInterface &pciw , uint_4 sizeFrame,uint_4 paqSize, RAcqMemZoneMgr& mem, 
 | 
|---|
| [3623] | 99 |                      uint_4 nmax=100, BRDataFmtConv swapall=BR_SwapAll);  
 | 
|---|
 | 100 |   virtual void run(); 
 | 
|---|
 | 101 |    void Stop();
 | 
|---|
 | 102 |   inline void STOP() { stop_ = true; }  
 | 
|---|
 | 103 | protected:
 | 
|---|
 | 104 |   RAcqMemZoneMgr& memgr;
 | 
|---|
 | 105 |   uint_4 nmax_;  // Nombre maxi de blocs MemZone traites
 | 
|---|
 | 106 |   BRDataFmtConv swapall_;  // select data swap/format conversion for BRPaquet
 | 
|---|
 | 107 |   bool stop_;  
 | 
|---|
 | 108 |   unsigned int sizeFr_ ;
 | 
|---|
| [3628] | 109 |   PCIEWrapperInterface& pciw_;
 | 
|---|
| [3623] | 110 |   uint_4 packSize_;
 | 
|---|
 | 111 | };
 | 
|---|
| [3658] | 112 | //------------------------------------------------------------------
 | 
|---|
 | 113 | // Classe thread de lecture PCI-Express multi fibre (ou multi DMA)
 | 
|---|
 | 114 | //------------------------------------------------------------------
 | 
|---|
| [3623] | 115 | 
 | 
|---|
| [3658] | 116 | class PCIEMultiReader : public ZThread {
 | 
|---|
 | 117 | public:
 | 
|---|
| [3672] | 118 |   PCIEMultiReader(vector<PCIEWrapperInterface*> vec_pciw , RAcqMemZoneMgr& mem, BRParList const& par);
 | 
|---|
| [3658] | 119 |   virtual void run(); 
 | 
|---|
 | 120 |    void Stop();
 | 
|---|
 | 121 |   inline void STOP() { stop_ = true; }  
 | 
|---|
 | 122 | 
 | 
|---|
 | 123 | protected: 
 | 
|---|
 | 124 |   // Permet d'avancer d'un paquet dans la zone - renvoie true si probleme
 | 
|---|
 | 125 |   inline bool MoveToNextTarget()  {
 | 
|---|
 | 126 |     if ((mmbuf_ == NULL )||(targ_npaq_ >= max_targ_npaq)) 
 | 
|---|
 | 127 |       if (MZoneManage()) return true;
 | 
|---|
 | 128 |     targ_npaq_++;
 | 
|---|
 | 129 |     return false;
 | 
|---|
 | 130 |   }
 | 
|---|
 | 131 |   inline Byte* GetPaquetTarget(int numfib)  {
 | 
|---|
 | 132 |     if ((mmbufib_[numfib] == NULL )||(targ_npaq_ > max_targ_npaq)||(targ_npaq_ == 0))  return NULL; 
 | 
|---|
 | 133 |     Byte* rb=mmbufib_[numfib]+(targ_npaq_-1)*packSizeInMgr_;
 | 
|---|
 | 134 |     return rb;
 | 
|---|
 | 135 |   }
 | 
|---|
 | 136 |   bool MZoneManage(bool clean=false);  // Renvoie true si probleme
 | 
|---|
| [3672] | 137 |   
 | 
|---|
 | 138 |   RAcqMemZoneMgr& memgr;
 | 
|---|
 | 139 |   BRParList par_;   // Parametres divers d'acquisition 
 | 
|---|
| [3658] | 140 | 
 | 
|---|
 | 141 |   uint_4 nmax_;  // Nombre maxi de blocs MemZone traites
 | 
|---|
 | 142 |   BRDataFmtConv swapall_;  // select data swap/format conversion for BRPaquet
 | 
|---|
 | 143 |   bool stop_;  
 | 
|---|
 | 144 |   unsigned int sizeFr_ ;
 | 
|---|
 | 145 |   vector<PCIEWrapperInterface *> vec_pciw_;
 | 
|---|
 | 146 |   uint_4 packSize_;
 | 
|---|
 | 147 |   uint_4 packSizeInMgr_;
 | 
|---|
 | 148 |   uint_4 nbDma_;
 | 
|---|
 | 149 |   int mid_;  // Identificateur zone memoire
 | 
|---|
 | 150 |   uint_4 targ_npaq_;  // Numero de paquet dans une seule zone memoire 
 | 
|---|
 | 151 |   uint_4 max_targ_npaq; // =  mmgr.NbPaquets() = Max de targ_npaq_
 | 
|---|
 | 152 |   Byte* mmbuf_;  // Pointeur zone memoire rendu par RAcqMemZoneMgr 
 | 
|---|
 | 153 |   Byte* mmbufib_[MAXNBFIB];  // Pointeurs zone memoire de chaque fibre rendu par RAcqMemZoneMgr 
 | 
|---|
 | 154 | 
 | 
|---|
| [3911] | 155 |   string stopreason_;   // message descriptif de la raison d'arret 
 | 
|---|
| [3658] | 156 | };
 | 
|---|
 | 157 | 
 | 
|---|
 | 158 | 
 | 
|---|
 | 159 | 
 | 
|---|
 | 160 | //----------------------------------------------------------------------------------------
 | 
|---|
 | 161 | // Classe thread de sauvegarde sur fichiers - gerant plusieurs fibres dans RAcqMemZoneMgr
 | 
|---|
 | 162 | //----------------------------------------------------------------------------------------
 | 
|---|
 | 163 | 
 | 
|---|
| [3672] | 164 | // --- Cette classe utilise les parametres globaux d'acquisition BRAcqConfig
 | 
|---|
| [3658] | 165 | class MultiDataSaver : public ZThread {
 | 
|---|
 | 166 | public: 
 | 
|---|
| [3672] | 167 |   MultiDataSaver(RAcqMemZoneMgr& mem);
 | 
|---|
| [3658] | 168 | 
 | 
|---|
 | 169 |   virtual void run(); 
 | 
|---|
 | 170 |   void Stop(); 
 | 
|---|
 | 171 |   inline void STOP() { stop_ = true; }  
 | 
|---|
 | 172 | protected:
 | 
|---|
| [3909] | 173 |   int  AddFitsKWStart(MiniFITSFile* mff, BRAcqConfig& acpar, TimeStamp& ts);
 | 
|---|
 | 174 |   int  AddFitsKWEnd(MiniFITSFile* mff, BRAcqConfig& acpar, TimeStamp& ts);
 | 
|---|
| [3671] | 175 | 
 | 
|---|
| [3658] | 176 |   RAcqMemZoneMgr& memgr;
 | 
|---|
| [3672] | 177 | 
 | 
|---|
| [3658] | 178 |   uint_4 nfiles_;  // Nombre maxi de fichiers cree
 | 
|---|
 | 179 |   uint_4 nblocperfile_;  // Nombre de bloc (zone memoire) mis dans un fichier
 | 
|---|
 | 180 |   uint_4 nmax_;  // Nombre maxi de blocs MemZone traites = nfiles * nblocperfile_
 | 
|---|
 | 181 |   bool savesig_; // Si false, pas d'ecriture des fichiers FITS du signal 
 | 
|---|
 | 182 |   bool stop_;  
 | 
|---|
| [3674] | 183 |   uint_8 framecnt_first_[MAXNBFIB];  // Numero de framecounter first  
 | 
|---|
 | 184 |   uint_8 framecnt_last_[MAXNBFIB];   // Numero de framecounter last  
 | 
|---|
 | 185 |   uint_8 timetag_first_[MAXNBFIB];  // TimeTag first  
 | 
|---|
 | 186 |   
 | 
|---|
| [3658] | 187 | };
 | 
|---|
 | 188 | 
 | 
|---|
| [3537] | 189 | #endif
 | 
|---|