[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
|
---|
| 7 | BAORadio - LAL/IRFU R. Ansari, C. Magneville
|
---|
[3939] | 8 | Septembre 2010 - 2011
|
---|
[3872] | 9 | ---------------------------------------------------------- */
|
---|
| 10 |
|
---|
| 11 | // include standard c/c++
|
---|
| 12 | #include <iostream>
|
---|
| 13 | #include <string>
|
---|
| 14 | #include <exception>
|
---|
| 15 |
|
---|
| 16 | // include sophya mesure ressource CPU/memoire ...
|
---|
| 17 | #include "resusage.h"
|
---|
| 18 | #include "ctimer.h"
|
---|
| 19 | #include "timing.h"
|
---|
| 20 | #include "timestamp.h"
|
---|
| 21 | #include "strutilxx.h"
|
---|
| 22 | #include "tarrinit.h"
|
---|
| 23 | #include "histinit.h"
|
---|
| 24 |
|
---|
| 25 | #include "brpaqu.h"
|
---|
| 26 | #include "brfitsrd.h"
|
---|
| 27 | #include "brproc.h"
|
---|
[3943] | 28 |
|
---|
| 29 | //JEC 19/1/11 START
|
---|
| 30 | #include "brprocGain.h"
|
---|
| 31 | //JEC END
|
---|
| 32 |
|
---|
[3872] | 33 | #include "brdiskw.h"
|
---|
| 34 |
|
---|
| 35 | #include "branap.h"
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | //----------------------------------------------------
|
---|
| 40 | //----------------------------------------------------
|
---|
| 41 | int main(int narg, char* arg[])
|
---|
| 42 | {
|
---|
| 43 |
|
---|
| 44 | TArrayInitiator _inia;
|
---|
| 45 |
|
---|
| 46 | int rc = 0;
|
---|
| 47 | try {
|
---|
| 48 | // Decodage parametres
|
---|
| 49 | BRAnaParam par;
|
---|
| 50 | par.action_="mspec";
|
---|
| 51 | cout << " ===> specmfib.cc: decoding command line arguments " << endl;
|
---|
| 52 | rc = par.DecodeArgs(narg, arg);
|
---|
| 53 | if (rc) return rc;
|
---|
| 54 | rc = par.PaqSizeFromFits();
|
---|
| 55 | if (rc) return rc;
|
---|
| 56 | par.Print(cout);
|
---|
[3943] | 57 | if ((par.action_!="cube3d")
|
---|
| 58 | &&(par.action_!="mspec")
|
---|
| 59 | &&(par.action_!="gain") //JEC 19/1/11 add gain action
|
---|
| 60 | &&(par.action_!="bproc")
|
---|
| 61 | ) {
|
---|
[3938] | 62 | cout << " !!! specmfib.cc BAD action = " << par.action_ << " possible values: mspec,cube3d,bproc" << endl;
|
---|
[3872] | 63 | return 5;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | cout << " ---------- specmfib.cc Start - Action= " << par.action_ << " ------------- " << endl;
|
---|
| 67 | ResourceUsage resu;
|
---|
| 68 | BRPaquet paq(par.paqsize_);
|
---|
| 69 | uint_4 procsz=sizeof(float)*(paq.DataSize()+4);
|
---|
[3905] | 70 | // if ((par.fgdatafft_)||(par.action_=="cube3d")) procsz = 0;
|
---|
[3872] | 71 | cout << " specmfib: Creating MemZoneMgr/threads - PaqSz= " << par.paqsize_
|
---|
| 72 | << " ProcPaqSz=" << procsz << endl;
|
---|
| 73 | RAcqMemZoneMgr mmgr(par.nzones_, par.dirlist_.size(), par.npaqinzone_, par.paqsize_, procsz);
|
---|
| 74 | if (par.action_ == "cube3d") mmgr.SetFinalizedMask((uint_4)MemZS_Saved);
|
---|
| 75 | else {
|
---|
| 76 | if (par.fgdatafft_) mmgr.SetFinalizedMask((uint_4)MemZS_ProcA);
|
---|
| 77 | else mmgr.SetFinalizedMask((uint_4)MemZS_ProcB);
|
---|
| 78 | }
|
---|
[3883] | 79 | BRMultiFitsReader reader(mmgr, par.dirlist_, par.rdsamefc_, par.imin_, par.imax_, par.istep_);
|
---|
| 80 | reader.SetPrintLevel(par.prtlevel_,par.prtmodulo_);
|
---|
[3872] | 81 |
|
---|
| 82 | BRMeanSpecCalculator procms(mmgr, par.outpath_, par.nmean_, par.fgdatafft_, par.fgsinglechannel_);
|
---|
[3886] | 83 | procms.SetVarianceLimits(par.vmin_, par.vmax_);
|
---|
[3943] | 84 | if (par.nbands_>0) procms.SetNumberOfBands(par.nbands_,par.bandfirst_,par.bandlast_);
|
---|
| 85 | //JEC 27/1/11 see below if (par.gainfile_.length()>0) procms.ReadGainFitsFile(par.gainfile_);
|
---|
[3938] | 86 | procms.SetPrintLevel(par.prtlevel_,par.prtmodulo_);
|
---|
[3993] | 87 | if (par.fgdtpaq_) procms.DefinePerPaquetDataTable();
|
---|
| 88 | if (par.fgdtms_) procms.DefineTimeAvgPowerDataTable(par.freqmin_,par.freqmax_,par.nbinfreq_);
|
---|
| 89 |
|
---|
[3980] | 90 | if(par.fgtimeselect_) procms.SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
|
---|
[3888] | 91 |
|
---|
[3943] | 92 | BRGainCalculator* procgain_p=NULL;
|
---|
| 93 | if (par.action_=="gain") {
|
---|
| 94 | procgain_p =
|
---|
| 95 | new BRGainCalculator(mmgr, par.outpath_, par.nmean_, par.fgdatafft_, par.fgsinglechannel_);
|
---|
| 96 | procgain_p->SetPrintLevel(par.prtlevel_,par.prtmodulo_);
|
---|
[3992] | 97 | if(par.fgfreqfilter_){
|
---|
| 98 | procgain_p->SetOnMedianFreqFilt();
|
---|
| 99 | //add possibility to set the half width of the Freq. Median Filter
|
---|
| 100 | //default is 50 if par.fgfreqfilter_=true
|
---|
| 101 | if (par.medhalfwidth_>0) procgain_p->SetMedianFilterHalfWidth(par.medhalfwidth_);
|
---|
| 102 | }
|
---|
[3993] | 103 | if (par.fgdtpaq_) procgain_p->DefinePerPaquetDataTable();
|
---|
| 104 | if (par.fgdtms_) procgain_p->DefineTimeAvgPowerDataTable(par.freqmin_,par.freqmax_,par.nbinfreq_);
|
---|
[3980] | 105 | if(par.fgtimeselect_) procgain_p->SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
|
---|
[3943] | 106 | }
|
---|
| 107 |
|
---|
| 108 |
|
---|
[3872] | 109 | BRFFTCalculator procfft(mmgr, par.fgsinglechannel_);
|
---|
[3980] | 110 | if(par.fgtimeselect_) procfft.SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
|
---|
| 111 |
|
---|
[3943] | 112 | if (!par.fgdatafft_) {
|
---|
| 113 | procms.SetMemZAction(MemZA_ProcB);
|
---|
| 114 | if(procgain_p) procgain_p->SetMemZAction(MemZA_ProcB);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[3905] | 117 | if (par.spec_win_sz_>0) {
|
---|
| 118 | procms.SetSpectraWindowSize(par.spec_win_sz_, par.spw_ext_sz_);
|
---|
[3943] | 119 | procms.SetMaxNbSpecWinFiles(par.nbmax_specwfiles_);
|
---|
| 120 | if(procgain_p){
|
---|
| 121 | procgain_p->SetSpectraWindowSize(par.spec_win_sz_, par.spw_ext_sz_);
|
---|
| 122 | procgain_p->SetMaxNbSpecWinFiles(par.nbmax_specwfiles_);
|
---|
| 123 | }
|
---|
[3905] | 124 | }
|
---|
[3943] | 125 | //JEC 27/1/11 should be done after SetSpectraWindowSize to perform x-checking
|
---|
[3972] | 126 | if (par.gainfile_.length()>0) {
|
---|
| 127 | procms.ReadGainFitsFile(par.gainfile_);
|
---|
| 128 | if(procgain_p){ //JEC 5/4/2011 we can load previous gain...
|
---|
| 129 | procgain_p->ReadGainFitsFile(par.gainfile_);
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
[3943] | 132 |
|
---|
[3872] | 133 | FitsCubeWriter wrt(mmgr, par.outpath_, par.nbloc_);
|
---|
| 134 |
|
---|
[3938] | 135 | BRBaseProcessor* bproc_p=NULL;
|
---|
| 136 | if (par.action_=="bproc") {
|
---|
| 137 | bproc_p = new BRBaseProcessor(mmgr);
|
---|
| 138 | bproc_p->SetPrintLevel(par.prtlevel_,par.prtmodulo_);
|
---|
| 139 | if (!par.fgdatafft_) bproc_p->SetMemZAction(MemZA_ProcB);
|
---|
[3980] | 140 | if(par.fgtimeselect_) bproc_p->SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
|
---|
[3938] | 141 | }
|
---|
| 142 |
|
---|
[3943] | 143 | cout << " specmfib: Starting threads (reader + "<< par.action_ << ")" << endl;
|
---|
[3872] | 144 | reader.start();
|
---|
| 145 | if (par.action_ == "cube3d") wrt.start();
|
---|
| 146 | else { // Calcul spectre moyenne
|
---|
| 147 | if (!par.fgdatafft_) procfft.start();
|
---|
[3943] | 148 | //JEC 19/1/11 START add the gain process alternative
|
---|
[3938] | 149 | if (par.action_=="bproc") bproc_p->start();
|
---|
[3943] | 150 | else if (par.action_=="gain") procgain_p->start();
|
---|
[3938] | 151 | else procms.start();
|
---|
[3943] | 152 | //JEC END
|
---|
[3872] | 153 | }
|
---|
| 154 | usleep(200000);
|
---|
| 155 | reader.join();
|
---|
| 156 | if (par.action_ == "cube3d") wrt.join();
|
---|
| 157 | else {
|
---|
| 158 | if (!par.fgdatafft_) procfft.join();
|
---|
[3943] | 159 |
|
---|
| 160 | //JEC 19/1/11 START add the gain process alternative
|
---|
[3938] | 161 | if (par.action_=="bproc") bproc_p->join();
|
---|
[3943] | 162 | else if (par.action_=="gain") procgain_p->join();
|
---|
[3938] | 163 | else procms.join();
|
---|
[3943] | 164 | //JEC END
|
---|
[3872] | 165 | }
|
---|
| 166 | mmgr.Print(cout);
|
---|
[3938] | 167 | if (bproc_p) delete bproc_p;
|
---|
[3943] | 168 | if (procgain_p) delete procgain_p;
|
---|
[3872] | 169 | cout << resu ;
|
---|
| 170 | }
|
---|
| 171 | catch (std::exception& sex) {
|
---|
| 172 | cerr << "\n specmfib.cc std::exception :" << (string)typeid(sex).name()
|
---|
| 173 | << "\n msg= " << sex.what() << endl;
|
---|
| 174 | rc = 78;
|
---|
| 175 | }
|
---|
| 176 | catch (...) {
|
---|
| 177 | cerr << " specmfib.cc catched unknown (...) exception " << endl;
|
---|
| 178 | rc = 79;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | cout << ">>>> specmfib.cc ------- END ----------- RC=" << rc << endl;
|
---|
| 182 | return rc;
|
---|
| 183 |
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 |
|
---|