[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_="./";
|
---|
| 18 | nmean_=nmean;
|
---|
[3688] | 19 | nbloc_=1;
|
---|
[3687] | 20 | imin_=imax_=0;
|
---|
| 21 | istep_=1;
|
---|
[3883] | 22 | rdsamefc_=true; // read paquets with same frame counter
|
---|
[3688] | 23 | freqmin_=freqmax_=0;
|
---|
| 24 | nbinfreq_=1;
|
---|
[3687] | 25 | paqsize_=16424;
|
---|
| 26 | nzones_=nzon;
|
---|
| 27 | npaqinzone_=npaqz;
|
---|
[3872] | 28 | fgdatafft_=false; fgsinglechannel_=false;
|
---|
[3688] | 29 | prtlevel_=0;
|
---|
[3883] | 30 | prtmodulo_=50000;
|
---|
[3776] | 31 | nbcalgrp_=1;
|
---|
[3724] | 32 | nthreads_=1;
|
---|
[3886] | 33 |
|
---|
[3905] | 34 | spec_win_sz_=0;
|
---|
| 35 | spw_ext_sz_=0;
|
---|
| 36 | nbmax_specwfiles_=0;
|
---|
| 37 |
|
---|
[3886] | 38 | vmin_=0.; vmax_=9e99;
|
---|
[3888] | 39 | gainfile_="";
|
---|
[3687] | 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];
|
---|
[3688] | 57 | size_t lenp=outpath_.size();
|
---|
| 58 | if ((lenp>0)&&(outpath_[lenp-1]!='/')) outpath_+='/';
|
---|
[3687] | 59 | ka+=2;
|
---|
| 60 | }
|
---|
| 61 | else if (strcmp(arg[ka],"-nmean")==0) {
|
---|
| 62 | nmean_=atoi(arg[ka+1]);
|
---|
| 63 | ka+=2;
|
---|
| 64 | }
|
---|
[3688] | 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 | }
|
---|
[3687] | 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 | }
|
---|
[3883] | 80 | else if (strcmp(arg[ka],"-prt")==0) {
|
---|
| 81 | sscanf(arg[ka+1],"%d,%ld",&prtlevel_,&prtmodulo_);
|
---|
[3688] | 82 | ka+=2;
|
---|
| 83 | }
|
---|
[3724] | 84 | else if (strcmp(arg[ka],"-nthr")==0) {
|
---|
| 85 | nthreads_=atoi(arg[ka+1]);
|
---|
| 86 | ka+=2;
|
---|
| 87 | }
|
---|
[3776] | 88 | else if (strcmp(arg[ka],"-nvcal")==0) {
|
---|
| 89 | nbcalgrp_=atoi(arg[ka+1]);
|
---|
| 90 | ka+=2;
|
---|
| 91 | }
|
---|
[3883] | 92 | else if (strcmp(arg[ka],"-nosfc")==0) {
|
---|
| 93 | rdsamefc_=false;
|
---|
| 94 | ka++;
|
---|
| 95 | }
|
---|
[3886] | 96 | else if (strcmp(arg[ka],"-varcut")==0) {
|
---|
| 97 | sscanf(arg[ka+1],"%lg,%lg",&vmin_,&vmax_);
|
---|
| 98 | ka+=2;
|
---|
| 99 | }
|
---|
[3888] | 100 | else if (strcmp(arg[ka],"-gain")==0) {
|
---|
| 101 | gainfile_=arg[ka+1];
|
---|
| 102 | ka+=2;
|
---|
| 103 | }
|
---|
[3905] | 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 | }
|
---|
[3687] | 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;
|
---|
[3688] | 116 | while(ka<(narg-1)) {
|
---|
[3687] | 117 | string inpath = arg[ka];
|
---|
[3688] | 118 | size_t lenp=inpath.size();
|
---|
| 119 | if (lenp<1) inpath="./";
|
---|
| 120 | if ((lenp>0)&&(inpath[lenp-1]!='/')) inpath+='/';
|
---|
[3687] | 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 | }
|
---|
[3688] | 133 | else ka++;
|
---|
[3687] | 134 | }
|
---|
[3688] | 135 |
|
---|
[3687] | 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"
|
---|
[3724] | 148 | << " [-nbloc NBloc] [-freq NumFreqMin,NumFreqMax,NBinFreq] \n"
|
---|
[3888] | 149 | << " [-prt lev,modulo] [-nvcal n] [-nthr n] [-nosfc] \n"
|
---|
[3905] | 150 | << " [-gain filename] [-varcut min,max] [-tspwin wsz,extsz,nfiles] \n"
|
---|
[3687] | 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 | }
|
---|
[3774] | 156 | cout << " -act Action: cube3d or vis or viscktt or mspec \n"
|
---|
[3705] | 157 | << " cube3d: create 3D fits cubes, vis: compute visibilites, \n"
|
---|
[3706] | 158 | << " viscktt: compute visibilities and check TimeTag/FrameCounter\n "
|
---|
[3774] | 159 | << " mspec: compute and save mean spectra for each channel \n "
|
---|
[3687] | 160 | << " -out OutPath: Output directory name \n"
|
---|
| 161 | << " -nmean NMean: Number of packet used for spectra/visibility computation \n"
|
---|
[3688] | 162 | << " -nbloc NBloc: Number of MemMgr blocs in output file\n"
|
---|
[3687] | 163 | << " -zones NZones,NbPaqinZone : Number of Zones and number of paquets in one zone \n"
|
---|
[3688] | 164 | << " -freq NumFreqMin,NumFreqMax,NBinFreq : Frequency zone and number of bins \n"
|
---|
[3883] | 165 | << " -prt lev,modulo : Print level (0,1,2...) and print counter modulo (10000, 50000 ...) \n"
|
---|
[3776] | 166 | << " -nvcal n : number of BRVisibilityCalculator objects running in parallel in BRVisCalcGroup (default=1) \n"
|
---|
| 167 | << " -nthr n : number of threads for parallel execution in BRVisibilityCalculator (default=1) \n"
|
---|
[3883] | 168 | << " -nosfc : Don't force reading with SAME FrameCounter \n"
|
---|
[3886] | 169 | << " -varcut min,max : min-max cut on variance \n"
|
---|
[3888] | 170 | << " -gain filename : spectral response fits file name \n"
|
---|
[3905] | 171 | << " -tspwin wsz,extsz,nfiles : spectra time (paquet no) window (ex: -tspwin 120,4,5) \n"
|
---|
| 172 | << " wsz,extsz= window,extension size; nfiles= maximum number of windows saved \n"
|
---|
[3687] | 173 | << " -in : input files/directory definition : \n"
|
---|
| 174 | << " Imin,Imax,Istep: fits files signalII.fits Imin<=II<=Imax Istep=increment \n"
|
---|
| 175 | << " InPath: Input directerory fits files in InPath/FiberJJ directory \n"
|
---|
| 176 | << " FiberList: List of fiber numbers (JJ - Ex: 2,1,4 ) \n" << endl;
|
---|
| 177 | return 1;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | /* --Fonction-- */
|
---|
| 181 | int BRAnaParam::PaqSizeFromFits()
|
---|
| 182 | {
|
---|
| 183 | uint_4 paqsz, npaqf;
|
---|
| 184 | char flnm[1024];
|
---|
| 185 | sprintf(flnm,"%s/signal%d.fits",dirlist_[0].c_str(),imin_);
|
---|
[3872] | 186 | return DecodeMiniFitsHeader(flnm,paqsize_, npaqinfile_,fgdatafft_, fgsinglechannel_);
|
---|
[3687] | 187 | }
|
---|
| 188 |
|
---|
| 189 | /* --Fonction-- */
|
---|
| 190 | ostream& BRAnaParam::Print(ostream& os)
|
---|
| 191 | {
|
---|
| 192 | os << " BRAnaParam::Print() dirlist_.size()=" << dirlist_.size() << " Input directories: " << endl;
|
---|
| 193 | for(size_t k=0; k< dirlist_.size(); k++)
|
---|
| 194 | cout << k+1 << " : " << dirlist_[k] << endl;
|
---|
[3883] | 195 | cout << " IMin= " << imin_ << " IMax= " << imax_ << " IStep= " << istep_
|
---|
| 196 | << ((rdsamefc_)?" SameFrameCounter read mode":" AllOKPaquets read mode ") << endl;
|
---|
[3687] | 197 | cout << " OutPath= " << outpath_ << endl;
|
---|
[3688] | 198 | cout << " Action=" << action_ << " NMean=" << nmean_ << " NBloc=" << nbloc_ << endl;
|
---|
| 199 | cout << " FreqMin= " << freqmin_ << " FreqMax= " << freqmax_ << " NBinFreq= " << nbinfreq_ << endl;
|
---|
[3888] | 200 | cout << " GainFileName=" << gainfile_ << " VarianceMin= " << vmin_ << " VarianceMax= " << vmax_ << endl;
|
---|
[3905] | 201 | cout << " Spectra TimeWindow (Nb.Paquets) Size=" << spec_win_sz_ << " ExtensionSize=" << spw_ext_sz_
|
---|
| 202 | << " MaxNbFile=" << nbmax_specwfiles_ << endl;
|
---|
[3688] | 203 | cout << " PaqSize=" << paqsize_ << " - NZones=" << nzones_ << " NPaqZone=" << npaqinzone_
|
---|
[3883] | 204 | << " PrtLevel=" << prtlevel_ << " PrtCntModulo=" << prtmodulo_ << endl;
|
---|
[3872] | 205 | cout << " AcqMode: " << ((fgdatafft_)?" Data_FFT " : " Data_Raw " )
|
---|
| 206 | << ((fgsinglechannel_)?" SingleChannel " : " TwoChannels " ) << endl;
|
---|
[3776] | 207 | cout << " NbVisibCalculator in Group: " << nbcalgrp_ << " with N//threads: " << nthreads_ << endl;
|
---|
| 208 |
|
---|
| 209 |
|
---|
[3687] | 210 | return os;
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | /* --Fonction-- */
|
---|
[3872] | 214 | int BRAnaParam::DecodeMiniFitsHeader(const char* filename, uint_4& paqsz, uint_4& npaq,
|
---|
| 215 | bool& fgdatafft, bool& fgsinglechannel)
|
---|
[3687] | 216 | {
|
---|
| 217 | cout << " DecodeMiniFitsHeader - Opening file: " << filename << endl;
|
---|
| 218 | MiniFITSFile mff(filename, MF_Read);
|
---|
[3872] | 219 | string acqmode=mff.GetKeyValue("ACQMODE");
|
---|
[3687] | 220 | cout << "DecodeMiniFitsHeader()... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1()
|
---|
[3872] | 221 | << " NAxis2=" << mff.NAxis2() << " AcqMode=" << acqmode << endl;
|
---|
[3687] | 222 | paqsz = mff.NAxis1();
|
---|
| 223 | npaq = mff.NAxis2();
|
---|
[3872] | 224 | if (acqmode.substr(0,3)=="fft") fgdatafft=true;
|
---|
| 225 | if (acqmode.find("1c") < acqmode.length()) fgsinglechannel=true;
|
---|
[3687] | 226 | return 0;
|
---|
| 227 | }
|
---|
| 228 |
|
---|