FACT++  1.0
bool zofits::WriteCatalog ( )
inlinevirtual

Write the data catalog

Returns
the state of the file

Reimplemented from ofits.

Definition at line 247 of file zofits.h.

248  {
249  const uint32_t one_catalog_row_size = fTable.num_cols*2*sizeof(uint64_t);
250  const uint32_t total_catalog_size = fNumTiles*one_catalog_row_size;
251 
252  // swap the catalog bytes before writing
253  std::vector<char> swapped_catalog(total_catalog_size);
254 
255  uint32_t shift = 0;
256  for (auto it=fCatalog.cbegin(); it!=fCatalog.cend(); it++)
257  {
258  revcpy<sizeof(uint64_t)>(swapped_catalog.data() + shift, (char*)(it->data()), fTable.num_cols*2);
259  shift += one_catalog_row_size;
260  }
261 
262  if (fCatalogSize < fNumTiles)
263  memset(swapped_catalog.data()+shift, 0, total_catalog_size-shift);
264 
265  // first time writing ? remember where we are
266  if (fCatalogOffset == 0)
267  fCatalogOffset = tellp();
268 
269  // remember where we came from
270  const off_t where_are_we = tellp();
271 
272  // write to disk
273  seekp(fCatalogOffset);
274  write(swapped_catalog.data(), total_catalog_size);
275 
276  if (where_are_we != fCatalogOffset)
277  seekp(where_are_we);
278 
279  // udpate checksum
280  fCatalogSum.reset();
281  fCatalogSum.add(swapped_catalog.data(), total_catalog_size);
282 
283  return good();
284  }
uint32_t fCatalogSize
Actual catalog size (.size() is slow on large lists)
Definition: zofits.h:978
Checksum fCatalogSum
Checksum of the catalog.
Definition: zofits.h:984
Table fTable
Definition: ofits.h:327
void reset()
Definition: checksum.h:15
off_t fCatalogOffset
Offset of the catalog from the beginning of the file.
Definition: zofits.h:981
uint32_t fNumTiles
Number of pre-reserved tiles.
Definition: zofits.h:979
size_t num_cols
Definition: ofits.h:308
CatalogType fCatalog
Catalog for this file.
Definition: zofits.h:977
bool add(const char *buf, size_t len, bool big_endian=true)
Definition: checksum.h:49