| 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"
|
|---|
| 16 | #include "pciewrap.h"
|
|---|
| 17 | #include "brtypes.h"
|
|---|
| 18 | #include "brpaqu.h"
|
|---|
| 19 | #include "brparam.h"
|
|---|
| 20 | #include "minifits.h"
|
|---|
| 21 |
|
|---|
| 22 | using namespace std;
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | // Quelques definitions globales
|
|---|
| 26 | // Nombre maximum de fibres geres par les classes MultiReader / MultiDiskWriter
|
|---|
| 27 | #ifndef MAXNBFIB
|
|---|
| 28 | #define MAXNBFIB 32
|
|---|
| 29 | #endif
|
|---|
| 30 |
|
|---|
| 31 | //-------------------------------------------------------
|
|---|
| 32 | // Classe thread de lecture PCI-Express
|
|---|
| 33 | //-------------------------------------------------------
|
|---|
| 34 |
|
|---|
| 35 | class PCIEReader : public ZThread {
|
|---|
| 36 | public:
|
|---|
| 37 | PCIEReader( PCIEWrapperInterface &pciw , uint_4 sizeFrame,uint_4 paqSize ,RAcqMemZoneMgr& mem,
|
|---|
| 38 | uint_4 nmax=100, BRDataFmtConv swapall=BR_SwapAll);
|
|---|
| 39 | virtual void run();
|
|---|
| 40 | void Stop();
|
|---|
| 41 | inline void STOP() { stop_ = true; }
|
|---|
| 42 |
|
|---|
| 43 | protected:
|
|---|
| 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 |
|
|---|
| 54 | RAcqMemZoneMgr& memgr;
|
|---|
| 55 | uint_4 nmax_; // Nombre maxi de blocs MemZone traites
|
|---|
| 56 | BRDataFmtConv swapall_; // select data swap/format conversion for BRPaquet
|
|---|
| 57 | bool stop_;
|
|---|
| 58 | unsigned int sizeFr_ ;
|
|---|
| 59 | PCIEWrapperInterface& pciw_;
|
|---|
| 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
|
|---|
| 66 |
|
|---|
| 67 | };
|
|---|
| 68 |
|
|---|
| 69 | //-------------------------------------------------------
|
|---|
| 70 | // Classe thread de sauvegarde sur fichiers
|
|---|
| 71 | //-------------------------------------------------------
|
|---|
| 72 |
|
|---|
| 73 | class DataSaver : public ZThread {
|
|---|
| 74 | public:
|
|---|
| 75 | DataSaver(RAcqMemZoneMgr& mem, string& path, uint_4 nfiles=100, uint_4 nblocperfile=1, bool savesig=true);
|
|---|
| 76 |
|
|---|
| 77 | virtual void run();
|
|---|
| 78 | void Stop();
|
|---|
| 79 | inline void STOP() { stop_ = true; }
|
|---|
| 80 | protected:
|
|---|
| 81 | RAcqMemZoneMgr& memgr;
|
|---|
| 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
|
|---|
| 86 | bool stop_;
|
|---|
| 87 | string path_;
|
|---|
| 88 | struct sigaction act;
|
|---|
| 89 |
|
|---|
| 90 | };
|
|---|
| 91 |
|
|---|
| 92 | //-------------------------------------------------------
|
|---|
| 93 | // Classe thread de lecture PCI-Express + Check
|
|---|
| 94 | //-------------------------------------------------------
|
|---|
| 95 |
|
|---|
| 96 | class PCIEReaderChecker : public ZThread {
|
|---|
| 97 | public:
|
|---|
| 98 | PCIEReaderChecker( PCIEWrapperInterface &pciw , uint_4 sizeFrame,uint_4 paqSize, RAcqMemZoneMgr& mem,
|
|---|
| 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_ ;
|
|---|
| 109 | PCIEWrapperInterface& pciw_;
|
|---|
| 110 | uint_4 packSize_;
|
|---|
| 111 | };
|
|---|
| 112 | //------------------------------------------------------------------
|
|---|
| 113 | // Classe thread de lecture PCI-Express multi fibre (ou multi DMA)
|
|---|
| 114 | //------------------------------------------------------------------
|
|---|
| 115 |
|
|---|
| 116 | class PCIEMultiReader : public ZThread {
|
|---|
| 117 | public:
|
|---|
| 118 | PCIEMultiReader(vector<PCIEWrapperInterface*> vec_pciw , RAcqMemZoneMgr& mem, BRParList const& par);
|
|---|
| 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
|
|---|
| 137 |
|
|---|
| 138 | RAcqMemZoneMgr& memgr;
|
|---|
| 139 | BRParList par_; // Parametres divers d'acquisition
|
|---|
| 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 |
|
|---|
| 155 | string stopreason_; // message descriptif de la raison d'arret
|
|---|
| 156 | };
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 | //----------------------------------------------------------------------------------------
|
|---|
| 161 | // Classe thread de sauvegarde sur fichiers - gerant plusieurs fibres dans RAcqMemZoneMgr
|
|---|
| 162 | //----------------------------------------------------------------------------------------
|
|---|
| 163 |
|
|---|
| 164 | // --- Cette classe utilise les parametres globaux d'acquisition BRAcqConfig
|
|---|
| 165 | class MultiDataSaver : public ZThread {
|
|---|
| 166 | public:
|
|---|
| 167 | MultiDataSaver(RAcqMemZoneMgr& mem);
|
|---|
| 168 |
|
|---|
| 169 | virtual void run();
|
|---|
| 170 | void Stop();
|
|---|
| 171 | inline void STOP() { stop_ = true; }
|
|---|
| 172 | protected:
|
|---|
| 173 | int AddFitsKWStart(MiniFITSFile* mff, BRAcqConfig& acpar, TimeStamp& ts);
|
|---|
| 174 | int AddFitsKWEnd(MiniFITSFile* mff, BRAcqConfig& acpar, TimeStamp& ts);
|
|---|
| 175 |
|
|---|
| 176 | RAcqMemZoneMgr& memgr;
|
|---|
| 177 |
|
|---|
| 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_;
|
|---|
| 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 |
|
|---|
| 187 | };
|
|---|
| 188 |
|
|---|
| 189 | #endif
|
|---|