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