Changeset 16882 for trunk/Mars/mcore
- Timestamp:
- 06/21/13 17:08:18 (11 years ago)
- Location:
- trunk/Mars/mcore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/fits.h
r16847 r16882 758 758 clear(rdstate()|ios::badbit); 759 759 } 760 uint8_t ReadRow(size_t row) 761 { 762 // For the checksum we need everything to be correctly aligned 763 const uint8_t offset = (row*fTable.bytes_per_row)%4; 764 765 auto ib = fBufferRow.begin(); 766 auto ie = fBufferRow.end(); 760 761 void ZeroBufferForChecksum(vector<char>& vec, const uint64_t extraZeros=0) 762 { 763 auto ib = vec.begin(); 764 auto ie = vec.end(); 765 767 766 *ib++ = 0; 768 767 *ib++ = 0; … … 770 769 *ib = 0; 771 770 772 *--ie = 0; 773 *--ie = 0; 774 *--ie = 0; 775 *--ie = 0; 776 *--ie = 0; 777 *--ie = 0; 778 *--ie = 0; 779 *--ie = 0; 771 for (uint64_t i=0;i<extraZeros+8;i++) 772 *--ie = 0; 773 } 774 775 uint8_t ReadRow(size_t row) 776 { 777 // For the checksum we need everything to be correctly aligned 778 const uint8_t offset = (row*fTable.bytes_per_row)%4; 779 780 ZeroBufferForChecksum(fBufferRow); 780 781 781 782 StageRow(row, fBufferRow.data()+offset); -
trunk/Mars/mcore/zfits.h
r16867 r16882 188 188 size_t fNumTiles; ///< Total number of tiles 189 189 size_t fNumRowsPerTile; ///< Number of rows per compressed tile 190 size_t fCurrentRow; ///< current row in memory.190 int64_t fCurrentRow; ///< current row in memory signed because we need -1 191 191 192 192 streamoff fHeapOff; ///< offset from the beginning of the file of the binary data 193 streamoff fHeapFromDataStart; ///< offset from the beginning of the data table 193 194 194 195 vector<vector<pair<int64_t, int64_t> > > fCatalog;///< Catalog, i.e. the main table that points to the compressed data. … … 202 203 203 204 fTransposedBuffer.resize(fTable.bytes_per_row*fNumRowsPerTile); 204 fCompressedBuffer.resize(fTable.bytes_per_row*fNumRowsPerTile + fTable.num_cols*(sizeof(BlockHeader)+256)); //use a bit more memory for block headers 205 fCompressedBuffer.resize(fTable.bytes_per_row*fNumRowsPerTile + 206 fTable.num_cols*(sizeof(BlockHeader)+256) + //use a bit more memory for block headers. 256 char coding the compression sequence max. 207 sizeof(TileHeader), //a bit more for the tile headers 208 8); //and a bit more for checksuming 205 209 } 206 210 … … 208 212 void ReadCatalog() 209 213 { 210 char readBuf[16];214 vector<char> readBuf(16); 211 215 fCatalog.resize(fNumTiles); 212 216 213 217 const streampos catalogStart = tellg(); 218 219 fChkData.reset(); 214 220 215 221 //do the actual reading … … 217 223 for (uint32_t j=0;j<fTable.num_cols;j++) 218 224 { 219 read(readBuf , 2*sizeof(int64_t));220 225 read(readBuf.data(), 2*sizeof(int64_t)); 226 fChkData.add(readBuf); 221 227 //swap the bytes 222 228 int64_t tempValues[2] = {0,0}; 223 revcpy<8>(reinterpret_cast<char*>(tempValues), readBuf , 2);229 revcpy<8>(reinterpret_cast<char*>(tempValues), readBuf.data(), 2); 224 230 if (tempValues[0] < 0 || tempValues[1] < 0) 225 231 { … … 250 256 //see if there is a gap before heap data 251 257 fHeapOff = tellg()+fTable.GetHeapShift(); 258 fHeapFromDataStart = fNumTiles*fTable.num_cols*2*sizeof(int64_t) + fTable.GetHeapShift(); 252 259 253 260 if (!fCopy.is_open()) … … 269 276 //overrides fits.h method with empty one 270 277 //work is done in ReadBinaryRow because it requires volatile data from ReadBinaryRow 271 virtual void WriteRowToCopyFile(size_t row) 272 { 273 if (row == fRow+1) 274 fChkData.add(fBufferRow); 278 virtual void WriteRowToCopyFile(size_t ) 279 { 280 275 281 } 276 282 … … 284 290 const uint32_t currentTile = fCurrentRow/fNumRowsPerTile; 285 291 292 bool addCheckSum = ((requestedTile == currentTile+1) || (fCurrentRow == -1)); 293 286 294 fCurrentRow = rowNum; 287 288 295 //should we read yet another chunk of data ? 289 296 if (requestedTile != currentTile) 290 297 { 291 298 //read yet another chunk from the file 292 const int64_t sizeToRead = fTileSize[requestedTile] ;299 const int64_t sizeToRead = fTileSize[requestedTile] + sizeof(TileHeader); 293 300 294 301 //skip to the beginning of the tile 295 seekg(fHeapOff+fCatalog[requestedTile][0].second - sizeof(TileHeader)); 296 TileHeader tHead; 297 read((char*)(&tHead), sizeof(TileHeader)); 298 read(fCompressedBuffer.data(), sizeToRead); 302 const int64_t tileStart = fCatalog[requestedTile][0].second - sizeof(TileHeader); 303 304 seekg(fHeapOff+tileStart); 305 306 //calculate the 32 bits offset of the current tile. 307 const uint32_t offset = (tileStart + fHeapFromDataStart)%4; 308 309 //point the tile header where it should be 310 //we ain't checking the header now 311 // TileHeader* tHead = reinterpret_cast<TileHeader*>(fCompressedBuffer.data()+offset); 312 313 ZeroBufferForChecksum(fCompressedBuffer, fCompressedBuffer.size()-(sizeToRead+offset+8)); 314 315 //read one tile from disk 316 read(fCompressedBuffer.data()+offset, sizeToRead); 317 318 if (addCheckSum) 319 fChkData.add(fCompressedBuffer); 299 320 300 321 if (requestedTile == currentTile+1 && … … 302 323 fCopy.good()) 303 324 { 304 fCopy.write((char*)(&tHead), sizeof(TileHeader)); 305 fCopy.write(fCompressedBuffer.data(), sizeToRead); 325 fCopy.write(fCompressedBuffer.data()+offset, sizeToRead); 306 326 if (!fCopy) 307 327 clear(rdstate()|ios::badbit); … … 314 334 315 335 //uncompress it 316 UncompressBuffer(requestedTile, thisRoundNumRows );336 UncompressBuffer(requestedTile, thisRoundNumRows, offset+sizeof(TileHeader)); 317 337 318 338 // pointer to column (source buffer) … … 413 433 // Data has been read from disk. Uncompress it ! 414 434 void UncompressBuffer(const uint32_t &catalogCurrentRow, 415 const uint32_t &thisRoundNumRows) 435 const uint32_t &thisRoundNumRows, 436 const uint32_t offset) 416 437 { 417 438 char *dest = fTransposedBuffer.data(); … … 425 446 426 447 //get the compression flag 427 const int64_t compressedOffset = fTileOffsets[catalogCurrentRow][i] ;448 const int64_t compressedOffset = fTileOffsets[catalogCurrentRow][i]+offset; 428 449 429 450 const BlockHeader* head = reinterpret_cast<BlockHeader*>(&fCompressedBuffer[compressedOffset]);
Note:
See TracChangeset
for help on using the changeset viewer.