source: Sophya/trunk/Poubelle/archTOI.old/toiiter.cc@ 555

Last change on this file since 555 was 555, checked in by ansari, 26 years ago

portage cxx en cours

File size: 8.2 KB
Line 
1// toiiter.cc
2// Eric Aubourg CEA/DAPNIA/SPP juillet 1999
3
4#include "ark.h"
5
6#include "toiiter.h"
7#include "toimanager.h"
8#include "toiproducer.h"
9#include "archparam.h"
10#include "asigps.h"
11#include "toiauxgpsproducer.h"
12#include <iostream.h>
13#include <fstream.h>
14
15#define CHK_INITED if (initDone) \
16 throw ArchExc("Trying to modify TOIIter after init done.");
17
18TOIIter::TOIIter() {
19 mjdStart = -999999999;
20 mjdEnd = 999999999;
21 utcStart = -999999999;
22 utcEnd = 999999999;
23 sStart = -999999999;
24 sEnd = 999999999;
25
26 underSample = 1;
27 curSample = -1;
28
29 initDone = false;
30 incDone = false;
31}
32
33#ifdef __MWERKS__
34#pragma mark -
35#endif
36
37void TOIIter::addDirectory(string dir) {
38 CHK_INITED
39 fset.addDirectory(dir);
40}
41
42void TOIIter::addFile(string fn) {
43 CHK_INITED
44 fset.addFile(fn);
45}
46
47void TOIIter::setMJDInterval(double tStart, double tEnd) {
48 CHK_INITED
49 if (tStart>0) mjdStart = tStart;
50 if (tEnd>0) mjdEnd = tEnd;
51}
52
53void TOIIter::setUTCInterval(double tStart, double tEnd) {
54 CHK_INITED
55 if (tStart>0) utcStart = tStart;
56 if (tEnd>0) utcEnd = tEnd;
57}
58
59void TOIIter::setSNInterval(long tStart, long tEnd) {
60 CHK_INITED
61 if (tStart>0) sStart = tStart;
62 if (tEnd>0) sEnd = tEnd;
63}
64
65void TOIIter::setUnderSample(int n) {
66 CHK_INITED
67 if (n<=1) n=1;
68 underSample = n;
69}
70
71int TOIIter::getUnderSample() {
72 return underSample;
73}
74
75void TOIIter::addTOI(TOI& toi, bool trg) {
76 CHK_INITED
77 TOIProducer* prod = TOIManager::findTOIProducer(toi);
78 if (!prod) throw ArchExc("Cannot produce " + toi.fullName());
79 prod->addTOI(toi, this);
80 request.push_back(TOIInfo(toi,prod,trg?1:0));
81}
82
83#ifdef __MWERKS__
84#pragma mark -
85#endif
86
87
88void TOIIter::registerReqHandler(RequestHandler* h) {
89 CHK_INITED
90 handlers.push_back(h);
91}
92
93
94void TOIIter::readReq(istream& str) {
95 CHK_INITED
96 if (!incDone) defaultInclude();
97 string line;
98 while (str) {
99 getline(str,line);
100 if (!str) break;
101 if (line.substr(0,4)=="#END" && (line.length()==4 || line[5] == ' ')) break;
102 if (line[0] != '@' && line[0] != '#') continue;
103 if (!processRequest(line)) {
104 throw ArchExc("Unrecognized directive " + line);
105 }
106 }
107}
108
109
110bool TOIIter::processRequest(string line) {
111 if (line[0] == '#') {
112 int x = line.find(' ');
113 string keyw = line.substr(0, x);
114 string args = (x>0) ? line.substr(x) : string("");
115 bool handled = processOption(keyw,args);
116 for (list<RequestHandler*>::iterator i = handlers.begin();
117 i != handlers.end(); i++) {
118 handled |= (*i)->processOption(keyw,args);
119 }
120 return handled;
121 }
122
123 if (line[0] == '@') {
124 TOI toi(line.substr(1));
125 // if (kind == sampleNum || kind == mjd || kind == mutc) notrig = true;
126 bool handled = processTOIReq(toi,line);
127 for (list<RequestHandler*>::iterator i = handlers.begin();
128 i != handlers.end(); i++) {
129 handled |= (*i)->processTOIReq(toi,line);
130 }
131 return handled;
132 }
133 return false;
134}
135
136
137bool TOIIter::processTOIReq(TOI& toi,string)
138{
139 TOI toi2 = toi;
140 bool trg=true;
141 if (toi.options.find("notrig") != toi.options.end()) {
142 toi2.options.erase("notrig");
143 trg=false;
144 }
145 addTOI(toi2, trg);
146 toi.unit = toi2.unit;
147 return true;
148}
149
150
151bool TOIIter::processOption(string key, string arg)
152{
153 if (arg.length()>0 && arg[0] == ' ') {
154 arg = arg.substr(arg.find_first_not_of(' '));
155 }
156 if (key == "#MJDRANGE") {
157 double tmin, tmax;
158 sscanf(arg.c_str(), "%lg %lg", &tmin, &tmax);
159 setMJDInterval(tmin, tmax);
160 } else if (key == "#UTCRANGE") {
161 double tmin, tmax;
162 sscanf(arg.c_str(), "%lg %lg", &tmin, &tmax);
163 setUTCInterval(tmin, tmax);
164 } else if (key == "#SNRANGE") {
165 long tmin, tmax;
166 sscanf(arg.c_str(), "%ld %ld", &tmin, &tmax);
167 setSNInterval(tmin, tmax);
168 } else if (key == "#PATH") {
169 addDirectory(arg);
170 } else if (key == "#FILE") {
171 addFile(arg);
172 } else if (key == "#UNDERSAMPLE") {
173 setUnderSample(atoi(arg.c_str()));
174 } else if (key == "#MJD0") {
175 double t0;
176 sscanf(arg.c_str(), "%lg", &t0);
177 archParam.acq.tBlock0 = t0;
178 } else if (key == "#UTCORIGIN") {
179 double t0;
180 sscanf(arg.c_str(), "%lg", &t0);
181 archParam.acq.utcOrigin = t0;
182 } else if (key == "#PERECH") {
183 double t0;
184 sscanf(arg.c_str(), "%lg", &t0);
185 archParam.acq.perEch = t0;
186 } else if (key == "#ASIGPS") {
187 ASIGPS* gps = new ASIGPS(arg);
188 TOIManager::registerProducer(new TOIAuxGPSProducer(gps));
189 // gps->FitsDump("GPSDump.fits");
190 } else if (key == "#INCLUDE") {
191 ifstream f(arg.c_str());
192 readReq(f);
193 } else {
194 return false;
195 }
196 return true;
197}
198
199
200void TOIIter::defaultInclude() {
201 incDone = true;
202 processRequest("#REQVERSION V_270999");
203 processRequest("#MJD0 1376.8358818");
204 processRequest("#PERECH 0.005836818076");
205 processRequest("#UTCORIGIN 1376.5");
206 processRequest("#ASIGPS ASI_GPS_archeops1999.ascii");
207 processRequest("#COMMENT Archtoi V2 -- october 1999 -- Eric Aubourg CEA/DAPNIA");
208 processRequest("#COMMENT ***WARNING***");
209 processRequest("#COMMENT ***SOME TOI'S ARE PRELIMINARY***");
210 processRequest("#COMMENT gyroSpeed is not calibrated");
211 processRequest("#COMMENT azimut/alpha/delta use galaxy crossings and ASI GPS data");
212 processRequest("#COMMENT and assume no pendulation");
213 processRequest("#COMMENT Focal plane center elevation found at 41.5 deg");
214 processRequest("#COMMENT with Jupiter");
215 processRequest("#COMMENT boloMuV2 is not protected against glitches");
216}
217
218#ifdef __MWERKS__
219#pragma mark -
220#endif
221
222void TOIIter::init() {
223 if (initDone) return;
224 initDone = true;
225
226 if (utcStart > 0) {
227 double t = (utcStart/24.) + archParam.acq.utcOrigin;
228 if (t > mjdStart) mjdStart=t;
229 }
230 if (utcEnd > 0) {
231 double t = (utcEnd/24.) + archParam.acq.utcOrigin;
232 if (t < mjdEnd) mjdEnd=t;
233 }
234
235 fset.setMJDRange(mjdStart-0.01, mjdEnd+0.01);
236 fset.setSNumRange(sStart-1000, sEnd+1000);
237
238 fset.init();
239 //curSample = fset.getSampleIndex();
240}
241
242bool TOIIter::isTrig(int column) {
243 return (request[column].third & triggering) != 0;
244}
245
246TOI TOIIter::getKind(int column) {
247 return request[column].first;
248}
249
250long TOIIter::getSampleNum() {
251 return curSample;
252}
253
254bool TOIIter::next() {
255 if (!initDone) init();
256 for (int ii=0; ii<underSample; ii++)
257 if (!next1()) return false;
258
259 return true;
260}
261
262bool TOIIter::next1() {
263// On tente de produire curSample+1 pour toutes les toi
264// Eventuellement en avancant sur le fichier...
265// Puis on regarde si une TOI triggering a eu une nouvelle
266// valeur.
267// Si on a epuise les fichiers de donnees, on s'arrete des qu'aucune
268// TOI n'a de valeurs apres curSample...
269 if (curSample <= 0) curSample = sStart-1;
270 if (curSample <= 0) curSample = fset.getSampleIndex()-1;
271
272 if (curSample >= sEnd || archParam.acq.SN2MJD(curSample) >= mjdEnd) return false;
273
274 static long lastClean = 0;
275 if (curSample - lastClean > 100) {
276 for (int i=0; i<request.size(); i++)
277 request[i].second->wontNeedEarlier(request[i].first, this, curSample);
278 lastClean = curSample;
279 }
280
281 bool endFound = false;
282 while(1) {
283 curSample++;
284 for (vector<TOIInfo>::iterator i = request.begin(); i != request.end(); i++) {
285 while ((*i).second->canGetValueLater(curSample, (*i).first)) {
286 if (! fset.next()) {endFound = true; break;} //return false;
287 }
288 }
289 bool found=false;
290 bool valuesAhead = false;
291 for (vector<TOIInfo>::iterator i = request.begin(); i != request.end(); i++) {
292 if (((*i).third & triggering) == 0) continue;
293 if ((*i).second->canGetValue(curSample, (*i).first)) {found=true;break;}
294 if ((*i).second->lastSampleNum((*i).first)>curSample) valuesAhead=true;
295 }
296 if (found) break;
297 if (endFound && !valuesAhead) return false;
298 }
299 return true;
300}
301
302int TOIIter::getColTOI(TOI const& toi) {
303 for (int i=0; i<request.size(); i++)
304 if (request[i].first == toi) return i;
305 throw ArchExc("getColTOI : no such TOI " + toi.name);
306}
307
308bool TOIIter::canGetValue(int column) {
309 TOIInfo& info = request[column];
310 return(info.second->canGetValue(curSample, info.first));
311}
312
313double TOIIter::getValue(int column) {
314 TOIInfo& info = request[column];
315 return(info.second->getValue(curSample, info.first));
316}
317
318bool TOIIter::canGetValue(TOI const& toi) {
319 return canGetValue(getColTOI(toi));
320}
321
322double TOIIter::getValue(TOI const& toi) {
323 return getValue(getColTOI(toi));
324}
325
Note: See TracBrowser for help on using the repository browser.