source: Sophya/trunk/AddOn/TAcq/brparam.cc@ 3897

Last change on this file since 3897 was 3897, checked in by ansari, 15 years ago

Amelioration des classes PCIEToEthernet et EthernetReader pour eviter des situations de blocage lorsque lecture avec ForceSameFrameCounter, Reza 04/10/2010

File size: 15.3 KB
Line 
1#include <stdlib.h>
2
3#include "brparam.h"
4#include "strutilxx.h"
5#include "bracqvers.h"
6
7#ifndef BRSPORTID
8#define BRSPORTID 6912
9#endif
10
11/* --Methode-- */
12ADCBoardDesc::ADCBoardDesc(int id, string sbid, string cyc_firmw, string str1_firmw, string str2_firmw)
13 : id_(id), sbid_(sbid), cyclone_firmware_(cyc_firmw), stratix1_firmware_(str1_firmw), stratix2_firmware_(str2_firmw)
14{
15
16}
17
18/* --Methode-- */
19ADCBoardDesc::ADCBoardDesc(ADCBoardDesc const& bdes)
20 : id_(bdes.id_), sbid_(bdes.sbid_), cyclone_firmware_(bdes.cyclone_firmware_),
21 stratix1_firmware_(bdes.stratix1_firmware_), stratix2_firmware_(bdes.stratix2_firmware_)
22{
23}
24
25/* --Methode-- */
26ADCBoardDesc& ADCBoardDesc::Set(ADCBoardDesc const & bdes)
27{
28 id_ = bdes.id_;
29 sbid_ = bdes.sbid_;
30 cyclone_firmware_ = bdes.cyclone_firmware_;
31 stratix1_firmware_ = bdes.stratix1_firmware_;
32 stratix2_firmware_ = bdes.stratix2_firmware_;
33 return(*this);
34}
35
36/* --Methode-- */
37ostream& ADCBoardDesc::Print(ostream& os)
38{
39 os << "ADCBoard#" << id_ << "(" << sbid_ << ") Cyclone:" << cyclone_firmware_
40 << " Stratix1: " << stratix1_firmware_ << " Stratix2: " << stratix2_firmware_ << endl;
41 return os;
42}
43
44/* --Methode-- */
45BRConfList::BRConfList()
46 : basedir_("./")
47{
48}
49
50/* --Methode-- */
51BRConfList::BRConfList(string basedir)
52 : basedir_(basedir)
53{
54}
55
56/* --Methode-- */
57BRConfList::BRConfList(string basedir, vector<ADCBoardDesc> boards)
58 : basedir_(basedir), boards_(boards)
59{
60 size_t len = basedir_.length();
61 if ((len>1)&&(basedir_[len-1]!='/')) basedir_ += '/';
62}
63
64/* --Methode-- */
65BRConfList::BRConfList(BRConfList const & cf)
66 : basedir_(cf.basedir_), boards_(cf.boards_)
67{
68}
69
70/* --Methode-- */
71void BRConfList::SetBaseDirectory(string basedir)
72{
73 basedir_=basedir;
74 size_t len = basedir_.length();
75 if ((len>1)&&(basedir_[len-1]!='/')) basedir_ += '/';
76}
77
78/* --Methode-- */
79void BRConfList::Set(BRConfList const & cf)
80{
81 basedir_=cf.basedir_;
82 boards_=cf.boards_;
83}
84
85/* --Methode-- */
86ostream& BRConfList::Print(ostream& os)
87{
88 os << " ----- BRConfList:: BaseDir:" << basedir_ << " NBoards= " << boards_.size() << endl;
89 for(size_t k=0; k<boards_.size(); k++) boards_[k].Print(os);
90 return os;
91}
92
93/* --Methode-- */
94void BRConfList::ReadDCFile(string file)
95{
96 // A FAIRE
97}
98
99// Classe qui memorise tous les parametres importants de l'acquisition
100
101/* --Methode-- */
102BRParList::BRParList(string acqmod, string fibres,unsigned int paqsz,
103 unsigned int dmaszkb, int nfiles, int nblocfile,
104 string outpath, uint_4 nzon , uint_4 npaqzon)
105{
106 AcqMode=acqmod;
107 fgdatafft=false;
108 fgsinglechannel=false;
109
110 FiberListS=fibres;
111 NbFibers=0;
112 for (int fib=0; fib<PMAXNBFIBRES;fib++) FiberNum[fib]=0;
113 PaqSize=paqsz;
114 dmasizekb=dmaszkb;
115
116 NbFiles=nfiles;
117 NBlocPerFile=nblocfile;
118 OutPathName=outpath;
119
120 nZones=nzon;
121 nPaqZone=npaqzon;
122
123 swapall=BR_Copy;
124 savesigfits=true;
125 fgnulldev4fits=false;
126
127 fg_hard_ctrlc=false;
128
129 fgreducpsize=false;
130 reducneedcopy=false;
131 pqreducmode=BR_CopyRA;
132 redpqsize=PaqSize;
133 reducoffset=0;
134
135 tcpportid=BRSPORTID;
136 pci2eth_fgdirect=false;
137 ethr_nlink=0;
138 ethr_forcesamefc_=false;
139 ethr_sfc_maxdpc_=50;
140 ethr_sfc_maxresync_=50;
141
142 skysource="";
143
144// --- variables de controle pour le monitoring
145 fgdoProc=false;
146 nmeanProc=512;
147 stepProc=5;
148 nmaxProc=0;
149// --- variables de controle pour le calcul des visibilites
150 fgdoVisiC = false;
151 nmeanVisiC=1024;
152 nbcalgrpVisiC=1;
153 nthrVisiC=1;
154 freqminVisiC=freqmaxVisiC=0;
155 nbinfreqVisiC=1;
156
157// Autres variables / variables speciales
158 monothr=false;
159 activate_pattern=false;
160 nopciLossRate=0.;
161
162// niveau d'impression,debug ...
163 prtlevel_=0;
164 prtmodulo_=50000;
165 Decode(); // On decode et on complete les parametres
166}
167
168/* --Methode-- */
169BRParList::BRParList(BRParList const & p)
170{
171 Set(p);
172}
173
174/* --Methode-- */
175void BRParList::Set(BRParList const & p)
176{
177 AcqMode=p.AcqMode;
178 fgdatafft=p.fgdatafft;
179 fgsinglechannel=p.fgsinglechannel;
180
181 FiberListS=p.FiberListS;
182 NbFibers=p.NbFibers;
183 for (int fib=0; fib<PMAXNBFIBRES;fib++) FiberNum[fib]=p.FiberNum[fib];
184
185 PaqSize=p.PaqSize;
186 dmasizekb=p.dmasizekb;
187
188 NbFiles=p.NbFiles;
189 NBlocPerFile=p.NBlocPerFile;
190 OutPathName=p.OutPathName;
191
192 nZones=p.nZones;
193 nPaqZone=p.nPaqZone;
194
195 swapall=p.swapall;
196 savesigfits=p.savesigfits;
197 fgnulldev4fits=p.fgnulldev4fits;
198 fg_hard_ctrlc=p.fg_hard_ctrlc;
199 fgnulldev4fits=p.fgnulldev4fits;
200
201 fgreducpsize=p.fgreducpsize;
202 reducneedcopy=p.reducneedcopy;
203 pqreducmode=p.pqreducmode;
204 redpqsize=p.redpqsize;
205 reducoffset=p.reducoffset;
206
207 tcpportid=p.tcpportid;
208 pci2eth_fgdirect=p.pci2eth_fgdirect;
209 eths_targets=p.eths_targets;
210 ethr_nlink=p.ethr_nlink;
211 ethr_forcesamefc_=p.ethr_forcesamefc_;
212 ethr_sfc_maxdpc_=p.ethr_sfc_maxdpc_;
213 ethr_sfc_maxresync_=p.ethr_sfc_maxresync_;
214
215 skysource=p.skysource;
216
217 fgdoProc=p.fgdoProc;
218 nmeanProc=p.nmeanProc;
219 stepProc=p.stepProc;
220 nmaxProc=p.nmaxProc;
221
222 monothr=p.monothr;
223 activate_pattern=p.activate_pattern;
224
225 nopciLossRate=p.nopciLossRate;
226
227 prtlevel_=p.prtlevel_;
228 prtmodulo_=p.prtlevel_;
229
230 return;
231}
232
233/* --Methode-- */
234void BRParList::ReadDCFile(string file)
235{
236 DataCards conf(file);
237 FiberListS= conf.SParam("fibres",0,"1");
238 OutPathName= conf.SParam("outpathname",0,"TstAcq");
239 skysource= conf.SParam("skysource",0,"");
240 PaqSize=(uint_4)conf.IParam("paqsize",0,16424);
241 dmasizekb =(uint_4) conf.IParam("dmasizekb",0,32);
242 NbFiles=conf.IParam("nbfiles",0,1);
243 NBlocPerFile=conf.IParam("nblocperfile",0,10);
244 AcqMode =conf.SParam("acqmode",0,"std");
245 nZones=(uint_4)conf.IParam("memmgr",0,4);
246 nPaqZone=(uint_4)conf.IParam("memmgr",1,128);
247 if (conf.HasKey("reducpaqsz")) { // reduction des tailles de paquets
248 fgreducpsize=true;
249 redpqsize=(uint_4)conf.IParam("reducpaqsz",0,PaqSize/4);
250 reducoffset=(uint_4)conf.IParam("reducpaqsz",1,0);
251 }
252 // Mot cle pour le mode envoi-reception sur ethernet
253 tcpportid=conf.IParam("tcpportid",0,BRSPORTID);
254 if (conf.HasKey("pci2ethdirect")) pci2eth_fgdirect = true; // Transfer direct DMA -> Ethernet
255 if (conf.HasKey("ethrtargets")) { // Machines destinations des paquets
256 for(int it=0; it<conf.NbParam("ethrtargets"); it++)
257 eths_targets.push_back(conf.SParam("ethrtargets",it));
258 }
259 ethr_nlink=conf.IParam("ethrnlink",0,0); // Nombre de sources de paquets en reception ethernet
260 if (conf.HasKey("ethrforcesamefc")) {
261 ethr_forcesamefc_=true; // force SAME FrameCounter on all links
262 ethr_sfc_maxdpc_=conf.IParam("ethrforcesamefc",0,50);
263 ethr_sfc_maxresync_=conf.IParam("ethrforcesamefc",1,50);
264 }
265
266 // Parametre de controle du monitoring
267 if (conf.HasKey("monitor")) {
268 fgdoProc=true;
269 nmeanProc=conf.IParam("monitor",0,512);
270 stepProc=conf.IParam("monitor",1,10);
271 nmaxProc=conf.IParam("monitor",2,0);
272 }
273 // Parametres pour le calcul des visibilites - le flag fgdoVisiC ne peut etre active
274 // qu'avec l'option de ligne de commande de mfacq
275 if (conf.HasKey("visicalc")) {
276 nmeanVisiC=conf.IParam("visicalc",0,1024);
277 nbcalgrpVisiC=conf.IParam("visicalc",1,1);
278 nthrVisiC=conf.IParam("visicalc",2,1);
279 }
280 if (conf.HasKey("visicfreq")) {
281 freqminVisiC=conf.IParam("visicfreq",0,0);
282 freqmaxVisiC=conf.IParam("visicfreq",1,0);
283 nbinfreqVisiC=conf.IParam("visicfreq",2,1);
284 }
285
286 nopciLossRate=conf.DParam("nopcilossrate",0,0.);
287 fg_hard_ctrlc=conf.HasKey("hard_ctrlc");
288 if (conf.HasKey("nosavesigfits")) savesigfits=false;
289 if (conf.HasKey("prtlev")) {
290 prtlevel_=conf.IParam("prtlev",0,0);
291 prtmodulo_=conf.IParam("prtlev",1,50000);
292 }
293
294 Decode();
295}
296
297/* --Methode-- */
298void BRParList::Decode()
299{
300 vector<string> fiblist;
301 FillVStringFrString(FiberListS, fiblist, ',');
302 NbFibers=fiblist.size();
303 for (int fib=0; fib<fiblist.size(); fib++) {
304 FiberNum[fib]=atoi(fiblist[fib].c_str());
305 }
306 if (OutPathName == "/dev/null") {
307 fgnulldev4fits=true;
308 }
309 else {
310 size_t len = OutPathName.length();
311 if ((len>1)&&(OutPathName[len-1]!='/')) OutPathName+='/';
312 fgnulldev4fits=false;
313 }
314 string acqmode = AcqMode;
315 fgdatafft=false; fgsinglechannel=false;
316 reducneedcopy=false; pqreducmode=BR_TwoChanReduc;
317 if ((acqmode == "std")||(acqmode=="raw2c")) swapall = BR_Copy ;
318 if (acqmode == "nosw") swapall = BR_Copy ;
319 if (acqmode == "nof") { swapall = BR_Copy ; savesigfits = false; }
320 if (acqmode == "fft1c") { swapall = BR_FFTOneChan; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
321 if (acqmode == "fft2c") { swapall = BR_FFTTwoChan; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
322 if (acqmode == "fft1cnof")
323 { swapall = BR_FFTOneChan; savesigfits = false; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
324 if (acqmode == "fft2cnof")
325 { swapall = BR_FFTTwoChan; savesigfits = false; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
326 if (acqmode == "mono") { monothr = true; swapall = BR_Copy; }
327 if (acqmode == "monodirect") { monothr = true; swapall = BR_CopyHDR;}
328 if (acqmode == "patmonodirect") { monothr = true; swapall = BR_CopyHDR; activate_pattern=true; }
329 if (acqmode == "patmono") { monothr = true; swapall = BR_Copy; activate_pattern=true; }
330 if (acqmode == "patnof") { savesigfits = false; swapall = BR_Copy; activate_pattern=true; }
331 if (acqmode == "pattern") { savesigfits = true; swapall = BR_Copy; activate_pattern=true; }
332
333 if (acqmode == "swapall") swapall = BR_SwapAll;
334 if (acqmode == "fft1csw")
335 { swapall = BR_FFTOneChanSwapAll; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
336 if (acqmode == "fft2csw")
337 { swapall = BR_FFTTwoChanSwapAll; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
338 if (acqmode == "fft1cswnof")
339 { swapall = BR_FFTOneChanSwapAll; savesigfits = false; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
340 if (acqmode == "fft2cswnof")
341 { swapall = BR_FFTTwoChanSwapAll; savesigfits = false; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
342 if ((acqmode == "swh") || (acqmode == "mxs") || (acqmode == "monoswh") ) swapall = BR_SwapHDR;
343 if ((acqmode == "swapallnof") || (acqmode == "mxs") ) savesigfits = false;
344 if (acqmode == "monoswh") { monothr = true; swapall = BR_SwapHDR;; }
345 if (acqmode == "monosw") { monothr = true; swapall = BR_SwapAll; }
346
347 if (acqmode == "swap32") swapall = BR_Swap32 ;
348 if (acqmode == "nof32") { swapall = BR_Swap32 ; savesigfits = false; }
349 if (acqmode == "fft1c32")
350 { swapall = BR_FFTOneChanSwap32; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
351 if (acqmode == "fft2c32")
352 { swapall = BR_FFTTwoChanSwap32; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
353 if (acqmode == "fft1cnof32")
354 { swapall = BR_FFTOneChanSwap32; savesigfits = false; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
355 if (acqmode == "fft2cnof32")
356 { swapall = BR_FFTTwoChanSwap32; savesigfits = false; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
357
358 if ((swapall==BR_FFTTwoChan)||(swapall==BR_FFTTwoChanSwapAll)||(swapall==BR_FFTTwoChanSwap32)) {
359 fgdatafft=true;
360 }
361 if ((swapall==BR_FFTOneChan)||(swapall==BR_FFTOneChanSwapAll)||(swapall==BR_FFTOneChanSwap32)) {
362 fgdatafft=true; fgsinglechannel=true;
363 }
364
365 if (fgreducpsize) {
366 if (redpqsize>=PaqSize) fgreducpsize=false;
367 else {
368 if(reducoffset>(PaqSize-redpqsize)/2) reducoffset=(PaqSize-redpqsize)/2;
369 }
370 }
371}
372
373/* --Methode-- */
374ostream& BRParList::Print(ostream& os)
375{
376 os << " ------ BRParList::Print() ----- " << endl;
377 os << " FiberListS=" << FiberListS ;
378 os << " PaqSize=" <<PaqSize;
379 os << " DMA_Size_kb=" <<dmasizekb << endl;
380 os << " AcqMode="<<AcqMode;
381 os << " Type of acquisition :" << BRPaquet::FmtConvToString( swapall) << endl;
382 os << " SkySource=" << skysource;
383 os << " NbFiles="<<NbFiles;
384 os << " NBlocPerFile="<<NBlocPerFile;
385 os << " OutPathName="<<OutPathName << endl;
386 os << " MemMgr: nZones="<<nZones;
387 os << " nPaqZone="<<nPaqZone<<endl;
388 if (fgreducpsize) {
389 os << " PaquetSize Reduction, ReducedSize=" << redpqsize << " Offset=" << reducoffset << endl;
390 }
391 if (eths_targets.size()>0) {
392 cout << " DMA->Ethernet NbTargets=" << eths_targets.size()
393 << ((pci2eth_fgdirect)?" (DirectTransferMode) " : " " ) << " :";
394 for(size_t it=0; it<eths_targets.size(); it++) cout << eths_targets[it] << " , ";
395 cout << endl;
396 }
397 cout << " TCP-PortId=" << tcpportid << " EthernetRead NbSources (=NbLinks)= " << ethr_nlink << endl;
398 if (ethr_forcesamefc_)
399 cout << "EthernetReader mode: ForceSameFrameCounter read mode with Max_PaquetCounterDiff= "
400 << ethr_sfc_maxdpc_ << " MaxNbResync=" << ethr_sfc_maxresync_ << endl;
401 else
402 cout << "EthernetReader mode: AllOKPaquets read mode " << endl;
403
404 if (fgdoProc>0)
405 os << " Monitoring NMeanProc=" << nmeanProc << " StepProc=" << stepProc << " NMaxProc=" << nmaxProc << endl;
406 else os << " No monotoring thread " << endl;
407 if (fgdoVisiC) {
408 os << " Visibility calculation, nbCalGrp=" << nbcalgrpVisiC << " NThr/VisCal=" << nthrVisiC << endl;
409 os << " ... VisiCalc FrequencyBinning FreqMin= " << freqminVisiC << " FreqMax= " << freqmaxVisiC
410 << " NBinFreq= " << nbinfreqVisiC<< endl;
411 }
412 os << " fg_hard_ctrlc=" << ((fg_hard_ctrlc)?"true":"false");
413 os << " Save to fits " << ((savesigfits)?"true":"false") << endl;
414 os << " monothr y(1)/n(0) " << ((monothr)?"true":"false");
415 os << " ActivatePattern " << ((activate_pattern)?"true":"false") << endl;
416 os << " PrtLevel=" << prtlevel_ << " PrtCntModulo=" << prtmodulo_ << endl;
417
418 return os;
419}
420
421
422//-------------------- Classe BRAcqConfig -----------------------
423
424BRParList* BRAcqConfig::param_=NULL;
425BRConfList* BRAcqConfig::config_=NULL;
426
427/* --Methode-- */
428BRAcqConfig::BRAcqConfig()
429{
430 if (param_==NULL) param_ = new BRParList;
431 if (config_==NULL) config_ = new BRConfList;
432}
433
434/* --Methode-- */
435ostream& BRAcqConfig::Print(ostream& os)
436{
437 os << " ------------ BAORadio Acq Run/Configuration -------- " << endl;
438 config_->Print(os);
439 param_->Print(os);
440 os << " ----------------------------------------------------- " << endl;
441}
442
443/* --Methode-- */
444int BRAcqConfig::CreateOutputDirectories()
445{
446 char cmd[1024];
447 if (param_->fgnulldev4fits!=true) {
448 sprintf(cmd,"mkdir %s%s",config_->BaseDirectory().c_str(), param_->OutPathName.c_str());
449 if (system(cmd) < 0) {
450 cout << "CreateOutputDirectories()/Error: Can not create subdirectory "
451 << cmd << " -> stop" << endl;
452 return 2;
453 }
454 cout << "CreateOutputDirectories() - Executed command " << cmd << endl;
455
456 memset(cmd,0,1024);
457 for (int i= 0; i< NFibers() ; i++) {
458 sprintf(cmd,"mkdir %s%s/Fiber%d",config_->BaseDirectory().c_str(), param_->OutPathName.c_str(),param_->FiberNum[i]);
459 if (system(cmd) < 0) {
460 cout << "CreateOutputDirectories()/Error: Can not create subdirectory "
461 << cmd << " -> stop" << endl;
462 return 3;
463 }
464 else cout << "CreateOutputDirectories() - Executed command " << cmd << endl;
465 }
466 }
467 else {
468 string ProcPathName = "./XZXZXZX/";
469 cout << " Using " << ProcPathName << " for other processed files ... " << endl;
470 char cmd[512];
471 sprintf(cmd,"mkdir %s",ProcPathName.c_str());
472 if (system(cmd) < 0) {
473 cout << "CreateOutputDirectories()/Error: Can not create subdirectory ./XZXZXZX/"
474 << "-> stop" << endl;
475 return 3;
476 }
477 else cout << "CreateOutputDirectories() - Executed command " << cmd << endl;
478 }
479 return 0;
480}
481
482/* --Methode-- */
483string BRAcqConfig::OutputDirectoryFib(int ifib)
484{
485 char buff[24];
486 sprintf(buff,"Fiber%d/",param_->FiberNum[ifib]);
487 return ( config_->BaseDirectory() + param_->OutPathName + buff );
488}
Note: See TracBrowser for help on using the repository browser.