Changeset 16888 for trunk


Ignore:
Timestamp:
06/22/13 15:30:59 (11 years ago)
Author:
tbretz
Message:
Given proper names to the enums... we are not programming Fortran style anymore.
File:
1 edited

Legend:

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

    r16882 r16888  
    1414#include "huffman.h"
    1515
    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'
    23 */
    24 
    25 
    2616#ifndef __MARS__
    2717namespace std
     
    2919#endif
    3020
    31 enum FACT_COMPRESSION_PROCESS
    32 {
    33     FACT_RAW = 0x0,
    34     FACT_SMOOTHING = 0x1,
    35     FACT_HUFFMAN16 = 0x2
    36 };
    37 
    38 enum FACT_ROW_ORDERING
    39 {
    40     FACT_COL_MAJOR = 'C',
    41     FACT_ROW_MAJOR = 'R'
    42 };
    43 
    4421class zfits : public fits
    4522{
    4623public:
     24
     25    enum CompressionProcess_t
     26    {
     27        kFactRaw       = 0x0,
     28        kFactSmoothing = 0x1,
     29        kFactHuffman16 = 0x2
     30    };
     31
     32    enum RowOrdering_t
     33    {
     34        kOrderByCol = 'C',
     35        kOrderByRow = 'R'
     36    };
    4737
    4838    // Basic constructor
     
    122112
    123113        BlockHeader(uint64_t      s=0,
    124                     char          o=FACT_ROW_MAJOR,
     114                    char          o=kOrderByRow,
    125115                    unsigned char n=1) : size(s),
    126116                                         ordering(o),
     
    140130
    141131        if (fTable.isCompressed)
    142         for (auto it=fTable.sortedCols.begin(); it!= fTable.sortedCols.end(); it++)
    143             if (it->comp != FACT)
    144             {
    145                     clear(rdstate()|ios::badbit);
     132        {
     133            for (auto it=fTable.sortedCols.begin(); it!= fTable.sortedCols.end(); it++)
     134            {
     135                if (it->comp == kCompFACT)
     136                    continue;
     137
     138                clear(rdstate()|ios::badbit);
    146139#ifdef __EXCEPTIONS
    147                     throw runtime_error("Only the FACT compression scheme is handled by this reader.");
     140                throw runtime_error("Only the FACT compression scheme is handled by this reader.");
    148141#else
    149                     gLog << ___err___ << "ERROR - Only the FACT compression scheme is handled by this reader." << endl;
    150                     return;
    151 #endif
    152             }
     142                gLog << ___err___ << "ERROR - Only the FACT compression scheme is handled by this reader." << endl;
     143                return;
     144#endif
     145            }
     146        }
    153147
    154148        fColumnOrdering.resize(fTable.sortedCols.size());
    155149        for (auto it=fColumnOrdering.begin(); it != fColumnOrdering.end(); it++)
    156             (*it) = FACT_ROW_MAJOR;
     150            (*it) = kOrderByRow;
    157151        //Get compressed specific keywords
    158152        fNumTiles       = fTable.isCompressed ? GetInt("NAXIS2") : 0;
     
    193187    streamoff fHeapFromDataStart; ///< offset from the beginning of the data table
    194188
    195     vector<vector<pair<int64_t, int64_t> > > fCatalog;///< Catalog, i.e. the main table that points to the compressed data.
    196     vector<size_t>                           fTileSize; ///< size in bytes of each compressed tile
    197     vector<vector<size_t> >                  fTileOffsets; ///< offset from start of tile of a given compressed column
     189    vector<vector<pair<int64_t, int64_t>>> fCatalog;///< Catalog, i.e. the main table that points to the compressed data.
     190    vector<size_t>                         fTileSize; ///< size in bytes of each compressed tile
     191    vector<vector<size_t>>                 fTileOffsets; ///< offset from start of tile of a given compressed column
    198192
    199193    // Get buffer space
     
    346340                switch (fColumnOrdering[i])
    347341                {
    348                     case FACT_ROW_MAJOR:
     342                    case kOrderByRow:
    349343                        // regular, "semi-transposed" copy
    350344                        for (char *dest=buffer; dest<buffer+thisRoundNumRows*fTable.bytes_per_row; dest+=fTable.bytes_per_row) // row-by-row
     
    355349                    break;
    356350
    357                     case FACT_COL_MAJOR:
     351                    case kOrderByCol:
    358352                        // transposed copy
    359353                        for (char *elem=buffer; elem<buffer+it->bytes; elem+=it->size) // element-by-element (arrays)
     
    452446            fColumnOrdering[i] = head->ordering;
    453447
    454             const uint32_t numRows = (head->ordering==FACT_ROW_MAJOR) ? thisRoundNumRows : col.num;
    455             const uint32_t numCols = (head->ordering==FACT_COL_MAJOR) ? thisRoundNumRows : col.num;
     448            const uint32_t numRows = (head->ordering==kOrderByRow) ? thisRoundNumRows : col.num;
     449            const uint32_t numCols = (head->ordering==kOrderByCol) ? thisRoundNumRows : col.num;
    456450
    457451            const char *src = fCompressedBuffer.data()+compressedOffset+sizeof(BlockHeader)+sizeof(uint16_t)*head->numProcs;
     
    463457                switch (head->processings[j])
    464458                {
    465                     case FACT_RAW:
    466                             sizeWritten = UncompressUNCOMPRESSED(dest, src, numRows*numCols, col.size);
    467                     break;
    468                     case FACT_SMOOTHING:
    469                             sizeWritten = UnApplySMOOTHING(reinterpret_cast<int16_t*>(dest), numRows*numCols);
    470                     break;
    471                     case FACT_HUFFMAN16:
    472                             sizeWritten = UncompressHUFFMAN16(dest, src, numRows);
    473                     break;
    474                     default:
    475                         clear(rdstate()|ios::badbit);
     459                case kFactRaw:
     460                    sizeWritten = UncompressUNCOMPRESSED(dest, src, numRows*numCols, col.size);
     461                    break;
     462
     463                case kFactSmoothing:
     464                    sizeWritten = UnApplySMOOTHING(reinterpret_cast<int16_t*>(dest), numRows*numCols);
     465                    break;
     466
     467                case kFactHuffman16:
     468                    sizeWritten = UncompressHUFFMAN16(dest, src, numRows);
     469                    break;
     470
     471                default:
     472                    clear(rdstate()|ios::badbit);
    476473#ifdef __EXCEPTIONS
    477474                    throw runtime_error("Unknown processing applied to data. Aborting");
     
    482479                }
    483480                //increment destination counter only when processing done.
    484                 if (j==0) dest+= sizeWritten;
     481                if (j==0)
     482                    dest+= sizeWritten;
    485483            }
    486484        }
Note: See TracChangeset for help on using the changeset viewer.