source: Sophya/trunk/AddOn/TAcq/racqurw.cc@ 3610

Last change on this file since 3610 was 3538, checked in by ansari, 17 years ago

This commit was generated by cvs2svn to compensate for changes in r3537,
which included commits to RCS files with non-trunk default branches.

File size: 3.2 KB
RevLine 
[3537]1//----------------------------------------------------------------
2// ---- classes de threads pour lecture (transfert DMA)
3// et ecriture disque pour acquisition BAORadio -----
4// LAL - R. Ansari - Juin/Juillet 2008
5//----------------------------------------------------------------
6
7#include "racqurw.h"
8
9#include <stdlib.h>
10#include <unistd.h>
11#include <fstream>
12
13#include "pexceptions.h"
14#include "timestamp.h"
15
16
17#include "pciewrap.h"
18#include "brpaqu.h"
19#include "minifits.h"
20
21
22//-------------------------------------------------------
23// Classe thread de lecture PCI-Express
24//-------------------------------------------------------
25
26PCIEReader::PCIEReader(RAcqMemZoneMgr& mem, uint_4 nmax)
27 : memgr(mem)
28{
29 nmax_ = nmax;
30 stop_ = false;
31}
32
33void PCIEReader::run()
34{
35 cout << " PCIEReader::run() - Starting , NMaxMemZones=" << nmax_ << endl;
36 setRC(1);
37 PCIEWrapper pciw;
38 uint_4 paqsz = memgr.PaqSize();
39 for (uint_4 kmz=0; kmz<nmax_; kmz++) {
40 int mid = memgr.FindMemZoneId(MemZA_Fill);
41 Byte* buff = memgr.GetMemZone(mid);
42 if (buff == NULL) {
43 cout << " PCIEReader::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
44 setRC(2);
45 return;
46 }
47 for(uint_4 i=0; i<memgr.NbPaquets(); i++) {
48 while(pciw.NBytesToRead() < 1) usleep(5);
49 pciw.Read(buff+i*paqsz,paqsz);
50 }
51 memgr.FreeMemZone(mid, MemZS_Filled);
52 }
53 setRC(0);
54 return;
55}
56
57
58
59//-------------------------------------------------------
60// Classe thread de sauvegarde sur fichiers
61//-------------------------------------------------------
62
63DataSaver::DataSaver(RAcqMemZoneMgr& mem, string& path, uint_4 nmax)
64 : memgr(mem)
65{
66 nmax_ = nmax;
67 stop_ = false;
68 path_ = path;
69}
70
71void DataSaver::run()
72{
73 setRC(1);
74 try {
75 TimeStamp ts;
76 cout << " DataSaver::run() - Starting " << ts << " NMaxMemZones=" << nmax_ << endl;
77 char fname[512];
78 sprintf(fname,"%s/saver.log",path_.c_str());
79 ofstream filog(fname);
80 filog << " DataProc::run() - starting log file " << ts << endl;
81
82 uint_4 paqsz = memgr.PaqSize();
83 for (uint_4 kmz=0; kmz<nmax_; kmz++) {
84 int mid = memgr.FindMemZoneId(MemZA_Save);
85 Byte* buff = memgr.GetMemZone(mid);
86 if (buff == NULL) {
87 cout << " DataSaver::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
88 setRC(2);
89 return;
90 }
91 sprintf(fname,"%s/signal%d.fits",path_.c_str(),(int)kmz);
92 MiniFITSFile mff(fname,MF_Write);
93 BRPaquet paq0(NULL, buff, paqsz);
94 mff.setDTypeNaxis(MF_Byte, paq0.DataSize(), memgr.NbPaquets());
95 for(uint_4 i=0; i<memgr.NbPaquets(); i++) {
96 BRPaquet paq(NULL, buff+i*paqsz, paqsz);
97 mff.WriteB(paq.Data(), paq.DataSize());
98 }
99 filog << ts << " : created data file " << fname << endl;
100 cout << " DataSaver::run() " << ts << " : created data file " << fname << endl;
101 memgr.FreeMemZone(mid, MemZS_Saved);
102 }
103 }
104 catch (MiniFITSException& exc) {
105 cout << " DataSaver::run()/catched MiniFITSException " << exc.Msg() << endl;
106 setRC(3);
107 return;
108 }
109 catch(...) {
110 cout << " DataSaver::run()/catched unknown ... exception " << endl;
111 setRC(4);
112 return;
113 }
114 setRC(0);
115 return;
116}
117
118
Note: See TracBrowser for help on using the repository browser.