[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 -------------------
|
---|
| 43 | int Usage(bool fgshort=true);
|
---|
| 44 | int DecodeProc(int narg, char* arg[]);
|
---|
| 45 | int ProcessADCFiles(string& inoutpath, string& outname, int imin, int imax, int istep, int jf1, int jf2, int nfreq);
|
---|
| 46 | int ComputeCorrel(TMatrix< complex<r_4> >& cfour, TMatrix< complex<r_8> >& correl);
|
---|
| 47 | //------------------------------------------------------------------------------------------------------------
|
---|
| 48 |
|
---|
| 49 | /* --Fonction-- */
|
---|
| 50 | int 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 | //----------------------------------------------------
|
---|
| 69 | int 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-- */
|
---|
| 106 | int 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-- */
|
---|
| 130 | int 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
|
---|
| 140 | #define NFREQUSED 1280
|
---|
| 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);
|
---|
| 146 |
|
---|
| 147 | FILE* fip[NBADC]={NULL,NULL};
|
---|
| 148 | FFTPackServer ffts(false);
|
---|
| 149 |
|
---|
| 150 | TVector<r_4> sigadc(ADCFLEN);
|
---|
| 151 | TVector< complex<r_4> > foursig;
|
---|
| 152 |
|
---|
| 153 | char fname[512];
|
---|
| 154 |
|
---|
| 155 | signed char rdbuff[16384];
|
---|
| 156 | int prtmodulo=50;
|
---|
| 157 | for(int ifile=imin; ifile<=imax; ifile+=istep) {
|
---|
| 158 | for(int ka=0; ka<NBADC; ka++) {
|
---|
| 159 | sprintf(fname, "%s/adcdumpN%dF%d.bd",inoutpath.c_str(),ka,ifile);
|
---|
| 160 | fip[ka]=fopen(fname,"rb");
|
---|
| 161 | if (fip[ka]==NULL) cout << "ProcessADCFiles/ERROR opening file " << fname << endl;
|
---|
| 162 | else cout << "ProcessADCFiles/Info - file " << fname << " opened ..." << endl;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | for(int m=0; m<ADCNREAD; m++) {
|
---|
| 166 | sa_size_t irc=0;
|
---|
| 167 | for(int ka=0; ka<NBADC; ka++) {
|
---|
| 168 | fread(rdbuff,1,ADCRDBLKSZ,fip[ka]);
|
---|
| 169 | for(int jac=0; jac<4; jac++) {
|
---|
| 170 | for(sa_size_t ls=0; ls<ADCFLEN; ls++) sigadc(ls)=(float)rdbuff[jac*ADCFLEN+ls];
|
---|
| 171 | ffts.FFTForward(sigadc, foursig);
|
---|
| 172 | cfour.Row(irc)=foursig(Range(400,1679)); irc++;
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 | ComputeCorrel(cfour, correl);
|
---|
| 176 | if (m%prtmodulo==0) cout << " ProcessADCFiles/Info Done read+FFT+correl m=" << m << " / Max=" << ADCNREAD << endl;
|
---|
| 177 | }
|
---|
| 178 | for(int ka=0; ka<NBADC; ka++) fclose(fip[ka]);
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 |
|
---|
| 182 | sprintf(fname, "%s/%s",inoutpath.c_str(),outname.c_str());
|
---|
| 183 | cout << "ProcessADCFiles: Opening file " << fname << " for writing correlation matrix" << endl;
|
---|
| 184 | POutPersist po(fname);
|
---|
| 185 | po << correl;
|
---|
| 186 | cout << "ProcessADCFiles: finished FFT + correlation computing " << endl;
|
---|
| 187 | return 0;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | /* --Fonction-- */
|
---|
| 191 | int ComputeCorrel(TMatrix< complex<r_4> >& cfour, TMatrix< complex<r_8> >& correl)
|
---|
| 192 | {
|
---|
| 193 | sa_size_t jcr=0;
|
---|
| 194 | for(sa_size_t j1=0; j1<cfour.NRows(); j1++) {
|
---|
| 195 | for(sa_size_t j2=j1; j2<cfour.NRows(); j2++) {
|
---|
| 196 | for(sa_size_t i=0; i<cfour.NCols(); i++)
|
---|
| 197 | correl(jcr,i) += complex<r_8> ( cfour(j1,i)*conj(cfour(j2,i)) );
|
---|
| 198 | jcr++;
|
---|
| 199 | }
|
---|
| 200 | }
|
---|
| 201 | return 0;
|
---|
| 202 | }
|
---|
| 203 |
|
---|