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

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

Ajout classes de transfert DMA vers Ethernet et lecture ethernet, Reza 29/04/2010

File size: 13.2 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
139 skysource="";
140
141 fgdoProc=false;
142 nmeanProc=512;
143 stepProc=5;
144 nmaxProc=0;
145
146 monothr=false;
147 activate_pattern=false;
148 nopciLossRate=0.;
149
150 Decode(); // On decode et on complete les parametres
151}
152
153/* --Methode-- */
154BRParList::BRParList(BRParList const & p)
155{
156 Set(p);
157}
158
159/* --Methode-- */
160void BRParList::Set(BRParList const & p)
161{
162 AcqMode=p.AcqMode;
163 fgdatafft=p.fgdatafft;
164 fgsinglechannel=p.fgsinglechannel;
165
166 FiberListS=p.FiberListS;
167 NbFibers=p.NbFibers;
168 for (int fib=0; fib<PMAXNBFIBRES;fib++) FiberNum[fib]=p.FiberNum[fib];
169
170 PaqSize=p.PaqSize;
171 dmasizekb=p.dmasizekb;
172
173 NbFiles=p.NbFiles;
174 NBlocPerFile=p.NBlocPerFile;
175 OutPathName=p.OutPathName;
176
177 nZones=p.nZones;
178 nPaqZone=p.nPaqZone;
179
180 swapall=p.swapall;
181 savesigfits=p.savesigfits;
182 fgnulldev4fits=p.fgnulldev4fits;
183 fg_hard_ctrlc=p.fg_hard_ctrlc;
184 fgnulldev4fits=p.fgnulldev4fits;
185
186 fgreducpsize=p.fgreducpsize;
187 reducneedcopy=p.reducneedcopy;
188 pqreducmode=p.pqreducmode;
189 redpqsize=p.redpqsize;
190 reducoffset=p.reducoffset;
191
192 pci2eth_fgdirect=p.pci2eth_fgdirect;
193 eths_targets=p.eths_targets;
194 ethr_nlink=p.ethr_nlink;
195
196 skysource=p.skysource;
197
198 fgdoProc=p.fgdoProc;
199 nmeanProc=p.nmeanProc;
200 stepProc=p.stepProc;
201 nmaxProc=p.nmaxProc;
202
203 monothr=p.monothr;
204 activate_pattern=p.activate_pattern;
205
206 nopciLossRate=p.nopciLossRate;
207 return;
208}
209
210/* --Methode-- */
211void BRParList::ReadDCFile(string file)
212{
213 DataCards conf(file);
214 FiberListS= conf.SParam("fibres",0,"1");
215 OutPathName= conf.SParam("outpathname",0,"TstAcq");
216 skysource= conf.SParam("skysource",0,"");
217 PaqSize=(uint_4)conf.IParam("paqsize",0,16424);
218 dmasizekb =(uint_4) conf.IParam("dmasizekb",0,32);
219 NbFiles=conf.IParam("nbfiles",0,1);
220 NBlocPerFile=conf.IParam("nblocperfile",0,10);
221 AcqMode =conf.SParam("acqmode",0,"std");
222 nZones=(uint_4)conf.IParam("memmgr",0,4);
223 nPaqZone=(uint_4)conf.IParam("memmgr",1,128);
224 if (conf.HasKey("reducpaqsz")) { // reduction des tailles de paquets
225 fgreducpsize=true;
226 redpqsize=(uint_4)conf.IParam("reducpaqsz",0,PaqSize/4);
227 reducoffset=(uint_4)conf.IParam("reducpaqsz",1,0);
228 }
229 // Mot cle pour le mode envoi-reception sur ethernet
230 tcpportid=conf.IParam("tcpportid",0,BRSPORTID);
231 if (conf.HasKey("pci2ethdirect")) pci2eth_fgdirect = true; // Transfer direct DMA -> Ethernet
232 if (conf.HasKey("ethrtargets")) { // Machines destinations des paquets
233 for(int it=0; it<conf.NbParam("ethrtargets"); it++)
234 eths_targets.push_back(conf.SParam("ethrtargets",it));
235 }
236 ethr_nlink=conf.IParam("ethrnlink",0,0); // Nombre de sources de paquets en reception ethernet
237
238
239 if (conf.HasKey("monitor")) {
240 fgdoProc=true;
241 nmeanProc=conf.IParam("monitor",0,512);
242 stepProc=conf.IParam("monitor",1,10);
243 nmaxProc=conf.IParam("monitor",2,0);
244 }
245 nopciLossRate=conf.DParam("nopcilossrate",0,0.);
246 fg_hard_ctrlc=conf.HasKey("hard_ctrlc");
247 if (conf.HasKey("nosavesigfits")) savesigfits=false;
248 Decode();
249}
250
251/* --Methode-- */
252void BRParList::Decode()
253{
254 vector<string> fiblist;
255 FillVStringFrString(FiberListS, fiblist, ',');
256 NbFibers=fiblist.size();
257 for (int fib=0; fib<fiblist.size(); fib++) {
258 FiberNum[fib]=atoi(fiblist[fib].c_str());
259 }
260 if (OutPathName == "/dev/null") {
261 fgnulldev4fits=true;
262 }
263 else {
264 size_t len = OutPathName.length();
265 if ((len>1)&&(OutPathName[len-1]!='/')) OutPathName+='/';
266 fgnulldev4fits=false;
267 }
268 string acqmode = AcqMode;
269 fgdatafft=false; fgsinglechannel=false;
270 reducneedcopy=false; pqreducmode=BR_TwoChanReduc;
271 if ((acqmode == "std")||(acqmode=="raw2c")) swapall = BR_Copy ;
272 if (acqmode == "nosw") swapall = BR_Copy ;
273 if (acqmode == "nof") { swapall = BR_Copy ; savesigfits = false; }
274 if (acqmode == "fft1c") { swapall = BR_FFTOneChan; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
275 if (acqmode == "fft2c") { swapall = BR_FFTTwoChan; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
276 if (acqmode == "fft1cnof")
277 { swapall = BR_FFTOneChan; savesigfits = false; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
278 if (acqmode == "fft2cnof")
279 { swapall = BR_FFTTwoChan; savesigfits = false; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
280 if (acqmode == "mono") { monothr = true; swapall = BR_Copy; }
281 if (acqmode == "monodirect") { monothr = true; swapall = BR_CopyHDR;}
282 if (acqmode == "patmonodirect") { monothr = true; swapall = BR_CopyHDR; activate_pattern=true; }
283 if (acqmode == "patmono") { monothr = true; swapall = BR_Copy; activate_pattern=true; }
284 if (acqmode == "patnof") { savesigfits = false; swapall = BR_Copy; activate_pattern=true; }
285 if (acqmode == "pattern") { savesigfits = true; swapall = BR_Copy; activate_pattern=true; }
286
287 if (acqmode == "swapall") swapall = BR_SwapAll;
288 if (acqmode == "fft1csw")
289 { swapall = BR_FFTOneChanSwapAll; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
290 if (acqmode == "fft2csw")
291 { swapall = BR_FFTTwoChanSwapAll; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
292 if (acqmode == "fft1cswnof")
293 { swapall = BR_FFTOneChanSwapAll; savesigfits = false; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
294 if (acqmode == "fft2cswnof")
295 { swapall = BR_FFTTwoChanSwapAll; savesigfits = false; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
296 if ((acqmode == "swh") || (acqmode == "mxs") || (acqmode == "monoswh") ) swapall = BR_SwapHDR;
297 if ((acqmode == "swapallnof") || (acqmode == "mxs") ) savesigfits = false;
298 if (acqmode == "monoswh") { monothr = true; swapall = BR_SwapHDR;; }
299 if (acqmode == "monosw") { monothr = true; swapall = BR_SwapAll; }
300
301 if (acqmode == "swap32") swapall = BR_Swap32 ;
302 if (acqmode == "nof32") { swapall = BR_Swap32 ; savesigfits = false; }
303 if (acqmode == "fft1c32")
304 { swapall = BR_FFTOneChanSwap32; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
305 if (acqmode == "fft2c32")
306 { swapall = BR_FFTTwoChanSwap32; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
307 if (acqmode == "fft1cnof32")
308 { swapall = BR_FFTOneChanSwap32; savesigfits = false; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
309 if (acqmode == "fft2cnof32")
310 { swapall = BR_FFTTwoChanSwap32; savesigfits = false; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
311
312 if ((swapall==BR_FFTTwoChan)||(swapall==BR_FFTTwoChanSwapAll)||(swapall==BR_FFTTwoChanSwap32)) {
313 fgdatafft=true;
314 }
315 if ((swapall==BR_FFTOneChan)||(swapall==BR_FFTOneChanSwapAll)||(swapall==BR_FFTOneChanSwap32)) {
316 fgdatafft=true; fgsinglechannel=true;
317 }
318
319 if (fgreducpsize) {
320 if (redpqsize>=PaqSize) fgreducpsize=false;
321 else {
322 if(reducoffset>(PaqSize-redpqsize)/2) reducoffset=(PaqSize-redpqsize)/2;
323 }
324 }
325}
326
327/* --Methode-- */
328ostream& BRParList::Print(ostream& os)
329{
330 os << " ------ BRParList::Print() ----- " << endl;
331 os << " FiberListS=" << FiberListS ;
332 os << " PaqSize=" <<PaqSize;
333 os << " DMA_Size_kb=" <<dmasizekb << endl;
334 os << " AcqMode="<<AcqMode;
335 os << " Type of acquisition :" << BRPaquet::FmtConvToString( swapall) << endl;
336 os << " SkySource=" << skysource;
337 os << " NbFiles="<<NbFiles;
338 os << " NBlocPerFile="<<NBlocPerFile;
339 os << " OutPathName="<<OutPathName << endl;
340 os << " MemMgr: nZones="<<nZones;
341 os << " nPaqZone="<<nPaqZone<<endl;
342 if (fgreducpsize) {
343 os << " PaquetSize Reduction, ReducedSize=" << redpqsize << " Offset=" << reducoffset << endl;
344 }
345 if (eths_targets.size()>0) {
346 cout << " DMA->Ethernet NbTargets=" << eths_targets.size() << ((pci2eth_fgdirect)?" (DirectTransferMode) " : " " ) << " :" << endl;
347 for(size_t it=0; it<eths_targets.size(); it++) cout << eths_targets[it] << " , ";
348 cout << endl;
349 }
350 cout << " EthernetRead NbSources (=NbLinks)= " << ethr_nlink << endl;
351 if (fgdoProc>0)
352 os << " Monitoring NMeanProc=" << nmeanProc << " StepProc=" << stepProc << " NMaxProc=" << nmaxProc << endl;
353 else os << " No monotoring thread " << endl;
354 os << " fg_hard_ctrlc=" << ((fg_hard_ctrlc)?"true":"false");
355 os << " Save to fits " << ((savesigfits)?"true":"false") << endl;
356 os << " monothr y(1)/n(0) " << ((monothr)?"true":"false");
357 os << " ActivatePattern " << ((activate_pattern)?"true":"false") << endl;
358
359 return os;
360}
361
362
363//-------------------- Classe BRAcqConfig -----------------------
364
365BRParList* BRAcqConfig::param_=NULL;
366BRConfList* BRAcqConfig::config_=NULL;
367
368/* --Methode-- */
369BRAcqConfig::BRAcqConfig()
370{
371 if (param_==NULL) param_ = new BRParList;
372 if (config_==NULL) config_ = new BRConfList;
373}
374
375/* --Methode-- */
376ostream& BRAcqConfig::Print(ostream& os)
377{
378 os << " ------------ BAORadio Acq Run/Configuration -------- " << endl;
379 config_->Print(os);
380 param_->Print(os);
381 os << " ----------------------------------------------------- " << endl;
382}
383
384/* --Methode-- */
385int BRAcqConfig::CreateOutputDirectories()
386{
387 char cmd[1024];
388 if (param_->fgnulldev4fits!=true) {
389 sprintf(cmd,"mkdir %s%s",config_->BaseDirectory().c_str(), param_->OutPathName.c_str());
390 if (system(cmd) < 0) {
391 cout << "CreateOutputDirectories()/Error: Can not create subdirectory "
392 << cmd << " -> stop" << endl;
393 return 2;
394 }
395 cout << "CreateOutputDirectories() - Executed command " << cmd << endl;
396
397 memset(cmd,0,1024);
398 for (int i= 0; i< NFibers() ; i++) {
399 sprintf(cmd,"mkdir %s%s/Fiber%d",config_->BaseDirectory().c_str(), param_->OutPathName.c_str(),param_->FiberNum[i]);
400 if (system(cmd) < 0) {
401 cout << "CreateOutputDirectories()/Error: Can not create subdirectory "
402 << cmd << " -> stop" << endl;
403 return 3;
404 }
405 else cout << "CreateOutputDirectories() - Executed command " << cmd << endl;
406 }
407 }
408 else {
409 string ProcPathName = "./XZXZXZX/";
410 cout << " Using " << ProcPathName << " for other processed files ... " << endl;
411 char cmd[512];
412 sprintf(cmd,"mkdir %s",ProcPathName.c_str());
413 if (system(cmd) < 0) {
414 cout << "CreateOutputDirectories()/Error: Can not create subdirectory ./XZXZXZX/"
415 << "-> stop" << endl;
416 return 3;
417 }
418 else cout << "CreateOutputDirectories() - Executed command " << cmd << endl;
419 }
420 return 0;
421}
422
423/* --Methode-- */
424string BRAcqConfig::OutputDirectoryFib(int ifib)
425{
426 char buff[24];
427 sprintf(buff,"Fiber%d/",param_->FiberNum[ifib]);
428 return ( config_->BaseDirectory() + param_->OutPathName + buff );
429}
Note: See TracBrowser for help on using the repository browser.