source: Sophya/trunk/AddOn/TAcq/corrcrtadc.cc@ 3997

Last change on this file since 3997 was 3997, checked in by ansari, 14 years ago

Modifs/debug prog lecture/traitement dump ADC Pittsburgh/CRT , Reza, 13/06/2011

File size: 6.6 KB
RevLine 
[3996]1// Utilisation de SOPHYA pour faciliter les tests ...
2#include "sopnamsp.h"
3#include "machdefs.h"
4
5/* ----------------------------------------------------------
6 Projet BAORadio - (C) LAL/IRFU 2008-2010
7
8 Programme de lecture des fichiers DUMP ADC du CRT (Pittsburgh)
9 pour calcul de spectres / correlations
10 R. Ansari, C. Magneville - LAL/Irfu - Juin 2011
11 V : Mai 2009
12 ---------------------------------------------------------- */
13
14// include standard c/c++
15#include <math.h>
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19
20#include <iostream>
21#include <string>
22
23#include "pexceptions.h"
24#include "tvector.h"
25#include "fioarr.h"
26// #include "tarrinit.h"
27#include "ntuple.h"
28#include "datatable.h"
29#include "histinit.h"
30#include "matharr.h"
31#include "timestamp.h"
32#include "fftwserver.h"
33#include "fftpserver.h"
34#include "utilarr.h"
35
36// include sophya mesure ressource CPU/memoire ...
37#include "resusage.h"
38#include "ctimer.h"
39#include "timing.h"
40
41
42//--------------------------- Fonctions de ce fichier -------------------
43int Usage(bool fgshort=true);
44int DecodeProc(int narg, char* arg[]);
45int ProcessADCFiles(string& inoutpath, string& outname, int imin, int imax, int istep, int jf1, int jf2, int nfreq);
[3997]46int ComputeCorrel(TMatrix< complex<r_4> >& cfour, TMatrix< complex<r_8> >& correl, TMatrix< complex<r_8> >& autocorrel);
[3996]47//------------------------------------------------------------------------------------------------------------
48
49/* --Fonction-- */
50int Usage(bool fgshort)
51{
52 cout << " --- corrcrtadc.cc : Read CRT-ADC dump files to produce time-frequency\n"
53 << " correlation matrices " << endl;
54 cout << " Usage: corrcrtadc InOutPath OutFile Imin,Imax,step [NumFreq1,NumFreq2,NBinFreq] \n" << endl;
55 if (fgshort) {
56 cout << " corrcrtadc -h for detailed instructions" << endl;
57 return 1;
58 }
59 cout << " InOutPath : Input/Output directory name \n"
60 << " OutFile : Output PPF file name \n"
61 << " Imin,Imax,IStep: Input ADC dump files sequence number \n"
62 << " FileNames=InOutPath/adcdumpNJFII.fits Imin<=II<=Imax II+=IStep , J=0,1,2 \n"
63 << " NumFreq1,NumFreq2,NBinFreq: Freq Zone and number of frequency bins for ntuple" << endl;
64 return 1;
65}
66
67//----------------------------------------------------
68//----------------------------------------------------
69int main(int narg, char* arg[])
70{
71 if ((narg>1)&&(strcmp(arg[1],"-h")==0)) return Usage(false);
72 if (narg<4) return Usage(true);
73 HiStatsInitiator _inia;
74 // TArrayInitiator _inia;
75
76 int rc = 0;
77 try {
78 ResourceUsage resu;
79 DecodeProc(narg-1, arg+1);
80 resu.Update();
81 cout << resu;
82 }
83 catch (PException& exc) {
84 cerr << " corrcrtadc.cc catched PException " << exc.Msg() << endl;
85 rc = 77;
86 }
87 catch (std::exception& sex) {
88 cerr << "\n corrcrtadc.cc std::exception :"
89 << (string)typeid(sex).name() << "\n msg= "
90 << sex.what() << endl;
91 rc = 78;
92 }
93 catch (...) {
94 cerr << " corrcrtadc.cc catched unknown (...) exception " << endl;
95 rc = 79;
96 }
97
98 cout << ">>>> corrcrtadc.cc ------- END ----------- RC=" << rc << endl;
99 return rc;
100
101}
102
103//--------------------------------------------------------------------
104// Traitement fichiers produits par vismfib (V Nov09)
105/* --Fonction-- */
106int DecodeProc(int narg, char* arg[])
107{
108 // Decodage des arguments et traitement
109 string inoutpath = arg[0];
110 string outname = arg[1];
111 int imin=0;
112 int imax=0;
113 int istep=1;
114 sscanf(arg[2],"%d,%d,%d",&imin,&imax,&istep);
115 int jf1=0;
116 int jf2=0;
117 int nfreq=0;
118 if (narg>3)
119 sscanf(arg[3],"%d,%d,%d",&jf1,&jf2,&nfreq);
120
121 cout << " ----- corrcrtadc/DecodeProc - Start - InOutPath= " << inoutpath << " OutFileName=" << outname << endl;
122 cout << " IMin,Max,Step=" << imin << "," << imax << "," << istep
123 << "Frequency num range JF=" << jf1 << "," << jf2 << "," << nfreq << " ------- " << endl;
124 int rc=ProcessADCFiles(inoutpath, outname, imin, imax, istep, jf1, jf2, nfreq);
125 return rc;
126}
127
128// Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
129/* --Fonction-- */
130int ProcessADCFiles(string& inoutpath, string& outname, int imin, int imax, int istep, int jf1, int jf2, int nfreq)
131{
132 Timer tm("ProcessADCFiles");
133
134 // Taille des fichiers 4 voies = 1024*1024*128 ===> 32 x 1024 x 1024 samples / voie
135 // On lit par paquet de 4096 = 4 x 1024 / voie --> ADCRDBLKSZ=16x1024=16384
136#define ADCFLEN 4096
137#define ADCRDBLKSZ 16384
138#define ADCNREAD 8192
139#define NBADC 2
[3997]140#define NFREQUSED 2000
[3996]141
142 sa_size_t NCHAN = 4*NBADC;
143 TMatrix< complex<r_4> > cfour(NCHAN, NFREQUSED);
144 sa_size_t NCORREL = NCHAN*(NCHAN+1)/2;
145 TMatrix< complex<r_8> > correl(NCORREL,NFREQUSED);
[3997]146 TMatrix< complex<r_8> > autocorrel(NCHAN,NFREQUSED);
[3996]147
148 FILE* fip[NBADC]={NULL,NULL};
149 FFTPackServer ffts(false);
150
151 TVector<r_4> sigadc(ADCFLEN);
152 TVector< complex<r_4> > foursig;
153
154 char fname[512];
155
[3997]156 signed char rdbuff[ADCRDBLKSZ];
[3996]157 int prtmodulo=50;
158 for(int ifile=imin; ifile<=imax; ifile+=istep) {
159 for(int ka=0; ka<NBADC; ka++) {
160 sprintf(fname, "%s/adcdumpN%dF%d.bd",inoutpath.c_str(),ka,ifile);
161 fip[ka]=fopen(fname,"rb");
162 if (fip[ka]==NULL) cout << "ProcessADCFiles/ERROR opening file " << fname << endl;
163 else cout << "ProcessADCFiles/Info - file " << fname << " opened ..." << endl;
164 }
165
166 for(int m=0; m<ADCNREAD; m++) {
167 sa_size_t irc=0;
168 for(int ka=0; ka<NBADC; ka++) {
169 fread(rdbuff,1,ADCRDBLKSZ,fip[ka]);
170 for(int jac=0; jac<4; jac++) {
[3997]171 for(sa_size_t ls=0; ls<ADCFLEN; ls++) sigadc(ls)=(float)rdbuff[ls*4+jac];
[3996]172 ffts.FFTForward(sigadc, foursig);
[3997]173 cfour.Row(irc)=foursig(Range(400,1679)).Transpose(); irc++;
[3996]174 }
175 }
[3997]176 ComputeCorrel(cfour, correl, autocorrel);
[3996]177 if (m%prtmodulo==0) cout << " ProcessADCFiles/Info Done read+FFT+correl m=" << m << " / Max=" << ADCNREAD << endl;
178 }
179 for(int ka=0; ka<NBADC; ka++) fclose(fip[ka]);
180 }
181
182
183 sprintf(fname, "%s/%s",inoutpath.c_str(),outname.c_str());
184 cout << "ProcessADCFiles: Opening file " << fname << " for writing correlation matrix" << endl;
185 POutPersist po(fname);
[3997]186 po << PPFNameTag("correlmtx") << correl;
187 po << PPFNameTag("acorrmtx") << autocorrel;
188
[3996]189 cout << "ProcessADCFiles: finished FFT + correlation computing " << endl;
190 return 0;
191}
192
193/* --Fonction-- */
[3997]194int ComputeCorrel(TMatrix< complex<r_4> >& cfour, TMatrix< complex<r_8> >& correl, TMatrix< complex<r_8> >& autocorrel)
[3996]195{
196 sa_size_t jcr=0;
197 for(sa_size_t j1=0; j1<cfour.NRows(); j1++) {
198 for(sa_size_t j2=j1; j2<cfour.NRows(); j2++) {
199 for(sa_size_t i=0; i<cfour.NCols(); i++)
200 correl(jcr,i) += complex<r_8> ( cfour(j1,i)*conj(cfour(j2,i)) );
[3997]201 if (j1==j2) autocorrel.Row(j1)=correl.Row(jcr);
[3996]202 jcr++;
203 }
204 }
205 return 0;
206}
207
Note: See TracBrowser for help on using the repository browser.