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