FACT++  1.0
void zfits::ReadCatalog ( )
inlineprivate

Definition at line 181 of file zfits.h.

References ___err___, Checksum::add(), clear(), fits::fChkData, fits::fCopy, fNumTiles, fShrinkFactor, fits::fTable, fits::Table::GetHeapShift(), fits::GetUInt(), gLog, fits::HasKey(), i, fits::Table::num_cols, Checksum::reset(), second, and fits::Table::total_bytes.

Referenced by InitCompressionReading().

182  {
183  std::vector<char> readBuf(16);
184  fCatalog.resize(fNumTiles);
185 
186  const streampos catalogStart = tellg();
187 
188  fChkData.reset();
189 
190  //do the actual reading
191  for (uint32_t i=0;i<fNumTiles;i++)
192  for (uint32_t j=0;j<fTable.num_cols;j++)
193  {
194  read(readBuf.data(), 2*sizeof(int64_t));
195  fChkData.add(readBuf);
196  //swap the bytes
197  int64_t tempValues[2] = {0,0};
198  revcpy<8>(reinterpret_cast<char*>(tempValues), readBuf.data(), 2);
199  if (tempValues[0] < 0 || tempValues[1] < 0)
200  {
201  clear(rdstate()|std::ios::badbit);
202 #ifdef __EXCEPTIONS
203  throw std::runtime_error("Negative value in the catalog");
204 #else
205  gLog << ___err___ << "ERROR - negative value in the catalog" << std::endl;
206  return;
207 #endif
208  }
209  //add catalog entry
210  fCatalog[i].emplace_back(tempValues[0], tempValues[1]);
211  }
212 
213  //see if there is a gap before heap data
214  fHeapOff = tellg()+fTable.GetHeapShift();
215  fHeapFromDataStart = fNumTiles*fTable.num_cols*2*sizeof(int64_t) + fTable.GetHeapShift();
216 
217  //check if the catalog has been shrinked
218  fShrinkFactor = HasKey("ZSHRINK") ? GetUInt("ZSHRINK") : 1;
219 
221  {
222  clear(rdstate()|std::ios::badbit);
223 #ifdef __EXCEPTIONS
224  throw std::runtime_error("Rows per tile and shrink factor do not match");
225 #else
226  gLog << ___err___ << "ERROR - Rows per tile and shrink factor do not match" << std::endl;
227  return;
228 #endif
229  }
230 
231  if (fShrinkFactor>0)
233 
234  //compute the total size of each compressed tile
235  fTileSize.resize(fNumTiles);
236  fTileOffsets.resize(fNumTiles);
237  for (uint32_t i=0;i<fNumTiles;i++)
238  {
239  fTileSize[i] = 0;
240  for (uint32_t j=0;j<fTable.num_cols;j++)
241  {
242  fTileSize[i] += fCatalog[i][j].first;
243  fTileOffsets[i].emplace_back(fCatalog[i][j].second - fCatalog[i][0].second);
244  }
245  }
246 
247  if (!fCopy.is_open())
248  return;
249 
250  //write catalog and heap gap to target file
251  seekg(catalogStart);
252 
253  const size_t catSize = fTable.GetHeapShift() + fTable.total_bytes;
254 
255  std::vector<char> buf(catSize);
256  read(buf.data(), catSize);
257 
258  fCopy.write(buf.data(), catSize);
259  if (!fCopy)
260  clear(rdstate()|std::ios::badbit);
261  }
size_t fNumRowsPerTile
Number of rows per compressed tile.
Definition: zfits.h:143
bool HasKey(const std::string &key) const
Definition: fits.h:1002
uint64_t GetUInt(const std::string &key) const
Definition: fits.h:1009
streamoff fHeapOff
offset from the beginning of the file of the binary data
Definition: zfits.h:147
int i
Definition: db_dim_client.c:21
int64_t second
offset of this column in the tile, from the start of the heap area
Definition: zofits.h:27
size_t num_cols
Definition: fits.h:98
std::ofstream fCopy
Definition: fits.h:499
#define gLog
Definition: fits.h:36
size_t total_bytes
Definition: fits.h:99
Checksum fChkData
Definition: fits.h:517
#define ___err___
Definition: fits.h:37
Table fTable
Definition: fits.h:502
void reset()
Definition: checksum.h:15
std::vector< std::vector< std::pair< int64_t, int64_t > > > fCatalog
Catalog, i.e. the main table that points to the compressed data.
Definition: zfits.h:150
streamoff GetHeapShift() const
Definition: fits.h:454
std::vector< size_t > fTileSize
size in bytes of each compressed tile
Definition: zfits.h:151
std::vector< std::vector< size_t > > fTileOffsets
offset from start of tile of a given compressed column
Definition: zfits.h:152
size_t fNumTiles
Total number of tiles.
Definition: zfits.h:142
void clear()
Definition: HeadersFTM.h:216
streamoff fHeapFromDataStart
offset from the beginning of the data table
Definition: zfits.h:148
bool add(const char *buf, size_t len, bool big_endian=true)
Definition: checksum.h:49
size_t fShrinkFactor
shrink factor
Definition: zfits.h:145

+ Here is the call graph for this function:

+ Here is the caller graph for this function: