| [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_); | 
|---|
| [3943] | 87 | if (par.fgdt_) procms.DefineDataTable(); | 
|---|
| [3980] | 88 | if(par.fgtimeselect_) procms.SetProcTimeWindow(par.proctimestart_,par.proctimeend_); | 
|---|
| [3888] | 89 |  | 
|---|
| [3943] | 90 | BRGainCalculator* procgain_p=NULL; | 
|---|
|  | 91 | if (par.action_=="gain") { | 
|---|
|  | 92 | procgain_p = | 
|---|
|  | 93 | new BRGainCalculator(mmgr, par.outpath_, par.nmean_, par.fgdatafft_, par.fgsinglechannel_); | 
|---|
|  | 94 | procgain_p->SetPrintLevel(par.prtlevel_,par.prtmodulo_); | 
|---|
| [3946] | 95 | if(par.fgfreqfilter_) procgain_p->SetOnMedianFreqFilt(); | 
|---|
| [3980] | 96 | if(par.fgtimeselect_) procgain_p->SetProcTimeWindow(par.proctimestart_,par.proctimeend_); | 
|---|
| [3943] | 97 | } | 
|---|
|  | 98 |  | 
|---|
|  | 99 |  | 
|---|
| [3872] | 100 | BRFFTCalculator procfft(mmgr, par.fgsinglechannel_); | 
|---|
| [3980] | 101 | if(par.fgtimeselect_) procfft.SetProcTimeWindow(par.proctimestart_,par.proctimeend_); | 
|---|
|  | 102 |  | 
|---|
| [3943] | 103 | if (!par.fgdatafft_) { | 
|---|
|  | 104 | procms.SetMemZAction(MemZA_ProcB); | 
|---|
|  | 105 | if(procgain_p) procgain_p->SetMemZAction(MemZA_ProcB); | 
|---|
|  | 106 | } | 
|---|
|  | 107 |  | 
|---|
| [3905] | 108 | if (par.spec_win_sz_>0) { | 
|---|
|  | 109 | procms.SetSpectraWindowSize(par.spec_win_sz_, par.spw_ext_sz_); | 
|---|
| [3943] | 110 | procms.SetMaxNbSpecWinFiles(par.nbmax_specwfiles_); | 
|---|
|  | 111 | if(procgain_p){ | 
|---|
|  | 112 | procgain_p->SetSpectraWindowSize(par.spec_win_sz_, par.spw_ext_sz_); | 
|---|
|  | 113 | procgain_p->SetMaxNbSpecWinFiles(par.nbmax_specwfiles_); | 
|---|
|  | 114 | } | 
|---|
| [3905] | 115 | } | 
|---|
| [3943] | 116 | //JEC 27/1/11 should be done after SetSpectraWindowSize to perform x-checking | 
|---|
| [3972] | 117 | if (par.gainfile_.length()>0) { | 
|---|
|  | 118 | procms.ReadGainFitsFile(par.gainfile_); | 
|---|
|  | 119 | if(procgain_p){ //JEC 5/4/2011 we can load previous gain... | 
|---|
|  | 120 | procgain_p->ReadGainFitsFile(par.gainfile_); | 
|---|
|  | 121 | } | 
|---|
|  | 122 | } | 
|---|
| [3943] | 123 |  | 
|---|
| [3872] | 124 | FitsCubeWriter wrt(mmgr, par.outpath_, par.nbloc_); | 
|---|
|  | 125 |  | 
|---|
| [3938] | 126 | BRBaseProcessor* bproc_p=NULL; | 
|---|
|  | 127 | if (par.action_=="bproc") { | 
|---|
|  | 128 | bproc_p = new BRBaseProcessor(mmgr); | 
|---|
|  | 129 | bproc_p->SetPrintLevel(par.prtlevel_,par.prtmodulo_); | 
|---|
|  | 130 | if (!par.fgdatafft_)  bproc_p->SetMemZAction(MemZA_ProcB); | 
|---|
| [3980] | 131 | if(par.fgtimeselect_) bproc_p->SetProcTimeWindow(par.proctimestart_,par.proctimeend_); | 
|---|
| [3938] | 132 | } | 
|---|
|  | 133 |  | 
|---|
| [3943] | 134 | cout << " specmfib: Starting threads (reader + "<< par.action_ << ")" << endl; | 
|---|
| [3872] | 135 | reader.start(); | 
|---|
|  | 136 | if (par.action_ == "cube3d")   wrt.start(); | 
|---|
|  | 137 | else {  // Calcul spectre moyenne | 
|---|
|  | 138 | if (!par.fgdatafft_)  procfft.start(); | 
|---|
| [3943] | 139 | //JEC 19/1/11 START add the gain process alternative | 
|---|
| [3938] | 140 | if (par.action_=="bproc")  bproc_p->start(); | 
|---|
| [3943] | 141 | else if (par.action_=="gain") procgain_p->start(); | 
|---|
| [3938] | 142 | else procms.start(); | 
|---|
| [3943] | 143 | //JEC END | 
|---|
| [3872] | 144 | } | 
|---|
|  | 145 | usleep(200000); | 
|---|
|  | 146 | reader.join(); | 
|---|
|  | 147 | if (par.action_ == "cube3d")  wrt.join(); | 
|---|
|  | 148 | else { | 
|---|
|  | 149 | if (!par.fgdatafft_)  procfft.join(); | 
|---|
| [3943] | 150 |  | 
|---|
|  | 151 | //JEC 19/1/11 START add the gain process alternative | 
|---|
| [3938] | 152 | if (par.action_=="bproc")  bproc_p->join(); | 
|---|
| [3943] | 153 | else if (par.action_=="gain") procgain_p->join(); | 
|---|
| [3938] | 154 | else procms.join(); | 
|---|
| [3943] | 155 | //JEC END | 
|---|
| [3872] | 156 | } | 
|---|
|  | 157 | mmgr.Print(cout); | 
|---|
| [3938] | 158 | if (bproc_p) delete bproc_p; | 
|---|
| [3943] | 159 | if (procgain_p) delete procgain_p; | 
|---|
| [3872] | 160 | cout << resu ; | 
|---|
|  | 161 | } | 
|---|
|  | 162 | catch (std::exception& sex) { | 
|---|
|  | 163 | cerr << "\n specmfib.cc std::exception :"  << (string)typeid(sex).name() | 
|---|
|  | 164 | << "\n msg= " << sex.what() << endl; | 
|---|
|  | 165 | rc = 78; | 
|---|
|  | 166 | } | 
|---|
|  | 167 | catch (...) { | 
|---|
|  | 168 | cerr << " specmfib.cc catched unknown (...) exception  " << endl; | 
|---|
|  | 169 | rc = 79; | 
|---|
|  | 170 | } | 
|---|
|  | 171 |  | 
|---|
|  | 172 | cout << ">>>> specmfib.cc ------- END ----------- RC=" << rc << endl; | 
|---|
|  | 173 | return rc; | 
|---|
|  | 174 |  | 
|---|
|  | 175 | } | 
|---|
|  | 176 |  | 
|---|
|  | 177 |  | 
|---|