FACT++  1.0
virtual bool ofits::WriteRow ( const void *  ptr,
size_t  cnt,
bool  byte_swap = true 
)
inlinevirtual

Reimplemented in zofits.

Definition at line 884 of file ofits.h.

References ___err___, Checksum::add(), buffer, ofits::Table::bytes_per_row, ofits::Table::cols, gLog, ofits::Table::num_rows, ofits::Key::offset, and ofits::Table::offset.

Referenced by main(), SetDefaultKeys(), and WriteRow().

885  {
886  // FIXME: Make sure that header was already written
887  // or write header now!
888  if (cnt!=fTable.bytes_per_row)
889  {
890  std::ostringstream sout;
891  sout << "WriteRow - Size " << cnt << " does not match expected size " << fTable.bytes_per_row;
892 #ifdef __EXCEPTIONS
893  throw std::runtime_error(sout.str());
894 #else
895  gLog << ___err___ << "ERROR - " << sout.str() << std::endl;
896  return false;
897 #endif
898  }
899 
900  // For the checksum we need everything to be correctly aligned
901  const uint8_t offset = fTable.offset%4;
902 
903  char *buffer = fOutputBuffer.data() + offset;
904 
905  auto ib = fOutputBuffer.begin();
906  auto ie = fOutputBuffer.rbegin();
907  *ib++ = 0;
908  *ib++ = 0;
909  *ib++ = 0;
910  *ib = 0;
911 
912  *ie++ = 0;
913  *ie++ = 0;
914  *ie++ = 0;
915  *ie = 0;
916 
917  if (!byte_swap)
918  memcpy(buffer, ptr, cnt);
919  else
920  {
921  for (auto it=fTable.cols.cbegin(); it!=fTable.cols.cend(); it++)
922  {
923  const char *src = reinterpret_cast<const char*>(ptr) + it->offset;
924  char *dest = buffer + it->offset;
925 
926  // Let the compiler do some optimization by
927  // knowing the we only have 1, 2, 4 and 8
928  switch (it->size)
929  {
930  case 1: memcpy (dest, src, it->num*it->size); break;
931  case 2: revcpy<2>(dest, src, it->num); break;
932  case 4: revcpy<4>(dest, src, it->num); break;
933  case 8: revcpy<8>(dest, src, it->num); break;
934  }
935  }
936  }
937 
938  write(buffer, cnt);
940 
941  fTable.num_rows++;
942  fTable.offset += cnt;
943  return good();
944  }
Checksum fDataSum
Definition: ofits.h:340
off_t offset
Definition: ofits.h:304
#define gLog
Definition: fits.h:36
#define ___err___
Definition: fits.h:37
Table fTable
Definition: ofits.h:327
size_t bytes_per_row
Definition: ofits.h:306
std::vector< Column > cols
Definition: ofits.h:319
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
size_t num_rows
Definition: ofits.h:307
std::vector< char > fOutputBuffer
Definition: ofits.h:329
bool add(const char *buf, size_t len, bool big_endian=true)
Definition: checksum.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function: