Changeset 16855 for trunk/Mars/mcore
- Timestamp:
- 06/15/13 19:10:02 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/zfits.h
r16844 r16855 15 15 16 16 17 #define FACT_RAW 0x018 #define FACT_SMOOTHING 0x119 #define FACT_HUFFMAN16 0x220 21 #define FACT_COL_MAJOR 'C'22 #define FACT_ROW_MAJOR 'R'23 24 25 17 #ifndef __MARS__ 26 18 namespace std … … 35 27 zfits(const string& fname, const string& tableName="", 36 28 bool force=false) : fits(fname, tableName, force), 37 fBuffer(0),38 fTransposedBuffer(0),39 fCompressedBuffer(0),40 29 fNumTiles(0), 41 30 fNumRowsPerTile(0), … … 50 39 zfits(const string& fname, const string& fout, const string& tableName, 51 40 bool force=false) : fits(fname, fout, tableName, force), 52 fBuffer(0),53 fTransposedBuffer(0),54 fCompressedBuffer(0),55 41 fNumTiles(0), 56 42 fNumRowsPerTile(0), … … 87 73 88 74 private: 89 75 #ifndef __CINT__ 90 76 //Structure helper for reading tiles headers 91 typedefstruct TileHeader77 struct TileHeader 92 78 { 93 79 char id[4]; … … 102 88 size(s) 103 89 { }; 104 } __attribute__((__packed__)) TileHeader;90 } __attribute__((__packed__)); 105 91 106 92 //Structure helper for reading blocks headers and compresion schemes 107 typedefstruct BlockHeader93 struct BlockHeader 108 94 { 109 95 uint64_t size; … … 113 99 114 100 BlockHeader(uint64_t s=0, 115 char o= FACT_ROW_MAJOR,101 char o='R'/*FACT_ROW_MAJOR*/, 116 102 unsigned char n=1) : size(s), 117 103 ordering(o), 118 104 numProcs(n) 119 105 {} 120 } __attribute__((__packed__)) BlockHeader;121 106 } __attribute__((__packed__)); 107 #endif 122 108 // Do what it takes to initialize the compressed structured 123 109 void InitCompressionReading() … … 134 120 if (it->comp != FACT) 135 121 { 122 clear(rdstate()|ios::badbit); 136 123 #ifdef __EXCEPTIONS 137 throw runtime_error(" ERROR:Only the FACT compression scheme is handled by this reader.");124 throw runtime_error("Only the FACT compression scheme is handled by this reader."); 138 125 #else 139 gLog << ___err___ << "ERROR :Only the FACT compression scheme is handled by this reader." << endl;126 gLog << ___err___ << "ERROR - Only the FACT compression scheme is handled by this reader." << endl; 140 127 return; 141 128 #endif … … 144 131 fColumnOrdering.resize(fTable.sortedCols.size()); 145 132 for (auto it=fColumnOrdering.begin(); it != fColumnOrdering.end(); it++) 146 (*it) = FACT_ROW_MAJOR; 133 (*it) = 'R';//FACT_ROW_MAJOR; 134 147 135 //Get compressed specific keywords 148 136 fNumTiles = fTable.isCompressed ? GetInt("NAXIS2") : 0; … … 273 261 const uint32_t requestedTile = rowNum/fNumRowsPerTile; 274 262 const uint32_t currentTile = fCurrentRow/fNumRowsPerTile; 275 const size_t previousRow = fCurrentRow;276 263 277 264 fCurrentRow = rowNum; … … 285 272 //skip to the beginning of the tile 286 273 seekg(fHeapOff+fCatalog[requestedTile][0].second - sizeof(TileHeader)); 274 287 275 TileHeader tHead; 288 276 read((char*)(&tHead), sizeof(TileHeader)); … … 317 305 switch (fColumnOrdering[i]) 318 306 { 319 caseFACT_ROW_MAJOR:307 case 'R': //FACT_ROW_MAJOR: 320 308 // regular, "semi-transposed" copy 321 309 for (char *dest=buffer; dest<buffer+thisRoundNumRows*fTable.bytes_per_row; dest+=fTable.bytes_per_row) // row-by-row … … 326 314 break; 327 315 328 caseFACT_COL_MAJOR:316 case 'C'://FACT_COL_MAJOR: 329 317 // transposed copy 330 318 for (char *elem=buffer; elem<buffer+it->bytes; elem+=it->size) // element-by-element (arrays) … … 338 326 break; 339 327 default: 328 clear(rdstate()|ios::badbit); 340 329 #ifdef __EXCEPTIONS 341 330 throw runtime_error("Unkown column ordering scheme"); 342 331 #else 343 332 gLog << ___err___ << "ERROR - unkown column ordering scheme" << endl; 344 return ;333 return false; 345 334 #endif 346 335 break; … … 417 406 const int64_t compressedOffset = fTileOffsets[catalogCurrentRow][i]; 418 407 419 BlockHeader* head = reinterpret_cast<BlockHeader*>(&fCompressedBuffer[compressedOffset]);408 const BlockHeader* head = reinterpret_cast<BlockHeader*>(&fCompressedBuffer[compressedOffset]); 420 409 421 410 fColumnOrdering[i] = head->ordering; 422 411 423 uint32_t numRows = (head->ordering==FACT_ROW_MAJOR) ? thisRoundNumRows : col.num;424 uint32_t numCols = (head->ordering==FACT_COL_MAJOR) ? thisRoundNumRows : col.num;412 const uint32_t numRows = (head->ordering=='R'/*FACT_ROW_MAJOR*/) ? thisRoundNumRows : col.num; 413 const uint32_t numCols = (head->ordering=='C'/*FACT_COL_MAJOR*/) ? thisRoundNumRows : col.num; 425 414 426 415 const char *src = fCompressedBuffer.data()+compressedOffset+sizeof(BlockHeader)+sizeof(uint16_t)*head->numProcs; … … 432 421 switch (head->processings[j]) 433 422 { 434 caseFACT_RAW:423 case 0x0://FACT_RAW: 435 424 sizeWritten = UncompressUNCOMPRESSED(dest, src, numRows*numCols, col.size); 436 425 break; 437 caseFACT_SMOOTHING:426 case 0x1://FACT_SMOOTHING: 438 427 sizeWritten = UnApplySMOOTHING(reinterpret_cast<int16_t*>(dest), numRows*numCols); 439 428 break; 440 caseFACT_HUFFMAN16:429 case 0x2://FACT_HUFFMAN16: 441 430 sizeWritten = UncompressHUFFMAN16(dest, src, numRows); 442 431 break; 443 432 default: 433 clear(rdstate()|ios::badbit); 444 434 #ifdef __EXCEPTIONS 445 435 throw runtime_error("Unknown processing applied to data. Aborting"); … … 448 438 return; 449 439 #endif 450 break;451 440 } 452 441 //increment destination counter only when processing done. … … 481 470 break; 482 471 //padding or corrupt data 483 if (tileHead.id[0] != 'T' || tileHead.id[1] != 'I' || 484 tileHead.id[2] != 'L' || tileHead.id[3] != 'E') 472 if (memcmp(tileHead.id, "TILE", 4)) 485 473 break; 486 474 487 475 //a new tile begins here 488 catalog. push_back(vector<pair<int64_t, int64_t> >(0));476 catalog.emplace_back(0);//push_back(vector<pair<int64_t, int64_t> >(0)); 489 477 offsetInHeap += sizeof(TileHeader); 490 478 … … 495 483 if (fTable.sortedCols[i].num == 0) 496 484 { 497 catalog.back(). push_back(make_pair(0,0));485 catalog.back().emplace_back(0,0); 498 486 continue; 499 487 } … … 503 491 if (!good()) 504 492 break; 505 catalog.back().emplace_back( make_pair((int64_t)(columnHead.size),offsetInHeap));493 catalog.back().emplace_back(int64_t(columnHead.size),offsetInHeap); 506 494 offsetInHeap += columnHead.size; 507 495 seekg(fHeapOff+offsetInHeap); … … 522 510 numRows != fTable.num_rows) 523 511 { 512 clear(rdstate()|ios::badbit); 524 513 #ifdef __EXCEPTIONS 525 throw runtime_error("Heap data does not agree with header. Aborting");514 throw runtime_error("Heap data does not agree with header."); 526 515 #else 527 516 gLog << ___err___ << "ERROR - Heap data does not agree with header." << endl; … … 536 525 catalog[i][j].second != fCatalog[i][j].second) 537 526 { 527 clear(rdstate()|ios::badbit); 538 528 #ifdef __EXCEPTIONS 539 throw runtime_error("Heap data does not agree with header. Aborting");529 throw runtime_error("Heap data does not agree with header."); 540 530 #else 541 531 gLog << ___err___ << "ERROR - Heap data does not agree with header." << endl;
Note:
See TracChangeset
for help on using the changeset viewer.