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

Last change on this file since 3710 was 3704, checked in by cmv, 16 years ago

ajout stdlib.h manquant, rz+cmv 07/12/2009

File size: 12.2 KB
Line 
1#include <stdlib.h>
2
3#include "brparam.h"
4#include "strutilxx.h"
5#include "bracqvers.h"
6
7/* --Methode-- */
8ADCBoardDesc::ADCBoardDesc(int id, string sbid, string cyc_firmw, string str1_firmw, string str2_firmw)
9 : id_(id), sbid_(sbid), cyclone_firmware_(cyc_firmw), stratix1_firmware_(str1_firmw), stratix2_firmware_(str2_firmw)
10{
11
12}
13
14/* --Methode-- */
15ADCBoardDesc::ADCBoardDesc(ADCBoardDesc const& bdes)
16 : id_(bdes.id_), sbid_(bdes.sbid_), cyclone_firmware_(bdes.cyclone_firmware_),
17 stratix1_firmware_(bdes.stratix1_firmware_), stratix2_firmware_(bdes.stratix2_firmware_)
18{
19}
20
21/* --Methode-- */
22ADCBoardDesc& ADCBoardDesc::Set(ADCBoardDesc const & bdes)
23{
24 id_ = bdes.id_;
25 sbid_ = bdes.sbid_;
26 cyclone_firmware_ = bdes.cyclone_firmware_;
27 stratix1_firmware_ = bdes.stratix1_firmware_;
28 stratix2_firmware_ = bdes.stratix2_firmware_;
29 return(*this);
30}
31
32/* --Methode-- */
33ostream& ADCBoardDesc::Print(ostream& os)
34{
35 os << "ADCBoard#" << id_ << "(" << sbid_ << ") Cyclone:" << cyclone_firmware_
36 << " Stratix1: " << stratix1_firmware_ << " Stratix2: " << stratix2_firmware_ << endl;
37 return os;
38}
39
40/* --Methode-- */
41BRConfList::BRConfList()
42 : basedir_("./")
43{
44}
45
46/* --Methode-- */
47BRConfList::BRConfList(string basedir)
48 : basedir_(basedir)
49{
50}
51
52/* --Methode-- */
53BRConfList::BRConfList(string basedir, vector<ADCBoardDesc> boards)
54 : basedir_(basedir), boards_(boards)
55{
56 size_t len = basedir_.length();
57 if ((len>1)&&(basedir_[len-1]!='/')) basedir_ += '/';
58}
59
60/* --Methode-- */
61BRConfList::BRConfList(BRConfList const & cf)
62 : basedir_(cf.basedir_), boards_(cf.boards_)
63{
64}
65
66/* --Methode-- */
67void BRConfList::SetBaseDirectory(string basedir)
68{
69 basedir_=basedir;
70 size_t len = basedir_.length();
71 if ((len>1)&&(basedir_[len-1]!='/')) basedir_ += '/';
72}
73
74/* --Methode-- */
75void BRConfList::Set(BRConfList const & cf)
76{
77 basedir_=cf.basedir_;
78 boards_=cf.boards_;
79}
80
81/* --Methode-- */
82ostream& BRConfList::Print(ostream& os)
83{
84 os << " ----- BRConfList:: BaseDir:" << basedir_ << " NBoards= " << boards_.size() << endl;
85 for(size_t k=0; k<boards_.size(); k++) boards_[k].Print(os);
86 return os;
87}
88
89/* --Methode-- */
90void BRConfList::ReadDCFile(string file)
91{
92 // A FAIRE
93}
94
95// Classe qui memorise tous les parametres importants de l'acquisition
96
97/* --Methode-- */
98BRParList::BRParList(string acqmod, string fibres,unsigned int paqsz,
99 unsigned int dmaszkb, int nfiles, int nblocfile,
100 string outpath, uint_4 nzon , uint_4 npaqzon)
101{
102 AcqMode=acqmod;
103 fgdatafft=false;
104 fgsinglechannel=false;
105
106 FiberListS=fibres;
107 NbFibers=0;
108 for (int fib=0; fib<PMAXNBFIBRES;fib++) FiberNum[fib]=0;
109 PaqSize=paqsz;
110 dmasizekb=dmaszkb;
111
112 NbFiles=nfiles;
113 NBlocPerFile=nblocfile;
114 OutPathName=outpath;
115
116 nZones=nzon;
117 nPaqZone=npaqzon;
118
119 swapall=BR_Copy;
120 savesigfits=true;
121 fgnulldev4fits=false;
122
123 fg_hard_ctrlc=false;
124
125 fgreducpsize=false;
126 reducneedcopy=false;
127 pqreducmode=BR_CopyRA;
128 redpqsize=PaqSize;
129 reducoffset=0;
130
131 skysource="";
132
133 fgdoProc=false;
134 nmeanProc=512;
135 stepProc=5;
136 nmaxProc=0;
137
138 monothr=false;
139 activate_pattern=false;
140 nopciLossRate=0.;
141
142 Decode(); // On decode et on complete les parametres
143}
144
145/* --Methode-- */
146BRParList::BRParList(BRParList const & p)
147{
148 Set(p);
149}
150
151/* --Methode-- */
152void BRParList::Set(BRParList const & p)
153{
154 AcqMode=p.AcqMode;
155 fgdatafft=p.fgdatafft;
156 fgsinglechannel=p.fgsinglechannel;
157
158 FiberListS=p.FiberListS;
159 NbFibers=p.NbFibers;
160 for (int fib=0; fib<PMAXNBFIBRES;fib++) FiberNum[fib]=p.FiberNum[fib];
161
162 PaqSize=p.PaqSize;
163 dmasizekb=p.dmasizekb;
164
165 NbFiles=p.NbFiles;
166 NBlocPerFile=p.NBlocPerFile;
167 OutPathName=p.OutPathName;
168
169 nZones=p.nZones;
170 nPaqZone=p.nPaqZone;
171
172 swapall=p.swapall;
173 savesigfits=p.savesigfits;
174 fgnulldev4fits=p.fgnulldev4fits;
175 fg_hard_ctrlc=p.fg_hard_ctrlc;
176 fgnulldev4fits=p.fgnulldev4fits;
177
178 fgreducpsize=p.fgreducpsize;
179 reducneedcopy=p.reducneedcopy;
180 pqreducmode=p.pqreducmode;
181 redpqsize=p.redpqsize;
182 reducoffset=p.reducoffset;
183
184 skysource=p.skysource;
185
186 fgdoProc=p.fgdoProc;
187 nmeanProc=p.nmeanProc;
188 stepProc=p.stepProc;
189 nmaxProc=p.nmaxProc;
190
191 monothr=p.monothr;
192 activate_pattern=p.activate_pattern;
193
194 nopciLossRate=p.nopciLossRate;
195 return;
196}
197
198/* --Methode-- */
199void BRParList::ReadDCFile(string file)
200{
201 DataCards conf(file);
202 FiberListS= conf.SParam("fibres",0,"1");
203 OutPathName= conf.SParam("outpathname",0,"TstAcq");
204 skysource= conf.SParam("skysource",0,"");
205 PaqSize=(uint_4)conf.IParam("paqsize",0,16424);
206 dmasizekb =(uint_4) conf.IParam("dmasizekb",0,32);
207 NbFiles=conf.IParam("nbfiles",0,1);
208 NBlocPerFile=conf.IParam("nblocperfile",0,10);
209 AcqMode =conf.SParam("acqmode",0,"std");
210 nZones=(uint_4)conf.IParam("memmgr",0,4);
211 nPaqZone=(uint_4)conf.IParam("memmgr",1,128);
212 if (conf.HasKey("reducpaqsz")) { // reduction des tailles de paquets
213 fgreducpsize=true;
214 redpqsize=(uint_4)conf.IParam("reducpaqsz",0,PaqSize/4);
215 reducoffset=(uint_4)conf.IParam("reducpaqsz",1,0);
216 }
217 if (conf.HasKey("monitor")) {
218 fgdoProc=true;
219 nmeanProc=conf.IParam("monitor",0,512);
220 stepProc=conf.IParam("monitor",1,10);
221 nmaxProc=conf.IParam("monitor",2,0);
222 }
223 nopciLossRate=conf.DParam("nopcilossrate",0,0.);
224
225 fg_hard_ctrlc=conf.HasKey("hard_ctrlc");
226 if (conf.HasKey("nosavesigfits")) savesigfits=false;
227 Decode();
228}
229
230/* --Methode-- */
231void BRParList::Decode()
232{
233 vector<string> fiblist;
234 FillVStringFrString(FiberListS, fiblist, ',');
235 NbFibers=fiblist.size();
236 for (int fib=0; fib<fiblist.size(); fib++) {
237 FiberNum[fib]=atoi(fiblist[fib].c_str());
238 }
239 if (OutPathName == "/dev/null") {
240 fgnulldev4fits=true;
241 }
242 else {
243 size_t len = OutPathName.length();
244 if ((len>1)&&(OutPathName[len-1]!='/')) OutPathName+='/';
245 fgnulldev4fits=false;
246 }
247 string acqmode = AcqMode;
248 fgdatafft=false; fgsinglechannel=false;
249 reducneedcopy=false; pqreducmode=BR_TwoChanReduc;
250 if ((acqmode == "std")||(acqmode=="raw2c")) swapall = BR_Copy ;
251 if (acqmode == "nosw") swapall = BR_Copy ;
252 if (acqmode == "nof") { swapall = BR_Copy ; savesigfits = false; }
253 if (acqmode == "fft1c") { swapall = BR_FFTOneChan; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
254 if (acqmode == "fft2c") { swapall = BR_FFTTwoChan; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
255 if (acqmode == "fft1cnof")
256 { swapall = BR_FFTOneChan; savesigfits = false; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
257 if (acqmode == "fft2cnof")
258 { swapall = BR_FFTTwoChan; savesigfits = false; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
259 if (acqmode == "mono") { monothr = true; swapall = BR_Copy; }
260 if (acqmode == "monodirect") { monothr = true; swapall = BR_CopyHDR;}
261 if (acqmode == "patmonodirect") { monothr = true; swapall = BR_CopyHDR; activate_pattern=true; }
262 if (acqmode == "patmono") { monothr = true; swapall = BR_Copy; activate_pattern=true; }
263 if (acqmode == "patnof") { savesigfits = false; swapall = BR_Copy; activate_pattern=true; }
264 if (acqmode == "pattern") { savesigfits = true; swapall = BR_Copy; activate_pattern=true; }
265
266 if (acqmode == "swapall") swapall = BR_SwapAll;
267 if (acqmode == "fft1csw")
268 { swapall = BR_FFTOneChanSwapAll; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
269 if (acqmode == "fft2csw")
270 { swapall = BR_FFTTwoChanSwapAll; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
271 if (acqmode == "fft1cswnof")
272 { swapall = BR_FFTOneChanSwapAll; savesigfits = false; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
273 if (acqmode == "fft2cswnof")
274 { swapall = BR_FFTTwoChanSwapAll; savesigfits = false; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
275 if ((acqmode == "swh") || (acqmode == "mxs") || (acqmode == "monoswh") ) swapall = BR_SwapHDR;
276 if ((acqmode == "swapallnof") || (acqmode == "mxs") ) savesigfits = false;
277 if (acqmode == "monoswh") { monothr = true; swapall = BR_SwapHDR;; }
278 if (acqmode == "monosw") { monothr = true; swapall = BR_SwapAll; }
279
280 if (acqmode == "swap32") swapall = BR_Swap32 ;
281 if (acqmode == "nof32") { swapall = BR_Swap32 ; savesigfits = false; }
282 if (acqmode == "fft1c32")
283 { swapall = BR_FFTOneChanSwap32; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
284 if (acqmode == "fft2c32")
285 { swapall = BR_FFTTwoChanSwap32; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
286 if (acqmode == "fft1cnof32")
287 { swapall = BR_FFTOneChanSwap32; savesigfits = false; reducneedcopy=true; pqreducmode=BR_OneChanReducK0; }
288 if (acqmode == "fft2cnof32")
289 { swapall = BR_FFTTwoChanSwap32; savesigfits = false; reducneedcopy=true; pqreducmode=BR_TwoChanReducK0; }
290
291 if ((swapall==BR_FFTTwoChan)||(swapall==BR_FFTTwoChanSwapAll)||(swapall==BR_FFTTwoChanSwap32)) {
292 fgdatafft=true;
293 }
294 if ((swapall==BR_FFTOneChan)||(swapall==BR_FFTOneChanSwapAll)||(swapall==BR_FFTOneChanSwap32)) {
295 fgdatafft=true; fgsinglechannel=true;
296 }
297
298 if (fgreducpsize) {
299 if (redpqsize>=PaqSize) fgreducpsize=false;
300 else {
301 if(reducoffset>(PaqSize-redpqsize)/2) reducoffset=(PaqSize-redpqsize)/2;
302 }
303 }
304}
305
306/* --Methode-- */
307ostream& BRParList::Print(ostream& os)
308{
309 os << " ------ BRParList::Print() ----- " << endl;
310 os << " FiberListS=" << FiberListS ;
311 os << " PaqSize=" <<PaqSize;
312 os << " DMA_Size_kb=" <<dmasizekb << endl;
313 os << " AcqMode="<<AcqMode;
314 os << " Type of acquisition :" << BRPaquet::FmtConvToString( swapall) << endl;
315 os << " SkySource=" << skysource;
316 os << " NbFiles="<<NbFiles;
317 os << " NBlocPerFile="<<NBlocPerFile;
318 os << " OutPathName="<<OutPathName << endl;
319 os << " MemMgr: nZones="<<nZones;
320 os << " nPaqZone="<<nPaqZone<<endl;
321 if (fgreducpsize) {
322 os << " PaquetSize Reduction, ReducedSize=" << redpqsize << " Offset=" << reducoffset << endl;
323 }
324 if (fgdoProc>0)
325 os << " Monitoring NMeanProc=" << nmeanProc << " StepProc=" << stepProc << " NMaxProc=" << nmaxProc << endl;
326 else os << " No monotoring thread " << endl;
327 os << " fg_hard_ctrlc=" << ((fg_hard_ctrlc)?"true":"false");
328 os << " Save to fits " << ((savesigfits)?"true":"false") << endl;
329 os << " monothr y(1)/n(0) " << ((monothr)?"true":"false");
330 os << " ActivatePattern " << ((activate_pattern)?"true":"false") << endl;
331
332 return os;
333}
334
335
336//-------------------- Classe BRAcqConfig -----------------------
337
338BRParList* BRAcqConfig::param_=NULL;
339BRConfList* BRAcqConfig::config_=NULL;
340
341/* --Methode-- */
342BRAcqConfig::BRAcqConfig()
343{
344 if (param_==NULL) param_ = new BRParList;
345 if (config_==NULL) config_ = new BRConfList;
346}
347
348/* --Methode-- */
349ostream& BRAcqConfig::Print(ostream& os)
350{
351 os << " ------------ BAORadio Acq Run/Configuration -------- " << endl;
352 config_->Print(os);
353 param_->Print(os);
354 os << " ----------------------------------------------------- " << endl;
355}
356
357/* --Methode-- */
358int BRAcqConfig::CreateOutputDirectories()
359{
360 char cmd[1024];
361 if (param_->fgnulldev4fits!=true) {
362 sprintf(cmd,"mkdir %s%s",config_->BaseDirectory().c_str(), param_->OutPathName.c_str());
363 if (system(cmd) < 0) {
364 cout << "CreateOutputDirectories()/Error: Can not create subdirectory "
365 << cmd << " -> stop" << endl;
366 return 2;
367 }
368 cout << "CreateOutputDirectories() - Executed command " << cmd << endl;
369
370 memset(cmd,0,1024);
371 for (int i= 0; i< NFibers() ; i++) {
372 sprintf(cmd,"mkdir %s%s/Fiber%d",config_->BaseDirectory().c_str(), param_->OutPathName.c_str(),param_->FiberNum[i]);
373 if (system(cmd) < 0) {
374 cout << "CreateOutputDirectories()/Error: Can not create subdirectory "
375 << cmd << " -> stop" << endl;
376 return 3;
377 }
378 else cout << "CreateOutputDirectories() - Executed command " << cmd << endl;
379 }
380 }
381 else {
382 string ProcPathName = "./XZXZXZX/";
383 cout << " Using " << ProcPathName << " for other processed files ... " << endl;
384 char cmd[512];
385 sprintf(cmd,"mkdir %s",ProcPathName.c_str());
386 if (system(cmd) < 0) {
387 cout << "CreateOutputDirectories()/Error: Can not create subdirectory ./XZXZXZX/"
388 << "-> stop" << endl;
389 return 3;
390 }
391 else cout << "CreateOutputDirectories() - Executed command " << cmd << endl;
392 }
393 return 0;
394}
395
396/* --Methode-- */
397string BRAcqConfig::OutputDirectoryFib(int ifib)
398{
399 char buff[24];
400 sprintf(buff,"Fiber%d/",param_->FiberNum[ifib]);
401 return ( config_->BaseDirectory() + param_->OutPathName + buff );
402}
Note: See TracBrowser for help on using the repository browser.