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

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

Codage remplissage n_tuple avec les variances, Reza 23/09/2010

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