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

Last change on this file since 3893 was 3888, checked in by ansari, 15 years ago

Introduction correction de gain/reponse filtre et amelioration n-tuple ds BRMeanSpecCalculator, Reza+JEC 24/09/2010

File size: 7.5 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;
29 prtlevel_=0;
30 prtmodulo_=50000;
31 nbcalgrp_=1;
32 nthreads_=1;
33
34 vmin_=0.; vmax_=9e99;
35 gainfile_="";
36}
37
38/* --Methode-- */
39int 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];
53 size_t lenp=outpath_.size();
54 if ((lenp>0)&&(outpath_[lenp-1]!='/')) outpath_+='/';
55 ka+=2;
56 }
57 else if (strcmp(arg[ka],"-nmean")==0) {
58 nmean_=atoi(arg[ka+1]);
59 ka+=2;
60 }
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 }
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 }
76 else if (strcmp(arg[ka],"-prt")==0) {
77 sscanf(arg[ka+1],"%d,%ld",&prtlevel_,&prtmodulo_);
78 ka+=2;
79 }
80 else if (strcmp(arg[ka],"-nthr")==0) {
81 nthreads_=atoi(arg[ka+1]);
82 ka+=2;
83 }
84 else if (strcmp(arg[ka],"-nvcal")==0) {
85 nbcalgrp_=atoi(arg[ka+1]);
86 ka+=2;
87 }
88 else if (strcmp(arg[ka],"-nosfc")==0) {
89 rdsamefc_=false;
90 ka++;
91 }
92 else if (strcmp(arg[ka],"-varcut")==0) {
93 sscanf(arg[ka+1],"%lg,%lg",&vmin_,&vmax_);
94 ka+=2;
95 }
96 else if (strcmp(arg[ka],"-gain")==0) {
97 gainfile_=arg[ka+1];
98 ka+=2;
99 }
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;
106 while(ka<(narg-1)) {
107 string inpath = arg[ka];
108 size_t lenp=inpath.size();
109 if (lenp<1) inpath="./";
110 if ((lenp>0)&&(inpath[lenp-1]!='/')) inpath+='/';
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 }
123 else ka++;
124 }
125
126 if (!okarg) {
127 cout << " BRAnaParam::DecodeArgs() / Argument error " << endl;
128 return Usage(true);
129 }
130 return 0;
131}
132
133/* --Methode-- */
134int 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"
138 << " [-nbloc NBloc] [-freq NumFreqMin,NumFreqMax,NBinFreq] \n"
139 << " [-prt lev,modulo] [-nvcal n] [-nthr n] [-nosfc] \n"
140 << " [-gain filename] [-varcut min,max] \n"
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 }
146 cout << " -act Action: cube3d or vis or viscktt or mspec \n"
147 << " cube3d: create 3D fits cubes, vis: compute visibilites, \n"
148 << " viscktt: compute visibilities and check TimeTag/FrameCounter\n "
149 << " mspec: compute and save mean spectra for each channel \n "
150 << " -out OutPath: Output directory name \n"
151 << " -nmean NMean: Number of packet used for spectra/visibility computation \n"
152 << " -nbloc NBloc: Number of MemMgr blocs in output file\n"
153 << " -zones NZones,NbPaqinZone : Number of Zones and number of paquets in one zone \n"
154 << " -freq NumFreqMin,NumFreqMax,NBinFreq : Frequency zone and number of bins \n"
155 << " -prt lev,modulo : Print level (0,1,2...) and print counter modulo (10000, 50000 ...) \n"
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"
158 << " -nosfc : Don't force reading with SAME FrameCounter \n"
159 << " -varcut min,max : min-max cut on variance \n"
160 << " -gain filename : spectral response fits file name \n"
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-- */
169int BRAnaParam::PaqSizeFromFits()
170{
171 uint_4 paqsz, npaqf;
172 char flnm[1024];
173 sprintf(flnm,"%s/signal%d.fits",dirlist_[0].c_str(),imin_);
174 return DecodeMiniFitsHeader(flnm,paqsize_, npaqinfile_,fgdatafft_, fgsinglechannel_);
175}
176
177/* --Fonction-- */
178ostream& 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;
183 cout << " IMin= " << imin_ << " IMax= " << imax_ << " IStep= " << istep_
184 << ((rdsamefc_)?" SameFrameCounter read mode":" AllOKPaquets read mode ") << endl;
185 cout << " OutPath= " << outpath_ << endl;
186 cout << " Action=" << action_ << " NMean=" << nmean_ << " NBloc=" << nbloc_ << endl;
187 cout << " FreqMin= " << freqmin_ << " FreqMax= " << freqmax_ << " NBinFreq= " << nbinfreq_ << endl;
188 cout << " GainFileName=" << gainfile_ << " VarianceMin= " << vmin_ << " VarianceMax= " << vmax_ << endl;
189 cout << " PaqSize=" << paqsize_ << " - NZones=" << nzones_ << " NPaqZone=" << npaqinzone_
190 << " PrtLevel=" << prtlevel_ << " PrtCntModulo=" << prtmodulo_ << endl;
191 cout << " AcqMode: " << ((fgdatafft_)?" Data_FFT " : " Data_Raw " )
192 << ((fgsinglechannel_)?" SingleChannel " : " TwoChannels " ) << endl;
193 cout << " NbVisibCalculator in Group: " << nbcalgrp_ << " with N//threads: " << nthreads_ << endl;
194
195
196 return os;
197}
198
199/* --Fonction-- */
200int BRAnaParam::DecodeMiniFitsHeader(const char* filename, uint_4& paqsz, uint_4& npaq,
201 bool& fgdatafft, bool& fgsinglechannel)
202{
203 cout << " DecodeMiniFitsHeader - Opening file: " << filename << endl;
204 MiniFITSFile mff(filename, MF_Read);
205 string acqmode=mff.GetKeyValue("ACQMODE");
206 cout << "DecodeMiniFitsHeader()... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1()
207 << " NAxis2=" << mff.NAxis2() << " AcqMode=" << acqmode << endl;
208 paqsz = mff.NAxis1();
209 npaq = mff.NAxis2();
210 if (acqmode.substr(0,3)=="fft") fgdatafft=true;
211 if (acqmode.find("1c") < acqmode.length()) fgsinglechannel=true;
212 return 0;
213}
214
Note: See TracBrowser for help on using the repository browser.