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