Changeset 16897
- Timestamp:
- 06/24/13 15:57:53 (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
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 -
trunk/Mars/mcore/checksum.h
r16670 r16897 47 47 48 48 49 bool add(const char *buf, size_t len )49 bool add(const char *buf, size_t len, bool big_endian = true) 50 50 { 51 51 // Avoid overflows in carry bits … … 73 73 uint32_t *hilo = reinterpret_cast<uint32_t*>(&buffer); 74 74 75 76 const uint16_t *end = sbuf + len/2; 77 78 if (big_endian) 79 addLoopSwapping(sbuf, end, hilo); 80 else 81 addLoop(sbuf, end, hilo); 82 /*const uint16_t *end = sbuf + len/2; 83 while (1) 84 { 85 if (sbuf==end) 86 break; 87 88 hilo[0] += ntohs(*sbuf++); 89 90 if (sbuf==end) 91 break; 92 93 hilo[1] += ntohs(*sbuf++); 94 }*/ 95 96 HandleCarryBits(); 97 98 return true; 99 } 100 101 void addLoopSwapping(const uint16_t *sbuf, const uint16_t *end, uint32_t* hilo) 102 { 75 103 /* 76 104 for (size_t i = 0; i < len/2; i++) … … 83 111 // This is about as twice as fast as the loop above 84 112 // ntohs is CPU optimized, i%2 doesn't need to be computed 85 const uint16_t *end = sbuf + len/2;86 113 while (1) 87 114 { … … 96 123 hilo[1] += ntohs(*sbuf++); 97 124 } 98 99 HandleCarryBits(); 100 101 return true; 102 } 103 104 bool add(const vector<char> &v) 105 { 106 return add(v.data(), v.size()); 125 } 126 127 void addLoop(const uint16_t *sbuf, const uint16_t *end, uint32_t* hilo) 128 { 129 while (1) 130 { 131 if (sbuf==end) 132 break; 133 134 hilo[0] += ntohs(*sbuf++); 135 136 if (sbuf==end) 137 break; 138 139 hilo[1] += ntohs(*sbuf++); 140 } 141 } 142 143 bool add(const vector<char> &v, bool big_endian = true) 144 { 145 return add(v.data(), v.size(), big_endian); 107 146 } 108 147 -
trunk/Mars/mcore/zfits.h
r16890 r16897 70 70 } 71 71 72 virtual bool IsFileOk() const 73 { 74 bool rawsum = true; 75 76 if (HasKey("RAWSUM")) 77 { 78 ostringstream str; 79 str << fRawsum.val(); 80 rawsum = (GetStr("RAWSUM") == str.str()); 81 } 82 83 return fits::IsFileOk() && rawsum; 84 }; 85 72 86 protected: 73 87 … … 130 144 131 145 if (fTable.is_compressed) 132 {133 for (auto it=fTable.sorted_cols.begin(); it!= fTable.sorted_cols.end(); it++)146 for (auto it=fTable.sorted_cols.begin(); it!= fTable.sorted_cols.end(); it++) 147 if (it->comp != kCompFACT) 134 148 { 135 149 if (it->comp == kCompFACT) … … 190 204 vector<size_t> fTileSize; ///< size in bytes of each compressed tile 191 205 vector<vector<size_t>> fTileOffsets; ///< offset from start of tile of a given compressed column 206 207 Checksum fRawsum; ///< Checksum of the uncompressed, raw data 192 208 193 209 // Get buffer space … … 270 286 //overrides fits.h method with empty one 271 287 //work is done in ReadBinaryRow because it requires volatile data from ReadBinaryRow 272 virtual void WriteRowToCopyFile(size_t ) 273 { 274 288 virtual void WriteRowToCopyFile(size_t row) 289 { 290 if (row == fRow+1) 291 fRawsum.add(fBufferRow, false); 275 292 } 276 293
Note:
See TracChangeset
for help on using the changeset viewer.