Ignore:
Timestamp:
05/29/13 22:02:43 (11 years ago)
Author:
lyard
Message:
more tweaks to factfits
File:
1 edited

Legend:

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

    r16418 r16443  
    633633    {
    634634        _transposedBuffer[i] = new char[_rowWidth*_numRowsPerTile];
    635         _compressedBuffer[i] = new char[_rowWidth*_numRowsPerTile + 1024*1024]; //use a bit more memory, in case the compression algorithms uses more
     635        _compressedBuffer[i] = new char[_rowWidth*_numRowsPerTile + _columns.size()]; //use a bit more memory for compression flags
    636636        if (_transposedBuffer[i] == NULL || _compressedBuffer[i] == NULL)
    637637            return false;
     
    736736    header.push_back(HeaderEntry("CHECKSUM", "'0000000000000000'  ", "Checksum for the whole HDU"));
    737737    header.push_back(HeaderEntry("DATASUM" ,  "         0"         , "Checksum for the data block"));
    738     header.push_back(HeaderEntry("EXTNAME" , "'DrsCalib'          ", "name of this binary table extension"));
     738    header.push_back(HeaderEntry("EXTNAME" , "'IntCalibration'    ", "name of this binary table extension"));
    739739    header.push_back(HeaderEntry("TTYPE1"  , "'OffsetCalibration' ", "label for field   1"));
    740740    header.push_back(HeaderEntry("TFORM1"  , "'1474560I'          ", "data format of field: 2-byte INTEGER"));
     
    10711071        setHeaderKey(HeaderEntry("TFIELDS", _columns.size(), "number of fields in each row"));
    10721072        int64_t heapSize = 0;
    1073         uint32_t compressedOffset = 0;
     1073        int64_t compressedOffset = 0;
    10741074        for (uint32_t i=0;i<_catalog.size();i++)
    10751075            for (uint32_t j=0;j<_catalog[i].size();j++)
     
    10771077                heapSize += _catalog[i][j].first;
    10781078                //set the catalog offsets to their actual values
     1079                if (compressedOffset < 0) return false;
    10791080                _catalog[i][j].second = compressedOffset;
    10801081                compressedOffset += _catalog[i][j].first;
     
    11981199        previousHuffmanSize = huffmanOutput.size();
    11991200    }
    1200     memcpy(&dest[huffmanOffset], huffmanOutput.data(), huffmanOutput.size());
    1201     return huffmanOutput.size() + huffmanOffset;
     1201    const size_t totalSize = huffmanOutput.size() + huffmanOffset;
     1202
     1203    //only copy if not larger than not-compressed size
     1204    if (totalSize < numRows*sizeOfElems*numRowElems)
     1205        memcpy(&dest[huffmanOffset], huffmanOutput.data(), huffmanOutput.size());
     1206
     1207    return totalSize;
    12021208}
    12031209
     
    17311737            for (int j=0;j<1440;j++)
    17321738            {
    1733                 int thisStartCell = reinterpret_cast<int16_t*>(&buffer[startCellOffset])[j];
     1739                const int thisStartCell = reinterpret_cast<int16_t*>(&buffer[startCellOffset])[j];
     1740                if (thisStartCell > -1)
    17341741                for (int k=0;k<numSlices;k++)
    17351742                    reinterpret_cast<int16_t*>(&buffer[dataOffset])[numSlices*j + k] -= drsCalib16[1024*j + (thisStartCell+k)%1024];
     
    17451752
    17461753    inFile.close();
    1747     outFile.close();
     1754    if (!outFile.close())
     1755    {
     1756        cout << "Something went wrong while writing the catalog: negative index" << endl;
     1757        return false;
     1758    }
     1759
    17481760    delete[] drsCalib16;
    17491761
     
    17621774
    17631775    //get a compressed reader
    1764     factfits verifyFile(fileNameOut, tableName, false);
     1776//TEMP try to copy the file too
     1777//    string copyName("/scratch/copyFile.fz");
     1778    string copyName("");
     1779    factfits verifyFile(fileNameOut, copyName, tableName, false);
    17651780
    17661781    //and the header of the compressed file
Note: See TracChangeset for help on using the changeset viewer.