| 1 | #include <stdlib.h> | 
|---|
| 2 | #include <string.h> | 
|---|
| 3 |  | 
|---|
| 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_="./"; | 
|---|
| 18 | nmean_=nmean; | 
|---|
| 19 | nbloc_=1; | 
|---|
| 20 | imin_=imax_=0; | 
|---|
| 21 | istep_=1; | 
|---|
| 22 | rdsamefc_=true;   // read paquets with same frame counter | 
|---|
| 23 | freqmin_=freqmax_=0; | 
|---|
| 24 | nbinfreq_=1; | 
|---|
| 25 | paqsize_=16424; | 
|---|
| 26 | nzones_=nzon; | 
|---|
| 27 | npaqinzone_=npaqz; | 
|---|
| 28 | fgdatafft_=false;  fgsinglechannel_=false; | 
|---|
| 29 | prtlevel_=0; | 
|---|
| 30 | prtmodulo_=50000; | 
|---|
| 31 | nbcalgrp_=1; | 
|---|
| 32 | nthreads_=1; | 
|---|
| 33 |  | 
|---|
| 34 | spec_win_sz_=0; | 
|---|
| 35 | spw_ext_sz_=0; | 
|---|
| 36 | nbmax_specwfiles_=0; | 
|---|
| 37 |  | 
|---|
| 38 | vmin_=0.;  vmax_=9e99; | 
|---|
| 39 | gainfile_=""; | 
|---|
| 40 | } | 
|---|
| 41 |  | 
|---|
| 42 | /* --Methode-- */ | 
|---|
| 43 | int BRAnaParam::DecodeArgs(int narg, char* arg[]) | 
|---|
| 44 | { | 
|---|
| 45 | if ((narg>1)&&(strcmp(arg[1],"-h")==0))  return Usage(false); | 
|---|
| 46 | if (narg<5) return Usage(true); | 
|---|
| 47 |  | 
|---|
| 48 | bool okarg=false; | 
|---|
| 49 | int ka=1; | 
|---|
| 50 | while (ka<(narg-1)) { | 
|---|
| 51 | if (strcmp(arg[ka],"-act")==0) { | 
|---|
| 52 | action_=arg[ka+1]; | 
|---|
| 53 | ka+=2; | 
|---|
| 54 | } | 
|---|
| 55 | else if (strcmp(arg[ka],"-out")==0) { | 
|---|
| 56 | outpath_=arg[ka+1]; | 
|---|
| 57 | size_t lenp=outpath_.size(); | 
|---|
| 58 | if ((lenp>0)&&(outpath_[lenp-1]!='/'))  outpath_+='/'; | 
|---|
| 59 | ka+=2; | 
|---|
| 60 | } | 
|---|
| 61 | else if (strcmp(arg[ka],"-nmean")==0) { | 
|---|
| 62 | nmean_=atoi(arg[ka+1]); | 
|---|
| 63 | ka+=2; | 
|---|
| 64 | } | 
|---|
| 65 | else if (strcmp(arg[ka],"-nbloc")==0) { | 
|---|
| 66 | nbloc_=atoi(arg[ka+1]); | 
|---|
| 67 | ka+=2; | 
|---|
| 68 | } | 
|---|
| 69 | else if (strcmp(arg[ka],"-freq")==0) { | 
|---|
| 70 | sscanf(arg[ka+1],"%d,%d,%d",&freqmin_,&freqmax_,&nbinfreq_); | 
|---|
| 71 | ka+=2; | 
|---|
| 72 | } | 
|---|
| 73 | else if (strcmp(arg[ka],"-zones")==0) { | 
|---|
| 74 | int nzon=4; | 
|---|
| 75 | int npaqz=128; | 
|---|
| 76 | sscanf(arg[ka+1],"%d,%d",&nzon,&npaqz); | 
|---|
| 77 | nzones_=nzon;  npaqinzone_=npaqz; | 
|---|
| 78 | ka+=2; | 
|---|
| 79 | } | 
|---|
| 80 | else if (strcmp(arg[ka],"-prt")==0) { | 
|---|
| 81 | sscanf(arg[ka+1],"%d,%ld",&prtlevel_,&prtmodulo_); | 
|---|
| 82 | ka+=2; | 
|---|
| 83 | } | 
|---|
| 84 | else if (strcmp(arg[ka],"-nthr")==0) { | 
|---|
| 85 | nthreads_=atoi(arg[ka+1]); | 
|---|
| 86 | ka+=2; | 
|---|
| 87 | } | 
|---|
| 88 | else if (strcmp(arg[ka],"-nvcal")==0) { | 
|---|
| 89 | nbcalgrp_=atoi(arg[ka+1]); | 
|---|
| 90 | ka+=2; | 
|---|
| 91 | } | 
|---|
| 92 | else if (strcmp(arg[ka],"-nosfc")==0) { | 
|---|
| 93 | rdsamefc_=false; | 
|---|
| 94 | ka++; | 
|---|
| 95 | } | 
|---|
| 96 | else if (strcmp(arg[ka],"-varcut")==0) { | 
|---|
| 97 | sscanf(arg[ka+1],"%lg,%lg",&vmin_,&vmax_); | 
|---|
| 98 | ka+=2; | 
|---|
| 99 | } | 
|---|
| 100 | else if (strcmp(arg[ka],"-gain")==0) { | 
|---|
| 101 | gainfile_=arg[ka+1]; | 
|---|
| 102 | ka+=2; | 
|---|
| 103 | } | 
|---|
| 104 | else if (strcmp(arg[ka],"-tspwin")==0) { | 
|---|
| 105 | int ai1=0,ai2=0,ai3=0; | 
|---|
| 106 | sscanf(arg[ka+1],"%d,%d,%d",&ai1,&ai2,&ai3); | 
|---|
| 107 | spec_win_sz_=ai1;  spw_ext_sz_=ai2;   nbmax_specwfiles_=ai3; | 
|---|
| 108 | ka+=2; | 
|---|
| 109 | } | 
|---|
| 110 | else if (strcmp(arg[ka],"-in")==0) { | 
|---|
| 111 | if ((narg-ka)<4)  { | 
|---|
| 112 | cout << " BRAnaParam::DecodeArgs() / Argument error " << endl; | 
|---|
| 113 | return Usage(true); | 
|---|
| 114 | } | 
|---|
| 115 | sscanf(arg[ka+1],"%d,%d,%d",&imin_,&imax_,&istep_);  ka+=2; | 
|---|
| 116 | while(ka<(narg-1)) { | 
|---|
| 117 | string inpath = arg[ka]; | 
|---|
| 118 | size_t lenp=inpath.size(); | 
|---|
| 119 | if (lenp<1)  inpath="./"; | 
|---|
| 120 | if ((lenp>0)&&(inpath[lenp-1]!='/'))  inpath+='/'; | 
|---|
| 121 | vector<string> fiblist; | 
|---|
| 122 | string sa1 = arg[ka+1]; | 
|---|
| 123 | FillVStringFrString(sa1, fiblist, ','); | 
|---|
| 124 | char dbuff[32]; | 
|---|
| 125 | for(size_t i=0; i<fiblist.size(); i++) { | 
|---|
| 126 | sprintf(dbuff,"Fiber%d/",(int)atoi(fiblist[i].c_str())); | 
|---|
| 127 | dirlist_.push_back(inpath+dbuff); | 
|---|
| 128 | } | 
|---|
| 129 | ka += 2; | 
|---|
| 130 | } | 
|---|
| 131 | okarg=true; | 
|---|
| 132 | } | 
|---|
| 133 | else ka++; | 
|---|
| 134 | } | 
|---|
| 135 |  | 
|---|
| 136 | if (!okarg) { | 
|---|
| 137 | cout << " BRAnaParam::DecodeArgs() / Argument error " << endl; | 
|---|
| 138 | return Usage(true); | 
|---|
| 139 | } | 
|---|
| 140 | return 0; | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | /* --Methode-- */ | 
|---|
| 144 | int BRAnaParam::Usage(bool fgshort) | 
|---|
| 145 | { | 
|---|
| 146 | cout << " --- BRAnaParam : Reading/Processing BAORadio FITS files parameters " << endl; | 
|---|
| 147 | cout << " Usage:  prgname [-act ACT] [-out OutPath] [-nmean NMean] [-zones NZones,nPaqinZone] \n" | 
|---|
| 148 | << "                 [-nbloc NBloc] [-freq NumFreqMin,NumFreqMax,NBinFreq] \n" | 
|---|
| 149 | << "                 [-prt lev,modulo] [-nvcal n] [-nthr n] [-nosfc] \n" | 
|---|
| 150 | << "                 [-gain filename] [-varcut min,max] [-tspwin wsz,extsz,nfiles] \n" | 
|---|
| 151 | << "         -in Imin,Imax,Istep InPath FiberList [InPath2 FiberList2 InPath3 FiberList3 ...] \n" << endl; | 
|---|
| 152 | if (fgshort) { | 
|---|
| 153 | cout << " prgname -h for detailed instructions" << endl; | 
|---|
| 154 | return 5; | 
|---|
| 155 | } | 
|---|
| 156 | cout << " -act Action: cube3d or vis or viscktt or mspec \n" | 
|---|
| 157 | << "    cube3d: create 3D fits cubes, vis: compute visibilites,  \n" | 
|---|
| 158 | << "    viscktt: compute visibilities and check TimeTag/FrameCounter\n " | 
|---|
| 159 | << "    mspec: compute and save mean spectra for each channel \n " | 
|---|
| 160 | << "    bproc: run BRBaseProcessor for debug/printing (use -prt)  \n " | 
|---|
| 161 | << " -out OutPath: Output directory name \n" | 
|---|
| 162 | << " -nmean NMean: Number of packet used for spectra/visibility computation \n" | 
|---|
| 163 | << " -nbloc NBloc: Number of MemMgr blocs in output file\n" | 
|---|
| 164 | << " -zones NZones,NbPaqinZone : Number of Zones and number of paquets in one zone \n" | 
|---|
| 165 | << " -freq NumFreqMin,NumFreqMax,NBinFreq : Frequency zone and number of bins \n" | 
|---|
| 166 | << " -prt lev,modulo : Print level (0,1,2...) and print counter modulo (10000, 50000 ...) \n" | 
|---|
| 167 | << " -nvcal n : number of BRVisibilityCalculator objects running in parallel in BRVisCalcGroup  (default=1) \n" | 
|---|
| 168 | << " -nthr n : number of threads for parallel execution in BRVisibilityCalculator (default=1) \n" | 
|---|
| 169 | << " -nosfc : Don't force reading with SAME FrameCounter \n" | 
|---|
| 170 | << " -varcut min,max : min-max cut on variance \n" | 
|---|
| 171 | << " -gain filename : spectral response fits file name \n" | 
|---|
| 172 | << " -tspwin wsz,extsz,nfiles : spectra time (paquet no) window (ex: -tspwin 120,4,5) \n" | 
|---|
| 173 | << "    wsz,extsz= window,extension size;  nfiles= maximum number of windows saved \n" | 
|---|
| 174 | << " -in : input files/directory definition : \n" | 
|---|
| 175 | << "       Imin,Imax,Istep: fits files signalII.fits Imin<=II<=Imax Istep=increment \n" | 
|---|
| 176 | << "       InPath: Input directerory fits files in InPath/FiberJJ directory \n" | 
|---|
| 177 | << "       FiberList: List of fiber numbers (JJ - Ex: 2,1,4 )  \n" << endl; | 
|---|
| 178 | return 1; | 
|---|
| 179 | } | 
|---|
| 180 |  | 
|---|
| 181 | /* --Fonction-- */ | 
|---|
| 182 | int BRAnaParam::PaqSizeFromFits() | 
|---|
| 183 | { | 
|---|
| 184 | uint_4 paqsz, npaqf; | 
|---|
| 185 | char flnm[1024]; | 
|---|
| 186 | sprintf(flnm,"%s/signal%d.fits",dirlist_[0].c_str(),imin_); | 
|---|
| 187 | return DecodeMiniFitsHeader(flnm,paqsize_, npaqinfile_,fgdatafft_, fgsinglechannel_); | 
|---|
| 188 | } | 
|---|
| 189 |  | 
|---|
| 190 | /* --Fonction-- */ | 
|---|
| 191 | ostream& BRAnaParam::Print(ostream& os) | 
|---|
| 192 | { | 
|---|
| 193 | os << " BRAnaParam::Print() dirlist_.size()=" << dirlist_.size() << " Input directories: " << endl; | 
|---|
| 194 | for(size_t k=0; k< dirlist_.size(); k++) | 
|---|
| 195 | cout << k+1 << " :  " << dirlist_[k] << endl; | 
|---|
| 196 | cout << " IMin= " << imin_ << " IMax= " << imax_ << " IStep= " << istep_ | 
|---|
| 197 | << ((rdsamefc_)?" SameFrameCounter read mode":" AllOKPaquets read mode ") << endl; | 
|---|
| 198 | cout << " OutPath= " << outpath_ << endl; | 
|---|
| 199 | cout << " Action=" << action_ << "  NMean=" << nmean_ << " NBloc=" << nbloc_ << endl; | 
|---|
| 200 | cout << " FreqMin= " << freqmin_ << " FreqMax= " << freqmax_ << " NBinFreq= " << nbinfreq_ << endl; | 
|---|
| 201 | cout << " GainFileName=" << gainfile_ << " VarianceMin= " << vmin_ << " VarianceMax= " << vmax_ << endl; | 
|---|
| 202 | cout << " Spectra TimeWindow (Nb.Paquets) Size=" << spec_win_sz_ << " ExtensionSize=" << spw_ext_sz_ | 
|---|
| 203 | << " MaxNbFile=" << nbmax_specwfiles_ << endl; | 
|---|
| 204 | cout << " PaqSize=" << paqsize_ << "  -  NZones=" << nzones_ << " NPaqZone=" << npaqinzone_ | 
|---|
| 205 | << " PrtLevel=" << prtlevel_ << " PrtCntModulo=" <<  prtmodulo_ << endl; | 
|---|
| 206 | cout << " AcqMode: " << ((fgdatafft_)?" Data_FFT " : " Data_Raw " ) | 
|---|
| 207 | << ((fgsinglechannel_)?" SingleChannel " : " TwoChannels " ) << endl; | 
|---|
| 208 | cout << " NbVisibCalculator in Group: " <<  nbcalgrp_ << " with N//threads: " << nthreads_ << endl; | 
|---|
| 209 |  | 
|---|
| 210 |  | 
|---|
| 211 | return os; | 
|---|
| 212 | } | 
|---|
| 213 |  | 
|---|
| 214 | /* --Fonction-- */ | 
|---|
| 215 | int BRAnaParam::DecodeMiniFitsHeader(const char* filename, uint_4& paqsz, uint_4& npaq, | 
|---|
| 216 | bool& fgdatafft, bool& fgsinglechannel) | 
|---|
| 217 | { | 
|---|
| 218 | cout << " DecodeMiniFitsHeader - Opening file: " << filename << endl; | 
|---|
| 219 | MiniFITSFile mff(filename, MF_Read); | 
|---|
| 220 | string acqmode=mff.GetKeyValue("ACQMODE"); | 
|---|
| 221 | cout << "DecodeMiniFitsHeader()... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1() | 
|---|
| 222 | << " NAxis2=" << mff.NAxis2() << " AcqMode=" << acqmode << endl; | 
|---|
| 223 | paqsz = mff.NAxis1(); | 
|---|
| 224 | npaq = mff.NAxis2(); | 
|---|
| 225 | if (acqmode.substr(0,3)=="fft") fgdatafft=true; | 
|---|
| 226 | if (acqmode.find("1c") < acqmode.length()) fgsinglechannel=true; | 
|---|
| 227 | return 0; | 
|---|
| 228 | } | 
|---|
| 229 |  | 
|---|