| [3872] | 1 | #ifndef  BRVISCALC_H_SEEN
 | 
|---|
 | 2 | #define  BRVISCALC_H_SEEN
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 | //----------------------------------------------------------------
 | 
|---|
 | 5 | // Projet BAORadio - (C) LAL/IRFU  2008-2010
 | 
|---|
 | 6 | // Classes de threads de calcul de visibilites pour BAORadio 
 | 
|---|
 | 7 | //  Principales classes utilisables 
 | 
|---|
 | 8 | //  - BRVisibilityCalculator (donnees FFT)
 | 
|---|
 | 9 | //  - BRVisCalcGroup  
 | 
|---|
 | 10 | //----------------------------------------------------------------
 | 
|---|
 | 11 | 
 | 
|---|
 | 12 | #include <string>
 | 
|---|
 | 13 | #include <vector>
 | 
|---|
 | 14 | #include <iostream>
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | // --- include SOPHYA
 | 
|---|
 | 17 | #include "machdefs.h"
 | 
|---|
 | 18 | #include "sopnamsp.h"
 | 
|---|
 | 19 | #include "tvector.h"
 | 
|---|
 | 20 | #include "parlex.h"
 | 
|---|
 | 21 | #include "datatable.h"
 | 
|---|
 | 22 | #include "ctimer.h"
 | 
|---|
 | 23 | 
 | 
|---|
 | 24 | //--- include BAORadio 
 | 
|---|
 | 25 | #include "racqumem.h"
 | 
|---|
 | 26 | #include "brpaqu.h"
 | 
|---|
 | 27 | #include "brbaseproc.h"
 | 
|---|
 | 28 | 
 | 
|---|
 | 29 | using namespace std;
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | //---------------------------------------------------------------------
 | 
|---|
 | 32 | // Classe de traitement - calcul de visibilite pour n fibres 
 | 
|---|
 | 33 | //---------------------------------------------------------------------
 | 
|---|
| [3909] | 34 | // Pour convertir une paire de numeros de canaux en un seul entier C1*CHANPAIRCONVFAC+C2
 | 
|---|
 | 35 | #define  CHANPAIRCONVFAC  1000 
 | 
|---|
 | 36 | 
 | 
|---|
| [3872] | 37 | class BRVisibilityCalculator : public BRBaseProcessor, ParallelTaskInterface {
 | 
|---|
 | 38 | public: 
 | 
|---|
 | 39 |   BRVisibilityCalculator(RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean=1000, size_t nthr=1);
 | 
|---|
 | 40 |   virtual ~BRVisibilityCalculator(); // Fait le nettoyage final , sauvegarde des objets ...
 | 
|---|
 | 41 | 
 | 
|---|
| [3956] | 42 |   // configuration avec donnees firmware FFT (defaut) 
 | 
|---|
| [3967] | 43 |   inline void SetFFTData()  { fgdataraw_=false; } 
 | 
|---|
 | 44 |   // configuration avec donnees firmware RAW  
 | 
|---|
| [3956] | 45 |   inline void SetRawData()  { fgdataraw_=true; } 
 | 
|---|
 | 46 | 
 | 
|---|
| [3872] | 47 |   // Pour definir le rang de l'objet lors d'un traitement avec plusieurs BRVisibilityCalculator en //
 | 
|---|
| [3915] | 48 |   void DefineRank(uint_4 nbc, uint_4 cid, uint_4 pair1=0, uint_4 nbpairs=999999999, bool fgpimp=false);
 | 
|---|
| [3872] | 49 | 
 | 
|---|
| [3893] | 50 |   // Pour limiter le calcul des visibilites a certaines voies, determine par les numeros de sequences des paires 
 | 
|---|
 | 51 |   // Exemple pour 2 fibres et 4 voies 
 | 
|---|
 | 52 |   // kpair=numero sequentiel de la paire: 0->(0,0), 1->(0,1), 2->(0,2), 3->(0,3), 4->(1,1), 5->(1,2) ...
 | 
|---|
| [3915] | 53 |   // fgpimp=true : on calcule uniquement les visib avec un numero de voie paire, un numero de voie impair
 | 
|---|
 | 54 |   //               fgpimp=true est utile pour le calcul des visib entre deux cylindres (E-W) 
 | 
|---|
 | 55 |   uint_4 SelectPairs(uint_4 pair1=0, uint_4 nbpairs=999999999, bool fgpimp=false);
 | 
|---|
| [3872] | 56 |   // pour definir le binning en frequence pour la VisibDataTable 
 | 
|---|
| [3876] | 57 |   // par defaut, toutes les frequences avec un pas de 1 
 | 
|---|
 | 58 |   int SelectFreqBinning(uint_4 freq1=0, uint_4 freq2=0, uint_4 nbfreq=0);
 | 
|---|
| [3872] | 59 | 
 | 
|---|
 | 60 |   // Pour activer la verification des timetag
 | 
|---|
 | 61 |   // Creation / sauvegarde d'une matrice de TimeTag / FrameCounter avec NCols=maxnpaq (nb de paquets/trigger)  
 | 
|---|
 | 62 |   int ActivateTimeTagCheck(uint_8 maxnpaq);
 | 
|---|
| [3920] | 63 |   // Pour activer le remplissage du DataTable des visibilites 
 | 
|---|
 | 64 |   inline void ActivateVisDTable(bool fgfdt=false)  { fgvisdt_=fgfdt;  return; }
 | 
|---|
| [3956] | 65 |   // Pour ecrire les fichiers de sortie au format fits (format PPF sinon) 
 | 
|---|
 | 66 |   inline void SetFitsOutput() { fgfitsout_=true; }
 | 
|---|
 | 67 |   // Pour ecrire les fichiers de sortie au format PPF (defaut) 
 | 
|---|
 | 68 |   inline void SetPPFOutput() { fgfitsout_=false; }
 | 
|---|
| [3872] | 69 | 
 | 
|---|
 | 70 |   // Methode d'execution standard du thread (on redefinit la methode de BRBaseProcessor)
 | 
|---|
 | 71 |   virtual void run();  
 | 
|---|
 | 72 |   // Methode de la classe ParallelTaskInterface 
 | 
|---|
| [3956] | 73 |   virtual int  execute(int tid);
 | 
|---|
| [3872] | 74 | 
 | 
|---|
 | 75 |   // Le nombre total d'operations effectuees
 | 
|---|
 | 76 |   inline r_8 TotNbFLOP() { return nb_flop_; }
 | 
|---|
| [3895] | 77 |   inline r_8 TotNbMegaFLOP() { return nb_flop_/(1024.e3); }
 | 
|---|
| [3872] | 78 | 
 | 
|---|
| [3923] | 79 |   //---- niveau d'impression 
 | 
|---|
 | 80 |   inline void SetPrintLevel(int lev=0, uint_8 prtmodulo=10) 
 | 
|---|
 | 81 |     { prtlev_=lev;   prtmodulo_=prtmodulo;}
 | 
|---|
 | 82 | 
 | 
|---|
| [3872] | 83 | protected:
 | 
|---|
| [3909] | 84 |   virtual void UpdateChanIds(); 
 | 
|---|
| [3872] | 85 |   virtual int Process(); 
 | 
|---|
| [3878] | 86 |   virtual void UpdateVisMtxInfo();
 | 
|---|
| [3872] | 87 |   virtual int FillVisibTable(double fcm, double ttm); 
 | 
|---|
 | 88 |   virtual int CheckTimeTag(); 
 | 
|---|
| [3956] | 89 |   inline const char* OutFileExtension() { return ((fgfitsout_)?"fits":"ppf"); } 
 | 
|---|
| [3872] | 90 | 
 | 
|---|
 | 91 |   ParallelExecutor paralex_;  // Pour l'execution en parallele  
 | 
|---|
 | 92 |   size_t nparthr_;
 | 
|---|
 | 93 | 
 | 
|---|
| [3956] | 94 |   bool fgdataraw_;  // true -> donnees provenant du firmware RAW 
 | 
|---|
| [3872] | 95 |   uint_4 nmean_;  // Nombre de spectres pour le calcul des moyennes 
 | 
|---|
 | 96 |   string outpath_;  // directory pour fichiers de sortie
 | 
|---|
 | 97 |   uint_4 nbcalc_, calcid_;  // Nombre total de threads/objets BRVisibilityCalculator parallèles, l'identificateur de l'objet  
 | 
|---|
 | 98 | 
 | 
|---|
| [3915] | 99 |   uint_4 pairst_, nbpairs_;   // Numero de la premiere paire, nombre de paires ( 1 paire= 1 visibilites)
 | 
|---|
 | 100 |   bool fgpimp_;    //  true -> calculer uniquement visibilities avec no voie pair-impair  
 | 
|---|
 | 101 | 
 | 
|---|
| [3872] | 102 |   uint_4 jf1_,jf2_,djf_;  // binning en frequence pour la datatable
 | 
|---|
 | 103 | 
 | 
|---|
| [3956] | 104 |   vector<TwoByteComplex*> vpdata_;   // donnees du fimrware FFT 
 | 
|---|
 | 105 |   vector< complex<r_4>* > vpdatar_;   // donnees du fimrware RAW apres FFT soft 
 | 
|---|
 | 106 | 
 | 
|---|
| [3872] | 107 |   bool* fgallfibok;  
 | 
|---|
 | 108 | 
 | 
|---|
| [3878] | 109 |   double moyfc_, moytt_;  // moyenne des FrameCounter / TimeTag pour chaque matrice de visibilite
 | 
|---|
 | 110 |   uint_8 first_fc_,first_tt_;  // Valeurs premier FrameCounter / TimeTag pour chaque matrice de visibilite
 | 
|---|
 | 111 |   TimeStamp first_tmstamp_;   // Date-Heure pour premier FrameCounter / TimeTag pour chaque matrice de visibilite
 | 
|---|
 | 112 |   
 | 
|---|
| [3872] | 113 |   TMatrix< complex<r_4> > vismtx_; 
 | 
|---|
| [3956] | 114 |   TVector< int_4 > chanids_;    // Numero de chaque canal=FiberId*2-1, FiberId*2
 | 
|---|
 | 115 |   TVector< int_4 > chanpairnumall_;  // Liste de tous les numeros de paires de canaux (forme 1000*C1+C2=IIIJJJ)
 | 
|---|
 | 116 |   TMatrix< int_4 > chanpairsall_ ;  // Liste de toutes paires de canaux (forme (C1,C2) )
 | 
|---|
 | 117 |   TVector< int_4 > chanpairnum_;    // Liste des paires de canaux calcules par ce BRVisibilityCalculator
 | 
|---|
 | 118 |   TMatrix< int_4 > chanpairs_ ;  // Liste des paires de canaux (forme (C1,C2) ) pour ce BRVisibilityCalculator
 | 
|---|
| [3909] | 119 | 
 | 
|---|
| [3956] | 120 |   bool fgfitsout_;  // if true -> write visibility matrices in fits format 
 | 
|---|
 | 121 | 
 | 
|---|
| [3872] | 122 |   //  FitsInOutFile dtfos_;
 | 
|---|
 | 123 |   DataTable visdt_;
 | 
|---|
| [3920] | 124 |   bool fgvisdt_;   // true -> fill datatable
 | 
|---|
| [3872] | 125 |   uint_4 numfile_;
 | 
|---|
 | 126 |   uint_8 totnbpaq_;
 | 
|---|
 | 127 | 
 | 
|---|
 | 128 |   r_8 nb_flop_;   // Nombre total d'operations effectuees
 | 
|---|
 | 129 | 
 | 
|---|
 | 130 |   // Variables/objets pour la verifications des timetag
 | 
|---|
 | 131 |   bool fgcktt_;  // true -> checktimetag 
 | 
|---|
 | 132 |   int_8 mindeltatt_;       // difference minimum de deux timetag successifs 
 | 
|---|
 | 133 |   TMatrix< uint_8 > fcmtx_; // matrices des framecounters
 | 
|---|
 | 134 |   TMatrix< uint_8 > ttmtx_; // matrices des timetag 
 | 
|---|
 | 135 |   vector< uint_8 > vlasttt_;  // dernieres valeurs de TimeTag / fibre
 | 
|---|
 | 136 |   vector< uint_8 > vbadtt_;  // Number of bad TimeTag paquets per fiber 
 | 
|---|
 | 137 |   vector< uint_8 > vnsamett_;  // Number of paquets having TimeTag <> TT_Fiber1 per fiber 
 | 
|---|
 | 138 |   vector< uint_8 > vndiff5tt_;  // Number of paquets having |TimeTag-TT_Fiber1|>5 per fiber 
 | 
|---|
 | 139 | 
 | 
|---|
| [3923] | 140 |   int prtlev_;    // print level 
 | 
|---|
 | 141 |   uint_8 prtmodulo_;   // print periodicity (modulo) 
 | 
|---|
| [3872] | 142 | };
 | 
|---|
 | 143 | 
 | 
|---|
 | 144 | 
 | 
|---|
 | 145 | //-------------------------------------------------------------------------------
 | 
|---|
| [3878] | 146 | // Classe Groupe (ensemble) de Calculateur de Visibilites, tournant en parallele
 | 
|---|
| [3872] | 147 | //-------------------------------------------------------------------------------
 | 
|---|
 | 148 | 
 | 
|---|
 | 149 | class BRVisCalcGroup {
 | 
|---|
 | 150 | public: 
 | 
|---|
| [3915] | 151 |   BRVisCalcGroup(size_t nbcalc, RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean=1000,
 | 
|---|
 | 152 |                  uint_4 pair1=0, uint_4 nbpairs=999999999, bool fgpimp=false, size_t nthr=1);
 | 
|---|
| [3872] | 153 |   ~BRVisCalcGroup();
 | 
|---|
| [3956] | 154 | 
 | 
|---|
 | 155 |   MemZStatus SetMemZAction(MemZaction mmact=MemZA_ProcA);
 | 
|---|
 | 156 | 
 | 
|---|
| [3872] | 157 |   int SelectFreqBinning(uint_4 freq1=0, uint_4 freq2=0, uint_4 nbfreq=1);
 | 
|---|
 | 158 |   inline int ActivateTimeTagCheck(uint_8 maxnpaq)
 | 
|---|
 | 159 |   { return viscalcp_[0]->ActivateTimeTagCheck(maxnpaq); }
 | 
|---|
| [3920] | 160 |   void ActivateVisDTable(bool fgfdt=false);
 | 
|---|
| [3956] | 161 |   // Pour ecrire les fichiers de sortie au format fits (format PPF sinon) 
 | 
|---|
 | 162 |   void SetFitsOutput();
 | 
|---|
 | 163 |   // Pour ecrire les fichiers de sortie au format PPF (defaut) 
 | 
|---|
 | 164 |   void SetPPFOutput();
 | 
|---|
| [3967] | 165 |   // configuration avec donnees firmware FFT (defaut) 
 | 
|---|
 | 166 |   void SetFFTData();  
 | 
|---|
 | 167 |   // configuration avec donnees firmware RAW  
 | 
|---|
 | 168 |   void SetRawData();  
 | 
|---|
 | 169 | 
 | 
|---|
| [3923] | 170 |   void SetPrintLevel(int lev=0, uint_8 prtmodulo=10);
 | 
|---|
| [3872] | 171 | 
 | 
|---|
 | 172 |   void start();
 | 
|---|
 | 173 |   void join();
 | 
|---|
 | 174 | protected:
 | 
|---|
 | 175 |   vector<BRVisibilityCalculator *> viscalcp_; 
 | 
|---|
 | 176 |   Timer tm_;
 | 
|---|
 | 177 | };
 | 
|---|
 | 178 | 
 | 
|---|
 | 179 | 
 | 
|---|
 | 180 | #endif
 | 
|---|