// Utilisation de SOPHYA ... #include "sopnamsp.h" #include "machdefs.h" /* --------------------------------------------------------------- Projet BAORadio-21cm intensity mapping - (C) LAL/IRFU 2008-2011 CRT (Pittsburgh-CMU) DUMP ADC read/processing program to compute spectra and correlations du CRT R. Ansari, C. Magneville - LAL/Irfu - Juin 2011 --------------------------------------------------------------- */ // include standard c/c++ #include #include #include #include #include #include // SOPHYA include files #include "pexceptions.h" #include "tvector.h" #include "fioarr.h" // #include "tarrinit.h" #include "ntuple.h" #include "datatable.h" #include "histinit.h" #include "matharr.h" #include "timestamp.h" #include "fftwserver.h" #include "fftpserver.h" #include "utilarr.h" #include "histats.h" // include sophya mesure ressource CPU/memoire ... #include "resusage.h" #include "ctimer.h" #include "timing.h" //--------------------------- Functions in this file ------------------- int Usage(bool fgshort=true); int DecodeProc(int narg, char* arg[]); int ProcessADCFiles(string& inoutpath, vector& adcids, string& outname, bool fgcombiq, int imin, int imax, int istep, int jf1, int jf2, int nfreq); int ComputeCorrel(TMatrix< complex >& cfour, bool fgcombiq, TMatrix< complex >& correl, TMatrix< complex >& autocorrel); int ADCFiles2Histo(string& inoutpath, vector& adcids, string& outname, int imin, int imax, int istep); int CombineIQPairs(TMatrix< complex >& cfour); //------------------------------------------------------------------------------------------------------------ /* --Fonction-- */ int Usage(bool fgshort) { cout << " --- corrcrtadc.cc : Read CRT-ADC dump files and process to produce correlation matrices \n" << " Usage: corrcrtadc -corr/-corciq/-hval InOutPath OutFile [AdcIds] [Imin,Imax,step]\n" << endl; if (fgshort) { cout << " corrcrtadc -h for detailed instructions" << endl; return 1; } cout << " -corr/-corciq/-hval : Compute correlations or Fill histograms for ADC sample values \n" << " -corciq : combine IQ pairs to separate side-bands ... \n" << " InOutPath : Input/Output directory name \n" << " ADCIds : ADC Id's to be processed (Example: 1,2,3,4, default=0,1) \n" << " OutFile : Output PPF file name \n" << " Imin,Imax,IStep: Input ADC dump files sequence number \n" << " FileNames=InOutPath/adcdumpNJFII.fits Imin<=II<=Imax II+=IStep , J=ADCIds \n" << endl; // << " NumFreq1,NumFreq2,NBinFreq: Freq Zone and number of frequency bins for ntuple" << endl; return 1; } //---------------------------------------------------- //---------------------------------------------------- int main(int narg, char* arg[]) { if ((narg>1)&&(strcmp(arg[1],"-h")==0)) return Usage(false); if (narg<4) return Usage(true); HiStatsInitiator _inia; // TArrayInitiator _inia; int rc = 0; try { ResourceUsage resu; DecodeProc(narg-1, arg+1); resu.Update(); cout << resu; } catch (PException& exc) { cerr << " corrcrtadc.cc catched PException " << exc.Msg() << endl; rc = 77; } catch (std::exception& sex) { cerr << "\n corrcrtadc.cc std::exception :" << (string)typeid(sex).name() << "\n msg= " << sex.what() << endl; rc = 78; } catch (...) { cerr << " corrcrtadc.cc catched unknown (...) exception " << endl; rc = 79; } cout << ">>>> corrcrtadc.cc ------- END ----------- RC=" << rc << endl; return rc; } //-------------------------------------------------------------------- // Traitement fichiers produits par vismfib (V Nov09) /* --Fonction-- */ int DecodeProc(int narg, char* arg[]) { // Decodage des arguments et traitement string popt = arg[0]; bool fillhis=false; bool fgcomiq=false; if (popt=="-hval") fillhis=true; else if (popt=="-corciq") fgcomiq=true; string inoutpath = arg[1]; string outname = arg[2]; int aids[8]={0,1,-1,-1,-1,-1,-1,-1}; if (narg>3) sscanf(arg[3],"%d,%d,%d,%d,%d,%d,%d,%d",aids,aids+1,aids+2,aids+3,aids+4,aids+5,aids+6,aids+7); vector adcids; for(int ii=0;ii<8;ii++) if((aids[ii]>=0)&&(aids[ii]<16)) adcids.push_back(aids[ii]); int imin=0; int imax=0; int istep=1; if (narg>4) sscanf(arg[4],"%d,%d,%d",&imin,&imax,&istep); int jf1=0; int jf2=0; int nfreq=0; if (narg>5) sscanf(arg[5],"%d,%d,%d",&jf1,&jf2,&nfreq); cout << " ----- corrcrtadc/DecodeProc - Start " << ((fillhis)? " Fill ADC-val histogram" : " Compute Correlation") << endl; cout << " InOutPath= " << inoutpath << " ADCIds: " ; for(size_t ii=0; ii 32 x 1024 x 1024 samples / voie // On lit par paquet de 4096 = 4 x 1024 / voie --> ADCRDBLKSZ=16x1024=16384 #define ADCFLEN 4096 #define ADCRDBLKSZ 16384 #define ADCNREAD 8192 static int PRTMODULO = 1000; // Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW) /* --Fonction-- */ int ProcessADCFiles(string& inoutpath, vector& adcids, string& outname, bool fgcombiq, int imin, int imax, int istep, int jf1, int jf2, int nfreq) { Timer tm("ProcessADCFiles"); #define NFREQUSED 2040 #define NFREQUSESTART 5 #define NFREBIN 4 sa_size_t NFREQREBIN = NFREQUSED/NFREBIN; sa_size_t NBADC = adcids.size(); sa_size_t NCHAN = 4*NBADC; TMatrix< complex > cfour(NCHAN, NFREQUSED); sa_size_t NCORREL = NCHAN*(NCHAN+1)/2; TMatrix< complex > correl(NCORREL,NFREQUSED); TMatrix< complex > autocorrel(NCHAN,NFREQUSED); double nsumcor=0.; vector fip; vector adcchans; for(size_t ka=0; ka sigadc(ADCFLEN); TVector< complex > foursig; char fname[512]; signed char rdbuff[ADCRDBLKSZ]; for(int ifile=imin; ifile<=imax; ifile+=istep) { for(int ka=0; ka ADCChans (" << adcchans[j1] << "," << adcchans[j2] << ") -- ("; Bid[0]=adcchans[j1]/4; Bid[1]=adcchans[j2]/4; Inpid[0]=adcchans[j1]%4; Inpid[1]=adcchans[j2]%4; if ((adcchans[j1]/4)%2==0) IQid[0]='I'; else IQid[0]='Q'; if ((adcchans[j2]/4)%2==0) IQid[1]='I'; else IQid[1]='Q'; if (adcchans[j1]%2==0) EWid[0]='E'; else EWid[0]='W'; if (adcchans[j2]%2==0) EWid[1]='E'; else EWid[1]='W'; cout << IQid[0] << '-' << EWid[0] << (Bid[0]/2)*2+Inpid[0]/2 << "," << IQid[1] << '-' << EWid[1] << (Bid[1]/2)*2+Inpid[1]/2 << ")" << endl; jcr++; } } cout << " ----------------------------------------------------------------------- " << endl; return 0; } /* --Fonction-- */ int ComputeCorrel(TMatrix< complex >& cfour, bool fgcombiq, TMatrix< complex >& correl, TMatrix< complex >& autocorrel) { if (fgcombiq) CombineIQPairs(cfour); sa_size_t jcr=0; for(sa_size_t j1=0; j1 ( cfour(j1,i)*conj(cfour(j2,i)) ); if (j1==j2) autocorrel.Row(j1)=correl.Row(jcr); jcr++; } } return 0; } int CombineIQPairs(TMatrix< complex >& cfour) { // to be coded ... return 0; } /* --Fonction-- */ int ADCFiles2Histo(string& inoutpath, vector& adcids, string& outname, int imin, int imax, int istep) { Timer tm("ADCFiles2Histo"); sa_size_t NBADC = adcids.size(); sa_size_t NCHAN = 4*NBADC; vector vhist; for(int ka=0; ka fip; for(size_t ka=0; ka