source: Sophya/trunk/AddOn/TAcq/branap.cc@ 3944

Last change on this file since 3944 was 3943, checked in by campagne, 15 years ago

release.txt

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