FACT++  1.0
uint32_t zofits::ShrinkCatalog ( )
inline

Shrinks a catalog that is too long to fit into the reserved space at the beginning of the file.

Definition at line 415 of file zofits.h.

References i.

416  {
417  //add empty row to get either the target number of rows, or a multiple of the allowed size
418  for (uint32_t i=0;i<fCatalogSize%fNumTiles;i++)
420 
421  //did we write more rows than what the catalog could host ?
422  if (fCatalogSize <= fNumTiles) // nothing to do
423  return 1;
424 
425  //always exact as extra rows were added just above
426  const uint32_t shrink_factor = fCatalogSize / fNumTiles;
427 
428  //shrink the catalog !
429  uint32_t entry_id = 1;
430  auto it = fCatalog.begin();
431  it++;
432  for (; it != fCatalog.end(); it++)
433  {
434  if (entry_id >= fNumTiles)
435  break;
436 
437  const uint32_t target_id = entry_id*shrink_factor;
438 
439  auto jt = it;
440  for (uint32_t i=0; i<target_id-entry_id; i++)
441  jt++;
442 
443  *it = *jt;
444 
445  entry_id++;
446  }
447 
448  const uint32_t num_tiles_to_remove = fCatalogSize-fNumTiles;
449 
450  //remove the too many entries
451  for (uint32_t i=0;i<num_tiles_to_remove;i++)
452  {
453  fCatalog.pop_back();
454  fCatalogSize--;
455  }
456 
457  //update header keywords
458  fNumRowsPerTile *= shrink_factor;
459 
460  SetInt("ZTILELEN", fNumRowsPerTile);
461  SetInt("ZSHRINK", shrink_factor);
462 
463  return shrink_factor;
464  }
bool SetInt(const std::string &key, int64_t i, const std::string &comment="")
Definition: ofits.h:535
uint32_t fNumRowsPerTile
Number of rows per tile.
Definition: zofits.h:980
int i
Definition: db_dim_client.c:21
CatalogRow & AddOneCatalogRow()
Definition: zofits.h:292
uint32_t fCatalogSize
Actual catalog size (.size() is slow on large lists)
Definition: zofits.h:978
uint32_t fNumTiles
Number of pre-reserved tiles.
Definition: zofits.h:979
CatalogType fCatalog
Catalog for this file.
Definition: zofits.h:977