Changeset 16897 for trunk/FACT++


Ignore:
Timestamp:
06/24/13 15:57:53 (12 years ago)
Author:
lyard
Message:
Removed bytes swapping for RAWSUM
File:
1 edited

Legend:

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

    r16882 r16897  
    433433        bool writeBinaryRow(const char* bufferToWrite);
    434434
     435        uint32_t getRowWidth();
     436
    435437        ///@brief assign a given (already loaded) drs calibration
    436438        void setDrsCalib(int16_t* data);
     
    627629    if (_buffer != NULL)
    628630    {
     631        _buffer = _buffer-4;
    629632        delete[] _buffer;
    630633        _buffer = NULL;
     
    649652    if (_buffer)
    650653    {
     654        _buffer = _buffer - 4;
    651655        delete[] _buffer;
    652656        for (uint32_t i=0;i<_compressedBuffer.size();i++)
     
    657661        }
    658662    }
    659     _buffer = new char[_rowWidth*_numRowsPerTile];
     663    _buffer = new char[_rowWidth*_numRowsPerTile + 12];
    660664    if (_buffer == NULL) return false;
     665    memset(_buffer, 0, 4);
     666    _buffer = _buffer + 4;
    661667    if (_compressedBuffer.size() != _numThreads)
    662668    {
     
    667673    {
    668674        _transposedBuffer[i] = new char[_rowWidth*_numRowsPerTile];
    669         _compressedBuffer[i] = new char[_rowWidth*_numRowsPerTile + _columns.size() + sizeof(TileHeader)]; //use a bit more memory for compression flags
     675        _compressedBuffer[i] = new char[_rowWidth*_numRowsPerTile + _columns.size() + sizeof(TileHeader) + 12]; //use a bit more memory for compression flags and checksumming
    670676        if (_transposedBuffer[i] == NULL || _compressedBuffer[i] == NULL)
    671677            return false;
     
    11331139        setHeaderKey(HeaderEntry("PCOUNT", 0, "size of special data area"));
    11341140    }
     1141    ostringstream str;
     1142
    11351143    writeHeader(true);
    11361144
    1137     ostringstream str;
     1145    str.str("");
    11381146    str << _checksum.val();
    11391147
     
    11601168{
    11611169    uint32_t thisRoundNumRows = (_totalNumRows%_numRowsPerTile) ? _totalNumRows%_numRowsPerTile : _numRowsPerTile;
     1170
    11621171    //copy the tile and transpose it
    11631172    uint32_t offset = 0;
     
    12151224    }
    12161225    return _file.good();
     1226}
     1227
     1228uint32_t CompressedFitsWriter::getRowWidth()
     1229{
     1230    return _rowWidth;
    12171231}
    12181232
     
    16421656    //allocate the buffer for temporary storage of each read/written row
    16431657    uint32_t rowWidth = inFile.GetUInt("NAXIS1");
    1644     char* buffer = new char[rowWidth];
     1658    char* buffer = new char[rowWidth + 12];
     1659    memset(buffer, 0, 4);
     1660    buffer = buffer+4;
    16451661
    16461662    //get the source columns
     
    16511667
    16521668    //Add columns.
     1669    uint32_t totalRowWidth = 0;
    16531670    for (uint32_t i=0;i<sortedColumns.size(); i++)
    16541671    {
     
    16741691        smoothmanProcessings[1] = FACT_HUFFMAN16;
    16751692//        smoothmanProcessings[2] = FACT_RAW;
     1693
     1694        totalRowWidth += sortedColumns[i].bytes;
    16761695
    16771696        //first lets see if we do have an explicit request
     
    17351754//        cout << i->first << endl;
    17361755    }
     1756
     1757    outFile.setHeaderKey(CompressedFitsFile::HeaderEntry("RAWSUM", "         0", "Checksum of raw littlen endian data"));
    17371758
    17381759    //deal with the DRS calib
     
    18261847    }
    18271848
     1849    Checksum rawsum;
    18281850    //Convert each row one after the other
    18291851    for (uint32_t i=0;i<inFile.GetNumRows();i++)
     
    18381860            count++;
    18391861        }
     1862
     1863        char* checkSumPointer = buffer;
     1864        const int chkOffset = (i*totalRowWidth)%4;
     1865        checkSumPointer -= chkOffset;
     1866        uint32_t sizeToChecksum = totalRowWidth + chkOffset;
     1867        if (sizeToChecksum%4 != 0)
     1868        {
     1869            int32_t extraBytes = 4 - (sizeToChecksum%4);
     1870            memset(checkSumPointer+sizeToChecksum, 0, extraBytes);
     1871            sizeToChecksum += extraBytes;
     1872        }
     1873        rawsum.add(checkSumPointer, sizeToChecksum, false);
    18401874
    18411875        if (startCellOffset != -1)
     
    18511885        outFile.writeBinaryRow(buffer);
    18521886    };
     1887    ostringstream strSum;
     1888    strSum << rawsum.val();
     1889    outFile.setHeaderKey(CompressedFitsFile::HeaderEntry("RAWSUM", strSum.str(), "Checksum of raw littlen endian data"));
    18531890
    18541891    //Get table name for later use in case the compressed file is to be verified
     
    19271964            continue;
    19281965        }
     1966        if (k == "RAWSUM")
     1967        {
     1968            continue;
     1969        }
    19291970
    19301971        if (k == "ZDTASUM")
     
    20282069//    verifyFile.close();
    20292070    if (!verifyFile.IsFileOk())
    2030         cout << "ERROR: file checksum seems wrong" << endl;
     2071        cout << "ERROR: file checksums seems wrong" << endl;
    20312072
    20322073    reconstructedFile.close();
     
    20512092    }
    20522093
     2094    buffer = buffer-4;
    20532095    delete[] buffer;
    20542096    return 0;
    2055 
    2056 }
    2057 
     2097}
     2098
Note: See TracChangeset for help on using the changeset viewer.