Changeset 16897 for trunk/FACT++
- Timestamp:
- 06/24/13 15:57:53 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/FACT++/src/fitsCompressor.cc ¶
r16882 r16897 433 433 bool writeBinaryRow(const char* bufferToWrite); 434 434 435 uint32_t getRowWidth(); 436 435 437 ///@brief assign a given (already loaded) drs calibration 436 438 void setDrsCalib(int16_t* data); … … 627 629 if (_buffer != NULL) 628 630 { 631 _buffer = _buffer-4; 629 632 delete[] _buffer; 630 633 _buffer = NULL; … … 649 652 if (_buffer) 650 653 { 654 _buffer = _buffer - 4; 651 655 delete[] _buffer; 652 656 for (uint32_t i=0;i<_compressedBuffer.size();i++) … … 657 661 } 658 662 } 659 _buffer = new char[_rowWidth*_numRowsPerTile ];663 _buffer = new char[_rowWidth*_numRowsPerTile + 12]; 660 664 if (_buffer == NULL) return false; 665 memset(_buffer, 0, 4); 666 _buffer = _buffer + 4; 661 667 if (_compressedBuffer.size() != _numThreads) 662 668 { … … 667 673 { 668 674 _transposedBuffer[i] = new char[_rowWidth*_numRowsPerTile]; 669 _compressedBuffer[i] = new char[_rowWidth*_numRowsPerTile + _columns.size() + sizeof(TileHeader) ]; //use a bit more memory for compression flags675 _compressedBuffer[i] = new char[_rowWidth*_numRowsPerTile + _columns.size() + sizeof(TileHeader) + 12]; //use a bit more memory for compression flags and checksumming 670 676 if (_transposedBuffer[i] == NULL || _compressedBuffer[i] == NULL) 671 677 return false; … … 1133 1139 setHeaderKey(HeaderEntry("PCOUNT", 0, "size of special data area")); 1134 1140 } 1141 ostringstream str; 1142 1135 1143 writeHeader(true); 1136 1144 1137 ostringstream str;1145 str.str(""); 1138 1146 str << _checksum.val(); 1139 1147 … … 1160 1168 { 1161 1169 uint32_t thisRoundNumRows = (_totalNumRows%_numRowsPerTile) ? _totalNumRows%_numRowsPerTile : _numRowsPerTile; 1170 1162 1171 //copy the tile and transpose it 1163 1172 uint32_t offset = 0; … … 1215 1224 } 1216 1225 return _file.good(); 1226 } 1227 1228 uint32_t CompressedFitsWriter::getRowWidth() 1229 { 1230 return _rowWidth; 1217 1231 } 1218 1232 … … 1642 1656 //allocate the buffer for temporary storage of each read/written row 1643 1657 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; 1645 1661 1646 1662 //get the source columns … … 1651 1667 1652 1668 //Add columns. 1669 uint32_t totalRowWidth = 0; 1653 1670 for (uint32_t i=0;i<sortedColumns.size(); i++) 1654 1671 { … … 1674 1691 smoothmanProcessings[1] = FACT_HUFFMAN16; 1675 1692 // smoothmanProcessings[2] = FACT_RAW; 1693 1694 totalRowWidth += sortedColumns[i].bytes; 1676 1695 1677 1696 //first lets see if we do have an explicit request … … 1735 1754 // cout << i->first << endl; 1736 1755 } 1756 1757 outFile.setHeaderKey(CompressedFitsFile::HeaderEntry("RAWSUM", " 0", "Checksum of raw littlen endian data")); 1737 1758 1738 1759 //deal with the DRS calib … … 1826 1847 } 1827 1848 1849 Checksum rawsum; 1828 1850 //Convert each row one after the other 1829 1851 for (uint32_t i=0;i<inFile.GetNumRows();i++) … … 1838 1860 count++; 1839 1861 } 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); 1840 1874 1841 1875 if (startCellOffset != -1) … … 1851 1885 outFile.writeBinaryRow(buffer); 1852 1886 }; 1887 ostringstream strSum; 1888 strSum << rawsum.val(); 1889 outFile.setHeaderKey(CompressedFitsFile::HeaderEntry("RAWSUM", strSum.str(), "Checksum of raw littlen endian data")); 1853 1890 1854 1891 //Get table name for later use in case the compressed file is to be verified … … 1927 1964 continue; 1928 1965 } 1966 if (k == "RAWSUM") 1967 { 1968 continue; 1969 } 1929 1970 1930 1971 if (k == "ZDTASUM") … … 2028 2069 // verifyFile.close(); 2029 2070 if (!verifyFile.IsFileOk()) 2030 cout << "ERROR: file checksum seems wrong" << endl;2071 cout << "ERROR: file checksums seems wrong" << endl; 2031 2072 2032 2073 reconstructedFile.close(); … … 2051 2092 } 2052 2093 2094 buffer = buffer-4; 2053 2095 delete[] buffer; 2054 2096 return 0; 2055 2056 } 2057 2097 } 2098
Note:
See TracChangeset
for help on using the changeset viewer.