[3537] | 1 | #include "racquproc.h"
|
---|
| 2 |
|
---|
| 3 | #include <stdlib.h>
|
---|
| 4 | #include <unistd.h>
|
---|
| 5 | #include <fstream>
|
---|
| 6 |
|
---|
| 7 | #include "pexceptions.h"
|
---|
| 8 | #include "tvector.h"
|
---|
| 9 | #include "fioarr.h"
|
---|
| 10 | #include "timestamp.h"
|
---|
| 11 | #include "fftpserver.h"
|
---|
| 12 | #include "fftwserver.h"
|
---|
| 13 |
|
---|
| 14 | #include "FFTW/fftw3.h"
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | #include "pciewrap.h"
|
---|
| 18 | #include "brpaqu.h"
|
---|
| 19 | #include "minifits.h"
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | //-------------------------------------------------------
|
---|
| 23 | // Classe thread de traitement
|
---|
| 24 | //-------------------------------------------------------
|
---|
| 25 |
|
---|
| 26 | DataProc::DataProc(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 nmax)
|
---|
| 27 | : memgr(mem)
|
---|
| 28 | {
|
---|
| 29 | nmax_ = nmax;
|
---|
| 30 | nmean_ = nmean;
|
---|
| 31 | stop_ = false;
|
---|
| 32 | path_ = path;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | inline r_4 Zmod2(complex<r_4> z)
|
---|
| 36 | { return (z.real()*z.real()+z.imag()*z.imag()); }
|
---|
| 37 |
|
---|
| 38 | void DataProc::run()
|
---|
| 39 | {
|
---|
| 40 |
|
---|
| 41 | setRC(1);
|
---|
| 42 | try {
|
---|
| 43 | TimeStamp ts;
|
---|
| 44 | cout << " DataProc::run() - Starting " << ts << " NMaxMemZones=" << nmax_ << endl;
|
---|
| 45 | char fname[512];
|
---|
| 46 | sprintf(fname,"%s/proc.log",path_.c_str());
|
---|
| 47 | ofstream filog(fname);
|
---|
| 48 | filog << " DataProc::run() - starting log file " << ts << endl;
|
---|
| 49 |
|
---|
| 50 | // Initialisation pour clcul FFT
|
---|
| 51 | TVector< complex<r_4> > cfour; // composant TF
|
---|
| 52 | uint_4 paqsz = memgr.PaqSize();
|
---|
| 53 | BRPaquet pq(NULL, NULL, paqsz);
|
---|
| 54 | TVector<r_4> vx(pq.DataSize());
|
---|
| 55 | vx = (r_4)(0.);
|
---|
| 56 | FFTPackServer ffts;
|
---|
| 57 | ffts.FFTForward(vx, cfour);
|
---|
| 58 | TVector<r_4> spectre;
|
---|
| 59 | spectre.ReSize(cfour.Size());
|
---|
| 60 |
|
---|
| 61 | fftwf_plan plan = fftwf_plan_dft_r2c_1d(pq.DataSize(), vx.Data(),
|
---|
| 62 | (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
|
---|
| 63 |
|
---|
| 64 | uint_4 ifile = 0;
|
---|
| 65 | for (uint_4 kmz=0; kmz<nmax_; kmz++) {
|
---|
| 66 | int mid = memgr.FindMemZoneId(MemZA_Proc);
|
---|
| 67 | Byte* buff = memgr.GetMemZone(mid);
|
---|
| 68 | if (buff == NULL) {
|
---|
| 69 | cout << " DataProc::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
|
---|
| 70 | setRC(2);
|
---|
| 71 | return;
|
---|
| 72 | }
|
---|
| 73 | BRPaquet paq0(NULL, buff, paqsz);
|
---|
| 74 | uint_4 nzm = 0;
|
---|
| 75 | for(uint_4 i=0; i<memgr.NbPaquets(); i++) {
|
---|
| 76 | BRPaquet paq(NULL, buff+i*paqsz, paqsz);
|
---|
| 77 | Byte min = 255;
|
---|
| 78 | Byte max = 0;
|
---|
| 79 |
|
---|
| 80 | for(sa_size_t j=0; j<vx.Size(); j++)
|
---|
| 81 | vx(j) = (r_4)(*(paq.Data()+j));
|
---|
| 82 | fftwf_execute(plan);
|
---|
| 83 | // ffts_.FFTForward(vx, cfour_);
|
---|
| 84 | for(sa_size_t j=0; j<spectre.Size(); j++)
|
---|
| 85 | spectre(j) += Zmod2(cfour(j));
|
---|
| 86 | nzm++;
|
---|
| 87 | }
|
---|
| 88 | if (nzm >= nmean_) {
|
---|
| 89 | spectre /= (r_4)(nzm);
|
---|
| 90 | sprintf(fname,"%s/spectre%d.ppf",path_.c_str(),(int)ifile);
|
---|
| 91 | POutPersist po(fname);
|
---|
| 92 | po << spectre;
|
---|
| 93 | spectre = (r_4)(0.);
|
---|
| 94 | nzm = 0; ifile++;
|
---|
| 95 | ts.SetNow();
|
---|
| 96 | filog << ts << " : proc file " << fname << endl;
|
---|
| 97 | cout << " DataProc::run() " << ts << " : created file " << fname << endl;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | memgr.FreeMemZone(mid, MemZS_Proc);
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | catch (PException& exc) {
|
---|
| 104 | cout << " DataProc::run()/catched PException " << exc.Msg() << endl;
|
---|
| 105 | setRC(3);
|
---|
| 106 | return;
|
---|
| 107 | }
|
---|
| 108 | catch(...) {
|
---|
| 109 | cout << " DataProc::run()/catched unknown ... exception " << endl;
|
---|
| 110 | setRC(4);
|
---|
| 111 | return;
|
---|
| 112 | }
|
---|
| 113 | setRC(0);
|
---|
| 114 | return;
|
---|
| 115 | }
|
---|