| 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 | #include "brdiskw.h" | 
|---|
| 29 |  | 
|---|
| 30 | #include "branap.h" | 
|---|
| 31 |  | 
|---|
| 32 |  | 
|---|
| 33 |  | 
|---|
| 34 | //---------------------------------------------------- | 
|---|
| 35 | //---------------------------------------------------- | 
|---|
| 36 | int main(int narg, char* arg[]) | 
|---|
| 37 | { | 
|---|
| 38 |  | 
|---|
| 39 | TArrayInitiator  _inia; | 
|---|
| 40 |  | 
|---|
| 41 | int rc = 0; | 
|---|
| 42 | try { | 
|---|
| 43 | // Decodage parametres | 
|---|
| 44 | BRAnaParam par; | 
|---|
| 45 | par.action_="mspec"; | 
|---|
| 46 | cout << " ===> specmfib.cc: decoding command line arguments " << endl; | 
|---|
| 47 | rc = par.DecodeArgs(narg, arg); | 
|---|
| 48 | if (rc) return rc; | 
|---|
| 49 | rc = par.PaqSizeFromFits(); | 
|---|
| 50 | if (rc) return rc; | 
|---|
| 51 | par.Print(cout); | 
|---|
| 52 | if ((par.action_!="cube3d")&&(par.action_!="mspec")&&(par.action_!="bproc")) { | 
|---|
| 53 | cout << " !!! specmfib.cc  BAD action = " << par.action_ << " possible values: mspec,cube3d,bproc" << endl; | 
|---|
| 54 | return 5; | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 | cout << " ---------- specmfib.cc Start - Action= " << par.action_ << " ------------- " << endl; | 
|---|
| 58 | ResourceUsage resu; | 
|---|
| 59 | BRPaquet paq(par.paqsize_); | 
|---|
| 60 | uint_4 procsz=sizeof(float)*(paq.DataSize()+4); | 
|---|
| 61 | //    if ((par.fgdatafft_)||(par.action_=="cube3d")) procsz = 0; | 
|---|
| 62 | cout << " specmfib: Creating MemZoneMgr/threads - PaqSz= " << par.paqsize_ | 
|---|
| 63 | << " ProcPaqSz=" << procsz << endl; | 
|---|
| 64 | RAcqMemZoneMgr mmgr(par.nzones_, par.dirlist_.size(), par.npaqinzone_, par.paqsize_, procsz); | 
|---|
| 65 | if (par.action_ == "cube3d")  mmgr.SetFinalizedMask((uint_4)MemZS_Saved); | 
|---|
| 66 | else { | 
|---|
| 67 | if (par.fgdatafft_)  mmgr.SetFinalizedMask((uint_4)MemZS_ProcA); | 
|---|
| 68 | else mmgr.SetFinalizedMask((uint_4)MemZS_ProcB); | 
|---|
| 69 | } | 
|---|
| 70 | BRMultiFitsReader reader(mmgr, par.dirlist_, par.rdsamefc_, par.imin_, par.imax_, par.istep_); | 
|---|
| 71 | reader.SetPrintLevel(par.prtlevel_,par.prtmodulo_); | 
|---|
| 72 |  | 
|---|
| 73 | BRMeanSpecCalculator procms(mmgr, par.outpath_, par.nmean_, par.fgdatafft_, par.fgsinglechannel_); | 
|---|
| 74 | procms.SetVarianceLimits(par.vmin_, par.vmax_); | 
|---|
| 75 | if (par.gainfile_.length()>0) procms.ReadGainFitsFile(par.gainfile_); | 
|---|
| 76 | procms.SetPrintLevel(par.prtlevel_,par.prtmodulo_); | 
|---|
| 77 | // Il faut appeler procms.DefineDataTable() si on veut remplir le DataTable | 
|---|
| 78 |  | 
|---|
| 79 | BRFFTCalculator procfft(mmgr, par.fgsinglechannel_); | 
|---|
| 80 | if (!par.fgdatafft_) procms.SetMemZAction(MemZA_ProcB); | 
|---|
| 81 | if (par.spec_win_sz_>0) { | 
|---|
| 82 | procms.SetSpectraWindowSize(par.spec_win_sz_, par.spw_ext_sz_); | 
|---|
| 83 | procms.SetMaxNbSepcWinFiles(par.nbmax_specwfiles_); | 
|---|
| 84 | } | 
|---|
| 85 | FitsCubeWriter wrt(mmgr, par.outpath_, par.nbloc_); | 
|---|
| 86 |  | 
|---|
| 87 | BRBaseProcessor* bproc_p=NULL; | 
|---|
| 88 | if (par.action_=="bproc") { | 
|---|
| 89 | bproc_p = new BRBaseProcessor(mmgr); | 
|---|
| 90 | bproc_p->SetPrintLevel(par.prtlevel_,par.prtmodulo_); | 
|---|
| 91 | if (!par.fgdatafft_)  bproc_p->SetMemZAction(MemZA_ProcB); | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | cout << " specmfib: Starting threads (reader meanSpecCalculator ...) ... " << endl; | 
|---|
| 95 | reader.start(); | 
|---|
| 96 | if (par.action_ == "cube3d")   wrt.start(); | 
|---|
| 97 | else {  // Calcul spectre moyenne | 
|---|
| 98 | if (!par.fgdatafft_)  procfft.start(); | 
|---|
| 99 | if (par.action_=="bproc")  bproc_p->start(); | 
|---|
| 100 | else procms.start(); | 
|---|
| 101 | } | 
|---|
| 102 | usleep(200000); | 
|---|
| 103 | reader.join(); | 
|---|
| 104 | if (par.action_ == "cube3d")  wrt.join(); | 
|---|
| 105 | else { | 
|---|
| 106 | if (!par.fgdatafft_)  procfft.join(); | 
|---|
| 107 | if (par.action_=="bproc")  bproc_p->join(); | 
|---|
| 108 | else procms.join(); | 
|---|
| 109 | } | 
|---|
| 110 | mmgr.Print(cout); | 
|---|
| 111 | if (bproc_p) delete bproc_p; | 
|---|
| 112 | cout << resu ; | 
|---|
| 113 | } | 
|---|
| 114 | catch (std::exception& sex) { | 
|---|
| 115 | cerr << "\n specmfib.cc std::exception :"  << (string)typeid(sex).name() | 
|---|
| 116 | << "\n msg= " << sex.what() << endl; | 
|---|
| 117 | rc = 78; | 
|---|
| 118 | } | 
|---|
| 119 | catch (...) { | 
|---|
| 120 | cerr << " specmfib.cc catched unknown (...) exception  " << endl; | 
|---|
| 121 | rc = 79; | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | cout << ">>>> specmfib.cc ------- END ----------- RC=" << rc << endl; | 
|---|
| 125 | return rc; | 
|---|
| 126 |  | 
|---|
| 127 | } | 
|---|
| 128 |  | 
|---|
| 129 |  | 
|---|