visip4reader.h 8.65 KB
Newer Older
1 2 3 4 5 6
/* ---------------------------------------------------------- 
   Projet BAORadio/PAON4 - (C) LAL/IRFU  2008-2017

   Classes de lecture des fichiers de visibilites PAON4
        R. Ansari                     2015-2017
   ---------------------------------------------------------- */
7
#ifndef  VISIP4READER_H_SEEN
8
#define  VISIP4READER_H_SEEN
9 10 11 12 13 14


#include <string>
#include <vector>
#include <iostream>

15 16 17
// Include utiles SOPHYA TArray
#include "array.h"
#include "timestamp.h" 
18 19 20 21

using namespace std;
using namespace SOPHYA;

22 23 24 25
//------------------------------------------------------------------------------------------------
//----- class VisiP4ReaderBase : classe de base pour le lecture des matrices de visibilite PAON4 
//------------------------------------------------------------------------------------------------

26 27 28
/*! \brief  Base class for reading PAON-4 visibility data 
  This class has pure virtual method ReadVisMtx() that should be implemented in derived classes */

29
class VisiP4ReaderBase {
30
public:
31 32 33 34
  //! Create and returns a VisiP4ReaderNoDB or VisiP4ReaderDB reader according to the existence of vmtxdbdesc.txt in the path 
  static VisiP4ReaderBase * getReader(vector<string> const& vpath);
  
  VisiP4ReaderBase(vector<string> const& vpath);
35 36 37 38
  virtual ~VisiP4ReaderBase();

  /*! \brief  Select range of Serial Number for Visibility Matrices to be processed 
    Process VisMtx with serial numbers   sn such as ser_first_<= sn <= ser_last_ , one matrix out of ser_step_ */
39
  virtual void SelectSerialNum(long first, long last, long step=1);
40 41 42
  /*! \brief  Select the time interval for Visibility Matrices to be processed 
      Default implementation throws an exception */
  virtual void SelectTimeFrame(TimeStamp const & tustart, TimeStamp const & tuend, int step=1);
43 44 45
  /*! \brief  Select all the available Visibility Matrices for processing 
      Default implementation throws an exception */
  virtual void SelectAll();
46 47 48 49 50 51 52 53

  //! return the first selected visibility matrix serial number (or sequence number)
  inline long  getSerialFirst() const { return ser_first_; }
  //! return the last selected visibility matrix serial number (or sequence number)
  inline long  getSerialLast() const { return ser_first_; }
  //! return the visibility matrix serial number (or sequence number) step 
  inline long  getSerialStep() const { return ser_step_; }

54 55 56 57
  //! Activate or deactivate frequency reordering when reading visibility matrices 
  inline void setFreqReordering(bool fg)
  { fgreorderfreq_ = fg; }

58 59
  /*! \brief Read the next visibility matrix in the selected visi matrix number range. 
      fills also the corresponding TimeStamp (TU) and mean hardware time-tag. return true if OK, false otherwise.   */
60 61
  bool ReadNext(TMatrix< complex<r_4> > & vismtx, TimeStamp& dateobs, double& mttag) 
  {
62 63 64
    bool readok = Read_P(cur_serialnum_, &vismtx, NULL, dateobs, mttag);
    if (readok)  cur_serialnum_+=ser_step_;
    return readok;
65
  }
66 67
  /*! \brief Read the next visibility matrix and mean Fourier coeff matrix in the selected visi matrix number range. 
      fills also the corresponding TimeStamp (TU) and mean hardware time-tag. return true if OK, false otherwise.   */
68 69 70
  bool ReadNext(TMatrix< complex<r_4> > & vismtx, TMatrix< complex<r_4> > & meanmtx, 
		TimeStamp& dateobs, double& mttag) 
  {
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
    bool readok = Read_P(cur_serialnum_, &vismtx, &meanmtx, dateobs, mttag);
    if (readok)  cur_serialnum_+=ser_step_;
    return readok;
  }

  /*! \brief Read the visibility matrix identified by the serial number \b sernum. 
      fills also the corresponding TimeStamp (TU) and mean hardware time-tag. return true if OK, false otherwise.  

      \warning : sernum should be in the selected range  */
  bool Read(long sernum, TMatrix< complex<r_4> > & vismtx, TimeStamp& dateobs, double& mttag) 
  {
    return Read_P(sernum, &vismtx, NULL, dateobs, mttag);
  }
  /*! \brief Read the next visibility matrix and mean Fourier coeff matrix identified by the serial number \b sernum.
    fills also the corresponding TimeStamp (TU) and mean hardware time-tag. return true if OK, false otherwise.   
    
    \warning : sernum should be in the selected range  */
  bool Read(long sernum, TMatrix< complex<r_4> > & vismtx, TMatrix< complex<r_4> > & meanmtx, 
	    TimeStamp& dateobs, double& mttag) 
  {
    return Read_P(sernum, &vismtx, &meanmtx, dateobs, mttag);
92
  }
93

94
  //! perform the reordering of the different frequency components (for FFT firmware of the ADC board) 
95
  void ReorderFreqs(TMatrix< complex<r_4> > & svismtx, TMatrix< complex<r_4> > & vismtx);
96

97
  //! Correcting for offset due to non zero mean fourier coeff matrix from visibilities 
98 99
  TMatrix< complex<r_4> > SubtractOffset(TMatrix< complex<r_4> > & vismtx, TMatrix< complex<r_4> > & meanmtx);

100 101 102 103
  
  inline void setNChan(sa_size_t nchan=8)   
  {  NCHAN=nchan; }

104 105
  inline void setNVis(sa_size_t nvis=36)   
  {  NVIS=nvis; }
106
  
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
  inline void setNFreq(sa_size_t nfreq=4096)   
  {  NFREQ=nfreq; }
  inline void setNBands(int nband=2)
  {  NBAND=nband; }
  inline void setNbVisGrp(int nvgrp=4)
  {  NVISGRP=nvgrp; }

  inline sa_size_t getNVis() const  
  { return NVIS; }
  inline sa_size_t getNFreq() const  
  { return NFREQ; }
  inline int       getNBands()  const 
  { return NBAND; }
  inline int       getNbVisGrp()  const
  { return NVISGRP; }
  
  inline void setPrintLevel(int lev=0) 
  {  prtlevel=lev; }
  inline int       getPrintLevel()  const
  { return prtlevel; }

protected:
129

130 131
  bool Read_P(long sernum, TMatrix< complex<r_4> >* vismtx, TMatrix< complex<r_4> >* meanmtx, 
		  TimeStamp& dateobs, double& mttag);
132 133
  
  virtual void ReadVisMtx(int band, int visgrp, long sernum, TMatrix< complex<r_4> > & vmtx, TMatrix< complex<r_4> > * mmtx) = 0; 
134

135
  vector<string> paths_;  // path for visibility files produced for each BAO5,BAO6 (first,second frequency band) 
136
  long ser_first_, ser_last_, ser_step_;  // VisMtx serial number I such as ser_first_<=I<=ser_last_ , one matrix out of ser_step_   
137 138
  bool fgreorderfreq_; 
  long cur_serialnum_;          // current file number 
139

140
  sa_size_t  NCHAN;    // nombre total de voies 
141 142
  sa_size_t  NVIS;    // nombre total de visibilites 
  sa_size_t  NFREQ;   // nombre total de frequence 
143
  int NBAND;          // nombre de bande de frequence (= nb de machines de calcul = paths_.size() )
144 145 146 147
  int NVISGRP;        // nombre de groupes de visibilites 

  int prtlevel;       // niveau d'impression
  TMatrix<int_2> chanpairs;
148 149
};

150 151 152
//------------------------------------------------------------------------------------------------
//----- class VisiP4ReaderNoDB : lecture des donnees ecrites sous forme d un fichier / matrice de visibilite
//------------------------------------------------------------------------------------------------
153 154 155

/*! \brief  Implementation of VisiP4ReaderBase to handle reading the first version of PAON4 visibility data, 
  with a single visibility matrix per file */
156 157
class VisiP4ReaderNoDB : public VisiP4ReaderBase {
public:
158
  VisiP4ReaderNoDB(vector<string> const& vpath, int first, int last, int step=1, bool reorderfreq=false);
159 160 161 162 163 164

protected:
  virtual void ReadVisMtx(int band, int visgrp, long sernum, TMatrix< complex<r_4> > & vmtx, TMatrix< complex<r_4> > * mmtx); 
};

//------------------------------------------------------------------------------------------------
165
//----- class VisiP4ReaderDB : lecture des donnees ecrites VisMtxDBWriter  (plusieurs matrices / fichier)
166
//------------------------------------------------------------------------------------------------
167 168 169 170

/*! \brief  Implementation of VisiP4ReaderBase to handle reading the second version of PAON4 visibility data, 
  saved through the TAcq/VisMtxDBWriter class */

171 172
class VisiP4ReaderDB : public VisiP4ReaderBase {
public:
173
  VisiP4ReaderDB(vector<string> const& vpath);
174 175 176
  VisiP4ReaderDB(vector<string> const& vpath, int first, int last, int step=1, bool reorderfreq=false);
  virtual ~VisiP4ReaderDB();
  
177
  virtual void SelectSerialNum(long first, long last, long step=1);
178
  virtual void SelectTimeFrame(TimeStamp const & tustart, TimeStamp const & tuend, int step=1);
179
  virtual void SelectAll();
180 181 182 183 184

protected:
  void Init();
  virtual void ReadVisMtx(int band, int visgrp, long sernum, TMatrix< complex<r_4> > & vmtx, TMatrix< complex<r_4> > * mmtx);
  void OpenFiles(size_t vdbidx);
185 186 187 188

  long db_first_ser_, db_end_ser_;  // first and last Matrix sequence number in directory
  int  db_first_filenum_, db_last_filenum_;  // first and last file number in directory

189 190 191 192 193 194
  typedef struct { int filenum, ser_start, ser_end; TimeStamp tu_start, tu_end; } VDBEL;
  std::vector< VDBEL > vdb_;
  int first_filenum_, last_filenum_;
  int cur_filenum_;
  size_t cur_vdb_index_;
  std::vector<PInPersist *> cur_filep_;
195
  bool fgopenok_;
196 197
};

198 199
//  For compatibility for old code 
typedef VisiP4ReaderNoDB VisiP4Reader;
200

201 202
#endif