source: Sophya/trunk/ArchTOIPipe/Kernel/fitstoirdr.cc@ 1689

Last change on this file since 1689 was 1629, checked in by ansari, 24 years ago
  • Ajout pthread_exit apres l'execution de run() ds TOIProcessor::ThreadStart()
  • Ajout de la classe ProcSampleCounter<T> pour affichage continu de stats ds toimanager.h .cc
  • correction mineure de toi2map.cc
  • Utilisation de ProcSampleCounter<T> ds tsttoi2map.cc et simtst.cc

Reza 8/8/2001

File size: 4.0 KB
Line 
1#include "fitstoirdr.h"
2#include "toimanager.h"
3
4
5
6FITSTOIReader::FITSTOIReader(string fn) {
7 fname = fn;
8 allfn.push_back(fn);
9 cout << "FITSTOIReader::FITSTOIReader" << endl;
10 cout << "FITSTOIReader::inited " << inited << endl;
11 name = "rdr";
12 fptr = NULL;
13 totnscount = 0;
14}
15
16FITSTOIReader::~FITSTOIReader() {
17}
18
19pthread_mutex_t fits_mutex = PTHREAD_MUTEX_INITIALIZER;
20void fits_lock();
21void fits_unlock();
22
23void fits_lock() {
24 pthread_mutex_lock(&fits_mutex);
25}
26void fits_unlock() {
27 pthread_mutex_unlock(&fits_mutex);
28}
29
30void FITSTOIReader::openFile(string fn) {
31 fits_lock();
32 if (fptr) {
33 fits_close_file(fptr,&fstatus);
34 fptr = NULL;
35 }
36 fname = fn;
37 cout << "FITSTOIReader::open FileName=" << fname << endl;
38 fstatus = 0;
39 // Open file
40 fits_open_file(&fptr,fname.c_str(),READONLY,&fstatus);
41 if (fstatus != 0) {
42 fits_report_error(stderr, fstatus);
43 fits_unlock();
44 exit (-1);
45 }
46
47 // Go to first extension, which should be a BINTABLE
48
49 int simple, bitpix, naxis;
50 long naxes;
51 long pcount, gcount;
52 int extend;
53 fits_read_imghdr(fptr, 1, &simple, &bitpix,
54 &naxis, &naxes, &pcount, &gcount, &extend, &fstatus);
55
56 fits_movabs_hdu(fptr, 2, NULL, &fstatus);
57
58 fits_get_num_cols(fptr,&ncols,&fstatus);
59 fits_get_num_rows(fptr,&nrows,&fstatus);
60
61 cout << "FITSTOIReader cols = " << ncols << " rows=" << nrows << endl;
62 int anyNul;
63 double y;
64 fits_read_col_dbl(fptr,1,1,1,1,0,&y,&anyNul,&fstatus);
65 firstSn = (int) (y+.1);
66 fits_unlock();
67}
68
69void FITSTOIReader::init() {
70 openFile(allfn.front());
71
72 fits_lock();
73 // Dans cette version, on s'attend a ce que la premiere colonne soit le samplenum
74 int itoi=-1;
75 for (int i=1; i<ncols; i++) {
76 char templt[10];
77 sprintf(templt, "%d", i+1);
78 char colname[200];
79 int colnum;
80 fits_get_colname(fptr, CASESEN, templt, colname, &colnum, &fstatus);
81 cout << "FITSTOIReader col " << colname << endl;
82 if (!strncmp(colname, "fg_", 3)) {
83 colsinput[itoi].second=true;
84 } else {
85 declareOutput(colname);
86 itoi++;
87 colsinput[itoi] = pair<int,bool>(i,false);
88 }
89 }
90 fits_unlock();
91
92 snBegin = firstSn;
93
94 openFile(allfn.back());
95 snEnd = firstSn+nrows-1;
96 cout << "FITSTOIReader range " << snBegin << " -> " << snEnd << endl;
97}
98
99int FITSTOIReader::calcMinOut() {
100 TOIManager* mgr = TOIManager::getManager();
101 int firstReq = mgr->getRequestedBegin();
102 return snBegin > firstReq ? snBegin : firstReq;
103}
104
105int FITSTOIReader::calcMaxOut() {
106 TOIManager* mgr = TOIManager::getManager();
107 int lastReq = mgr->getRequestedEnd();
108 return snEnd < lastReq ? snEnd : lastReq;
109}
110
111void FITSTOIReader::addFile(string fn) {
112 allfn.push_back(fn);
113}
114
115void FITSTOIReader::run() {
116 for (vector<string>::iterator i=allfn.begin(); i!=allfn.end(); i++) {
117 openFile(*i);
118 run1();
119 }
120}
121
122void FITSTOIReader::run1() {
123 // Il faudrait optimiser en fonction de ce qui a ete demande comme samplenum,
124 // mais cela implique de gerer aussi bien echant uniforme que non.
125 // On pourrait aussi lire plusieurs elements d'un coup.
126 int ncols = outIx.size();
127 cout << "reader reading... NRows=" << nrows << " firstSn= "
128 << firstSn << endl;
129
130 for (int i=0; i<nrows; i++) {
131 int anyNul;
132 double y;
133 fits_lock();
134 fits_read_col_dbl(fptr,1,i+1,1,1,0,&y,&anyNul,&fstatus);
135 fits_unlock();
136 int sn = (int) (y+.1);
137 TOIManager* mgr = TOIManager::getManager();
138 if (sn > mgr->getRequestedEnd()) break;
139 if (sn < mgr->getRequestedBegin()) continue;
140 // if (sn < mgr->getRequestedBegin()+10) cout << "rdr out " << sn << endl;
141 for (int k=0; k<getNOut(); k++) {
142 int j = colsinput[k].first;
143 if ( !checkOutputTOIIndex(k) ) continue; // Reza - Si TOI non connecte
144 fits_lock();
145 fits_read_col_dbl(fptr,j+1,i+1,1,1,0,&y,&anyNul,&fstatus);
146 long flg = 0;
147 if (colsinput[k].second) {
148 fits_read_col_lng(fptr,j+2,i+1,1,1,0,&flg,&anyNul,&fstatus);
149 }
150 fits_unlock();
151 putData(k, sn, y, flg);
152 }
153 totnscount++;
154 }
155 cout << "reader done reading... " << pthread_self() << endl;
156}
Note: See TracBrowser for help on using the repository browser.