FACT++  1.0
void zfits::CheckIfFileIsConsistent ( bool  update_catalog = false)
inlineprivate

Definition at line 567 of file zfits.h.

References ___err___, clear(), first, fits::fTable, gLog, i, FITS::TileHeader::id, fits::Table::num_cols, fits::Table::num_rows, numRows, FITS::TileHeader::numRows, second, FITS::BlockHeader::size, fits::Table::sorted_cols, str, and TileHeader().

568  {
569  //goto start of heap
570  const streamoff whereAreWe = tellg();
571  seekg(fHeapOff);
572 
573  //init number of rows to zero
574  uint64_t numRows = 0;
575 
576  //get number of columns from header
577  const size_t numCols = fTable.num_cols;
578 
579  std::vector<std::vector<std::pair<int64_t, int64_t> > > catalog;
580 
581  FITS::TileHeader tileHead;
582  FITS::BlockHeader columnHead;
583 
584  streamoff offsetInHeap = 0;
585  //skip through the heap
586  while (true)
587  {
588  read((char*)(&tileHead), sizeof(FITS::TileHeader));
589  //end of file
590  if (!good())
591  break;
592 
593  //padding or corrupt data
594  if (memcmp(tileHead.id, "TILE", 4))
595  {
596  clear(rdstate()|std::ios::badbit);
597  break;
598  }
599 
600  //a new tile begins here
601  catalog.emplace_back();
602  offsetInHeap += sizeof(FITS::TileHeader);
603 
604  //skip through the columns
605  for (size_t i=0;i<numCols;i++)
606  {
607  //zero sized column do not have headers. Skip it
608  if (fTable.sorted_cols[i].num == 0)
609  {
610  catalog.back().emplace_back(0,0);
611  continue;
612  }
613 
614  //read column header
615  read((char*)(&columnHead), sizeof(FITS::BlockHeader));
616 
617  //corrupted tile
618  if (!good())
619  break;
620 
621  catalog.back().emplace_back((int64_t)(columnHead.size),offsetInHeap);
622  offsetInHeap += columnHead.size;
623  seekg(fHeapOff+offsetInHeap);
624  }
625 
626  //if we ain't good, this means that something went wrong inside the current tile.
627  if (!good())
628  {
629  catalog.pop_back();
630  break;
631  }
632  //current tile is complete. Add rows
633  numRows += tileHead.numRows;
634  }
635 
636  if (numRows != fTable.num_rows)
637  {
638  clear(rdstate()|std::ios::badbit);
639  std::ostringstream str;
640  str << "Heap data does not agree with header: " << numRows << " calculated vs " << fTable.num_rows << " from header.";
641 #ifdef __EXCEPTIONS
642  throw std::runtime_error(str.str());
643 #else
644  gLog << ___err___ << "ERROR - " << str.str() << std::endl;
645  return;
646 #endif
647  }
648 
649  if (update_catalog)
650  {
651  fCatalog = catalog;
652  //clear the bad bit before seeking back (we hit eof)
653  clear();
654  seekg(whereAreWe);
655  return;
656  }
657 
658  if (catalog.size() != fCatalog.size())
659  {
660  clear(rdstate()|std::ios::badbit);
661 #ifdef __EXCEPTIONS
662  throw std::runtime_error("Heap data does not agree with header.");
663 #else
664  gLog << ___err___ << "ERROR - Heap data does not agree with header." << std::endl;
665  return;
666 #endif
667  }
668 
669  for (uint32_t i=0;i<catalog.size(); i++)
670  for (uint32_t j=0;j<numCols;j++)
671  {
672  if (catalog[i][j].first != fCatalog[i][j].first ||
673  catalog[i][j].second != fCatalog[i][j].second)
674  {
675  clear(rdstate()|std::ios::badbit);
676 #ifdef __EXCEPTIONS
677  throw std::runtime_error("Heap data does not agree with header.");
678 #else
679  gLog << ___err___ << "ERROR - Heap data does not agree with header." << std::endl;
680  return;
681 #endif
682  }
683  }
684  //go back to start of heap
685  //clear the bad bit before seeking back (we hit eof)
686  clear();
687  seekg(whereAreWe);
688  }
uint64_t size
Definition: FITS.h:130
streamoff fHeapOff
offset from the beginning of the file of the binary data
Definition: zfits.h:147
char id[4]
Definition: FITS.h:114
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
char str[80]
Definition: test_client.c:7
uint32_t numRows
Definition: FITS.h:115
size_t num_cols
Definition: fits.h:98
int64_t first
Size of this column in the tile.
Definition: zofits.h:26
SortedColumns sorted_cols
Definition: fits.h:117
#define gLog
Definition: fits.h:36
#define ___err___
Definition: fits.h:37
size_t num_rows
Definition: fits.h:97
Table fTable
Definition: fits.h:502
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
void clear()
Definition: HeadersFTM.h:216
uint32_t numRows
Definition: FITS.h:72
TileHeader()
Definition: FITS.h:75

+ Here is the call graph for this function: