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

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

Suite recherche de probleme de blocage avec transfert sur ethernet ds mfacq.cc (EthernetReader...), Reza 07/10/2010

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