FACT++  1.0
void CompressedFitsWriter::writeDrsCalib ( )
private

Write the drs calibration to disk, if any.

Definition at line 741 of file fitsCompressor.cc.

References _drsCalibData, _emptyBlock, CompressedFitsFile::_file, Checksum::add(), end, i, str, Checksum::str(), and Checksum::val().

Referenced by writeHeader().

742 {
743  //if file was not loaded, ignore
744  if (_drsCalibData == NULL)
745  return;
746  uint64_t whereDidIStart = _file.tellp();
747  vector<HeaderEntry> header;
748  header.push_back(HeaderEntry("XTENSION", "'BINTABLE' ", "binary table extension"));
749  header.push_back(HeaderEntry("BITPIX" , 8 , "8-bit bytes"));
750  header.push_back(HeaderEntry("NAXIS" , 2 , "2-dimensional binary table"));
751  header.push_back(HeaderEntry("NAXIS1" , 1024*1440*2 , "width of table in bytes"));
752  header.push_back(HeaderEntry("NAXIS2" , 1 , "number of rows in table"));
753  header.push_back(HeaderEntry("PCOUNT" , 0 , "size of special data area"));
754  header.push_back(HeaderEntry("GCOUNT" , 1 , "one data group (required keyword)"));
755  header.push_back(HeaderEntry("TFIELDS" , 1 , "number of fields in each row"));
756  header.push_back(HeaderEntry("CHECKSUM", "'0000000000000000' ", "Checksum for the whole HDU"));
757  header.push_back(HeaderEntry("DATASUM" , " 0" , "Checksum for the data block"));
758  header.push_back(HeaderEntry("EXTNAME" , "'ZDrsCellOffsets' ", "name of this binary table extension"));
759  header.push_back(HeaderEntry("TTYPE1" , "'OffsetCalibration' ", "label for field 1"));
760  header.push_back(HeaderEntry("TFORM1" , "'1474560I' ", "data format of field: 2-byte INTEGER"));
761 
762  for (uint32_t i=0;i<header.size();i++)
763  _file.write(header[i].fitsString().c_str(), 80);
764  //End the header
765  _file.write("END ", 80);
766  long here = _file.tellp();
767  if (here%2880)
768  _file.write(_emptyBlock.c_str(), 2880 - here%2880);
769  //now write the data itself
770  int16_t* swappedBytes = new int16_t[1024];
771  Checksum checksum;
772  for (int32_t i=0;i<1440;i++)
773  {
774  memcpy(swappedBytes, &(_drsCalibData[i*1024]), 2048);
775  for (int32_t j=0;j<2048;j+=2)
776  {
777  int8_t inter;
778  inter = reinterpret_cast<int8_t*>(swappedBytes)[j];
779  reinterpret_cast<int8_t*>(swappedBytes)[j] = reinterpret_cast<int8_t*>(swappedBytes)[j+1];
780  reinterpret_cast<int8_t*>(swappedBytes)[j+1] = inter;
781  }
782  _file.write(reinterpret_cast<char*>(swappedBytes), 2048);
783  checksum.add(reinterpret_cast<char*>(swappedBytes), 2048);
784  }
785  uint64_t whereDidIStop = _file.tellp();
786  delete[] swappedBytes;
787  //No need to pad the data, as (1440*1024*2)%2880==0
788 
789  //calculate the checksum from the header
790  ostringstream str;
791  str << checksum.val();
792  header[9] = HeaderEntry("DATASUM", str.str(), "Checksum for the data block");
793  for (vector<HeaderEntry>::iterator it=header.begin();it!=header.end(); it++)
794  checksum.add(it->fitsString().c_str(), 80);
795  string end("END ");
796  string space(" ");
797  checksum.add(end.c_str(), 80);
798  int headerRowsLeft = 36 - (header.size() + 1)%36;
799  for (int i=0;i<headerRowsLeft;i++)
800  checksum.add(space.c_str(), 80);
801  //udpate the checksum keyword
802  header[8] = HeaderEntry("CHECKSUM", checksum.str(), "Checksum for the whole HDU");
803  //and eventually re-write the header data
804  _file.seekp(whereDidIStart);
805  for (uint32_t i=0;i<header.size();i++)
806  _file.write(header[i].fitsString().c_str(), 80);
807  _file.seekp(whereDidIStop);
808 }
int i
Definition: db_dim_client.c:21
char str[80]
Definition: test_client.c:7
uint32_t val() const
Definition: checksum.h:20
int16_t * _drsCalibData
array of the Drs baseline mean
static string _emptyBlock
an empty block to be apened at the end of a file so that its length is a multiple of 2880 ...
fstream _file
The actual file streamer for accessing disk data.
std::string str(bool complm=true) const
Definition: checksum.h:148
double end
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: