FACT++  1.0
bool Fits::Write ( const Converter conv,
const void *  data 
)

Write one line of data. Use the given converter.

This writes one line of data to the file.

Parameters
convthe converter corresponding to the service being logged

Definition at line 377 of file Fits.cc.

References data, i, str, and Converter::ToFits().

378 {
379  //first copy the standard variables to the copy buffer
380  int shift = 0;
381  for (unsigned int i=0;i<fStandardNumBytes.size();i++)
382  {
383  const char *charSrc = reinterpret_cast<char*>(fStandardPointers[i]);
384  reverse_copy(charSrc, charSrc+fStandardNumBytes[i], fCopyBuffer.data()+shift);
385  shift += fStandardNumBytes[i];
386  }
387  try
388  {
389  //now take care of the DIM data. The Converter is here for that purpose
390  conv.ToFits(fCopyBuffer.data()+shift, data, fCopyBuffer.size()-shift);
391  }
392  catch (const runtime_error &e)
393  {
394  ostringstream str;
395  str << fFile->GetName() << ": " << e.what();
396  fMess->Error(str);
397  return false;
398  }
399 
400  // This is not necessary, is it?
401  // fFile->fTable->makeThisCurrent();
402  if (!fFile->AddRow())
403  {
404  Close();
406  return false;
407  }
408  if (!fFile->WriteData(fCopyBuffer))
409  {
410  Close();
411  return false;
412  }
413  const double tm = *reinterpret_cast<double*>(fStandardPointers[0]);
414 
415  //the first standard variable is the current MjD
416  if (fEndMjD==0)
417  {
418  // FIXME: Check error?
419  fFile->WriteKeyNT("TSTARTI", uint32_t(floor(tm)), "Time when first event received (integral part)");
420  fFile->WriteKeyNT("TSTARTF", fmod(tm, 1), "Time when first event received (fractional part)");
421  fFile->WriteKeyNT("TSTOPI", uint32_t(floor(fEndMjD)), "Time when last event received (integral part)");
422  fFile->WriteKeyNT("TSTOPF", fmod(fEndMjD, 1), "Time when last event received (fractional part)");
423 
424  fFile->WriteKeyNT("DATE-OBS", Time(tm+40587).Iso(),
425  "Time when first event received");
426 
427  fFile->WriteKeyNT("DATE-END", Time(fEndMjD+40587).Iso(),
428  "Time when last event received");
429  }
430 
431  fEndMjD = tm;
432 
433  return true;
434 }
vector< char > fCopyBuffer
the copy buffer. Required to put the standard and data variable in contguous memory ...
Definition: Fits.h:36
int i
Definition: db_dim_client.c:21
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
bool AddRow()
Definition: FitsFile.cc:368
vector< void * > fStandardPointers
the pointers to the standard variables
Definition: Fits.h:24
void MoveFileToCorruptedFile()
Definition: Fits.cc:349
MessageImp * fMess
were to log the errors
Definition: Fits.h:42
int Error(const std::string &str)
Definition: MessageImp.h:49
bool WriteKeyNT(const string &name, const T &value, const string &comment)
Definition: FitsFile.h:62
FitsFile * fFile
Definition: Fits.h:14
float data[4 *1440]
string GetName() const
Definition: FitsFile.h:100
vector< int > fStandardNumBytes
the number of bytes taken by each standard variable
Definition: Fits.h:26
bool WriteData(size_t &start, const void *ptr, size_t size)
Definition: FitsFile.cc:400
double fEndMjD
to keep track of the time of the latest written entry (to update the header when closing the file) ...
Definition: Fits.h:38
void Close()
Close the currently opened file.
Definition: Fits.cc:441
void ToFits(void *dest, const void *src, size_t size) const
Definition: Converter.cc:891

+ Here is the call graph for this function: