source: Sophya/trunk/AddOn/TAcq/mfacq.cc@ 3698

Last change on this file since 3698 was 3683, checked in by ansari, 16 years ago

Mise a jour et ajout de fichier pour taritement multifibres apres

prise de donnees de Nov2009 a Pittsburgh

  • Introduction des classes BRMultiFitsReader et BRBaseProcessor Reza, 27/11/2009
File size: 6.4 KB
Line 
1#include "mfacq.h"
2
3//---------------------------------------------------------------
4// Programme d'acquisition BAORadio multi-fibres/multi-threads
5// LAL - 2009 - 2010
6// R. Ansari, M.Taurigna
7//---------------------------------------------------------------
8
9static RAcqMemZoneMgr* pMmgr=NULL;
10static PCIEMultiReader* pPcierThr=NULL;
11
12void Stop(int s)
13{
14 if (s == 9765) cout << " Stop after exception ..." << endl;
15 else printf("............. MAIN ... receive signal %d \n",s);
16 if (pMmgr != NULL) pMmgr->Stop();
17 if (pPcierThr !=NULL) pPcierThr->Stop();
18
19}
20
21
22//-----------------------------------------------------------------------
23//-------------------- le programme principal ---------------------------
24//-----------------------------------------------------------------------
25int main(int narg, char* arg[])
26{
27
28 int rc = 0;
29 cout << " ============= BAORadio / Acquisition : mfacq =================" << endl;
30 cout << " ===============================================================" << endl;
31 cout << " ========= " <<BAOR_ACQ_VER_STR <<BAOR_ACQ_VER << " ===========" << endl;
32 cout << " ===============================================================" << endl;
33
34
35 InitTim();
36
37 // Initialisation
38 TArrayInitiator _arri;
39 FitsIOServerInitiator _fiosi;
40
41
42 if ((narg < 2)||(strcmp(arg[1],"-h"))==0) {
43 Usage(false);
44 return 1;
45 }
46
47 string pardcfile=arg[1];
48#ifndef NOPCIECARD
49 string basedir="/Raid";
50#else
51 string basedir="./";
52#endif
53 if (narg>2) basedir=arg[2];
54 try {
55 // Creation/initialisation parametres Acq
56 BRAcqConfig acpar;
57 acpar.ReadParamFile(arg[1]);
58 acpar.GetConfig().SetBaseDirectory(basedir);
59 // Creation des repertoires
60 if (acpar.CreateOutputDirectories()!=0) return 9;
61 acpar.Print(cout);
62 struct sigaction act;
63 if (!acpar.GetParams().fg_hard_ctrlc) {
64 act.sa_handler=Stop;
65 sigaction(SIGINT,&act,NULL);
66 }
67 rc = MultiFibreAcq();
68 }
69 catch (MiniFITSException& exc) {
70 cerr << " mfacq.cc catched MiniFITSException " << exc.Msg() << endl;
71 rc = 77;
72 }
73 catch (PCIEWException& exc) {
74 cerr << " mfacq.cc catched PCIEWException " << exc.Msg() << endl;
75 rc = 75;
76 }
77 catch (PThrowable& exc) {
78 cerr << " mfacq.cc catched Exception " << exc.Msg() << endl;
79 rc = 76;
80 }
81 catch (std::exception& sex) {
82 cerr << "\n mfacq.cc std::exception :"
83 << (string)typeid(sex).name() << "\n msg= "
84 << sex.what() << endl;
85 rc = 78;
86 }
87 catch (...) {
88 cerr << " mfacq.cc : Catched ... exception " << endl;
89 rc = 79;
90 }
91 cout << "mfacq[9] ----- END --- stopping acq program " << endl;
92 return rc;
93}
94
95
96/* --Nouvelle-Fonction-- */
97void Usage(bool fgshort)
98{
99 if (fgshort) {
100 cout << " Usage: mfacq DataCardFile [BaseDirectory] \n" << endl;
101 cout << " Parameters in DataCard : \n"
102 << " fibres outpathname skysource paqsize dmasizekb nbfiles \n"
103 << " nblocperfile acqmode memmgr monitor reducpaqsz "<< endl;
104 cout << " BaseDirectory (default= /Raid ) " << endl;
105 return;
106 }
107 return;
108}
109
110
111/* --Nouvelle-Fonction-- */
112int MultiFibreAcq()
113{
114 Timer tm("mfacq/MultiFibre");
115 cout << " ---------- mfacq/ MultiFibreAcq() ------------- " << endl;
116 PCIEWrapperInterface* pciwp[4]={NULL,NULL,NULL,NULL};
117
118 BRAcqConfig bpar;
119 BRParList& acpar=bpar.GetParams();
120
121 cout << " mfacq[1]/Info: Creating RAcqMemZoneMgr for" << acpar.NbFibers << " fibers , nZones="
122 << acpar.nZones << " NbPaquet/Zone=" << acpar.nPaqZone
123 << " MmgrPaqSize=" << acpar.MMgrPaquetSize() << endl;
124 RAcqMemZoneMgr mmgr(acpar.nZones, bpar.NFibers(), acpar.nPaqZone, acpar.MMgrPaquetSize());
125 pMmgr=&mmgr;
126 if (acpar.fgdoProc && (acpar.stepProc>0)) {
127 // Dans ce cas, toutes les zones doivent passer ds le thread de monitoring
128 // pour etre au moins marque comme traite - seul 1/acpar.stepProc sont effectivement traite
129 mmgr.SetFinalizedMask(((uint_4)MemZS_Saved) | ((uint_4)MemZS_Proc));
130 cout << " mfacq[1.b]/Info: Mmgr.SetFinalizedMask( MemZS_Saved | MemZS_Proc )" << endl;
131 }
132
133#ifndef NOPCIECARD
134 for (int i=0 ;i <acpar.NFibers() ;i++) {
135 UINT32 card=(acpar.FiberNum[i]-1)/2+1;
136 UINT32 cardfiber=(acpar.FiberNum[i]-1)%2;
137 cout <<"mfacq[2] CreatePCIEWrapperV6- indice " << i << "INIT card " << card
138 << " fibre " << cardfiber << endl;
139 pciwp[i] = CreatePCIEWrapperV6(card,acpar.PatternSize(),acpar.DMASizeBytes(),acpar.activate_pattern,cardfiber);
140 }
141#else
142 TestPCIWrapperNODMA pciw1(bpar.RecvPaquetSize(), acpar.nopciLossRate);
143 TestPCIWrapperNODMA pciw2(bpar.RecvPaquetSize(), acpar.nopciLossRate);
144 TestPCIWrapperNODMA pciw3(bpar.RecvPaquetSize(), acpar.nopciLossRate);
145 TestPCIWrapperNODMA pciw4(bpar.RecvPaquetSize(), acpar.nopciLossRate);
146 pciwp[0] = &pciw1;
147 pciwp[1] = &pciw2;
148 pciwp[2] = &pciw3;
149 pciwp[3] = &pciw4;
150#endif
151
152 cout <<"mfacq[2] Creating MultiDataSaver and MonitorProc thread objects ... " << endl;
153 MultiDataSaver DsThr(mmgr); // Utilise les parametres globaux BRAcqConfig
154 string ppath=bpar.OutputDirectory();
155 MonitorProc PrThr(mmgr);
156 vector<PCIEWrapperInterface*> vec_pciw;
157 for (int i=0 ;i<bpar.NFibers();i++) vec_pciw.push_back( pciwp[i]);
158 cout << "mfacq[3] Creating PCIEMultiReader thread object " << endl;
159 PCIEMultiReader PcierThr(vec_pciw, mmgr, bpar.GetParams());
160 // usleep(200); attente au cas ou ...
161 pPcierThr=&PcierThr;
162 tm.Split("Threads created");
163 if (acpar.fgdoProc>0)
164 cout << "mfacq[4] - starting three threads: PCIEMultiReader, MultiDataSaver, MonitorProc ... " << endl;
165 else
166 cout << "mfacq[4] - starting two threads: PCIEMultiReader, MultiDataSaver ... " << endl;
167
168 PcierThr.start();
169 DsThr.start();
170 if (acpar.fgdoProc>0) { // On ne demarre que si au moins NMaxProc>0
171 PrThr.start();
172 }
173
174 // On attend avant de declencher la terminaison des threads
175 usleep(200000);
176
177 cout << "mfacq[5] - Waiting for threads to finish ... " << endl;
178 PcierThr.join();
179 DsThr.join();
180 mmgr.Stop();
181 if (acpar.fgdoProc) { // On n'attend la fin que si le thread a ete demarre (NMaxProc>0)
182 PrThr.join();
183 }
184 pMmgr=NULL;
185 cout << "mfacq[6] ---------- threads finished ---------------- " << endl;
186 tm.Split("Threads Finished");
187
188 mmgr.Print(cout);
189#ifndef NOPCIECARD
190 for (int i=0 ;i <acpar.NbFibers ;i++) {
191 UINT32 card=(acpar.FiberNum[i]-1)/2+1;
192 UINT32 cardfiber=(acpar.FiberNum[i]-1)%2;
193 DeletePCIEWrapperV6(card,cardfiber);
194 }
195#endif
196return 0;
197
198}
Note: See TracBrowser for help on using the repository browser.