Changeset 16425 for trunk


Ignore:
Timestamp:
05/29/13 12:27:01 (11 years ago)
Author:
tbretz
Message:
requestedTile and currentTile should be uint32_t in ReadBinaryRow; no need to have ReadBinaryRow virtual; thisRoundNumRows and currentCatRow doesn't need to be recalculated in UnCompressBuffer; Replaced indices by pointers where they are not needed and a clear advantage is visible; took some hidden magic out of UncompressBuffer (as some obsolete large scope variables) and a continue at a random place
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/mcore/zfits.h

    r16418 r16425  
    146146                //swap the bytes
    147147                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);
    149149
    150150                //add catalog entry
     
    157157
    158158    // Compressed versin of the read row
    159     virtual bool ReadBinaryRow(uint64_t rowNum, char* bufferToRead)
     159    bool ReadBinaryRow(const size_t &rowNum, char *bufferToRead)
    160160    {
    161161        if (rowNum >= GetNumRows())
    162162            return false;
    163163
    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;
    166166
    167167        fCurrentRow = rowNum;
     
    182182            read(fCompressedBuffer.data(), sizeToRead);
    183183
     184            const uint32_t thisRoundNumRows = (GetNumRows()<fCurrentRow + fNumRowsPerTile) ? GetNumRows()%fNumRowsPerTile : fNumRowsPerTile;
     185
    184186            //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++)
    192193            {
    193                 switch (fTable.sortedCols[i].comp)
     194                char *buffer = fBuffer.data() + col->offset; // pointer to column (destination buffer)
     195
     196                switch (it->comp)
    194197                {
    195198                case UNCOMPRESSED:
    196199                case SMOOTHMAN:
    197                     //regular, "semi-transposed" copy
    198                     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
    199202                    {
    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
    202205                    }
    203206                    break;
    204207
    205208                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
    209213                        {
    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
    212216                        }
     217                    }
    213218                    break;
    214219                };
     
    284289
    285290    // 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
    294295        //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)
    300300                continue;
    301301
    302302            //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];
    304305
    305306            //#define COMPRESSED_FLAG 0x1
    306307            //#define UNCOMPRESSED_FLAG 0x0
    307308
     309            const char *src = fCompressedBuffer.data()+compressedOffset+1;
     310
    308311            //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;
    313313            switch (compression)
    314314            {
    315315                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;
    317318                    break;
    318319
    319320                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;
    321323                    break;
    322324
    323325                default:
    324326                    ;
    325             };
     327            }
    326328        }
    327329    }
Note: See TracChangeset for help on using the changeset viewer.