Changeset 16425 for trunk/Mars/mcore
- Timestamp:
- 05/29/13 12:27:01 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/zfits.h
r16418 r16425 146 146 //swap the bytes 147 147 int64_t tempValues[2] = {0,0}; 148 revcpy<8>(reinterpret_cast<char*>( &tempValues[0]), readBuf, 2);148 revcpy<8>(reinterpret_cast<char*>(tempValues), readBuf, 2); 149 149 150 150 //add catalog entry … … 157 157 158 158 // Compressed versin of the read row 159 virtual bool ReadBinaryRow(uint64_t rowNum, char*bufferToRead)159 bool ReadBinaryRow(const size_t &rowNum, char *bufferToRead) 160 160 { 161 161 if (rowNum >= GetNumRows()) 162 162 return false; 163 163 164 const int requestedTile = rowNum/fNumRowsPerTile;165 const int currentTile = fCurrentRow/fNumRowsPerTile;164 const uint32_t requestedTile = rowNum/fNumRowsPerTile; 165 const uint32_t currentTile = fCurrentRow/fNumRowsPerTile; 166 166 167 167 fCurrentRow = rowNum; … … 182 182 read(fCompressedBuffer.data(), sizeToRead); 183 183 184 const uint32_t thisRoundNumRows = (GetNumRows()<fCurrentRow + fNumRowsPerTile) ? GetNumRows()%fNumRowsPerTile : fNumRowsPerTile; 185 184 186 //uncompress it 185 UncompressBuffer(); 186 187 //copy the tile and transpose it 188 uint32_t offset=0; 189 190 const uint32_t thisRoundNumRows = (GetNumRows()<fCurrentRow + fNumRowsPerTile) ? GetNumRows()%fNumRowsPerTile : fNumRowsPerTile; 191 for (uint32_t i=0;i<fTable.sortedCols.size();i++) 187 UncompressBuffer(currentCatRow, thisRoundNumRows); 188 189 // pointer to column (source buffer) 190 const char *src = fTransposedBuffer.data(); 191 192 for (auto it=fTable.sortedCols.begin(); it!=fTable.sortedCold.end(); it++) 192 193 { 193 switch (fTable.sortedCols[i].comp) 194 char *buffer = fBuffer.data() + col->offset; // pointer to column (destination buffer) 195 196 switch (it->comp) 194 197 { 195 198 case UNCOMPRESSED: 196 199 case SMOOTHMAN: 197 // regular, "semi-transposed" copy198 for ( uint32_t k=0;k<thisRoundNumRows;k++)200 // regular, "semi-transposed" copy 201 for (char *dest=buffer; dest<buffer+thisRoundNumRows*fTable.bytes_per_row; dest+=fTable.bytes_per_row) // row-by-row 199 202 { 200 memcpy( fBuffer.data()+k*fTable.bytes_per_row + fTable.sortedCols[i].offset, fTransposedBuffer.data()+offset, fTable.sortedCols[i].size*fTable.sortedCols[i].num);201 offset += fTable.sortedCols[i].size*fTable.sortedCols[i].num;203 memcpy(dest, src, col->bytes); 204 src += it->bytes; // next column 202 205 } 203 206 break; 204 207 205 208 default: 206 //transposed copy 207 for (uint32_t j=0;j<fTable.sortedCols[i].num;j++) 208 for (uint32_t k=0;k<thisRoundNumRows;k++) 209 // transposed copy 210 for (char *elem=buffer; elem<buffer+col->bytes; elem+=col->size) // element-by-element (arrays) 211 { 212 for (char *dest=elem; dest<elem+thisRoundNumRows*fTable.bytes_per_row; dest+=fTable.bytes_per_row) // row-by-row 209 213 { 210 memcpy( fBuffer.data()+k*fTable.bytes_per_row + fTable.sortedCols[i].offset + fTable.sortedCols[i].size*j, fTransposedBuffer.data()+offset, fTable.sortedCols[i].size);211 offset += fTable.sortedCols[i].size;214 memcpy(dest, src, col->size); 215 src += it->size; // next element 212 216 } 217 } 213 218 break; 214 219 }; … … 284 289 285 290 // Data has been read from disk. Uncompress it ! 286 void UncompressBuffer() 287 { 288 const uint32_t catalogCurrentRow = fCurrentRow/fNumRowsPerTile; 289 const uint32_t thisRoundNumRows = (GetNumRows()<fCurrentRow + fNumRowsPerTile) ? GetNumRows()%fNumRowsPerTile : fNumRowsPerTile; 290 291 uint32_t offset = 0; 292 int64_t compressedOffset = 0; 293 291 void UncompressBuffer(const uint32_t &catalogCurrentRow, const uint32_t &thisRoundNumRows) 292 { 293 char *dest = fTransposeBuffer.data(); 294 294 295 //uncompress column by column 295 for (uint32_t i=0;i<fTable.sortedCols.size();i++) 296 { 297 compressedOffset = fCatalog[catalogCurrentRow][i].second - fCatalog[catalogCurrentRow][0].second; 298 299 if (fTable.sortedCols[i].num == 0) 296 for (uint32_t i=0; i<fTable.sortedCols.size(); i++) 297 { 298 const Column &col = fTable.sortedCols[i]; 299 if (col.num == 0) 300 300 continue; 301 301 302 302 //get the compression flag 303 const char compressedFlag = fCompressedBuffer[compressedOffset++]; 303 const int64_t compressedOffset = fCatalog[catalogCurrentRow][i].second - fCatalog[catalogCurrentRow][0].second; 304 const char compressedFlag = fCompressedBuffer[compressedOffset]; 304 305 305 306 //#define COMPRESSED_FLAG 0x1 306 307 //#define UNCOMPRESSED_FLAG 0x0 307 308 309 const char *src = fCompressedBuffer.data()+compressedOffset+1; 310 308 311 //if this bunch of data is not compressed, modify the compression flag 309 uint32_t compression = fTable.sortedCols[i].comp; 310 if (compressedFlag == 0) 311 compression = UNCOMPRESSED; 312 312 const uint32_t compression = compressedFlag==0 ? UNCOMPRESSED : col.comp; 313 313 switch (compression) 314 314 { 315 315 case UNCOMPRESSED: 316 offset += UncompressUNCOMPRESSED(fTransposedBuffer.data()+offset, fCompressedBuffer.data()+compressedOffset, thisRoundNumRows, fTable.sortedCols[i].size, fTable.sortedCols[i].num); 316 const uint32_t offset = UncompressUNCOMPRESSED(dest, src, thisRoundNumRows, col.size, col.num); 317 dest += offset; 317 318 break; 318 319 319 320 case SMOOTHMAN: 320 offset += UncompressSMOOTHMAN(reinterpret_cast<int16_t*>(fTransposedBuffer.data()+offset), fCompressedBuffer.data()+compressedOffset, thisRoundNumRows, fTable.sortedCols[i].size, fTable.sortedCols[i].num); 321 const uint32_t offset = UncompressSMOOTHMAN(reinterpret_cast<int16_t*>(dest), src, thisRoundNumRows, col.size, col.num); 322 dest += offset; 321 323 break; 322 324 323 325 default: 324 326 ; 325 } ;327 } 326 328 } 327 329 }
Note:
See TracChangeset
for help on using the changeset viewer.