| [3872] | 1 | // Utilisation de SOPHYA pour faciliter les tests ...
 | 
|---|
 | 2 | #include "sopnamsp.h"
 | 
|---|
 | 3 | #include "machdefs.h"
 | 
|---|
 | 4 | 
 | 
|---|
 | 5 | /* ---------------------------------------------------------- 
 | 
|---|
 | 6 |    Programme de lecture multifibres, calcul de spectres 
 | 
|---|
| [4016] | 7 |    BAORadio -   LAL/IRFU      R. Ansari, C. Magneville, J.E. Campagne
 | 
|---|
 | 8 |    2010 - 2011
 | 
|---|
| [3872] | 9 |    ---------------------------------------------------------- */
 | 
|---|
| [4016] | 10 | /*!
 | 
|---|
 | 11 |    \ingroup TAcq
 | 
|---|
 | 12 |    \file specmfib.cc
 | 
|---|
| [3872] | 13 | 
 | 
|---|
| [4016] | 14 |    \brief Data cleaning and computation of mean spectrum of gain/normalization spectrum
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 |    This program uses the BRMeanSpecCalculator, BRGainCalculator and BRMultiFitsReader classes
 | 
|---|
 | 17 |    to clean data and compute mean spectra and normalization/gain spectrum from 
 | 
|---|
 | 18 |    raw or FFT data read from FITS files (data in BRPaquet format). 
 | 
|---|
 | 19 |    The BRFFTCalculator class is used to compute fourier coefficients on raw data and 
 | 
|---|
 | 20 |    BRAnaParam class is used for defining and decoding the program run parameters.
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 |   \verbatim
 | 
|---|
 | 23 | csh> specmfib 
 | 
|---|
 | 24 |  ===> specmfib.cc: decoding command line arguments 
 | 
|---|
 | 25 |  --- BRAnaParam : Reading/Processing BAORadio FITS files parameters 
 | 
|---|
 | 26 |  Usage:  prgname [-act ACT] [-out OutPath] [-fitsout] 
 | 
|---|
 | 27 |                  [-nmean NMean] [-tmint dtime] [-zones NZones,nPaqinZone] 
 | 
|---|
 | 28 |                  [-nbloc NBloc] [-freq NumFreqMin,NumFreqMax,NBinFreq] 
 | 
|---|
 | 29 |                  [-prt lev,modulo,mod2] [-nvcal n] [-nthr n] [-nosfc]
 | 
|---|
 | 30 |                  [-singlechan] [-twochan] [-fftdata] [-rawdata] 
 | 
|---|
 | 31 |                  [-freqfilter medhw] [-gain filename] [-varcut min,max] [-nband nband,first,last] 
 | 
|---|
 | 32 |                  [-freqfilter] [-gain filename] [-varcut min,max] [-nband nband,first,last] 
 | 
|---|
 | 33 |                  [-tmproc hh:mm:ss,nseconds] [-fdtpaq] [-fdtms] [-tspwin wsz,extsz,nfiles] 
 | 
|---|
 | 34 |          -in Imin,Imax,Istep InPath FiberList [InPath2 FiberList2 InPath3 FiberList3 ...] 
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 |  prgname -h for detailed instructions
 | 
|---|
 | 37 |   \endverbatim 
 | 
|---|
 | 38 | */
 | 
|---|
 | 39 | 
 | 
|---|
| [3872] | 40 | // include standard c/c++
 | 
|---|
 | 41 | #include <iostream>
 | 
|---|
 | 42 | #include <string>
 | 
|---|
 | 43 | #include <exception>
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 | // include sophya mesure ressource CPU/memoire ...
 | 
|---|
 | 46 | #include "resusage.h"
 | 
|---|
 | 47 | #include "ctimer.h"
 | 
|---|
 | 48 | #include "timing.h"
 | 
|---|
 | 49 | #include "timestamp.h"
 | 
|---|
 | 50 | #include "strutilxx.h"
 | 
|---|
 | 51 | #include "tarrinit.h"
 | 
|---|
 | 52 | #include "histinit.h"
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 | #include "brpaqu.h"
 | 
|---|
 | 55 | #include "brfitsrd.h"
 | 
|---|
 | 56 | #include "brproc.h"
 | 
|---|
| [3943] | 57 | 
 | 
|---|
 | 58 | //JEC 19/1/11 START
 | 
|---|
 | 59 | #include "brprocGain.h"
 | 
|---|
 | 60 | //JEC END
 | 
|---|
 | 61 | 
 | 
|---|
| [3872] | 62 | #include "brdiskw.h"
 | 
|---|
 | 63 | 
 | 
|---|
 | 64 | #include "branap.h"
 | 
|---|
 | 65 | 
 | 
|---|
 | 66 | 
 | 
|---|
 | 67 | 
 | 
|---|
 | 68 | //----------------------------------------------------
 | 
|---|
 | 69 | //----------------------------------------------------
 | 
|---|
 | 70 | int main(int narg, char* arg[])
 | 
|---|
 | 71 | {
 | 
|---|
 | 72 | 
 | 
|---|
 | 73 |   TArrayInitiator  _inia;
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 |   int rc = 0;
 | 
|---|
 | 76 |   try {
 | 
|---|
 | 77 |     // Decodage parametres 
 | 
|---|
 | 78 |     BRAnaParam par;
 | 
|---|
 | 79 |     par.action_="mspec";
 | 
|---|
 | 80 |     cout << " ===> specmfib.cc: decoding command line arguments " << endl;
 | 
|---|
 | 81 |     rc = par.DecodeArgs(narg, arg);
 | 
|---|
 | 82 |     if (rc) return rc;
 | 
|---|
 | 83 |     rc = par.PaqSizeFromFits();
 | 
|---|
 | 84 |     if (rc) return rc;
 | 
|---|
 | 85 |     par.Print(cout);
 | 
|---|
| [3943] | 86 |     if ((par.action_!="cube3d")
 | 
|---|
 | 87 |         &&(par.action_!="mspec")
 | 
|---|
 | 88 |         &&(par.action_!="gain") //JEC 19/1/11 add gain action
 | 
|---|
 | 89 |         &&(par.action_!="bproc") 
 | 
|---|
 | 90 |         ) {
 | 
|---|
| [3938] | 91 |       cout << " !!! specmfib.cc  BAD action = " << par.action_ << " possible values: mspec,cube3d,bproc" << endl;
 | 
|---|
| [3872] | 92 |       return 5;
 | 
|---|
 | 93 |     }   
 | 
|---|
 | 94 | 
 | 
|---|
 | 95 |     cout << " ---------- specmfib.cc Start - Action= " << par.action_ << " ------------- " << endl;
 | 
|---|
 | 96 |     ResourceUsage resu;
 | 
|---|
 | 97 |     BRPaquet paq(par.paqsize_);
 | 
|---|
 | 98 |     uint_4 procsz=sizeof(float)*(paq.DataSize()+4);
 | 
|---|
| [3905] | 99 | //    if ((par.fgdatafft_)||(par.action_=="cube3d")) procsz = 0;
 | 
|---|
| [3872] | 100 |     cout << " specmfib: Creating MemZoneMgr/threads - PaqSz= " << par.paqsize_ 
 | 
|---|
 | 101 |          << " ProcPaqSz=" << procsz << endl;
 | 
|---|
 | 102 |     RAcqMemZoneMgr mmgr(par.nzones_, par.dirlist_.size(), par.npaqinzone_, par.paqsize_, procsz);
 | 
|---|
 | 103 |     if (par.action_ == "cube3d")  mmgr.SetFinalizedMask((uint_4)MemZS_Saved);
 | 
|---|
 | 104 |     else {
 | 
|---|
 | 105 |       if (par.fgdatafft_)  mmgr.SetFinalizedMask((uint_4)MemZS_ProcA);
 | 
|---|
 | 106 |       else mmgr.SetFinalizedMask((uint_4)MemZS_ProcB);
 | 
|---|
 | 107 |     }
 | 
|---|
| [3883] | 108 |     BRMultiFitsReader reader(mmgr, par.dirlist_, par.rdsamefc_, par.imin_, par.imax_, par.istep_);
 | 
|---|
 | 109 |     reader.SetPrintLevel(par.prtlevel_,par.prtmodulo_);
 | 
|---|
| [3872] | 110 | 
 | 
|---|
 | 111 |     BRMeanSpecCalculator procms(mmgr, par.outpath_, par.nmean_, par.fgdatafft_, par.fgsinglechannel_);
 | 
|---|
| [3886] | 112 |     procms.SetVarianceLimits(par.vmin_, par.vmax_);
 | 
|---|
| [3943] | 113 |     if (par.nbands_>0) procms.SetNumberOfBands(par.nbands_,par.bandfirst_,par.bandlast_);
 | 
|---|
 | 114 |     //JEC 27/1/11 see below    if (par.gainfile_.length()>0) procms.ReadGainFitsFile(par.gainfile_);
 | 
|---|
| [3938] | 115 |     procms.SetPrintLevel(par.prtlevel_,par.prtmodulo_);
 | 
|---|
| [3993] | 116 |     if (par.fgdtpaq_) procms.DefinePerPaquetDataTable();
 | 
|---|
 | 117 |     if (par.fgdtms_) procms.DefineTimeAvgPowerDataTable(par.freqmin_,par.freqmax_,par.nbinfreq_);
 | 
|---|
 | 118 | 
 | 
|---|
| [3980] | 119 |     if(par.fgtimeselect_) procms.SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
 | 
|---|
| [3888] | 120 | 
 | 
|---|
| [3943] | 121 |     BRGainCalculator* procgain_p=NULL;
 | 
|---|
 | 122 |     if (par.action_=="gain") {
 | 
|---|
 | 123 |       procgain_p = 
 | 
|---|
 | 124 |         new BRGainCalculator(mmgr, par.outpath_, par.nmean_, par.fgdatafft_, par.fgsinglechannel_);
 | 
|---|
 | 125 |       procgain_p->SetPrintLevel(par.prtlevel_,par.prtmodulo_);
 | 
|---|
| [3992] | 126 |       if(par.fgfreqfilter_){ 
 | 
|---|
 | 127 |         procgain_p->SetOnMedianFreqFilt();
 | 
|---|
 | 128 |         //add possibility to set the half width of the Freq. Median Filter
 | 
|---|
 | 129 |         //default is 50 if par.fgfreqfilter_=true
 | 
|---|
 | 130 |         if (par.medhalfwidth_>0) procgain_p->SetMedianFilterHalfWidth(par.medhalfwidth_);
 | 
|---|
 | 131 |       }
 | 
|---|
| [3993] | 132 |       if (par.fgdtpaq_) procgain_p->DefinePerPaquetDataTable();
 | 
|---|
 | 133 |       if (par.fgdtms_) procgain_p->DefineTimeAvgPowerDataTable(par.freqmin_,par.freqmax_,par.nbinfreq_);
 | 
|---|
| [3980] | 134 |       if(par.fgtimeselect_) procgain_p->SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
 | 
|---|
| [3943] | 135 |     }
 | 
|---|
 | 136 | 
 | 
|---|
 | 137 | 
 | 
|---|
| [3872] | 138 |     BRFFTCalculator procfft(mmgr, par.fgsinglechannel_);
 | 
|---|
| [3980] | 139 |     if(par.fgtimeselect_) procfft.SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
 | 
|---|
 | 140 | 
 | 
|---|
| [3943] | 141 |     if (!par.fgdatafft_) { 
 | 
|---|
 | 142 |       procms.SetMemZAction(MemZA_ProcB);
 | 
|---|
 | 143 |       if(procgain_p) procgain_p->SetMemZAction(MemZA_ProcB);
 | 
|---|
 | 144 |     }
 | 
|---|
 | 145 | 
 | 
|---|
| [3905] | 146 |     if (par.spec_win_sz_>0) { 
 | 
|---|
 | 147 |       procms.SetSpectraWindowSize(par.spec_win_sz_, par.spw_ext_sz_);
 | 
|---|
| [3943] | 148 |       procms.SetMaxNbSpecWinFiles(par.nbmax_specwfiles_);
 | 
|---|
 | 149 |       if(procgain_p){
 | 
|---|
 | 150 |         procgain_p->SetSpectraWindowSize(par.spec_win_sz_, par.spw_ext_sz_);
 | 
|---|
 | 151 |         procgain_p->SetMaxNbSpecWinFiles(par.nbmax_specwfiles_);
 | 
|---|
 | 152 |       }
 | 
|---|
| [3905] | 153 |     }
 | 
|---|
| [3943] | 154 |     //JEC 27/1/11 should be done after SetSpectraWindowSize to perform x-checking
 | 
|---|
| [3972] | 155 |     if (par.gainfile_.length()>0) {
 | 
|---|
 | 156 |       procms.ReadGainFitsFile(par.gainfile_);
 | 
|---|
 | 157 |       if(procgain_p){ //JEC 5/4/2011 we can load previous gain...
 | 
|---|
 | 158 |         procgain_p->ReadGainFitsFile(par.gainfile_);
 | 
|---|
 | 159 |       }
 | 
|---|
 | 160 |     }
 | 
|---|
| [3943] | 161 | 
 | 
|---|
| [3872] | 162 |     FitsCubeWriter wrt(mmgr, par.outpath_, par.nbloc_);
 | 
|---|
 | 163 | 
 | 
|---|
| [3938] | 164 |     BRBaseProcessor* bproc_p=NULL; 
 | 
|---|
 | 165 |     if (par.action_=="bproc") { 
 | 
|---|
 | 166 |        bproc_p = new BRBaseProcessor(mmgr);
 | 
|---|
 | 167 |        bproc_p->SetPrintLevel(par.prtlevel_,par.prtmodulo_);
 | 
|---|
 | 168 |        if (!par.fgdatafft_)  bproc_p->SetMemZAction(MemZA_ProcB);
 | 
|---|
| [3980] | 169 |        if(par.fgtimeselect_) bproc_p->SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
 | 
|---|
| [3938] | 170 |     }
 | 
|---|
 | 171 | 
 | 
|---|
| [3943] | 172 |     cout << " specmfib: Starting threads (reader + "<< par.action_ << ")" << endl;
 | 
|---|
| [3872] | 173 |     reader.start();
 | 
|---|
 | 174 |     if (par.action_ == "cube3d")   wrt.start();
 | 
|---|
 | 175 |     else {  // Calcul spectre moyenne 
 | 
|---|
 | 176 |       if (!par.fgdatafft_)  procfft.start(); 
 | 
|---|
| [3943] | 177 |       //JEC 19/1/11 START add the gain process alternative
 | 
|---|
| [3938] | 178 |       if (par.action_=="bproc")  bproc_p->start();
 | 
|---|
| [3943] | 179 |       else if (par.action_=="gain") procgain_p->start();
 | 
|---|
| [3938] | 180 |       else procms.start();
 | 
|---|
| [3943] | 181 |       //JEC END
 | 
|---|
| [3872] | 182 |     }
 | 
|---|
 | 183 |     usleep(200000);
 | 
|---|
 | 184 |     reader.join();
 | 
|---|
 | 185 |     if (par.action_ == "cube3d")  wrt.join();
 | 
|---|
 | 186 |     else {
 | 
|---|
 | 187 |       if (!par.fgdatafft_)  procfft.join(); 
 | 
|---|
| [3943] | 188 | 
 | 
|---|
 | 189 |       //JEC 19/1/11 START add the gain process alternative
 | 
|---|
| [3938] | 190 |       if (par.action_=="bproc")  bproc_p->join();
 | 
|---|
| [3943] | 191 |       else if (par.action_=="gain") procgain_p->join();
 | 
|---|
| [3938] | 192 |       else procms.join();
 | 
|---|
| [3943] | 193 |       //JEC END
 | 
|---|
| [3872] | 194 |     }
 | 
|---|
 | 195 |     mmgr.Print(cout);
 | 
|---|
| [3938] | 196 |     if (bproc_p) delete bproc_p;
 | 
|---|
| [3943] | 197 |     if (procgain_p) delete procgain_p;
 | 
|---|
| [3872] | 198 |     cout << resu ; 
 | 
|---|
 | 199 |   }
 | 
|---|
 | 200 |   catch (std::exception& sex) {
 | 
|---|
 | 201 |     cerr << "\n specmfib.cc std::exception :"  << (string)typeid(sex).name() 
 | 
|---|
 | 202 |          << "\n msg= " << sex.what() << endl;
 | 
|---|
 | 203 |     rc = 78;
 | 
|---|
 | 204 |   }
 | 
|---|
 | 205 |   catch (...) {
 | 
|---|
 | 206 |     cerr << " specmfib.cc catched unknown (...) exception  " << endl; 
 | 
|---|
 | 207 |     rc = 79; 
 | 
|---|
 | 208 |   } 
 | 
|---|
 | 209 | 
 | 
|---|
 | 210 |   cout << ">>>> specmfib.cc ------- END ----------- RC=" << rc << endl;
 | 
|---|
 | 211 |   return rc;
 | 
|---|
 | 212 | 
 | 
|---|
 | 213 | }
 | 
|---|
 | 214 | 
 | 
|---|
 | 215 | 
 | 
|---|