Changeset 16814


Ignore:
Timestamp:
06/12/13 15:56:12 (12 years ago)
Author:
lyard
Message:
added block headers and changed compression mechanism
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/fitsCompressor.cc

    r16810 r16814  
    1919
    2020using namespace std;
     21
     22typedef struct TileHeader
     23{
     24  char     id[4];
     25  uint32_t numRows;
     26  uint64_t size;
     27  TileHeader(uint32_t nRows=0,
     28             uint64_t s=0) : id({'T', 'I', 'L', 'E'}),
     29                             numRows(nRows),
     30                             size(s)
     31  { };
     32} __attribute__((__packed__)) TileHeader;
     33
     34typedef struct BlockHeader
     35{
     36    uint64_t      size;
     37    char          ordering;
     38    unsigned char numProcs;
     39    BlockHeader(uint64_t      s=0,
     40                char          o=FACT_ROW_MAJOR,
     41                unsigned char n=1) : size(s),
     42                                     ordering(o),
     43                                     numProcs(n)
     44    {}
     45} __attribute__((__packed__)) BlockHeader;
    2146
    2247class CompressedFitsFile
     
    249274                        char          t,
    250275                        int           numOf,
    251                         uint32_t      comp) : _name(n),
    252                                               _num(numOf),
    253                                               _typeSize(0),
    254                                               _offset(0),
    255                                               _type(t),
    256                                               _description(""),
    257                                               _compression(comp)
     276                        BlockHeader&   head,
     277                        vector<uint16_t>& seq) : _name(n),
     278                                                 _num(numOf),
     279                                                 _typeSize(0),
     280                                                 _offset(0),
     281                                                 _type(t),
     282                                                 _description(""),
     283                                                 _header(head),
     284                                                 _compSequence(seq)
    258285            {
    259286                switch (t)
     
    297324            char          type()                 const { return _type;};
    298325            string        getDescription()       const { return _description;}
    299             uint32_t      getCompression()       const { return _compression;}
     326            BlockHeader& getBlockHeader()  { return _header;}
     327            const vector<uint16_t>& getCompressionSequence() const { return _compSequence;}
     328            const char& getColumnOrdering() const { return _header.ordering;}
     329
    300330
    301331            string        getCompressionString() const
    302332            {
    303                 switch (_compression)
     333                return "FACT";
     334             /*
     335                ostringstream str;
     336                for (uint32_t i=0;i<_compSequence.size();i++)
     337                switch (_compSequence[i])
    304338                {
    305                     case UNCOMPRESSED: return "RAW";
    306                     case SMOOTHMAN: return "SMOO";
     339                    case FACT_RAW: if (str.str().size() == 0) str << "RAW"; break;
     340                    case FACT_SMOOTHING: str << "SMOOTHING "; break;
     341                    case FACT_HUFFMAN16: str << "HUFFMAN16 "; break;
    307342                };
    308                 return "UNKNOWN";
     343                return str.str();*/
    309344            }
    310345
     
    317352            char   _type;          ///< the type of the column, as specified by the fits documentation
    318353            string _description;   ///< a description for the column. It will be placed in the header
    319             uint32_t _compression; ///< the compression of the column. Only looked for if used by the compressed writer
     354            BlockHeader _header;
     355            vector<uint16_t> _compSequence;
    320356    };
    321357
     
    435471        uint32_t      compressHUFFMAN(char* dest, const char* src, uint32_t numRows, uint32_t sizeOfElems, uint32_t numRowElems);
    436472        uint32_t    compressSMOOTHMAN(char* dest, char* src, uint32_t numRows, uint32_t sizeOfElems, uint32_t numRowElems);
     473        uint32_t       applySMOOTHING(char* dest, char* src, uint32_t numRows, uint32_t sizeOfElems, uint32_t numRowElems);
    437474
    438475        int32_t         _checkOffset;  ///< offset to the data pointer to calculate the checksum
     
    452489const uint32_t CompressedFitsFile::_THREAD_READ_      = 4;
    453490const uint32_t CompressedFitsFile::_THREAD_EXIT_      = 5;
    454 
    455 #define COMPRESSED_FLAG 0x1
    456 #define UNCOMPRESSED_FLAG 0x0
    457 
    458 typedef struct TileHeader
    459 {
    460   char     id[4];
    461   uint32_t numRows;
    462   uint64_t size;
    463   TileHeader(uint32_t nRows=0,
    464              uint64_t s=0) : id({'T', 'I', 'L', 'E'}),
    465                              numRows(nRows),
    466                              size(s)
    467   { };
    468 } __attribute__((__packed__)) TileHeader;
    469 
    470 typedef struct BlockHeader
    471 {
    472     uint64_t size;
    473     char ordering;
    474     unsigned char numProcs;
    475     uint16_t procs[];
    476 } __attribute__((__packed__)) BlockHeader;
    477491
    478492template<>
     
    11401154    for (uint32_t i=0;i<_columns.size();i++)
    11411155    {
    1142         switch (_columns[i].getCompression())
    1143         {
    1144             case UNCOMPRESSED:
    1145             case SMOOTHMAN:
     1156        switch (_columns[i].getColumnOrdering())//getCompression())
     1157        {
     1158            case FACT_ROW_MAJOR:
    11461159                for (uint32_t k=0;k<thisRoundNumRows;k++)
    11471160                {//regular, "semi-transposed" copy
     
    11501163                }
    11511164            break;
    1152             default :
     1165
     1166            case FACT_COL_MAJOR :
    11531167                for (int j=0;j<_columns[i].numElems();j++)
    11541168                    for (uint32_t k=0;k<thisRoundNumRows;k++)
     
    11581172                    }
    11591173            break;
     1174            default:
     1175                    cout << "Error: unknown column ordering: " << _columns[i].getColumnOrdering() << endl;
    11601176
    11611177        };
     
    12471263}
    12481264
     1265uint32_t CompressedFitsWriter::applySMOOTHING(char* , char* src, uint32_t numRows, uint32_t sizeOfElems, uint32_t numRowElems)
     1266{
     1267    uint32_t colWidth = numRowElems;
     1268    for (int j=colWidth*numRows-1;j>1;j--)
     1269        reinterpret_cast<int16_t*>(src)[j] = reinterpret_cast<int16_t*>(src)[j] - (reinterpret_cast<int16_t*>(src)[j-1]+reinterpret_cast<int16_t*>(src)[j-2])/2;
     1270
     1271    return numRows*sizeOfElems*numRowElems;
     1272}
    12491273/****************************************************************
    12501274 *                  COMPRESS BUFFER
     
    12621286        _catalog[currentCatalogRow][i].second = compressedOffset;
    12631287
    1264         uint32_t compression = _columns[i].getCompression();
    1265 
    12661288        if (_columns[i].numElems() == 0) continue;
     1289
     1290        BlockHeader& head = _columns[i].getBlockHeader();
     1291        const vector<uint16_t>& sequence = _columns[i].getCompressionSequence();
    12671292        //set the default byte telling if uncompressed the compressed Flag
    12681293        uint64_t previousOffset = compressedOffset;
    1269         _compressedBuffer[threadIndex][compressedOffset++] = COMPRESSED_FLAG;
    1270         switch (compression)
    1271         {
    1272             case UNCOMPRESSED:
    1273                 compressedOffset += compressUNCOMPRESSED(&(_compressedBuffer[threadIndex][compressedOffset]), &(_transposedBuffer[threadIndex][offset]), thisRoundNumRows, _columns[i].sizeOfElems(), _columns[i].numElems());
    1274             break;
    1275             case SMOOTHMAN:
    1276                 compressedOffset += compressSMOOTHMAN(&(_compressedBuffer[threadIndex][compressedOffset]), &(_transposedBuffer[threadIndex][offset]), thisRoundNumRows, _columns[i].sizeOfElems(), _columns[i].numElems());
    1277             break;
    1278 
    1279             default:
    1280                 ;
    1281         };
     1294        //skip header data
     1295        compressedOffset += sizeof(BlockHeader) + sizeof(uint16_t)*sequence.size();
     1296
     1297        for (uint32_t j=0;j<sequence.size(); j++)
     1298        {
     1299            switch (sequence[j])
     1300            {
     1301                case FACT_RAW:
     1302                    if (head.numProcs == 1)
     1303                        compressedOffset += compressUNCOMPRESSED(&(_compressedBuffer[threadIndex][compressedOffset]), &(_transposedBuffer[threadIndex][offset]), thisRoundNumRows, _columns[i].sizeOfElems(), _columns[i].numElems());
     1304                break;
     1305                case FACT_SMOOTHING:
     1306                        applySMOOTHING(&(_compressedBuffer[threadIndex][compressedOffset]), &(_transposedBuffer[threadIndex][offset]), thisRoundNumRows, _columns[i].sizeOfElems(), _columns[i].numElems());
     1307                break;
     1308                case FACT_HUFFMAN16:
     1309                    if (head.ordering == FACT_COL_MAJOR)
     1310                        compressedOffset += compressHUFFMAN(&(_compressedBuffer[threadIndex][compressedOffset]), &(_transposedBuffer[threadIndex][offset]), thisRoundNumRows, _columns[i].sizeOfElems(), _columns[i].numElems());
     1311                    else
     1312                        compressedOffset += compressHUFFMAN(&(_compressedBuffer[threadIndex][compressedOffset]), &(_transposedBuffer[threadIndex][offset]), _columns[i].numElems(), _columns[i].sizeOfElems(),  thisRoundNumRows);
     1313                break;
     1314                default:
     1315                    cout << "ERROR: Unkown compression sequence entry: " << sequence[i] << endl;
     1316                break;
     1317            }
     1318        }
     1319
    12821320        //check if compressed size is larger than uncompressed
    1283         if (compression != UNCOMPRESSED &&
    1284             compressedOffset - previousOffset > _columns[i].sizeOfElems()*_columns[i].numElems()*thisRoundNumRows+1)
     1321        if (sequence[0] != FACT_RAW &&
     1322            compressedOffset - previousOffset > _columns[i].sizeOfElems()*_columns[i].numElems()*thisRoundNumRows+sizeof(BlockHeader)+sizeof(uint16_t)*sequence.size())
    12851323        {//if so set flag and redo it uncompressed
    1286             compressedOffset = previousOffset;
    1287             _compressedBuffer[threadIndex][compressedOffset++] = UNCOMPRESSED_FLAG;
     1324            cout << "REDOING UNCOMPRESSED" << endl;
     1325            compressedOffset = previousOffset + sizeof(BlockHeader) + 1;
    12881326            compressedOffset += compressUNCOMPRESSED(&(_compressedBuffer[threadIndex][compressedOffset]), &(_transposedBuffer[threadIndex][offset]), thisRoundNumRows, _columns[i].sizeOfElems(), _columns[i].numElems());
    1289         }
     1327            BlockHeader he;
     1328            he.size = compressedOffset - previousOffset;
     1329            he.numProcs = 1;
     1330            he.ordering = FACT_ROW_MAJOR;
     1331            memcpy(&(_compressedBuffer[threadIndex][previousOffset]), (char*)(&he), sizeof(BlockHeader));
     1332            _compressedBuffer[threadIndex][previousOffset+sizeof(BlockHeader)] = FACT_RAW;
     1333            offset += thisRoundNumRows*_columns[i].sizeOfElems()*_columns[i].numElems();
     1334           _catalog[currentCatalogRow][i].first = compressedOffset - _catalog[currentCatalogRow][i].second;
     1335           continue;
     1336        }
     1337        head.size = compressedOffset - previousOffset;
     1338        memcpy(&(_compressedBuffer[threadIndex][previousOffset]), (char*)(&head), sizeof(BlockHeader));
     1339        memcpy(&(_compressedBuffer[threadIndex][previousOffset+sizeof(BlockHeader)]), sequence.data(), sizeof(uint16_t)*sequence.size());
     1340
    12901341         offset += thisRoundNumRows*_columns[i].sizeOfElems()*_columns[i].numElems();
    12911342        _catalog[currentCatalogRow][i].first = compressedOffset - _catalog[currentCatalogRow][i].second;
    12921343    }
     1344
    12931345    TileHeader tHead(thisRoundNumRows, compressedOffset);
    1294 //    tHead.numRows = thisRoundNumRows;
    1295 //    tHead.size = compressedOffset;
    12961346    memcpy(_compressedBuffer[threadIndex], &tHead, sizeof(TileHeader));
    12971347    return compressedOffset;
     
    13381388    pthread_mutex_unlock(&(myself->_mutex));
    13391389    uint32_t threadToWaitForBeforeWriting = (myID == 0) ? myself->_numThreads-1 : myID-1;
     1390
    13401391    while (myself->_threadStatus[myID] != _THREAD_EXIT_)
    13411392    {
     
    16031654        }
    16041655
     1656        //get header structures
     1657        BlockHeader rawHeader;
     1658        BlockHeader smoothmanHeader(0, FACT_ROW_MAJOR, 3);
     1659        vector<uint16_t> rawProcessings(1);
     1660        rawProcessings[0] = FACT_RAW;
     1661        vector<uint16_t> smoothmanProcessings(3);
     1662        smoothmanProcessings[0] = FACT_SMOOTHING;
     1663        smoothmanProcessings[1] = FACT_HUFFMAN16;
     1664        smoothmanProcessings[2] = FACT_RAW;
     1665
    16051666        //first lets see if we do have an explicit request
    16061667        bool explicitRequest = false;
     
    16121673                if (displayText) cout << compressions[j].second << endl;
    16131674                if (compressions[j].second == "UNCOMPRESSED")
    1614                     outFile.addColumn(CompressedFitsFile::ColumnEntry(colName, sortedColumns[i].type, sortedColumns[i].num, CompressedFitsFile::UNCOMPRESSED));
     1675                    outFile.addColumn(CompressedFitsFile::ColumnEntry(colName, sortedColumns[i].type, sortedColumns[i].num, rawHeader, rawProcessings));
    16151676                if (compressions[j].second == "SMOOTHMAN")
    1616                     outFile.addColumn(CompressedFitsFile::ColumnEntry(colName, sortedColumns[i].type,  sortedColumns[i].num, CompressedFitsFile::SMOOTHMAN));
     1677                    outFile.addColumn(CompressedFitsFile::ColumnEntry(colName, sortedColumns[i].type,  sortedColumns[i].num, smoothmanHeader, smoothmanProcessings));
    16171678                break;
    16181679            }
     
    16241685        {
    16251686            if (displayText) cout << "UNCOMPRESSED" << endl;
    1626             outFile.addColumn(CompressedFitsFile::ColumnEntry(colName, sortedColumns[i].type,  sortedColumns[i].num, CompressedFitsFile::UNCOMPRESSED));
     1687            outFile.addColumn(CompressedFitsFile::ColumnEntry(colName, sortedColumns[i].type,  sortedColumns[i].num, rawHeader, rawProcessings));
    16271688        }
    16281689        else
    16291690        {
    16301691            if (displayText) cout << "SMOOTHMAN" << endl;
    1631             outFile.addColumn(CompressedFitsFile::ColumnEntry(colName, sortedColumns[i].type,  sortedColumns[i].num, CompressedFitsFile::SMOOTHMAN));
     1692            outFile.addColumn(CompressedFitsFile::ColumnEntry(colName, sortedColumns[i].type,  sortedColumns[i].num, smoothmanHeader, smoothmanProcessings));
    16321693        }
    16331694    }
  • trunk/Mars/mcore/zfits.h

    r16811 r16814  
    1313#include "fits.h"
    1414#include "huffman.h"
     15
     16
     17#define FACT_RAW       0x0
     18#define FACT_SMOOTHING 0x1
     19#define FACT_HUFFMAN16 0x2
     20
     21#define FACT_COL_MAJOR 'C'
     22#define FACT_ROW_MAJOR 'R'
    1523
    1624
     
    7987
    8088private:
     89
     90    //Structure helper for reading tiles headers
    8191    typedef struct TileHeader
    8292    {
     
    8494      uint32_t numRows;
    8595      uint64_t size;
    86       TileHeader(uint32_t nRows=0,
    87                  uint64_t s=0) : id({'T', 'I', 'L', 'E'}),
     96
     97      TileHeader() {}
     98
     99      TileHeader(uint32_t nRows,
     100                 uint64_t s) : id({'T', 'I', 'L', 'E'}),
    88101                                 numRows(nRows),
    89102                                 size(s)
    90103      { };
    91       friend ostream& operator << (ostream& out, const TileHeader& h)
    92       {
    93           out << h.id[0] << h.id[1] << h.id[2] << h.id[3] << " num Rows: " << h.numRows << ", tile size: " << h.size;
    94           return out;
    95       }
    96104    } __attribute__((__packed__)) TileHeader;
     105
     106    //Structure helper for reading blocks headers and compresion schemes
     107    typedef struct BlockHeader
     108    {
     109        uint64_t      size;
     110        char          ordering;
     111        unsigned char numProcs;
     112        uint16_t      processings[];
     113
     114        BlockHeader(uint64_t      s=0,
     115                    char          o=FACT_ROW_MAJOR,
     116                    unsigned char n=1) : size(s),
     117                                         ordering(o),
     118                                         numProcs(n)
     119        {}
     120    } __attribute__((__packed__)) BlockHeader;
    97121
    98122    // Do what it takes to initialize the compressed structured
     
    103127            return;
    104128
     129        if (fTable.isCompressed)
     130        for (auto it=fTable.sortedCols.begin(); it!= fTable.sortedCols.end(); it++)
     131            if (it->comp != FACT)
     132            {
     133#ifdef __EXCEPTIONS
     134                    throw runtime_error("ERROR: Only the FACT compression scheme is handled by this reader.");
     135#else
     136                    gLog << ___err___ << "ERROR: Only the FACT compression scheme is handled by this reader." << endl;
     137                    return;
     138#endif
     139            }
     140
     141        fColumnOrdering.resize(fTable.sortedCols.size());
     142        for (auto it=fColumnOrdering.begin(); it != fColumnOrdering.end(); it++)
     143            (*it) = FACT_ROW_MAJOR;
    105144        //Get compressed specific keywords
    106145        fNumTiles       = fTable.isCompressed ? GetInt("NAXIS2") : 0;
     
    129168    vector<char> fTransposedBuffer; ///<intermediate buffer to transpose the rows
    130169    vector<char> fCompressedBuffer; ///<compressed rows
     170    vector<char> fColumnOrdering; ///< ordering of the column's rows
    131171
    132172    size_t fNumTiles;       ///< Total number of tiles
     
    137177
    138178    vector<vector<pair<int64_t, int64_t> > > fCatalog;///< Catalog, i.e. the main table that points to the compressed data.
    139     vector<size_t> fTileSize; ///< size in bytes of each compressed tile
    140     vector<vector<size_t> > fTileOffsets; ///< offset from start of tile of a given compressed column
     179    vector<size_t>                           fTileSize; ///< size in bytes of each compressed tile
     180    vector<vector<size_t> >                  fTileOffsets; ///< offset from start of tile of a given compressed column
    141181
    142182    void AllocateBuffers()
     
    148188
    149189        fTransposedBuffer.resize(fTable.bytes_per_row*fNumRowsPerTile);
    150         fCompressedBuffer.resize(fTable.bytes_per_row*fNumRowsPerTile + fTable.num_cols); //use a bit more memory for compression flags
     190        fCompressedBuffer.resize(fTable.bytes_per_row*fNumRowsPerTile + fTable.num_cols*(sizeof(BlockHeader)+256)); //use a bit more memory for block headers
    151191    }
    152192
     
    266306            const char *src = fTransposedBuffer.data();
    267307
    268             for (auto it=fTable.sortedCols.begin(); it!=fTable.sortedCols.end(); it++)
     308            uint32_t i=0;
     309            for (auto it=fTable.sortedCols.begin(); it!=fTable.sortedCols.end(); it++, i++)
    269310            {
    270311                char *buffer = fBuffer.data() + it->offset; // pointer to column (destination buffer)
    271312
    272                 switch (it->comp)
     313                switch (fColumnOrdering[i])
    273314                {
    274                 case UNCOMPRESSED:
    275                 case SMOOTHMAN:
    276                     // regular, "semi-transposed" copy
    277                     for (char *dest=buffer; dest<buffer+thisRoundNumRows*fTable.bytes_per_row; dest+=fTable.bytes_per_row) // row-by-row
    278                     {
    279                         memcpy(dest, src, it->bytes);
    280                         src += it->bytes;  // next column
    281                     }
    282                     break;
    283 
    284                 default:
    285                     // transposed copy
    286                     for (char *elem=buffer; elem<buffer+it->bytes; elem+=it->size) // element-by-element (arrays)
    287                     {
    288                         for (char *dest=elem; dest<elem+thisRoundNumRows*fTable.bytes_per_row; dest+=fTable.bytes_per_row) // row-by-row
     315                    case FACT_ROW_MAJOR:
     316                        // regular, "semi-transposed" copy
     317                        for (char *dest=buffer; dest<buffer+thisRoundNumRows*fTable.bytes_per_row; dest+=fTable.bytes_per_row) // row-by-row
    289318                        {
    290                             memcpy(dest, src, it->size);
    291                             src += it->size; // next element
     319                            memcpy(dest, src, it->bytes);
     320                            src += it->bytes;  // next column
    292321                        }
    293                     }
     322                    break;
     323
     324                    case FACT_COL_MAJOR:
     325                        // transposed copy
     326                        for (char *elem=buffer; elem<buffer+it->bytes; elem+=it->size) // element-by-element (arrays)
     327                        {
     328                            for (char *dest=elem; dest<elem+thisRoundNumRows*fTable.bytes_per_row; dest+=fTable.bytes_per_row) // row-by-row
     329                            {
     330                                memcpy(dest, src, it->size);
     331                                src += it->size; // next element
     332                            }
     333                        }
     334                    break;
     335                    default:
     336    #ifdef __EXCEPTIONS
     337                        throw runtime_error("Unkown column ordering scheme");
     338    #else
     339                        gLog << ___err___ << "ERROR - unkown column ordering scheme" << endl;
     340                        return;
     341    #endif
    294342                    break;
    295343                };
     
    305353    uint32_t UncompressUNCOMPRESSED(char*       dest,
    306354                                    const char* src,
    307                                     uint32_t    numRows,
    308                                     uint32_t    sizeOfElems,
    309                                     uint32_t    numRowElems)
    310     {
    311         memcpy(dest, src, numRows*sizeOfElems*numRowElems);
    312         return numRows*sizeOfElems*numRowElems;
     355                                    uint32_t    numElems,
     356                                    uint32_t    sizeOfElems)
     357    {
     358        memcpy(dest, src, numElems*sizeOfElems);
     359        return numElems*sizeOfElems;
    313360    }
    314361
    315362    // Read a bunch of data compressed with the Huffman algorithm
    316     uint32_t UncompressHUFFMAN(char*       dest,
    317                                const char* src,
    318                                uint32_t ,
    319                                uint32_t    sizeOfElems,
    320                                uint32_t    numRowElems)
    321     {
    322         if (sizeOfElems < 2)
    323         {
    324             cout << "Error, Huffman only works on shorts or longer types. (here: " << sizeOfElems << "). Aborting." << endl;
    325             return -1;
    326         }
    327 
     363    uint32_t UncompressHUFFMAN16(char*       dest,
     364                                 const char* src,
     365                                 uint32_t    numChunks)
     366    {
    328367        vector<uint16_t> uncompressed;
    329368
    330369        //read compressed sizes (one per row)
    331370        const uint32_t* compressedSizes = reinterpret_cast<const uint32_t*>(src);
    332         src += sizeof(uint32_t)*numRowElems;
     371        src += sizeof(uint32_t)*numChunks;
    333372
    334373        //uncompress the rows, one by one
    335374        uint32_t sizeWritten = 0;
    336         for (uint32_t j=0;j<numRowElems;j++)
     375        for (uint32_t j=0;j<numChunks;j++)
    337376        {
    338377            Huffman::Decode(reinterpret_cast<const unsigned char*>(src), compressedSizes[j], uncompressed);
     
    347386    }
    348387
    349     //Read a bunch of data compressed with the smoothman algorithm
    350     uint32_t UncompressSMOOTHMAN(int16_t*   dest,
    351                                  const char* src,
    352                                  uint32_t numRows,
    353                                  uint32_t sizeOfElems,
    354                                  uint32_t numRowElems)
    355     {
    356         //call huffman transposed
    357         const uint32_t sizeWritten = UncompressHUFFMAN(reinterpret_cast<char*>(dest), src, numRowElems, sizeOfElems, numRows);
    358 
     388    uint32_t UnApplySMOOTHING(int16_t*   data,
     389                              uint32_t numElems)
     390    {
    359391        //un-do the integer smoothing
    360         for (uint32_t j=2;j<numRowElems*numRows;j++)
    361             dest[j] = dest[j] + (dest[j-1]+dest[j-2])/2;
    362 
    363         return sizeWritten;
    364     }
    365 
     392        for (uint32_t j=2;j<numElems;j++)
     393            data[j] = data[j] + (data[j-1]+data[j-2])/2;
     394
     395        return numElems*sizeof(uint16_t);
     396    }
    366397    // Data has been read from disk. Uncompress it !
    367398    void UncompressBuffer(const uint32_t &catalogCurrentRow, const uint32_t &thisRoundNumRows)
     
    377408
    378409            //get the compression flag
    379             const int64_t compressedOffset = fTileOffsets[catalogCurrentRow][i];//fCatalog[catalogCurrentRow][i].second - fCatalog[catalogCurrentRow][0].second;
    380             const char    compressedFlag   = fCompressedBuffer[compressedOffset];
    381 
    382             //#define COMPRESSED_FLAG 0x1
    383             //#define UNCOMPRESSED_FLAG 0x0
    384 
    385             const char *src = fCompressedBuffer.data()+compressedOffset+1;
    386 
    387             //if this bunch of data is not compressed, modify the compression flag
    388             const uint32_t compression = compressedFlag==0 ? UNCOMPRESSED : col.comp;
    389             switch (compression)
    390             {
    391                 case UNCOMPRESSED:
    392                     dest += UncompressUNCOMPRESSED(dest, src, thisRoundNumRows, col.size, col.num);
    393                     break;
    394 
    395                 case SMOOTHMAN:
    396                     dest += UncompressSMOOTHMAN(reinterpret_cast<int16_t*>(dest), src, thisRoundNumRows, col.size, col.num);
    397                     break;
    398 
    399                 default:
    400                     ;
     410            const int64_t compressedOffset = fTileOffsets[catalogCurrentRow][i];
     411
     412            BlockHeader* head = reinterpret_cast<BlockHeader*>(&fCompressedBuffer[compressedOffset]);
     413
     414            fColumnOrdering[i] = head->ordering;
     415
     416            uint32_t numRows = (head->ordering==FACT_ROW_MAJOR) ? thisRoundNumRows : col.num;
     417            uint32_t numCols = (head->ordering==FACT_COL_MAJOR) ? thisRoundNumRows : col.num;
     418
     419            const char *src = fCompressedBuffer.data()+compressedOffset+sizeof(BlockHeader)+sizeof(uint16_t)*head->numProcs;
     420
     421            for (uint32_t j=head->numProcs;j != 0; j--)
     422            {
     423                uint32_t sizeWritten=0;
     424
     425                switch (head->processings[j-1])
     426                {
     427                    case FACT_RAW:
     428                            if (head->numProcs == 1)
     429                                sizeWritten = UncompressUNCOMPRESSED(dest, src, numRows*numCols, col.size);
     430                    break;
     431                    case FACT_SMOOTHING:
     432                            sizeWritten = UnApplySMOOTHING(reinterpret_cast<int16_t*>(dest), numRows*numCols);
     433                    break;
     434                    case FACT_HUFFMAN16:
     435                            sizeWritten = UncompressHUFFMAN16(dest, src, numRows);
     436                    break;
     437                    default:
     438#ifdef __EXCEPTIONS
     439                    throw runtime_error("Unknown processing applied to data. Aborting");
     440#else
     441                    gLog << ___err___ << "ERROR - Unknown processing applied to data. Aborting" << endl;
     442                    return;
     443#endif
     444                    break;
     445                }
     446                //increment destination counter only when processing done.
     447                if (j==1) dest+= sizeWritten;
    401448            }
    402449        }
Note: See TracChangeset for help on using the changeset viewer.