FACT++  1.0
bool Checksum::add ( const char *  buf,
size_t  len,
bool  big_endian = true 
)
inline

Definition at line 49 of file checksum.h.

References ___err___, addLoop(), addLoopSwapping(), buffer, end, gLog, and HandleCarryBits().

Referenced by add(), CompressedFitsWriter::addHeaderChecksum(), main(), ofits::Key::Out(), zfits::ReadBinaryRow(), fits::ReadBlock(), zfits::ReadCatalog(), CompressedFitsWriter::writeCatalog(), CompressedFitsWriter::writeCompressedDataToDisk(), CompressedFitsWriter::writeDrsCalib(), factofits::WriteDrsOffsetsTable(), ofits::WriteRow(), zfits::WriteRowToCopyFile(), and fits::WriteRowToCopyFile().

50  {
51  // Avoid overflows in carry bits
52  if (len>262140) // 2^18-4
53  {
54  add(buf, 262140);
55  return add(buf+262140, len-262140);
56  }
57 
58  if (len%4>0)
59  {
60  std::ostringstream sout;
61  sout << "Length " << len << " not dividable by 4";
62 
63 #ifdef __EXCEPTIONS
64  throw std::runtime_error(sout.str());
65 #else
66  gLog << ___err___ << "ERROR - " << sout.str() << std::endl;
67  return false;
68 #endif
69  }
70 
71  const uint16_t *sbuf = reinterpret_cast<const uint16_t *>(buf);
72 
73  uint32_t *hilo = reinterpret_cast<uint32_t*>(&buffer);
74 
75 
76  const uint16_t *end = sbuf + len/2;
77 
78  if (big_endian)
79  addLoopSwapping(sbuf, end, hilo);
80  else
81  addLoop(sbuf, end, hilo);
82  /*const uint16_t *end = sbuf + len/2;
83  while (1)
84  {
85  if (sbuf==end)
86  break;
87 
88  hilo[0] += ntohs(*sbuf++);
89 
90  if (sbuf==end)
91  break;
92 
93  hilo[1] += ntohs(*sbuf++);
94  }*/
95 
97 
98  return true;
99  }
void HandleCarryBits()
Definition: checksum.h:24
void addLoop(const uint16_t *sbuf, const uint16_t *end, uint32_t *hilo)
Definition: checksum.h:127
#define gLog
Definition: fits.h:36
#define ___err___
Definition: fits.h:37
uint64_t buffer
Definition: checksum.h:13
double end
void addLoopSwapping(const uint16_t *sbuf, const uint16_t *end, uint32_t *hilo)
Definition: checksum.h:101
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: