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 |
|
---|
9 | static RAcqMemZoneMgr* pMmgr=NULL;
|
---|
10 | static PCIEMultiReader* pPcierThr=NULL;
|
---|
11 |
|
---|
12 | void 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 | //-----------------------------------------------------------------------
|
---|
25 | int 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 |
|
---|
48 | try {
|
---|
49 | // Creation/initialisation parametres Acq
|
---|
50 | BRAcqConfig acpar;
|
---|
51 | acpar.ReadDCFile(arg[1]);
|
---|
52 | // Creation des repertoires
|
---|
53 | if (acpar.CreateOutputDirectories()!=0) return 9;
|
---|
54 | acpar.Print(cout);
|
---|
55 | struct sigaction act;
|
---|
56 | if (!acpar.GetParams().fg_hard_ctrlc) {
|
---|
57 | act.sa_handler=Stop;
|
---|
58 | sigaction(SIGINT,&act,NULL);
|
---|
59 | }
|
---|
60 | rc = MultiFibreAcq();
|
---|
61 | }
|
---|
62 | catch (MiniFITSException& exc) {
|
---|
63 | cerr << " mfacq.cc catched MiniFITSException " << exc.Msg() << endl;
|
---|
64 | rc = 77;
|
---|
65 | }
|
---|
66 | catch (PCIEWException& exc) {
|
---|
67 | cerr << " mfacq.cc catched MiniFITSException " << exc.Msg() << endl;
|
---|
68 | rc = 75;
|
---|
69 | }
|
---|
70 | catch (PThrowable& exc) {
|
---|
71 | cerr << " mfacq.cc catched Exception " << exc.Msg() << endl;
|
---|
72 | rc = 76;
|
---|
73 | }
|
---|
74 | catch (std::exception& sex) {
|
---|
75 | cerr << "\n mfacq.cc std::exception :"
|
---|
76 | << (string)typeid(sex).name() << "\n msg= "
|
---|
77 | << sex.what() << endl;
|
---|
78 | rc = 78;
|
---|
79 | }
|
---|
80 | catch (...) {
|
---|
81 | cerr << " mfacq.cc : Catched ... exception " << endl;
|
---|
82 | rc = 79;
|
---|
83 | }
|
---|
84 | cout << "mfacq[9] ----- END --- stopping acq program " << endl;
|
---|
85 | return rc;
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | /* --Nouvelle-Fonction-- */
|
---|
90 | void Usage(bool fgshort)
|
---|
91 | {
|
---|
92 | if (fgshort) {
|
---|
93 | cout << " Usage: mfacq DataCardFile \n" << endl;
|
---|
94 | cout << "parameter in DataCard :Fibres PaquetSize NFrameDMA NFiles NBlocPerFile \n"
|
---|
95 | << " NMaxProc DataDirPath acqmode nZones nPaqZones fg_hard_ctrlc" << endl;
|
---|
96 | cout << " type mfacq -h for detailed usage " << endl;
|
---|
97 | return;
|
---|
98 | }
|
---|
99 | return;
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | /* --Nouvelle-Fonction-- */
|
---|
104 | int MultiFibreAcq()
|
---|
105 | {
|
---|
106 | Timer tm("mfacq/MultiFibre");
|
---|
107 | cout << " ---------- mfacq/ MultiFibreAcq() ------------- " << endl;
|
---|
108 | PCIEWrapperInterface* pciwp[4]={NULL,NULL,NULL,NULL};
|
---|
109 |
|
---|
110 | BRAcqConfig bpar;
|
---|
111 | BRParList& acpar=bpar.GetParams();
|
---|
112 |
|
---|
113 | cout << " mfacq[1]/Info: Creating RAcqMemZoneMgr for" << acpar.NbFibers << " fibers , nZones="
|
---|
114 | << acpar.nZones << " NbPaquet/Zone=" << acpar.nPaqZone
|
---|
115 | << " mmgrPaqSize=" << acpar.MMgrPaquetSize() << endl;
|
---|
116 | RAcqMemZoneMgr mmgr(acpar.nZones, bpar.NFibers(), acpar.nPaqZone, acpar.MMgrPaquetSize());
|
---|
117 | pMmgr=&mmgr;
|
---|
118 | int stepproc = 2;
|
---|
119 | int nmean = acpar.nPaqZone*acpar.NBlocPerFile/stepproc;
|
---|
120 |
|
---|
121 | #ifndef NOPCIECARD
|
---|
122 | for (int i=0 ;i <acpar.NFibers() ;i++) {
|
---|
123 | UINT32 card=(acpar.FiberNum[i]-1)/2+1;
|
---|
124 | UINT32 cardfiber=(acpar.FiberNum[i]-1)%2
|
---|
125 | cout <<"mfacq[2] CreatePCIEWrapperV6- indice " << i << "INIT card " << card
|
---|
126 | << " fibre " << cardfiber << endl;
|
---|
127 | pciwp[i] = CreatePCIEWrapperV6(card,patternSZ,dmaSize,activate_pattern,cardfiber);
|
---|
128 | }
|
---|
129 | #else
|
---|
130 | TestPCIWrapperNODMA pciw1(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
131 | TestPCIWrapperNODMA pciw2(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
132 | TestPCIWrapperNODMA pciw3(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
133 | TestPCIWrapperNODMA pciw4(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
134 | pciwp[0] = &pciw1;
|
---|
135 | pciwp[1] = &pciw2;
|
---|
136 | pciwp[2] = &pciw3;
|
---|
137 | pciwp[3] = &pciw4;
|
---|
138 | #endif
|
---|
139 |
|
---|
140 | cout <<"mfacq[3] Creating DataSaver and DataProc2C objects ... " << endl;
|
---|
141 | MultiDataSaver DsThr(mmgr, bpar.OutputDirectory(), bpar.MaxNbFiles(),
|
---|
142 | bpar.BlocPerFile(), bpar.GetSaveFits());
|
---|
143 | string ppath=bpar.OutputDirectory();
|
---|
144 | DataProc2C PrThr(mmgr, ppath, 1280, stepproc, acpar.NMaxProc);
|
---|
145 | vector<PCIEWrapperInterface*> vec_pciw;
|
---|
146 | for (int i=0 ;i<bpar.NFibers();i++) vec_pciw.push_back( pciwp[i]);
|
---|
147 | cout << "mfacq[3] Creating PCIEMultiReader " << endl;
|
---|
148 | PCIEMultiReader PcierThr(vec_pciw,bpar.DMASizeBytes(),bpar.RecvPaquetSize(),
|
---|
149 | mmgr, bpar.MaxNbBlocs(), bpar.GetDataConvFg());
|
---|
150 | usleep(200); // attente au cas ou ...
|
---|
151 | pPcierThr=&PcierThr;
|
---|
152 | tm.Split("Threads created");
|
---|
153 | cout << "mfacq[4] - starting 3 threads pcir, ds, pr ... " << endl;
|
---|
154 | PcierThr.start();
|
---|
155 | DsThr.start();
|
---|
156 | if (acpar.NMaxProc>0) { // On ne demarre que si au moins NMaxProc>0
|
---|
157 | PrThr.start();
|
---|
158 | }
|
---|
159 |
|
---|
160 | // On attend avant de declencher la terminaison des threads
|
---|
161 | usleep(100000);
|
---|
162 |
|
---|
163 | cout << "mfacq[5] - Waiting for threads to finish ... " << endl;
|
---|
164 | PcierThr.join();
|
---|
165 | DsThr.join();
|
---|
166 | mmgr.Stop();
|
---|
167 | if (acpar.NMaxProc>0) { // On ne demarre que si au moins NMaxProc>0
|
---|
168 | PrThr.join();
|
---|
169 | }
|
---|
170 | pMmgr=NULL;
|
---|
171 | cout << "mfacq[6] ---------- threads finished ---------------- " << endl;
|
---|
172 | tm.Split("Threads Finished");
|
---|
173 |
|
---|
174 | #ifndef NOPCIECARD
|
---|
175 | for (int i=0 ;i <acpar.NbFibers ;i++) {
|
---|
176 | UINT32 card=(acpar.FiberNum[i]-1)/2+1;
|
---|
177 | UINT32 cardfiber=(acpar.FiberNum[i]-1)%2;
|
---|
178 | DeletePCIEWrapperV6(card,cardfiber);
|
---|
179 | }
|
---|
180 | #endif
|
---|
181 | return 0;
|
---|
182 |
|
---|
183 | }
|
---|