Changeset 315 in Sophya for trunk/Poubelle/archTOI.old/toiiter.cc
- Timestamp:
- Jun 15, 1999, 3:53:04 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Poubelle/archTOI.old/toiiter.cc
r310 r315 1 1 #include "toiiter.h" 2 #include "toiinterpolator.h" 2 3 #include <dirent.h> 3 4 … … 17 18 18 19 tBlock0 = -1; 20 21 rawIter = NULL; 22 interp = NULL; 23 lastSample = -1; 24 maxLookAhead = 1000; 19 25 20 26 } … … 32 38 infos = x.infos; 33 39 34 file = new ArcheopsFile(*x.file); 40 if (x.file) 41 file = new ArcheopsFile(*x.file); 42 else 43 file = NULL; 44 45 if (x.rawIter) { 46 rawIter = new TOIIter(*x.rawIter); 47 interp = new TOIInterpolator[infos.size()]; 48 for (int i=0; i<infos.size(); i++) 49 interp[i] = x.interp[i]; 50 } else { 51 rawIter = NULL; 52 interp = NULL; 53 } 54 55 lastSample = x.lastSample; 56 maxLookAhead = x.maxLookAhead; 35 57 } 36 58 37 59 TOIIter::~TOIIter() { 38 60 delete file; 61 delete rawIter; 62 delete[] interp; 39 63 } 40 64 41 65 void TOIIter::Init() { 66 67 // $CHECK$ a deplacer, pour gerer repertoires... 42 68 if (directory == "") { 43 69 file = new ArcheopsFile(fileName); … … 60 86 // mieux en prenant le min de tous les delta_T. 61 87 62 63 #if 0 88 tBlock0 = file->getStartMJD(); 89 64 90 file->pushMark(); 65 91 if (file->lastGPS() || file->nextBlock(block_gps_mask)) { … … 71 97 } 72 98 file->popMark(); 73 #endif 99 100 bool hasInterp = false; 74 101 75 102 trigMask = 0; 76 103 for (vector<info>::iterator i = infos.begin(); i != infos.end(); i++) { 104 if ((*i).interpolated) hasInterp = true; 77 105 if ((*i).triggering) { 78 106 switch ((*i).kind) { … … 86 114 break; 87 115 case azimut: 116 file->needSSTProcessMask(SSTHandler::findPeriod); 88 117 trigMask |= block_sst_mask; 89 118 break; 90 case alpha: 91 case delta: 119 case sstStarZ: 120 case sstStarF: 121 file->needSSTProcessMask(SSTHandler::findStars); 122 trigMask |= block_sst_mask; 123 break; 124 case sstSignal: 125 file->needSSTProcessMask(SSTHandler::rmveOffset); 126 trigMask |= block_sst_mask; 127 break; 128 case alphaAxis: 129 case deltaAxis: 130 case alphaBolo: 131 case deltaBolo: 132 file->needSSTProcessMask(SSTHandler::findAxis); 92 133 trigMask |= block_sst_mask; 93 134 break; … … 101 142 imes = 0; 102 143 } 144 145 if (hasInterp) { 146 rawIter = new TOIIter(*this); 147 interp = new TOIInterpolator[infos.size()]; 148 for (int i=0; i<infos.size(); i++) { 149 rawIter->infos[i].interpolated = false; 150 } 151 delete file; file = NULL; // on ne travaille plus sur le fichier directement... 152 } 103 153 } 104 154 105 155 bool TOIIter::NextFile() { 156 if (rawIter) 157 return rawIter->NextFile(); 158 106 159 if (directory == "") { 107 160 return false; … … 119 172 120 173 bool TOIIter::Next() { 121 174 if (rawIter) { // Delegation pour interpolation 175 // Trouve prochain sample disponible 176 for (int k=0; k<2; k++) { 177 long smp = 2147483647L; 178 for (int i=0; i<infos.size(); i++) { 179 long ss = interp[i].nextSample(lastSample+1); 180 if (ss > 0 && ss < smp) smp=ss; 181 } 182 if (smp != 2147483647L) { 183 lastSample = smp; 184 break; 185 } 186 if (!fetchAhead()) // tout le monde etait en bout de course, 187 return false; // on lit un echantillon, ca suffit, d'ou le k<2 188 } 189 // Verifie que tous les interpolateurs ont assez de donnees pour 190 // trouver la valeur correspondante 191 for (int i=0; i<infos.size(); i++) { 192 //rif (infos[i].interpolated) 193 while (interp[i].needMoreDataFor(lastSample) && 194 rawIter->getSampleIndex() - lastSample < maxLookAhead) 195 if (!fetchAhead()) return false; 196 } 197 198 // On est pret... 199 return true; 200 } 122 201 123 202 // trigger sur info indexee dans bloc bolo ou bloc sst ? … … 129 208 130 209 // soit pas d'info indexee, soit fin bloc courant... 131 132 if (file->nextBlock(trigMask)) { 133 return true; 134 } 135 if (!NextFile()) return false; 136 return file->nextBlock(trigMask); 137 } 138 139 double TOIIter::getTime() { // MJD 210 while (1) { 211 if (file->nextBlock(trigMask)) { 212 while (file->sameBlockNumAhead()) { // tant que meme numero de bloc, on lit 213 if (!file->nextBlock()) { // fin de fichier ? 214 if (NextFile()) file->nextBlock(); 215 else break; 216 } 217 } 218 return true; 219 } 220 if (!NextFile()) return false; 221 } 222 } 223 224 /* double TOIIter::getTime() { // MJD 140 225 // le temps du bloc courant, en secondes 141 226 double dt = file->blockNum() * file->perBlock(); 142 227 return tBlock0 + dt/86400. + imes*file->perEchant()/86400.; 143 228 } 144 145 double TOIIter::getValue(int column) { 146 if (column < 0 || column >= infos.size()) return -1; 229 */ 230 231 bool TOIIter::canGetValue(int column) { 232 if (column < 0 || column >= infos.size()) return false; 233 if (rawIter) { 234 return interp[column].canGet(lastSample); 235 } 147 236 TOIKind kind = infos[column].kind; 148 237 int index = infos[column].index; 149 238 switch (kind) { 239 case sampleNum: 240 case internalTime: 241 case utc: 242 return true; 243 case boloTens: 244 case boloRaw: 245 return file->lastBolo() != NULL; 246 case sstSignal: 247 return file->lastSST() != NULL; 248 case longitude: 249 case latitude: 250 return file->lastGPS() != NULL; 251 case azimut: 252 case alphaAxis: 253 case deltaAxis: 254 return (file->lastGPS() != NULL && file->lastSST() != NULL); 255 } 256 return false; 257 } 258 259 double TOIIter::getValue(int column) { 260 if (column < 0 || column >= infos.size()) return -1; 261 if (rawIter) { 262 if (infos[column].interpolated) 263 return interp[column].getIValue(lastSample); 264 else 265 return interp[column].getEValue(lastSample); 266 } 267 TOIKind kind = infos[column].kind; 268 int index = infos[column].index; 269 switch (kind) { 270 case sampleNum: 271 return file->blockNum() * file->nEchBlock() + imes; 272 case internalTime: 273 return (file->blockNum() * file->nEchBlock() + imes) * file->perEchant(); 274 case utc: 275 /* printf("utc: %d %d %g %g %g\n",file->blockNum(), 276 (file->blockNum() * file->nEchBlock() + imes), 277 file->perEchant(), 278 (file->blockNum() * file->nEchBlock() + imes) * file->perEchant()/86400., 279 tBlock0+(file->blockNum() * file->nEchBlock() + imes) * file->perEchant()/86400.); */ 280 return tBlock0+(file->blockNum() * file->nEchBlock() + imes) * file->perEchant()/86400.; 150 281 case boloTens: 151 282 return file->getMuVBolo(index, imes); 152 283 case boloRaw: 153 284 return file->getRawBolo(index, imes); 285 case sstSignal: 286 return file->getSSTSignal(index, imes); 154 287 case longitude: 155 288 return file->getGPSLong(); // $CHECK$ TBD gerer interpolation (dans file) 156 289 case latitude: 157 290 return file->getGPSLat(); // $CHECK$ TBD gerer interpolation (dans file) 158 291 case azimut: 159 292 return file->getAzimut(imes); 160 case alpha:293 case alphaAxis: 161 294 return file->getAlpha(imes); 162 case delta:295 case deltaAxis: 163 296 return file->getDelta(imes); 164 297 } 165 298 return -1; 166 167 168 299 } 300 301 bool TOIIter::newValue(int column) { 169 302 if (column < 0 || column >= infos.size()) return false; 170 303 TOIKind kind = infos[column].kind; 171 304 switch (kind) { 305 case sampleNum: 306 case internalTime: 307 case utc: 308 return true; 172 309 case boloTens: 173 return file->block Kind() == block_bolo;310 return file->blockNum() == file->getBoloBlockNum(); 174 311 case boloRaw: 175 return file->blockKind() == block_bolo; 312 return file->blockNum() == file->getBoloBlockNum(); 313 case sstSignal: 314 return file->blockNum() == file->getSSTBlockNum(); 176 315 case longitude: 177 return file->block Kind() == block_gps;316 return file->blockNum() == file->getGPSBlockNum() && imes==0; 178 317 case latitude: 179 return file->block Kind() == block_gps;180 181 return file->blockKind() == block_sst || file->blockKind() == block_bolo;182 case alpha:183 return file->blockKind() == block_sst || file->blockKind() == block_bolo;184 case delta:185 return file->blockKind() == block_sst || file->blockKind() == block_bolo;318 return file->blockNum() == file->getGPSBlockNum() && imes==0; 319 case azimut: 320 return true; // $CHECK$ with SSTHandler 321 case alphaAxis: 322 return true; // $CHECK$ with SSTHandler 323 case deltaAxis: 324 return true; // $CHECK$ with SSTHandler 186 325 } 187 326 return false; 188 189 190 191 return !newValue(column);192 193 194 bool TOIIter::interpValue(int /*column*/) {195 return false; // $CHECK$ TBD gerer interpolation196 197 198 327 } 328 329 bool TOIIter::extendValue(int column) { 330 return (!infos[column].interpolated && !newValue(column)); 331 } 332 333 bool TOIIter::interpValue(int column) { 334 return (infos[column].interpolated && !newValue(column)); 335 } 336 337 TOIKind TOIIter::getKind(int column) { 199 338 if (column < 0 || column >= infos.size()) return (TOIKind)-1; 200 339 return infos[column].kind; 201 202 203 340 } 341 342 int TOIIter::getIndex(int column) { 204 343 if (column < 0 || column >= infos.size()) return (TOIKind)-1; 205 344 return infos[column].index; 206 } 345 } 346 347 int TOIIter::getColTOI(TOIKind kind, int index) { 348 for (int i=0; i<infos.size(); i++) 349 if (infos[i].kind == kind && infos[i].index == index) 350 return i; 351 return -1; 352 } 353 354 bool TOIIter::canGetTOI(TOIKind kind, int index) { 355 int col = getColTOI(kind, index); 356 if (col<0) return false; 357 return canGetValue(col); 358 } 359 360 double TOIIter::getTOI(TOIKind kind, int index) { 361 int col = getColTOI(kind, index); 362 if (col<0) return -9.e99; 363 return getValue(col); 364 } 365 207 366 208 int TOIIter::getSampleIndex() {367 int TOIIter::getBlockSampleIndex() { 209 368 return imes; 210 } 369 } 370 371 int TOIIter::getSampleIndex() { 372 return file->blockNum() * file->nEchBlock() + imes; 373 } 374 375 bool TOIIter::fetchAhead() { // Seulement si delegation 376 if (!rawIter) return false; 377 if (!rawIter->Next()) return false; 378 long sample = rawIter->getSampleIndex(); 379 for (int i=0; i<infos.size(); i++) { 380 if (rawIter->canGetValue(i) && rawIter->newValue(i)) 381 interp[i].enterValue(rawIter->getValue(i), sample); 382 } 383 return true; 384 } 385
Note:
See TracChangeset
for help on using the changeset viewer.