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

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

Ajout de la fonctionalite de calcul des visibilites (sur donnees firmware FFT uniquement) dans le programme d'acquisition mfacq.cc , Reza 09/09/2010

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