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

write one row of data Note, in a multi-threaded environment (NumThreads>0), the return code should be checked rather than the badbit() of the stream (it might have been set by a thread before the errno has been set) errno will then contain the correct error number of the last error which happened during writing.

Parameters
ptrthe source buffer
thenumber of bytes to write
Returns
the state of the file. WARNING: with multithreading, this will most likely be the state of the file before the data is actually written

Reimplemented from ofits.

Definition at line 312 of file zofits.h.

References ___err___, buffer, and gLog.

313  {
314  if (cnt != fRealRowWidth)
315  {
316 #ifdef __EXCEPTIONS
317  throw std::runtime_error("Wrong size of row given to WriteRow");
318 #else
319  gLog << ___err___ << "ERROR - Wrong size of row given to WriteRow" << std::endl;
320  return false;
321 #endif
322  }
323 
324 #ifdef __EXCEPTIONS
325  //check if something hapenned while the compression threads were working
326  //if so, re-throw the exception that was generated
328  std::rethrow_exception(fThreadsException);
329 #endif
330 
331  //copy current row to pool or rows waiting for compression
332  char* target_location = fSmartBuffer.get() + fRealRowWidth*(fTable.num_rows%fNumRowsPerTile);
333  memcpy(target_location, ptr, fRealRowWidth);
334 
335  //for now, make an extra copy of the data, for RAWSUM checksuming.
336  //Ideally this should be moved to the threads
337  //However, because the RAWSUM must be calculated before the tile is transposed, I am not sure whether
338  //one extra memcpy per row written is worse than 100 rows checksumed when the tile is full....
339  const uint32_t rawOffset = (fTable.num_rows*fRealRowWidth)%4;
340  char* buffer = fRawSumBuffer.data() + rawOffset;
341  auto ib = fRawSumBuffer.begin();
342  auto ie = fRawSumBuffer.rbegin();
343  *ib++ = 0;
344  *ib++ = 0;
345  *ib++ = 0;
346  *ib = 0;
347 
348  *ie++ = 0;
349  *ie++ = 0;
350  *ie++ = 0;
351  *ie = 0;
352 
353  memcpy(buffer, ptr, fRealRowWidth);
354 
355  fRawSum.add(fRawSumBuffer, false);
356 
357  fTable.num_rows++;
358 
359  if (fTable.num_rows % fNumRowsPerTile != 0)
360  {
361  errno = fErrno;
362  return errno==0;
363  }
364 
365  // use the least occupied queue
366  const auto imin = std::min_element(fCompressionQueues.begin(), fCompressionQueues.end());
367 
368  if (!imin->emplace(InitNextCompression()))
369  {
370 #ifdef __EXCEPTIONS
371  throw std::runtime_error("The compression queues are not started. Did you close the file before writing this row?");
372 #else
373  gLog << ___err___ << "The compression queues are not started. Did you close the file before writing this row?" << std::endl;
374  errno = 0;
375  return false;
376 #endif
377  }
378 
379  errno = fErrno;
380  return errno==0;
381  }
std::vector< char > fRawSumBuffer
buffer used for checksuming the incoming data, before compression
Definition: zofits.h:1008
uint32_t fNumRowsPerTile
Number of rows per tile.
Definition: zofits.h:980
#define gLog
Definition: fits.h:36
Checksum fRawSum
Raw sum (specific to FACT)
Definition: zofits.h:985
#define ___err___
Definition: fits.h:37
Table fTable
Definition: ofits.h:327
std::vector< Queue< CompressionTarget > > fCompressionQueues
Processing queues (=threads)
Definition: zofits.h:973
void * exception_ptr
Definition: zofits.h:24
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
int fErrno
propagate errno to main thread
Definition: zofits.h:1011
size_t num_rows
Definition: ofits.h:307
uint32_t fRealRowWidth
Width in bytes of one uncompressed row.
Definition: zofits.h:1006
std::exception_ptr fThreadsException
exception pointer to store exceptions coming from the threads
Definition: zofits.h:1010
CompressionTarget InitNextCompression()
Definition: zofits.h:393
bool add(const char *buf, size_t len, bool big_endian=true)
Definition: checksum.h:49
std::shared_ptr< char > fSmartBuffer
Smart pointer to the buffer where the incoming rows are written.
Definition: zofits.h:1007