| 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
 | 
|---|
| 8 |    Septembre 2010 - 2011
 | 
|---|
| 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"
 | 
|---|
| 28 | 
 | 
|---|
| 29 | //JEC 19/1/11 START
 | 
|---|
| 30 | #include "brprocGain.h"
 | 
|---|
| 31 | //JEC END
 | 
|---|
| 32 | 
 | 
|---|
| 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);
 | 
|---|
| 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 |         ) {
 | 
|---|
| 62 |       cout << " !!! specmfib.cc  BAD action = " << par.action_ << " possible values: mspec,cube3d,bproc" << endl;
 | 
|---|
| 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);
 | 
|---|
| 70 | //    if ((par.fgdatafft_)||(par.action_=="cube3d")) procsz = 0;
 | 
|---|
| 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 |     }
 | 
|---|
| 79 |     BRMultiFitsReader reader(mmgr, par.dirlist_, par.rdsamefc_, par.imin_, par.imax_, par.istep_);
 | 
|---|
| 80 |     reader.SetPrintLevel(par.prtlevel_,par.prtmodulo_);
 | 
|---|
| 81 | 
 | 
|---|
| 82 |     BRMeanSpecCalculator procms(mmgr, par.outpath_, par.nmean_, par.fgdatafft_, par.fgsinglechannel_);
 | 
|---|
| 83 |     procms.SetVarianceLimits(par.vmin_, par.vmax_);
 | 
|---|
| 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_);
 | 
|---|
| 86 |     procms.SetPrintLevel(par.prtlevel_,par.prtmodulo_);
 | 
|---|
| 87 |     if (par.fgdt_) procms.DefineDataTable();
 | 
|---|
| 88 |     if(par.fgtimeselect_) procms.SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
 | 
|---|
| 89 | 
 | 
|---|
| 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_);
 | 
|---|
| 95 |       if(par.fgfreqfilter_) procgain_p->SetOnMedianFreqFilt();
 | 
|---|
| 96 |       if(par.fgtimeselect_) procgain_p->SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
 | 
|---|
| 97 |     }
 | 
|---|
| 98 | 
 | 
|---|
| 99 | 
 | 
|---|
| 100 |     BRFFTCalculator procfft(mmgr, par.fgsinglechannel_);
 | 
|---|
| 101 |     if(par.fgtimeselect_) procfft.SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
 | 
|---|
| 102 | 
 | 
|---|
| 103 |     if (!par.fgdatafft_) { 
 | 
|---|
| 104 |       procms.SetMemZAction(MemZA_ProcB);
 | 
|---|
| 105 |       if(procgain_p) procgain_p->SetMemZAction(MemZA_ProcB);
 | 
|---|
| 106 |     }
 | 
|---|
| 107 | 
 | 
|---|
| 108 |     if (par.spec_win_sz_>0) { 
 | 
|---|
| 109 |       procms.SetSpectraWindowSize(par.spec_win_sz_, par.spw_ext_sz_);
 | 
|---|
| 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 |       }
 | 
|---|
| 115 |     }
 | 
|---|
| 116 |     //JEC 27/1/11 should be done after SetSpectraWindowSize to perform x-checking
 | 
|---|
| 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 |     }
 | 
|---|
| 123 | 
 | 
|---|
| 124 |     FitsCubeWriter wrt(mmgr, par.outpath_, par.nbloc_);
 | 
|---|
| 125 | 
 | 
|---|
| 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);
 | 
|---|
| 131 |        if(par.fgtimeselect_) bproc_p->SetProcTimeWindow(par.proctimestart_,par.proctimeend_);
 | 
|---|
| 132 |     }
 | 
|---|
| 133 | 
 | 
|---|
| 134 |     cout << " specmfib: Starting threads (reader + "<< par.action_ << ")" << endl;
 | 
|---|
| 135 |     reader.start();
 | 
|---|
| 136 |     if (par.action_ == "cube3d")   wrt.start();
 | 
|---|
| 137 |     else {  // Calcul spectre moyenne 
 | 
|---|
| 138 |       if (!par.fgdatafft_)  procfft.start(); 
 | 
|---|
| 139 |       //JEC 19/1/11 START add the gain process alternative
 | 
|---|
| 140 |       if (par.action_=="bproc")  bproc_p->start();
 | 
|---|
| 141 |       else if (par.action_=="gain") procgain_p->start();
 | 
|---|
| 142 |       else procms.start();
 | 
|---|
| 143 |       //JEC END
 | 
|---|
| 144 |     }
 | 
|---|
| 145 |     usleep(200000);
 | 
|---|
| 146 |     reader.join();
 | 
|---|
| 147 |     if (par.action_ == "cube3d")  wrt.join();
 | 
|---|
| 148 |     else {
 | 
|---|
| 149 |       if (!par.fgdatafft_)  procfft.join(); 
 | 
|---|
| 150 | 
 | 
|---|
| 151 |       //JEC 19/1/11 START add the gain process alternative
 | 
|---|
| 152 |       if (par.action_=="bproc")  bproc_p->join();
 | 
|---|
| 153 |       else if (par.action_=="gain") procgain_p->join();
 | 
|---|
| 154 |       else procms.join();
 | 
|---|
| 155 |       //JEC END
 | 
|---|
| 156 |     }
 | 
|---|
| 157 |     mmgr.Print(cout);
 | 
|---|
| 158 |     if (bproc_p) delete bproc_p;
 | 
|---|
| 159 |     if (procgain_p) delete procgain_p;
 | 
|---|
| 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 | 
 | 
|---|