FACT++  1.0
uint64_t zofits::compressBuffer ( char *  dest,
char *  src,
uint32_t  num_rows,
CatalogRow catalog_row 
)
inlineprotected

Compress a given buffer based on its source and destination.

Parameters
destthe buffer hosting the compressed data
srcthe buffer hosting the transposed data
num_rowsthe number of uncompressed rows in the transposed buffer
thenumber of bytes of the compressed data

Definition at line 765 of file zofits.h.

References FITS::Compression::getNumProcs(), FITS::Compression::getOrdering(), FITS::Compression::getProc(), FITS::Compression::getSizeOnDisk(), i, FITS::kFactHuffman16, FITS::kFactRaw, FITS::kFactSmoothing, FITS::kOrderByCol, FITS::Compression::Memcpy(), FITS::Compression::SetBlockSize(), and TileHeader().

766  {
767  const uint32_t thisRoundNumRows = (num_rows%fNumRowsPerTile) ? num_rows%fNumRowsPerTile : fNumRowsPerTile;
768  uint32_t offset = 0;
769 
770  //skip the checksum reserved area
771  dest += 4;
772 
773  //skip the 'TILE' marker and tile size entry
774  uint64_t compressedOffset = sizeof(FITS::TileHeader);
775 
776  //now compress each column one by one by calling compression on arrays
777  for (uint32_t i=0;i<fRealColumns.size();i++)
778  {
779  catalog_row[i].second = compressedOffset;
780 
781  if (fRealColumns[i].col.num == 0)
782  continue;
783 
784  FITS::Compression& head = fRealColumns[i].block_head;
785 
786  //set the default byte telling if uncompressed the compressed Flag
787  const uint64_t previousOffset = compressedOffset;
788 
789  //skip header data
790  compressedOffset += head.getSizeOnDisk();
791 
792  for (uint32_t j=0;j<head.getNumProcs();j++)//sequence.size(); j++)
793  {
794  switch (head.getProc(j))
795  {
796  case FITS::kFactRaw:
797  compressedOffset += compressUNCOMPRESSED(dest + compressedOffset, src + offset, thisRoundNumRows*fRealColumns[i].col.size*fRealColumns[i].col.num);
798  break;
799 
801  applySMOOTHING(src + offset, thisRoundNumRows*fRealColumns[i].col.num);
802  break;
803 
805  if (head.getOrdering() == FITS::kOrderByCol)
806  compressedOffset += compressHUFFMAN16(dest + compressedOffset, src + offset, thisRoundNumRows, fRealColumns[i].col.size, fRealColumns[i].col.num);
807  else
808  compressedOffset += compressHUFFMAN16(dest + compressedOffset, src + offset, fRealColumns[i].col.num, fRealColumns[i].col.size, thisRoundNumRows);
809  break;
810  }
811  }
812 
813  //check if compressed size is larger than uncompressed
814  //if so set flag and redo it uncompressed
815  if ((head.getProc(0) != FITS::kFactRaw) && (compressedOffset - previousOffset > fRealColumns[i].col.size*fRealColumns[i].col.num*thisRoundNumRows+head.getSizeOnDisk()))// && two)
816  {
817  //de-smooth !
818  if (head.getProc(0) == FITS::kFactSmoothing)
819  UnApplySMOOTHING(src+offset, fRealColumns[i].col.num*thisRoundNumRows);
820 
822 
823  compressedOffset = previousOffset + he.getSizeOnDisk();
824  compressedOffset += compressUNCOMPRESSED(dest + compressedOffset, src + offset, thisRoundNumRows*fRealColumns[i].col.size*fRealColumns[i].col.num);
825 
826  he.SetBlockSize(compressedOffset - previousOffset);
827  he.Memcpy(dest+previousOffset);
828 
829  offset += thisRoundNumRows*fRealColumns[i].col.size*fRealColumns[i].col.num;
830 
831  catalog_row[i].first = compressedOffset - catalog_row[i].second;
832  continue;
833  }
834 
835  head.SetBlockSize(compressedOffset - previousOffset);
836  head.Memcpy(dest + previousOffset);
837 
838  offset += thisRoundNumRows*fRealColumns[i].col.size*fRealColumns[i].col.num;
839  catalog_row[i].first = compressedOffset - catalog_row[i].second;
840  }
841 
842  const FITS::TileHeader tile_head(thisRoundNumRows, compressedOffset);
843  memcpy(dest, &tile_head, sizeof(FITS::TileHeader));
844 
845  return compressedOffset;
846  }
uint32_t fNumRowsPerTile
Number of rows per tile.
Definition: zofits.h:980
RowOrdering_t getOrdering() const
Definition: FITS.h:170
int i
Definition: db_dim_client.c:21
uint32_t compressHUFFMAN16(char *dest, const char *src, uint32_t numRows, uint32_t sizeOfElems, uint32_t numRowElems)
Definition: zofits.h:900
void Memcpy(char *dest) const
Definition: FITS.h:176
uint32_t getSizeOnDisk() const
Definition: FITS.h:171
uint32_t UnApplySMOOTHING(char *data, uint32_t numElems)
Definition: zofits.h:956
uint16_t getNumProcs() const
Definition: FITS.h:173
uint32_t compressUNCOMPRESSED(char *dest, const char *src, uint32_t size)
Definition: zofits.h:887
CompressionProcess_t getProc(uint32_t i) const
Definition: FITS.h:172
uint32_t applySMOOTHING(char *data, uint32_t numElems)
Definition: zofits.h:943
std::vector< CompressedColumn > fRealColumns
Vector hosting the columns of the file.
Definition: zofits.h:1005
TileHeader()
Definition: FITS.h:75
void SetBlockSize(uint64_t size)
Definition: FITS.h:175

+ Here is the call graph for this function: