1 | //----------------------------------------------------------------
|
---|
2 | // ---- classes de threads pour lecture fichiers minifits
|
---|
3 | // LAL - R. Ansari - Mai 2009
|
---|
4 | //----------------------------------------------------------------
|
---|
5 |
|
---|
6 |
|
---|
7 | #include "brfitsrd.h"
|
---|
8 |
|
---|
9 | #include <stdlib.h>
|
---|
10 | #include <unistd.h>
|
---|
11 | #include <fstream>
|
---|
12 | #include <signal.h>
|
---|
13 | #include "pexceptions.h"
|
---|
14 | #include "timestamp.h"
|
---|
15 | #include "ctimer.h"
|
---|
16 |
|
---|
17 | #include "brpaqu.h"
|
---|
18 | #include "minifits.h"
|
---|
19 |
|
---|
20 | #include "resusage.h" // Pour mesure temps elapsed/CPU ...
|
---|
21 | #include "datatable.h" // Pour sauver les entetes de paquet
|
---|
22 | #include <sys/time.h> // pour gettimeofday
|
---|
23 |
|
---|
24 | //-------------------------------------------------------
|
---|
25 | // Classe thread de sauvegarde sur fichiers
|
---|
26 | //-------------------------------------------------------
|
---|
27 |
|
---|
28 | BRFitsReader::BRFitsReader(RAcqMemZoneMgr& mem, vector<string>& infiles, bool fgnotrl)
|
---|
29 | : memgr(mem), infiles_(infiles), fgnotrl_(fgnotrl)
|
---|
30 | {
|
---|
31 | }
|
---|
32 | void BRFitsReader::Stop()
|
---|
33 | {
|
---|
34 | // cout<< " BRFitsReader:Stop ........ " << endl;
|
---|
35 | stop_=true;
|
---|
36 | }
|
---|
37 | void BRFitsReader::run()
|
---|
38 | {
|
---|
39 | setRC(1);
|
---|
40 | BRPaqChecker pcheck; // Verification/comptage des paquets
|
---|
41 |
|
---|
42 | try {
|
---|
43 | TimeStamp ts;
|
---|
44 | Timer tm("BRFitsReader");
|
---|
45 | size_t totnbytesrd = 0;
|
---|
46 | cout << " BRFitsReader::run() - Starting " << ts << " NbFiles=" << infiles_.size()
|
---|
47 | << " memgr.PaqSize() = " << memgr.PaqSize() << endl;
|
---|
48 |
|
---|
49 | uint_4 nfileok = 0;
|
---|
50 | uint_8 nbytesrd = 0;
|
---|
51 | for(int ifile=0; ifile<infiles_.size(); ifile++) {
|
---|
52 | string ffname = infiles_[ifile];
|
---|
53 | // -------------- Lecture de bytes
|
---|
54 | cout << "BRFitsReader::run() [" << ifile <<"]Ouverture/lecture fichier " << ffname << endl;
|
---|
55 | MiniFITSFile mff(ffname, MF_Read);
|
---|
56 | cout << "... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1()
|
---|
57 | << " NAxis2=" << mff.NAxis2() << endl;
|
---|
58 | if (mff.DataType() != MF_Byte) {
|
---|
59 | cout << "BRFitsReader::run() PB : DataType!=MF_Byte --> skipping " << endl;
|
---|
60 | continue;
|
---|
61 | }
|
---|
62 | // Les fichier FITS contiennent l'entet (24 bytes), mais pas le trailer (16 bytes) si fgnotrl=true
|
---|
63 | int incpaqsz=0;
|
---|
64 | int paqsz = 0;
|
---|
65 | if (fgnotrl_) {
|
---|
66 | incpaqsz=16;
|
---|
67 | cout << " Warning : FITS files without frame trailers ..." << endl;
|
---|
68 | }
|
---|
69 | if (paqsz == 0) { // premier passage, on fixe la taille de paquet et on alloue le buffer
|
---|
70 | paqsz = mff.NAxis1()+incpaqsz;
|
---|
71 | if (paqsz != memgr.PaqSize()) {
|
---|
72 | cout << "BRFitsReader::run() mff.NAxis1() incompatible with memgr.PaqSize() -> exception " << endl;
|
---|
73 | throw SzMismatchError(" fits file size incompatible with memgr.PaqSize()");
|
---|
74 | }
|
---|
75 | if (mff.NAxis2() != memgr.NbPaquets()) {
|
---|
76 | cout << "BRFitsReader::run() mff.NAxis2() <> memgr.NbPaquets() -> exception " << endl;
|
---|
77 | throw SzMismatchError(" fits file NAxies2() <> memgr.NbPaquets()");
|
---|
78 | }
|
---|
79 | }
|
---|
80 | else {
|
---|
81 | if (paqsz != mff.NAxis1()+incpaqsz) {
|
---|
82 | cout << " PB : paqsz=" << paqsz << " != mff.NAxis1()+" << incpaqsz << " --> skipping " << endl;
|
---|
83 | continue;
|
---|
84 | }
|
---|
85 | if (memgr.NbPaquets() != mff.NAxis2()) {
|
---|
86 | cout << " PB memgr.NbPaquets() != mff.NAxis2() --> skipping " << endl;
|
---|
87 | continue;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | int mid = memgr.FindMemZoneId(MemZA_Fill);
|
---|
91 | Byte* buff = memgr.GetMemZone(mid);
|
---|
92 | if (buff == NULL) {
|
---|
93 | cout << " BRFitsReader::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
|
---|
94 | setRC(2);
|
---|
95 | return;
|
---|
96 | }
|
---|
97 | size_t sx = mff.NAxis1();
|
---|
98 | size_t sy = mff.NAxis2();
|
---|
99 |
|
---|
100 | for(int j=0; j<mff.NAxis2(); j++) {
|
---|
101 | mff.ReadB(buff+j*paqsz, sx, j*sx);
|
---|
102 | BRPaquet paq(NULL, buff+j*paqsz, paqsz);
|
---|
103 | pcheck.Check(paq); // Verification du paquet / FrameCounter
|
---|
104 |
|
---|
105 | }
|
---|
106 | nfileok++;
|
---|
107 | size_t nbytesrd = sx*sy;
|
---|
108 | totnbytesrd += nbytesrd;
|
---|
109 | memgr.FreeMemZone(mid, MemZS_Filled);
|
---|
110 | } // Fin de la boucle sur les fichiers
|
---|
111 |
|
---|
112 |
|
---|
113 | // sprintf(fname,"%s/.log",path_.c_str());
|
---|
114 | // ofstream filog(fname);
|
---|
115 | // filog << " DataProc::run() - starting log file " << ts << endl;
|
---|
116 | // filog << " NbFiles=" << nfiles_ << " NBloc/File=" << nblocperfile_ << " NMaxMemZones=" << nmax_ << endl;
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 | cout << " ------------------ BRFitsReader::run() END ----------------- " << endl;
|
---|
121 | ts.SetNow();
|
---|
122 | tm.Split();
|
---|
123 | cout << " END reading " << ts << " NFileOK=" << nfileok << endl;
|
---|
124 | cout << " TotalDiskRead= " << totnbytesrd/(1024*1024) << " MBytes Disk-Read rate= "
|
---|
125 | << (double)(totnbytesrd)/1024./tm.PartialElapsedTimems() << " MB/s" << endl;
|
---|
126 | pcheck.Print(cout);
|
---|
127 | cout << " ---------------------------------------------------------- " << endl;
|
---|
128 |
|
---|
129 | } // Fin du bloc try
|
---|
130 | catch (MiniFITSException& exc) {
|
---|
131 | cout << " BRFitsReader::run()/catched MiniFITSException " << exc.Msg() << endl;
|
---|
132 | setRC(3);
|
---|
133 | return;
|
---|
134 | }
|
---|
135 | catch(...) {
|
---|
136 | cout << " BRFitsReader::run()/catched unknown ... exception " << endl;
|
---|
137 | setRC(4);
|
---|
138 | return;
|
---|
139 | }
|
---|
140 | setRC(0);
|
---|
141 | return;
|
---|
142 | }
|
---|