Changeset 16825
- Timestamp:
- 06/13/13 16:04:19 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/zfits.h
r16820 r16825 123 123 void InitCompressionReading() 124 124 { 125 if (!fTable.isCompressed) 126 return; 127 125 128 //The constructor may have failed 126 129 if (!good()) … … 151 154 //read the file's catalog 152 155 ReadCatalog(); 156 157 //check that heap agrees with head 158 //CheckIfFileIsConsistent(); 153 159 } 154 160 … … 183 189 void AllocateBuffers() 184 190 { 185 if (!fTable.isCompressed)186 return;187 188 191 fBuffer.resize(fTable.bytes_per_row*fNumRowsPerTile); 189 192 … … 195 198 void ReadCatalog() 196 199 { 197 if (!fTable.isCompressed)198 return;199 200 200 char readBuf[16]; 201 201 fCatalog.resize(fNumTiles); … … 455 455 } 456 456 457 void CheckIfFileIsConsistent() 458 { 459 //goto start of heap 460 streamoff whereAreWe = tellg(); 461 seekg(fHeapOff); 462 463 //init number of rows to zero 464 uint64_t numRows = 0; 465 466 //get number of columns from header 467 size_t numCols = fTable.num_cols; 468 469 vector<vector<pair<int64_t, int64_t> > > catalog; 470 471 TileHeader tileHead; 472 BlockHeader columnHead; 473 streamoff offsetInHeap = 0; 474 //skip through the heap 475 while (true) 476 { 477 read((char*)(&tileHead), sizeof(TileHeader)); 478 //end of file 479 if (!good()) 480 break; 481 //padding or corrupt data 482 if (tileHead.id[0] != 'T' || tileHead.id[1] != 'I' || 483 tileHead.id[2] != 'L' || tileHead.id[3] != 'E') 484 break; 485 486 //a new tile begins here 487 catalog.push_back(vector<pair<int64_t, int64_t> >(0)); 488 offsetInHeap += sizeof(TileHeader); 489 490 //skip through the columns 491 for (size_t i=0;i<numCols;i++) 492 { 493 //zero sized column do not have headers. Skip it 494 if (fTable.sortedCols[i].num == 0) 495 { 496 catalog.back().push_back(make_pair(0,0)); 497 continue; 498 } 499 //read column header 500 read((char*)(&columnHead), sizeof(BlockHeader)); 501 //corrupted tile 502 if (!good()) 503 break; 504 catalog.back().push_back(make_pair((int64_t)(columnHead.size),offsetInHeap)); 505 offsetInHeap += columnHead.size; 506 seekg(fHeapOff+offsetInHeap); 507 } 508 509 //if we ain't good, this means that something went wrong inside the current tile. 510 if (!good()) 511 { 512 break; 513 catalog.pop_back(); 514 } 515 516 //current tile is complete. Add rows 517 numRows += tileHead.numRows; 518 } 519 520 if (catalog.size() != fCatalog.size() || 521 numRows != fTable.num_rows) 522 { 523 #ifdef __EXCEPTIONS 524 throw runtime_error("Heap data does not agree with header. Aborting"); 525 #else 526 gLog << ___err___ << "ERROR - Heap data does not agree with header." << endl; 527 return; 528 #endif 529 } 530 531 for (uint32_t i=0;i<catalog.size(); i++) 532 for (uint32_t j=0;j<numCols;j++) 533 { 534 if (catalog[i][j].first != fCatalog[i][j].first || 535 catalog[i][j].second != fCatalog[i][j].second) 536 { 537 #ifdef __EXCEPTIONS 538 throw runtime_error("Heap data does not agree with header. Aborting"); 539 #else 540 gLog << ___err___ << "ERROR - Heap data does not agree with header." << endl; 541 return; 542 #endif 543 } 544 } 545 //go back to start of heap 546 seekg(whereAreWe); 547 } 548 457 549 };//class zfits 458 550
Note:
See TracChangeset
for help on using the changeset viewer.