Changeset 3623 in Sophya for trunk/AddOn/TAcq/racquproc.cc
- Timestamp:
- May 22, 2009, 9:59:38 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/AddOn/TAcq/racquproc.cc
r3538 r3623 4 4 #include <unistd.h> 5 5 #include <fstream> 6 #include <signal.h> 6 7 7 8 #include "pexceptions.h" … … 18 19 #include "brpaqu.h" 19 20 #include "minifits.h" 20 21 struct sigaction act; 21 22 22 23 //------------------------------------------------------- 23 // Classe thread de traitement 24 // Classe thread de traitement avec 1 voie par frame 24 25 //------------------------------------------------------- 25 26 26 DataProc::DataProc(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 nmax) 27 void DataProcSignal(int s) 28 { 29 cout <<"............................................... receive CtrlC" << endl; 30 31 } 32 33 DataProc::DataProc(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax) 27 34 : memgr(mem) 28 35 { 29 36 nmax_ = nmax; 30 37 nmean_ = nmean; 38 step_ = step; 31 39 stop_ = false; 32 40 path_ = path; 41 act.sa_handler=DataProcSignal; 33 42 } 34 43 … … 36 45 { return (z.real()*z.real()+z.imag()*z.imag()); } 37 46 47 void DataProc::Stop() 48 { 49 stop_=true; 50 // cout <<" DataProc::Stop ... > STOP " << endl; 51 } 52 38 53 void DataProc::run() 39 54 { 40 55 56 // sigaddset(&act.sa_mask,SIGINT); // pour proteger le transfert DMA 57 // sigaction(SIGINT,&act,NULL); 41 58 setRC(1); 42 59 try { 43 60 TimeStamp ts; 44 cout << " DataProc::run() - Starting " << ts << " NMaxMemZones=" << nmax_ << endl; 61 cout << " DataProc::run() - Starting " << ts << " NMaxMemZones=" << nmax_ 62 << " NMean=" << nmean_ << " Step=" << step_ << endl; 45 63 char fname[512]; 46 64 sprintf(fname,"%s/proc.log",path_.c_str()); 47 65 ofstream filog(fname); 48 66 filog << " DataProc::run() - starting log file " << ts << endl; 67 filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl; 49 68 50 69 // Initialisation pour clcul FFT … … 59 78 spectre.ReSize(cfour.Size()); 60 79 61 fftwf_plan plan = fftwf_plan_dft_r2c_1d( pq.DataSize(), vx.Data(),62 (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);80 fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(), 81 (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE); 63 82 64 83 uint_4 ifile = 0; 84 uint_4 nzm = 0; 65 85 for (uint_4 kmz=0; kmz<nmax_; kmz++) { 86 if (stop_) break; 66 87 int mid = memgr.FindMemZoneId(MemZA_Proc); 67 88 Byte* buff = memgr.GetMemZone(mid); … … 72 93 } 73 94 BRPaquet paq0(NULL, buff, paqsz); 74 uint_4 nzm = 0; 75 for(uint_4 i=0; i<memgr.NbPaquets(); i++) { 95 for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) { 76 96 BRPaquet paq(NULL, buff+i*paqsz, paqsz); 77 97 Byte min = 255; … … 79 99 80 100 for(sa_size_t j=0; j<vx.Size(); j++) 81 vx(j) = (r_4)(*(paq.Data ()+j));101 vx(j) = (r_4)(*(paq.Data1()+j))-127.5; 82 102 fftwf_execute(plan); 83 //ffts_.FFTForward(vx, cfour_);103 // ffts_.FFTForward(vx, cfour_); 84 104 for(sa_size_t j=0; j<spectre.Size(); j++) 85 105 spectre(j) += Zmod2(cfour(j)); 86 106 nzm++; 87 107 } 88 if ( nzm >= nmean_) {108 if ((nzm >= nmean_) ||(kmz==(nmax_-1))) { 89 109 spectre /= (r_4)(nzm); 110 spectre.Info()["NPaqMoy"] = nzm; 90 111 sprintf(fname,"%s/spectre%d.ppf",path_.c_str(),(int)ifile); 91 112 POutPersist po(fname); … … 114 135 return; 115 136 } 137 138 //--------------------------------------------------------------- 139 // Classe thread de traitement donnees ADC avec 2 voies par frame 140 //--------------------------------------------------------------- 141 142 DataProc2C::DataProc2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax) 143 : memgr(mem) 144 { 145 nmax_ = nmax; 146 nmean_ = nmean; 147 step_ = step; 148 stop_ = false; 149 path_ = path; 150 act.sa_handler=DataProcSignal; 151 } 152 void DataProc2C::Stop() 153 { 154 stop_=true; 155 // cout <<" DataProc2C::Stop ... > STOP " << endl; 156 } 157 158 void DataProc2C::run() 159 { 160 // sigaction(SIGINT,&act,NULL); 161 setRC(1); 162 try { 163 TimeStamp ts; 164 cout << " DataProc2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_ 165 << " NMean=" << nmean_ << " Step=" << step_ << endl; 166 char fname[512]; 167 sprintf(fname,"%s/proc.log",path_.c_str()); 168 ofstream filog(fname); 169 filog << " DataProc2C::run() - starting log file " << ts << endl; 170 filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl; 171 172 // Initialisation pour clcul FFT 173 TVector< complex<r_4> > cfour; // composant TF 174 uint_4 paqsz = memgr.PaqSize(); 175 BRPaquet pq(NULL, NULL, paqsz); 176 TVector<r_4> vx(pq.DataSize()/2); 177 vx = (r_4)(0.); 178 FFTPackServer ffts; 179 ffts.FFTForward(vx, cfour); 180 TVector<r_4> spectreV1, spectreV2; 181 spectreV1.ReSize(cfour.Size()); 182 spectreV2.ReSize(cfour.Size()); 183 184 fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(), 185 (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE); 186 187 uint_4 ifile = 0; 188 uint_4 nzm = 0; 189 for (uint_4 kmz=0; kmz<nmax_; kmz++) { 190 if (stop_) break; 191 int mid = memgr.FindMemZoneId(MemZA_Proc); 192 Byte* buff = memgr.GetMemZone(mid); 193 if (buff == NULL) { 194 cout << " DataProc2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl; 195 setRC(2); 196 return; 197 } 198 BRPaquet paq0(NULL, buff, paqsz); 199 for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) { 200 BRPaquet paq(NULL, buff+i*paqsz, paqsz); 201 Byte min = 255; 202 Byte max = 0; 203 204 for(sa_size_t j=0; j<vx.Size(); j++) 205 vx(j) = (r_4)(*(paq.Data1()+j))-127.5; 206 fftwf_execute(plan); 207 // ffts_.FFTForward(vx, cfour_); 208 for(sa_size_t j=0; j<spectreV1.Size(); j++) 209 spectreV1(j) += Zmod2(cfour(j)); 210 211 for(sa_size_t j=0; j<vx.Size(); j++) 212 vx(j) = (r_4)(*(paq.Data2()+j))-127.5; 213 fftwf_execute(plan); 214 // ffts_.FFTForward(vx, cfour_); 215 for(sa_size_t j=0; j<spectreV2.Size(); j++) 216 spectreV2(j) += Zmod2(cfour(j)); 217 218 nzm++; 219 } 220 if ((nzm >= nmean_) ||(kmz==(nmax_-1))) { 221 spectreV1 /= (r_4)(nzm); 222 spectreV2 /= (r_4)(nzm); 223 spectreV1.Info()["NPaqMoy"] = nzm; 224 spectreV2.Info()["NPaqMoy"] = nzm; 225 { 226 sprintf(fname,"%s/spectre2C_%d.ppf",path_.c_str(),(int)ifile); 227 POutPersist po(fname); 228 po << PPFNameTag("specV1") << spectreV1; 229 po << PPFNameTag("specV2") << spectreV2; 230 } 231 spectreV1 = (r_4)(0.); 232 spectreV2 = (r_4)(0.); 233 nzm = 0; ifile++; 234 ts.SetNow(); 235 filog << ts << " : proc file " << fname << endl; 236 cout << " DataProc2C::run() " << ts << " : created file " << fname << endl; 237 } 238 239 memgr.FreeMemZone(mid, MemZS_Proc); 240 } 241 } 242 catch (PException& exc) { 243 cout << " DataProc2C::run()/catched PException " << exc.Msg() << endl; 244 setRC(3); 245 return; 246 } 247 catch(...) { 248 cout << " DataProc2C::run()/catched unknown ... exception " << endl; 249 setRC(4); 250 return; 251 } 252 setRC(0); 253 return; 254 } 255 256 257 258 259 //--------------------------------------------------------------- 260 // Classe thread de traitement donnees FFT avec 2 voies par frame 261 //--------------------------------------------------------------- 262 263 inline r_4 Zmod2TwoByte(TwoByteComplex z) 264 { return (z.realD()*z.realD()+z.imagD()*z.imagD()); } 265 266 DataProcFFT2C::DataProcFFT2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax) 267 : memgr(mem) 268 { 269 nmax_ = nmax; 270 nmean_ = nmean; 271 step_ = step; 272 stop_ = false; 273 path_ = path; 274 act.sa_handler=DataProcSignal; 275 } 276 void DataProcFFT2C::Stop() 277 { 278 stop_=true; 279 // cout <<" DataProcFFT2C::Stop ... > STOP " << endl; 280 } 281 282 void DataProcFFT2C::run() 283 { 284 // sigaction(SIGINT,&act,NULL); 285 setRC(1); 286 try { 287 TimeStamp ts; 288 cout << " DataProcFFT2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_ 289 << " NMean=" << nmean_ << " Step=" << step_ << endl; 290 char fname[512]; 291 sprintf(fname,"%s/proc.log",path_.c_str()); 292 ofstream filog(fname); 293 filog << " DataProcFFT2C::run() - starting log file " << ts << endl; 294 filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl; 295 296 // Initialisation pour clcul FFT 297 TVector< complex<r_4> > cfour; // composant TF 298 uint_4 paqsz = memgr.PaqSize(); 299 BRPaquet pq(NULL, NULL, paqsz); 300 301 TVector<r_4> spectreV1(pq.DataSize()/4+1), spectreV2(pq.DataSize()/4+1); 302 303 uint_4 ifile = 0; 304 for (uint_4 kmz=0; kmz<nmax_; kmz++) { 305 if (stop_ ) break; 306 int mid = memgr.FindMemZoneId(MemZA_Proc); 307 Byte* buff = memgr.GetMemZone(mid); 308 if (buff == NULL) { 309 cout << " DataProcFFT2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl; 310 setRC(2); 311 return; 312 } 313 BRPaquet paq0(NULL, buff, paqsz); 314 uint_4 nzm = 0; 315 for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) { 316 BRPaquet paq(NULL, buff+i*paqsz, paqsz); 317 Byte min = 255; 318 Byte max = 0; 319 320 TwoByteComplex* zz; 321 // Traitement Voie 1 322 zz = (TwoByteComplex*)paq.Data1(); 323 spectreV1(0) += zz[0].realD()*zz[0].realD(); // Composante continue, partie reelle uniquement 324 for(sa_size_t j=1; j<spectreV1.Size()-1; j++) spectreV1(j) += Zmod2TwoByte(zz[j]); 325 326 spectreV1(spectreV1.Size()-1) += zz[0].imagD()*zz[0].imagD(); // Freq. Nyquist a N/2 327 328 // Traitement Voie 2 329 zz = (TwoByteComplex*)paq.Data2(); 330 spectreV2(0) += zz[0].realD()*zz[0].realD(); // Composante continue, partie reelle uniquement 331 for(sa_size_t j=1; j<spectreV2.Size()-1; j++) spectreV2(j) += Zmod2TwoByte(zz[j]); 332 333 spectreV2(spectreV2.Size()-1) += zz[0].imagD()*zz[0].imagD(); // Freq. Nyquist a N/2 334 335 nzm++; 336 } 337 if ((nzm >= nmean_) ||(kmz==(nmax_-1))) { 338 spectreV1 /= (r_4)(nzm); 339 spectreV2 /= (r_4)(nzm); 340 spectreV1.Info()["NPaqMoy"] = nzm; 341 spectreV2.Info()["NPaqMoy"] = nzm; 342 { 343 sprintf(fname,"%s/spectreFFT2C_%d.ppf",path_.c_str(),(int)ifile); 344 POutPersist po(fname); 345 po << PPFNameTag("specV1") << spectreV1; 346 po << PPFNameTag("specV2") << spectreV2; 347 } 348 spectreV1 = (r_4)(0.); 349 spectreV2 = (r_4)(0.); 350 nzm = 0; ifile++; 351 ts.SetNow(); 352 filog << ts << " : proc file " << fname << endl; 353 cout << " DataProcFFT2C::run() " << ts << " : created file " << fname << endl; 354 } 355 356 memgr.FreeMemZone(mid, MemZS_Proc); 357 } 358 } 359 catch (PException& exc) { 360 cout << " DataProcFFT2C::run()/catched PException " << exc.Msg() << endl; 361 setRC(3); 362 return; 363 } 364 catch(...) { 365 cout << " DataProcFFT2C::run()/catched unknown ... exception " << endl; 366 setRC(4); 367 return; 368 } 369 setRC(0); 370 return; 371 }
Note:
See TracChangeset
for help on using the changeset viewer.