| 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
|
|---|
| 7 | BAORadio - LAL/IRFU R. Ansari, C. Magneville, J.E. Campagne
|
|---|
| 8 | 2010 - 2011
|
|---|
| 9 | ---------------------------------------------------------- */
|
|---|
| 10 | /*!
|
|---|
| 11 | \ingroup TAcq
|
|---|
| 12 | \file specmfib.cc
|
|---|
| 13 |
|
|---|
| 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 |
|
|---|
| 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"
|
|---|
| 57 |
|
|---|
| 58 | //JEC 19/1/11 START
|
|---|
| 59 | #include "brprocGain.h"
|
|---|
| 60 | //JEC END
|
|---|
| 61 |
|
|---|
| 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);
|
|---|
| 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 | ) {
|
|---|
| 91 | cout << " !!! specmfib.cc BAD action = " << par.action_ << " possible values: mspec,cube3d,bproc" << endl;
|
|---|
| 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);
|
|---|
| 99 | // if ((par.fgdatafft_)||(par.action_=="cube3d")) procsz = 0;
|
|---|
| 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 | }
|
|---|
| 108 | BRMultiFitsReader reader(mmgr, par.dirlist_, par.rdsamefc_, par.imin_, par.imax_, par.istep_);
|
|---|
| 109 | reader.SetPrintLevel(par.prtlevel_,par.prtmodulo_);
|
|---|
| 110 |
|
|---|
| 111 | BRMeanSpecCalculator procms(mmgr, par.outpath_, par.nmean_, par.fgdatafft_, par.fgsinglechannel_);
|
|---|
| 112 | procms.SetVarianceLimits(par.vmin_, par.vmax_);
|
|---|
| 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_);
|
|---|
| 115 | procms.SetPrintLevel(par.prtlevel_,par.prtmodulo_);
|
|---|
| 116 | if (par.fgdtpaq_) procms.DefinePerPaquetDataTable();
|
|---|
| 117 | if (par.fgdtms_) procms.DefineTimeAvgPowerDataTable(par.freqmin_,par.freqmax_,par.nbinfreq_);
|
|---|
| 118 |
|
|---|
| 119 | if(par.fgtimeselect_) procms.SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
|
|---|
| 120 |
|
|---|
| 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_);
|
|---|
| 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 | }
|
|---|
| 132 | if (par.fgdtpaq_) procgain_p->DefinePerPaquetDataTable();
|
|---|
| 133 | if (par.fgdtms_) procgain_p->DefineTimeAvgPowerDataTable(par.freqmin_,par.freqmax_,par.nbinfreq_);
|
|---|
| 134 | if(par.fgtimeselect_) procgain_p->SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 | BRFFTCalculator procfft(mmgr, par.fgsinglechannel_);
|
|---|
| 139 | if(par.fgtimeselect_) procfft.SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
|
|---|
| 140 |
|
|---|
| 141 | if (!par.fgdatafft_) {
|
|---|
| 142 | procms.SetMemZAction(MemZA_ProcB);
|
|---|
| 143 | if(procgain_p) procgain_p->SetMemZAction(MemZA_ProcB);
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | if (par.spec_win_sz_>0) {
|
|---|
| 147 | procms.SetSpectraWindowSize(par.spec_win_sz_, par.spw_ext_sz_);
|
|---|
| 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 | }
|
|---|
| 153 | }
|
|---|
| 154 | //JEC 27/1/11 should be done after SetSpectraWindowSize to perform x-checking
|
|---|
| 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 | }
|
|---|
| 161 |
|
|---|
| 162 | FitsCubeWriter wrt(mmgr, par.outpath_, par.nbloc_);
|
|---|
| 163 |
|
|---|
| 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);
|
|---|
| 169 | if(par.fgtimeselect_) bproc_p->SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | cout << " specmfib: Starting threads (reader + "<< par.action_ << ")" << endl;
|
|---|
| 173 | reader.start();
|
|---|
| 174 | if (par.action_ == "cube3d") wrt.start();
|
|---|
| 175 | else { // Calcul spectre moyenne
|
|---|
| 176 | if (!par.fgdatafft_) procfft.start();
|
|---|
| 177 | //JEC 19/1/11 START add the gain process alternative
|
|---|
| 178 | if (par.action_=="bproc") bproc_p->start();
|
|---|
| 179 | else if (par.action_=="gain") procgain_p->start();
|
|---|
| 180 | else procms.start();
|
|---|
| 181 | //JEC END
|
|---|
| 182 | }
|
|---|
| 183 | usleep(200000);
|
|---|
| 184 | reader.join();
|
|---|
| 185 | if (par.action_ == "cube3d") wrt.join();
|
|---|
| 186 | else {
|
|---|
| 187 | if (!par.fgdatafft_) procfft.join();
|
|---|
| 188 |
|
|---|
| 189 | //JEC 19/1/11 START add the gain process alternative
|
|---|
| 190 | if (par.action_=="bproc") bproc_p->join();
|
|---|
| 191 | else if (par.action_=="gain") procgain_p->join();
|
|---|
| 192 | else procms.join();
|
|---|
| 193 | //JEC END
|
|---|
| 194 | }
|
|---|
| 195 | mmgr.Print(cout);
|
|---|
| 196 | if (bproc_p) delete bproc_p;
|
|---|
| 197 | if (procgain_p) delete procgain_p;
|
|---|
| 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 |
|
|---|