| [3704] | 1 | #include <stdlib.h>
 | 
|---|
 | 2 | #include <string.h>
 | 
|---|
 | 3 | 
 | 
|---|
| [3687] | 4 | #include "branap.h"
 | 
|---|
 | 5 | #include "minifits.h"
 | 
|---|
 | 6 | #include "strutilxx.h"
 | 
|---|
 | 7 | #include "sopnamsp.h"
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 | //--------------------------------------------------------------
 | 
|---|
 | 10 | // Projet BAORadio - (C) LAL/IRFU  2008-2010
 | 
|---|
 | 11 | // Classe de gestion des parametres programmes d'analyse 
 | 
|---|
 | 12 | //--------------------------------------------------------------
 | 
|---|
 | 13 | 
 | 
|---|
 | 14 | /* --Methode-- */
 | 
|---|
 | 15 | BRAnaParam::BRAnaParam(uint_4 nmean, uint_4 nzon, uint_4 npaqz)
 | 
|---|
 | 16 | {
 | 
|---|
 | 17 |   outpath_="./";
 | 
|---|
| [3956] | 18 |   fgfitsout_=false;
 | 
|---|
| [3687] | 19 |   nmean_=nmean;
 | 
|---|
| [3688] | 20 |   nbloc_=1;
 | 
|---|
| [3687] | 21 |   imin_=imax_=0;
 | 
|---|
 | 22 |   istep_=1;
 | 
|---|
| [3883] | 23 |   rdsamefc_=true;   // read paquets with same frame counter
 | 
|---|
| [3688] | 24 |   freqmin_=freqmax_=0;
 | 
|---|
 | 25 |   nbinfreq_=1;  
 | 
|---|
| [3687] | 26 |   paqsize_=16424;
 | 
|---|
 | 27 |   nzones_=nzon;
 | 
|---|
 | 28 |   npaqinzone_=npaqz;
 | 
|---|
| [3956] | 29 |   fgdatafft_=false;   fgforceraworfft_=false; 
 | 
|---|
| [3967] | 30 |   fgsinglechannel_=false; fgforcesingleortwochan_=false;
 | 
|---|
| [3688] | 31 |   prtlevel_=0;
 | 
|---|
| [3883] | 32 |   prtmodulo_=50000;
 | 
|---|
| [3776] | 33 |   nbcalgrp_=1;
 | 
|---|
| [3724] | 34 |   nthreads_=1;
 | 
|---|
| [3886] | 35 | 
 | 
|---|
| [3905] | 36 |   spec_win_sz_=0;
 | 
|---|
 | 37 |   spw_ext_sz_=0;
 | 
|---|
 | 38 |   nbmax_specwfiles_=0;
 | 
|---|
 | 39 | 
 | 
|---|
| [3886] | 40 |   vmin_=0.;  vmax_=9e99;
 | 
|---|
| [3943] | 41 |   nbands_=0; bandfirst_ = bandlast_ = 0;
 | 
|---|
 | 42 |   fgdt_ = false;
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 |   fgfreqfilter_=false; //JEC 1/2/11
 | 
|---|
 | 45 | 
 | 
|---|
| [3888] | 46 |   gainfile_="";
 | 
|---|
| [3687] | 47 | }
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 | /* --Methode-- */
 | 
|---|
 | 50 | int BRAnaParam::DecodeArgs(int narg, char* arg[])
 | 
|---|
 | 51 | {
 | 
|---|
 | 52 |   if ((narg>1)&&(strcmp(arg[1],"-h")==0))  return Usage(false);
 | 
|---|
 | 53 |   if (narg<5) return Usage(true);
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 |   bool okarg=false;
 | 
|---|
 | 56 |   int ka=1;
 | 
|---|
 | 57 |   while (ka<(narg-1)) {
 | 
|---|
 | 58 |     if (strcmp(arg[ka],"-act")==0) {
 | 
|---|
 | 59 |       action_=arg[ka+1];
 | 
|---|
 | 60 |       ka+=2;
 | 
|---|
 | 61 |     }
 | 
|---|
 | 62 |     else if (strcmp(arg[ka],"-out")==0) {
 | 
|---|
 | 63 |       outpath_=arg[ka+1];
 | 
|---|
| [3688] | 64 |       size_t lenp=outpath_.size();
 | 
|---|
 | 65 |       if ((lenp>0)&&(outpath_[lenp-1]!='/'))  outpath_+='/';
 | 
|---|
| [3687] | 66 |       ka+=2;
 | 
|---|
 | 67 |     }
 | 
|---|
| [3956] | 68 |     else if (strcmp(arg[ka],"-fitsout")==0) {
 | 
|---|
 | 69 |       fgfitsout_=true; 
 | 
|---|
 | 70 |       ka++;
 | 
|---|
 | 71 |     }
 | 
|---|
| [3687] | 72 |     else if (strcmp(arg[ka],"-nmean")==0) {
 | 
|---|
 | 73 |       nmean_=atoi(arg[ka+1]);
 | 
|---|
 | 74 |       ka+=2;
 | 
|---|
 | 75 |     }
 | 
|---|
| [3688] | 76 |     else if (strcmp(arg[ka],"-nbloc")==0) {
 | 
|---|
 | 77 |       nbloc_=atoi(arg[ka+1]);
 | 
|---|
 | 78 |       ka+=2;
 | 
|---|
 | 79 |     }
 | 
|---|
 | 80 |     else if (strcmp(arg[ka],"-freq")==0) {
 | 
|---|
 | 81 |       sscanf(arg[ka+1],"%d,%d,%d",&freqmin_,&freqmax_,&nbinfreq_);  
 | 
|---|
 | 82 |       ka+=2;
 | 
|---|
 | 83 |     }
 | 
|---|
| [3687] | 84 |     else if (strcmp(arg[ka],"-zones")==0) {
 | 
|---|
 | 85 |       int nzon=4;
 | 
|---|
 | 86 |       int npaqz=128;
 | 
|---|
 | 87 |       sscanf(arg[ka+1],"%d,%d",&nzon,&npaqz);
 | 
|---|
 | 88 |       nzones_=nzon;  npaqinzone_=npaqz;
 | 
|---|
 | 89 |       ka+=2;
 | 
|---|
 | 90 |     }
 | 
|---|
| [3883] | 91 |     else if (strcmp(arg[ka],"-prt")==0) {
 | 
|---|
 | 92 |       sscanf(arg[ka+1],"%d,%ld",&prtlevel_,&prtmodulo_);
 | 
|---|
| [3688] | 93 |       ka+=2;
 | 
|---|
 | 94 |     }
 | 
|---|
| [3724] | 95 |     else if (strcmp(arg[ka],"-nthr")==0) {
 | 
|---|
 | 96 |       nthreads_=atoi(arg[ka+1]);
 | 
|---|
 | 97 |       ka+=2;
 | 
|---|
 | 98 |     }
 | 
|---|
| [3776] | 99 |     else if (strcmp(arg[ka],"-nvcal")==0) {
 | 
|---|
 | 100 |       nbcalgrp_=atoi(arg[ka+1]);
 | 
|---|
 | 101 |       ka+=2;
 | 
|---|
 | 102 |     }
 | 
|---|
| [3883] | 103 |     else if (strcmp(arg[ka],"-nosfc")==0) {
 | 
|---|
 | 104 |       rdsamefc_=false;
 | 
|---|
 | 105 |       ka++;
 | 
|---|
 | 106 |     }
 | 
|---|
| [3943] | 107 |     else if (strcmp(arg[ka],"-singlechan")==0) {
 | 
|---|
| [3967] | 108 |       fgsinglechannel_=true; fgforcesingleortwochan_ = true; 
 | 
|---|
| [3943] | 109 |       ka++;
 | 
|---|
 | 110 |     }
 | 
|---|
| [3967] | 111 |     else if (strcmp(arg[ka],"-twochan")==0) {
 | 
|---|
 | 112 |       fgsinglechannel_=false; fgforcesingleortwochan_ = true; 
 | 
|---|
 | 113 |       ka++;
 | 
|---|
 | 114 |     }
 | 
|---|
| [3956] | 115 |     else if (strcmp(arg[ka],"-rawdata")==0) {
 | 
|---|
 | 116 |       fgforceraworfft_=true; fgdatafft_ = false; 
 | 
|---|
 | 117 |       ka++;
 | 
|---|
 | 118 |     }
 | 
|---|
 | 119 |     else if (strcmp(arg[ka],"-fftdata")==0) {
 | 
|---|
 | 120 |       fgforceraworfft_=true; fgdatafft_ = true; 
 | 
|---|
 | 121 |       ka++;
 | 
|---|
 | 122 |     }
 | 
|---|
| [3886] | 123 |     else if (strcmp(arg[ka],"-varcut")==0) {
 | 
|---|
 | 124 |       sscanf(arg[ka+1],"%lg,%lg",&vmin_,&vmax_);
 | 
|---|
 | 125 |       ka+=2;
 | 
|---|
 | 126 |     }
 | 
|---|
| [3943] | 127 |     else if (strcmp(arg[ka],"-nband")==0) {
 | 
|---|
 | 128 |       sscanf(arg[ka+1],"%d,%d,%d",&nbands_,&bandfirst_,&bandlast_);
 | 
|---|
 | 129 |       ka+=2;
 | 
|---|
 | 130 |     }
 | 
|---|
 | 131 |     else if (strcmp(arg[ka],"-filldt")==0) {
 | 
|---|
 | 132 |       fgdt_=true;
 | 
|---|
 | 133 |       ka++;
 | 
|---|
 | 134 |     }
 | 
|---|
 | 135 |     else if (strcmp(arg[ka],"-freqfilter")==0) {
 | 
|---|
 | 136 |       fgfreqfilter_=true;
 | 
|---|
 | 137 |       ka++;
 | 
|---|
 | 138 |     }    
 | 
|---|
| [3888] | 139 |     else if (strcmp(arg[ka],"-gain")==0) {
 | 
|---|
 | 140 |       gainfile_=arg[ka+1];
 | 
|---|
 | 141 |       ka+=2;
 | 
|---|
 | 142 |     }
 | 
|---|
| [3905] | 143 |     else if (strcmp(arg[ka],"-tspwin")==0) {
 | 
|---|
 | 144 |       int ai1=0,ai2=0,ai3=0;
 | 
|---|
 | 145 |       sscanf(arg[ka+1],"%d,%d,%d",&ai1,&ai2,&ai3);
 | 
|---|
 | 146 |       spec_win_sz_=ai1;  spw_ext_sz_=ai2;   nbmax_specwfiles_=ai3; 
 | 
|---|
 | 147 |       ka+=2;
 | 
|---|
 | 148 |     }
 | 
|---|
| [3687] | 149 |     else if (strcmp(arg[ka],"-in")==0) {
 | 
|---|
 | 150 |       if ((narg-ka)<4)  {
 | 
|---|
 | 151 |         cout << " BRAnaParam::DecodeArgs() / Argument error " << endl;
 | 
|---|
 | 152 |         return Usage(true);
 | 
|---|
 | 153 |       }
 | 
|---|
 | 154 |       sscanf(arg[ka+1],"%d,%d,%d",&imin_,&imax_,&istep_);  ka+=2;
 | 
|---|
| [3688] | 155 |       while(ka<(narg-1)) {
 | 
|---|
| [3687] | 156 |         string inpath = arg[ka]; 
 | 
|---|
| [3688] | 157 |         size_t lenp=inpath.size();
 | 
|---|
 | 158 |         if (lenp<1)  inpath="./";
 | 
|---|
 | 159 |         if ((lenp>0)&&(inpath[lenp-1]!='/'))  inpath+='/';
 | 
|---|
| [3687] | 160 |         vector<string> fiblist;
 | 
|---|
 | 161 |         string sa1 = arg[ka+1]; 
 | 
|---|
 | 162 |         FillVStringFrString(sa1, fiblist, ',');
 | 
|---|
 | 163 |         char dbuff[32];
 | 
|---|
 | 164 |         for(size_t i=0; i<fiblist.size(); i++) {
 | 
|---|
 | 165 |           sprintf(dbuff,"Fiber%d/",(int)atoi(fiblist[i].c_str()));
 | 
|---|
 | 166 |           dirlist_.push_back(inpath+dbuff);
 | 
|---|
 | 167 |         }
 | 
|---|
 | 168 |         ka += 2;
 | 
|---|
 | 169 |       }
 | 
|---|
 | 170 |       okarg=true;
 | 
|---|
 | 171 |     }
 | 
|---|
| [3688] | 172 |     else ka++;
 | 
|---|
| [3687] | 173 |   }
 | 
|---|
| [3688] | 174 | 
 | 
|---|
| [3687] | 175 |   if (!okarg) {
 | 
|---|
 | 176 |     cout << " BRAnaParam::DecodeArgs() / Argument error " << endl;
 | 
|---|
 | 177 |     return Usage(true);
 | 
|---|
 | 178 |   }
 | 
|---|
 | 179 |   return 0;
 | 
|---|
 | 180 | }
 | 
|---|
 | 181 | 
 | 
|---|
 | 182 | /* --Methode-- */
 | 
|---|
 | 183 | int BRAnaParam::Usage(bool fgshort)
 | 
|---|
 | 184 | {
 | 
|---|
 | 185 |   cout << " --- BRAnaParam : Reading/Processing BAORadio FITS files parameters " << endl;
 | 
|---|
| [3956] | 186 |   cout << " Usage:  prgname [-act ACT] [-out OutPath] [-fitsout] \n" 
 | 
|---|
 | 187 |        << "                 [-nmean NMean] [-zones NZones,nPaqinZone] \n" 
 | 
|---|
| [3724] | 188 |        << "                 [-nbloc NBloc] [-freq NumFreqMin,NumFreqMax,NBinFreq] \n" 
 | 
|---|
| [3956] | 189 |        << "                 [-prt lev,modulo] [-nvcal n] [-nthr n] [-nosfc]\n"
 | 
|---|
| [3967] | 190 |        << "                 [-singlechan] [-twochan] [-fftdata] [-rawdata] \n"
 | 
|---|
| [3956] | 191 |        << "                 [-freqfilter] [-gain filename] [-varcut min,max] [-nband nband,first,last] \n"
 | 
|---|
| [3943] | 192 |        << "                 [-filldt] [-tspwin wsz,extsz,nfiles] \n" 
 | 
|---|
| [3687] | 193 |        << "         -in Imin,Imax,Istep InPath FiberList [InPath2 FiberList2 InPath3 FiberList3 ...] \n" << endl; 
 | 
|---|
 | 194 |   if (fgshort) {
 | 
|---|
 | 195 |     cout << " prgname -h for detailed instructions" << endl;
 | 
|---|
 | 196 |     return 5;
 | 
|---|
 | 197 |   }
 | 
|---|
| [3774] | 198 |   cout << " -act Action: cube3d or vis or viscktt or mspec \n"
 | 
|---|
| [3967] | 199 |        << "    cube3d: create 3D fits cubes \n" 
 | 
|---|
| [3956] | 200 |        << "    vis: compute visibilites (vismfib program) \n" 
 | 
|---|
| [3967] | 201 |        << "    viscktt: compute visibilities and check TimeTag/FrameCounter (vismfib program)\n"
 | 
|---|
 | 202 |        << "    mspec: compute and save mean spectra for each channel \n"
 | 
|---|
 | 203 |        << "    bproc: run BRBaseProcessor for debug/printing (use -prt)  \n"
 | 
|---|
| [3687] | 204 |        << " -out OutPath: Output directory name \n"
 | 
|---|
| [3956] | 205 |        << " -fitsout : Force FITS format for output files  \n"
 | 
|---|
| [3687] | 206 |        << " -nmean NMean: Number of packet used for spectra/visibility computation \n"
 | 
|---|
| [3688] | 207 |        << " -nbloc NBloc: Number of MemMgr blocs in output file\n"
 | 
|---|
| [3956] | 208 |        << " -zones NZones,NbPaqinZone : Number of Zones and number of paquets in one zone (RAcqMemZoneMgr) \n" 
 | 
|---|
| [3688] | 209 |        << " -freq NumFreqMin,NumFreqMax,NBinFreq : Frequency zone and number of bins \n" 
 | 
|---|
| [3883] | 210 |        << " -prt lev,modulo : Print level (0,1,2...) and print counter modulo (10000, 50000 ...) \n" 
 | 
|---|
| [3776] | 211 |        << " -nvcal n : number of BRVisibilityCalculator objects running in parallel in BRVisCalcGroup  (default=1) \n" 
 | 
|---|
 | 212 |        << " -nthr n : number of threads for parallel execution in BRVisibilityCalculator (default=1) \n" 
 | 
|---|
| [3883] | 213 |        << " -nosfc : Don't force reading with SAME FrameCounter \n" 
 | 
|---|
| [3943] | 214 |        << " -singlechan : Force one channel per fiber \n"
 | 
|---|
| [3967] | 215 |        << " -twochan : Force two channels per fiber \n"
 | 
|---|
| [3956] | 216 |        << " -rawdata : Force raw data mode (firmware raw) \n"
 | 
|---|
 | 217 |        << " -fftdata : Force FFT data mode (firmware fft) \n"
 | 
|---|
| [3886] | 218 |        << " -varcut min,max : min-max cut on variance \n" 
 | 
|---|
| [3943] | 219 |        << " -nband nband,first,last: numbers of freq. bands and first and last bands used for cuts \n"
 | 
|---|
 | 220 |        << " -filldt : force data table filling \n"
 | 
|---|
 | 221 |        << " -freqfilter : force median filtering on the frequencies \n"
 | 
|---|
| [3888] | 222 |        << " -gain filename : spectral response fits file name \n" 
 | 
|---|
| [3905] | 223 |        << " -tspwin wsz,extsz,nfiles : spectra time (paquet no) window (ex: -tspwin 120,4,5) \n"
 | 
|---|
 | 224 |        << "    wsz,extsz= window,extension size;  nfiles= maximum number of windows saved \n"
 | 
|---|
| [3687] | 225 |        << " -in : input files/directory definition : \n"
 | 
|---|
 | 226 |        << "       Imin,Imax,Istep: fits files signalII.fits Imin<=II<=Imax Istep=increment \n" 
 | 
|---|
 | 227 |        << "       InPath: Input directerory fits files in InPath/FiberJJ directory \n"
 | 
|---|
 | 228 |        << "       FiberList: List of fiber numbers (JJ - Ex: 2,1,4 )  \n" << endl;
 | 
|---|
 | 229 |   return 1;
 | 
|---|
 | 230 | }
 | 
|---|
 | 231 | 
 | 
|---|
 | 232 | /* --Fonction-- */
 | 
|---|
 | 233 | int BRAnaParam::PaqSizeFromFits()
 | 
|---|
 | 234 | {
 | 
|---|
 | 235 |   uint_4 paqsz, npaqf;
 | 
|---|
 | 236 |   char flnm[1024];
 | 
|---|
 | 237 |   sprintf(flnm,"%s/signal%d.fits",dirlist_[0].c_str(),imin_);
 | 
|---|
| [3956] | 238 |   bool fgdatafft_in_fits=false;
 | 
|---|
| [3967] | 239 |   bool fgsinglechan_in_fits=false;
 | 
|---|
 | 240 |   int rc = DecodeMiniFitsHeader(flnm,paqsize_, npaqinfile_,fgdatafft_in_fits, fgsinglechan_in_fits); 
 | 
|---|
 | 241 |   if (!fgforcesingleortwochan_) fgsinglechannel_=fgsinglechan_in_fits;
 | 
|---|
| [3956] | 242 |   if (!fgforceraworfft_) fgdatafft_=fgdatafft_in_fits;
 | 
|---|
| [3943] | 243 |   return rc;
 | 
|---|
| [3687] | 244 | }
 | 
|---|
 | 245 | 
 | 
|---|
 | 246 | /* --Fonction-- */
 | 
|---|
 | 247 | ostream& BRAnaParam::Print(ostream& os)
 | 
|---|
 | 248 | {
 | 
|---|
 | 249 |   os << " BRAnaParam::Print() dirlist_.size()=" << dirlist_.size() << " Input directories: " << endl;
 | 
|---|
 | 250 |   for(size_t k=0; k< dirlist_.size(); k++) 
 | 
|---|
 | 251 |     cout << k+1 << " :  " << dirlist_[k] << endl;
 | 
|---|
| [3883] | 252 |   cout << " IMin= " << imin_ << " IMax= " << imax_ << " IStep= " << istep_ 
 | 
|---|
 | 253 |        << ((rdsamefc_)?" SameFrameCounter read mode":" AllOKPaquets read mode ") << endl;
 | 
|---|
| [3956] | 254 |   cout << " OutPath= " << outpath_ << (fgfitsout_?" force FITS output":" PPF output") << endl;
 | 
|---|
| [3688] | 255 |   cout << " Action=" << action_ << "  NMean=" << nmean_ << " NBloc=" << nbloc_ << endl;
 | 
|---|
 | 256 |   cout << " FreqMin= " << freqmin_ << " FreqMax= " << freqmax_ << " NBinFreq= " << nbinfreq_ << endl;
 | 
|---|
| [3943] | 257 |   cout<<  ((fgdt_)?" Fill DadaTable ":" NO DataTable") << endl;
 | 
|---|
 | 258 |   cout << " GainFileName=" << gainfile_ << " Variance: Min= " << vmin_ << " Max= " << vmax_ 
 | 
|---|
 | 259 |        << " Bands: N=" <<  nbands_ << " First=" << bandfirst_ << " Last=" << bandlast_
 | 
|---|
 | 260 |        << endl;
 | 
|---|
| [3946] | 261 |   cout << " force frequence median filtering (action gain)" << endl;
 | 
|---|
| [3905] | 262 |   cout << " Spectra TimeWindow (Nb.Paquets) Size=" << spec_win_sz_ << " ExtensionSize=" << spw_ext_sz_ 
 | 
|---|
 | 263 |        << " MaxNbFile=" << nbmax_specwfiles_ << endl; 
 | 
|---|
| [3688] | 264 |   cout << " PaqSize=" << paqsize_ << "  -  NZones=" << nzones_ << " NPaqZone=" << npaqinzone_ 
 | 
|---|
| [3883] | 265 |        << " PrtLevel=" << prtlevel_ << " PrtCntModulo=" <<  prtmodulo_ << endl;
 | 
|---|
| [3956] | 266 |   cout << " AcqDataMode: " << ((fgdatafft_)?" Data_FFT " : " Data_Raw " ) 
 | 
|---|
| [3872] | 267 |        << ((fgsinglechannel_)?" SingleChannel " : " TwoChannels " ) << endl;
 | 
|---|
| [3776] | 268 |   cout << " NbVisibCalculator in Group: " <<  nbcalgrp_ << " with N//threads: " << nthreads_ << endl;
 | 
|---|
 | 269 | 
 | 
|---|
 | 270 | 
 | 
|---|
| [3687] | 271 |   return os;
 | 
|---|
 | 272 | }
 | 
|---|
 | 273 | 
 | 
|---|
 | 274 | /* --Fonction-- */
 | 
|---|
| [3872] | 275 | int BRAnaParam::DecodeMiniFitsHeader(const char* filename, uint_4& paqsz, uint_4& npaq, 
 | 
|---|
 | 276 |                                      bool& fgdatafft, bool& fgsinglechannel) 
 | 
|---|
| [3687] | 277 | {
 | 
|---|
 | 278 |   cout << " DecodeMiniFitsHeader - Opening file: " << filename << endl;
 | 
|---|
 | 279 |   MiniFITSFile mff(filename, MF_Read);
 | 
|---|
| [3872] | 280 |   string acqmode=mff.GetKeyValue("ACQMODE");
 | 
|---|
| [3687] | 281 |   cout << "DecodeMiniFitsHeader()... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1() 
 | 
|---|
| [3872] | 282 |        << " NAxis2=" << mff.NAxis2() << " AcqMode=" << acqmode << endl;
 | 
|---|
| [3687] | 283 |   paqsz = mff.NAxis1();
 | 
|---|
 | 284 |   npaq = mff.NAxis2();
 | 
|---|
| [3872] | 285 |   if (acqmode.substr(0,3)=="fft") fgdatafft=true;
 | 
|---|
 | 286 |   if (acqmode.find("1c") < acqmode.length()) fgsinglechannel=true;
 | 
|---|
| [3687] | 287 |   return 0;
 | 
|---|
 | 288 | }
 | 
|---|
 | 289 | 
 | 
|---|