Commit 18878d65 authored by Réza Ansari's avatar Réza Ansari
Browse files

Modification de la classe lecteur des visibilites VisiP4Reader -

Introduction de la classe de base VisiP4ReaderBase, avec des methodes virtuelles pures
et deux classes derivees , VisiP4ReaderNoDB , pour la lecture des visibilites ecrites
sous forme d'une matrice / fichier et VisiP4ReaderDB pour la lecture des visi ecrites
avec la classe VisMtxDBWriter (plusieurs matrices de visi / fichier)
       Reza  12/09/2017
parent 411e7c8c
......@@ -3,25 +3,28 @@
// Classe(s) de lecture des fichiers de visibilites PAON4
//----------------------------------------------------------------
#include <fstream>
#include "visip4reader.h"
/* --Methode-- */
VisiP4Reader::VisiP4Reader(vector<string> const& vpath, int ifirst, int ilast, int istep, bool reorderfreq)
: paths(vpath), first(ifirst), last(ilast), step(istep), fgreorderfreq(reorderfreq),
curfilenum(ifirst)
VisiP4ReaderBase::VisiP4ReaderBase(vector<string> const& vpath, bool reorderfreq)
: paths_(vpath), fgreorderfreq_(reorderfreq),
cur_serialnum_(0)
{
SelectSerialNum(0,0);
setNChan();
setNVis();
setNFreq();
setNBands(paths.size());
setNBands(paths_.size());
setNbVisGrp();
setPrintLevel();
chanpairs.ReSize(NVIS,2);
char filenamebuff[2048];
cout << "VisiP4Reader channel pair list:"<<endl;
cout << "VisiP4ReaderBase channel pair list:"<<endl;
int r=0;
for(int g=0; g<NVISGRP; g++) {
sprintf(filenamebuff,"%s/chanum_%d.ppf",paths[0].c_str(), g);
sprintf(filenamebuff,"%s/chanum_%d.ppf",paths_[0].c_str(), g);
{
TMatrix<int_4> chanpg;
PInPersist pin(filenamebuff);
......@@ -37,23 +40,36 @@ VisiP4Reader::VisiP4Reader(vector<string> const& vpath, int ifirst, int ilast, i
}
/* --Methode-- */
bool VisiP4Reader::ReadNext_P(TMatrix< complex<r_4> >* vismtx, TMatrix< complex<r_4> >* meanmtx,
VisiP4ReaderBase::~VisiP4ReaderBase()
{
}
/* --Methode-- */
void VisiP4ReaderBase::SelectSerialNum(int first, int last, int step)
{
ser_first_=first; ser_last_=last; ser_step_=step;
cur_serialnum_=ser_first_;
return;
}
/* --Methode-- */
bool VisiP4ReaderBase::ReadNext_P(TMatrix< complex<r_4> >* vismtx, TMatrix< complex<r_4> >* meanmtx,
TimeStamp& dateobs, double& mttag)
{
if (paths.size() != NBAND) {
cout << " VisiP4Reader::ReadNext / ERROR: paths.size() != NBAND ..."<<endl;
if (paths_.size() != NBAND) {
cout << " VisiP4ReaderBase::ReadNext / ERROR: paths_.size() != NBAND ..."<<endl;
return false;
}
if (curfilenum > last) {
cout << "VisiP4Reader::ReadNext() passed last file to be read, curfilenum="<<curfilenum<< " last="<<last<<endl;
if (cur_serialnum_ > ser_last_) {
cout << "VisiP4ReaderBase::ReadNext() passed last VisibMatrix to be read, cur_serialnum_="<<cur_serialnum_<< " last="<<ser_last_<<endl;
return false;
}
bool fgwithmean = false;
if(meanmtx) fgwithmean = true;
if ( (prtlevel>1)||((prtlevel>0)&&(curfilenum%20==0)) ) {
cout << "---- VisiP4Reader::ReadNext() - curfilenum= "<<curfilenum<<" (LastNum="<<last<<")"
if ( (prtlevel>1)||((prtlevel>0)&&(cur_serialnum_%20==0)) ) {
cout << "---- VisiP4ReaderBase::ReadNext() - cur_serialnum_= "<<cur_serialnum_<<" (LastNum="<<ser_last_<<")"
<< (fgwithmean ? " Read also mean coef ":" ") <<endl;
}
......@@ -67,7 +83,7 @@ bool VisiP4Reader::ReadNext_P(TMatrix< complex<r_4> >* vismtx, TMatrix< complex<
TMatrix< complex<r_4> > * vmtxp = vismtx;
TMatrix< complex<r_4> > * mmtxp = meanmtx;
if (fgreorderfreq) { // s'il faut reordonner les frequences, on a besoin d'une matrice tampon
if (fgreorderfreq_) { // s'il faut reordonner les frequences, on a besoin d'une matrice tampon
svismtx.ReSize(NVIS, NFREQ);
vmtxp = &svismtx;
if(fgwithmean){
......@@ -76,7 +92,6 @@ bool VisiP4Reader::ReadNext_P(TMatrix< complex<r_4> >* vismtx, TMatrix< complex<
}
}
TMatrix< complex<r_4> > & myvismtx = (*vmtxp);
char filenamebuff[2048];
// loop over the files created by each VisCalculator (each file contains a set of visibilities)
for(int b=0; b<NBAND; b++) {
sa_size_t cvf=NFREQ/NBAND*b; // first column of vismtx to be filled (frequency number)
......@@ -86,18 +101,15 @@ bool VisiP4Reader::ReadNext_P(TMatrix< complex<r_4> >* vismtx, TMatrix< complex<
sa_size_t rvf=NVIS/NVISGRP*g; // first row of vismtx to be filled (pair number)
sa_size_t rvl=rvf+NVIS/NVISGRP-1; // last row of vismtx to be filled (pair number)
//DBG cout << " *DBG* row range:"<<rvf<<","<<rvl<<endl;
sprintf(filenamebuff,"%s/vismtx_%d_%d.ppf",paths[b].c_str(), g, curfilenum);
if (prtlevel>1)
cout << " VisiP4Reader::ReadNext() - opening file: "<<filenamebuff
if (prtlevel>2)
cout << " VisiP4ReaderBase::ReadNext() - Readding VisMtx with SerialNum= "<<cur_serialnum_
<<" freqRange="<<cvf<<"-"<<cvl;
{
PInPersist pin(filenamebuff);
TMatrix< complex<r_4> > vmtx, mmtx;
if(fgwithmean && (g == 0) ) {
pin>>vmtx >> mmtx;
} else {
pin>>vmtx;
}
TMatrix< complex<r_4> > vmtx, mmtx;
TMatrix< complex<r_4> > * pmmtx=(fgwithmean && (g == 0) )?&mmtx:NULL;
ReadVisMtx(b,g,cur_serialnum_,vmtx,pmmtx);
int npaq = vmtx.Info()["NPAQSUM"];
string sdate=vmtx.Info()["DATEOBS"];
dateobs=TimeStamp(sdate);
......@@ -116,27 +128,27 @@ bool VisiP4Reader::ReadNext_P(TMatrix< complex<r_4> >* vismtx, TMatrix< complex<
}
} // end-of-loop over visibility groups
} // end-of-loop over bands
if (prtlevel>0) {
if (prtlevel>1) {
cout<<"ReadNext() meanTT(ms)= ";
for(size_t i=0; i<vmtt.size(); i++) cout << vmtt[i] << " ";
cout<<endl;
}
if (fgreorderfreq){
if (fgreorderfreq_){
ReorderFreqs(myvismtx, *vismtx);
if(fgwithmean) ReorderFreqs(*mmtxp, *meanmtx);
}
curfilenum++;
cur_serialnum_+=ser_step_;
return true;
}
/* --Methode-- */
void VisiP4Reader::ReorderFreqs(TMatrix< complex<r_4> > & svismtx, TMatrix< complex<r_4> > & dvismtx)
void VisiP4ReaderBase::ReorderFreqs(TMatrix< complex<r_4> > & svismtx, TMatrix< complex<r_4> > & dvismtx)
{
// Ce bout de code pour reordonner les frequences provenant du coreFFT (firmware) a ete
// recopie depuis le fichier TAcq/brpaq.cc , BRPaquet::ReorderFFTData(SByte* src, SByte* dst, int N)
// cela ne fonctionne que pour NFreq=4096=nCoef
if (NFREQ != 4096) throw AssertionFailedError("VisiP4Reader::ReorderFreqs() NFREQ != 4096");
if (NFREQ != 4096) throw AssertionFailedError("VisiP4ReaderBase::ReorderFreqs() NFREQ != 4096");
sa_size_t debutIndex = NFREQ/2 + 1;
sa_size_t fifoSize = NFREQ/2 - 1;
// Sortie 1
......@@ -158,7 +170,7 @@ void VisiP4Reader::ReorderFreqs(TMatrix< complex<r_4> > & svismtx, TMatrix< comp
}
/* --Methode-- */
TMatrix< complex<r_4> > VisiP4Reader::SubtractOffset(TMatrix< complex<r_4> > & vismtx, TMatrix< complex<r_4> > & meanmtx)
TMatrix< complex<r_4> > VisiP4ReaderBase::SubtractOffset(TMatrix< complex<r_4> > & vismtx, TMatrix< complex<r_4> > & meanmtx)
{
r_4 npaqV = vismtx.Info()["NPAQSUM"];
r_4 npaqM = meanmtx.Info()["NPAQSUM"];
......@@ -184,3 +196,146 @@ TMatrix< complex<r_4> > VisiP4Reader::SubtractOffset(TMatrix< complex<r_4> > &
return resmtx;
}
/* --Methode-- */
VisiP4ReaderNoDB::VisiP4ReaderNoDB(vector<string> const& vpath, int first, int last, int step, bool reorderfreq)
: VisiP4ReaderBase(vpath, reorderfreq)
{
SelectSerialNum(first, last, step);
}
/* --Methode-- */
void VisiP4ReaderNoDB::ReadVisMtx(int band, int visgrp, long sernum, TMatrix< complex<r_4> > & vmtx, TMatrix< complex<r_4> > * pmmtx)
{
char filenamebuff[2048];
sprintf(filenamebuff,"%s/vismtx_%d_%ld.ppf",paths_[band].c_str(), visgrp, sernum);
if (prtlevel>3)
cout << " VisiP4ReaderNoDB::ReadVisMtx() - opening file: "<<filenamebuff<<endl;
PInPersist pin(filenamebuff);
if( pmmtx ) {
pin>>vmtx >> (*pmmtx);
} else {
pin>>vmtx;
}
return;
}
/* --Methode-- */
VisiP4ReaderDB::VisiP4ReaderDB(vector<string> const& vpath, bool reorderfreq)
: VisiP4ReaderBase(vpath, reorderfreq)
{
Init();
SelectSerialNum(0,0,1);
}
/* --Methode-- */
VisiP4ReaderDB::VisiP4ReaderDB(vector<string> const& vpath, int first, int last, int step, bool reorderfreq)
: VisiP4ReaderBase(vpath, reorderfreq)
{
Init();
SelectSerialNum(first, last, step);
}
/* --Methode-- */
VisiP4ReaderDB::~VisiP4ReaderDB()
{
for(size_t b=0; b<paths_.size(); b++) {
if ( cur_filep_[b] ) delete cur_filep_[b];
}
}
/* --Methode-- */
void VisiP4ReaderDB::SelectSerialNum(int first, int last, int step)
{
VisiP4ReaderBase::SelectSerialNum(first, last, step);
for(size_t k=0; k<vdb_.size(); k++) {
if ((ser_first_>=vdb_[k].ser_start)&&(ser_first_<vdb_[k].ser_end)) {
first_filenum_ = cur_filenum_ = vdb_[k].filenum;
cur_vdb_index_ = k ; // k should be same value as vdb_[k].filenum
}
if ((ser_last_>=vdb_[k].ser_start)&&(ser_last_<vdb_[k].ser_end))
last_filenum_ = vdb_[k].filenum;
}
OpenFiles(cur_vdb_index_);
}
/* --Methode-- */
void VisiP4ReaderDB::Init()
{
first_filenum_ = last_filenum_ =0;
cur_filenum_ = 0;
cur_vdb_index_ = 0;
for(size_t b=0; b<paths_.size(); b++) cur_filep_.push_back(NULL);
char filenamebuff[2048];
sprintf(filenamebuff,"%s/vmtxdbdesc.txt",paths_[0].c_str());
std::ifstream is(filenamebuff, std::ifstream::in);
string line;
size_t iv, nl;
int ms1,ms2,fs;
char date1[64], date2[64], tu1[64], tu2[64];
while (!is.eof()) {
line = "";
getline(is, line);
if ((is.good() || is.eof()) && (line.length()>0) && (line[0]!='#')) {
sscanf(line.c_str(),"%d %d %d %s %s UT %s %s", &fs, &ms1, &ms2, date1,tu1,date2,tu2);
VDBEL dbel;
dbel.filenum = fs;
dbel.ser_start = ms1;
dbel.ser_end = ms2;
dbel.tu_start = TimeStamp(date1,tu1);
dbel.tu_end = TimeStamp(date2,tu2);
vdb_.push_back(dbel);
}
}
cout << "VisiP4ReaderDB::Init(): "<<vdb_.size()<<" lines read from VisMtxDBWriter data description file"<<filenamebuff<<endl;
/*
for (size_t k=0; k<vdb_.size(); k++) {
if (k != vdb_[k].filenum) cout << " Init*DBG*ERROR/BUG k!= vdb_[k].filenum" << endl;
cout << "Init*DBG["<<k<<"] "<<vdb_[k].filenum<<" "<<vdb_[k].ser_start<<" "<<vdb_[k].ser_end<<" "
<< vdb_[k].tu_start.ToString() << " " << vdb_[k].tu_end.ToString() << endl;
}
*/
return;
}
/* --Methode-- */
void VisiP4ReaderDB::ReadVisMtx(int band, int visgrp, long sernum, TMatrix< complex<r_4> > & vmtx, TMatrix< complex<r_4> > * mmtxp)
{
if ((sernum < vdb_[cur_vdb_index_].ser_start)||(sernum >= vdb_[cur_vdb_index_].ser_end)) {
for(size_t k=0; k<vdb_.size(); k++) {
if ((sernum>=vdb_[k].ser_start)&&(sernum<vdb_[k].ser_end)) {
cur_filenum_ = vdb_[k].filenum;
cur_vdb_index_ = k ; // k should be same value as vdb_[k].filenum
break;
}
}
OpenFiles(cur_vdb_index_);
}
char tagbuff[128];
sprintf(tagbuff,"vismtx_%d_%ld",visgrp,sernum);
(*cur_filep_[band]) >> PPFNameTag(tagbuff) >> vmtx;
if (mmtxp) {
sprintf(tagbuff,"meanfourcoeff_%d_%ld",visgrp,sernum);
(*cur_filep_[band]) >> PPFNameTag(tagbuff) >> (*mmtxp);
}
return;
}
/* --Methode-- */
void VisiP4ReaderDB::OpenFiles(size_t vdbidx)
{
int cur_filenum_ = vdb_[vdbidx].filenum;
if (prtlevel>0)
cout << "VisiP4ReaderDB::OpenFiles()/Info Opening visdb_"<<cur_filenum_<<".ppf files for "<<paths_.size()
<< " bands (data directories)"<<endl;
for(size_t b=0; b<paths_.size(); b++) {
if ( cur_filep_[b] ) delete cur_filep_[b];
cur_filep_[b] = NULL;
char filenamebuff[2048];
sprintf(filenamebuff,"%s/visdb_%ld.ppf",paths_[b].c_str(),(long)cur_filenum_);
cur_filep_[b] = new PInPersist(filenamebuff);
}
cur_vdb_index_ = vdbidx;
return;
}
......@@ -2,7 +2,7 @@
#define VISIP4READER_H_SEEN
//----------------------------------------------------------------
// Projet BAORadio/PAON4 - (C) LAL/IRFU 2008-2011
// Projet BAORadio/PAON4 - (C) LAL/IRFU 2008-2017
// Classe(s) de lecture des fichiers de visibilites PAON4
//----------------------------------------------------------------
......@@ -17,14 +17,26 @@
using namespace std;
using namespace SOPHYA;
class VisiP4Reader {
//------------------------------------------------------------------------------------------------
//----- class VisiP4ReaderBase : classe de base pour le lecture des matrices de visibilite PAON4
//------------------------------------------------------------------------------------------------
class VisiP4ReaderBase {
public:
VisiP4Reader(vector<string> const& vpath, int ifirst, int ilast, int istep=1, bool reorderfreq=true);
VisiP4ReaderBase(vector<string> const& vpath, bool reorderfreq=true);
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_ */
virtual void SelectSerialNum(int first, int last, int step=1);
//! Activate or deactivate frequency reordering when reading visibility matrices
inline void setFreqReordering(bool fg)
{ fgreorderfreq_ = fg; }
bool ReadNext(TMatrix< complex<r_4> > & vismtx, TimeStamp& dateobs, double& mttag)
{
return ReadNext_P(&vismtx, NULL, dateobs, mttag);
}
bool ReadNext(TMatrix< complex<r_4> > & vismtx, TMatrix< complex<r_4> > & meanmtx,
TimeStamp& dateobs, double& mttag)
{
......@@ -41,7 +53,7 @@ public:
inline void setNVis(sa_size_t nvis=36)
{ NVIS=nvis; }
inline void setNFreq(sa_size_t nfreq=4096)
{ NFREQ=nfreq; }
inline void setNBands(int nband=2)
......@@ -67,22 +79,61 @@ protected:
bool ReadNext_P(TMatrix< complex<r_4> >* vismtx, TMatrix< complex<r_4> >* meanmtx,
TimeStamp& dateobs, double& mttag);
virtual void ReadVisMtx(int band, int visgrp, long sernum, TMatrix< complex<r_4> > & vmtx, TMatrix< complex<r_4> > * mmtx) = 0;
vector<string> paths; // path for visibility files produced for each BAO5,BAO6 (first,second frequency band)
int first, last, step; // visibility files with first<=I<=last are read , with step
bool fgreorderfreq;
int curfilenum; // current file number
vector<string> paths_; // path for visibility files produced for each BAO5,BAO6 (first,second frequency band)
int ser_first_, ser_last_, ser_step_; // VisMtx serial number I such as ser_first_<=I<=ser_last_ , one matrix out of ser_step_
bool fgreorderfreq_;
long cur_serialnum_; // current file number
sa_size_t NCHAN; // nombre total de voies
sa_size_t NVIS; // nombre total de visibilites
sa_size_t NFREQ; // nombre total de frequence
int NBAND; // nombre de bande de frequence (= nb de machines de calcul)
int NBAND; // nombre de bande de frequence (= nb de machines de calcul = paths_.size() )
int NVISGRP; // nombre de groupes de visibilites
int prtlevel; // niveau d'impression
TMatrix<int_2> chanpairs;
};
//------------------------------------------------------------------------------------------------
//----- class VisiP4ReaderNoDB : lecture des donnees ecrites sous forme d un fichier / matrice de visibilite
//------------------------------------------------------------------------------------------------
class VisiP4ReaderNoDB : public VisiP4ReaderBase {
public:
VisiP4ReaderNoDB(vector<string> const& vpath, int first, int last, int step=1, bool reorderfreq=true);
protected:
virtual void ReadVisMtx(int band, int visgrp, long sernum, TMatrix< complex<r_4> > & vmtx, TMatrix< complex<r_4> > * mmtx);
};
//------------------------------------------------------------------------------------------------
//----- class VisiP4ReaderNoDB : lecture des donnees ecrites VisMtxDBWriter (plusieurs matrices / fichier)
//------------------------------------------------------------------------------------------------
class VisiP4ReaderDB : public VisiP4ReaderBase {
public:
VisiP4ReaderDB(vector<string> const& vpath, bool reorderfreq=false);
VisiP4ReaderDB(vector<string> const& vpath, int first, int last, int step=1, bool reorderfreq=false);
virtual ~VisiP4ReaderDB();
virtual void SelectSerialNum(int first, int last, int step=1);
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);
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_;
};
// typedef VisiP4ReaderNoDB VisiP4Reader;
typedef VisiP4ReaderDB VisiP4Reader;
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment