CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CharBuffer.cc
Go to the documentation of this file.
1 #include "Alignment/Geners/interface/IOException.hh"
2 #include <cassert>
3 #include <climits>
4 #include <cstring>
5 
6 #include "Alignment/Geners/interface/CharBuffer.hh"
7 #include "Alignment/Geners/interface/binaryIO.hh"
8 
9 namespace gs {
10  bool CharBuffer::write(std::ostream &os) const {
11  unsigned long long tmp = 0ULL;
12  const char *buf = buf_.getPutBuffer(&tmp);
13  write_pod(os, tmp);
14  os.write(buf, tmp);
15  return !os.fail();
16  }
17 
18  unsigned long CharBuffer::size() const {
19  unsigned long long tmp = 0ULL;
20  buf_.getPutBuffer(&tmp);
21  if (tmp > ULONG_MAX)
22  throw gs::IOLengthError("In CharBuffer::size: buffer is too large");
23  return static_cast<unsigned long>(tmp);
24  }
25 
26  void CharBuffer::restore(const ClassId &id, std::istream &in, CharBuffer *buf) {
27  static const ClassId current(ClassId::makeId<CharBuffer>());
28 
29  assert(buf);
30  current.ensureSameId(id);
31 
32  unsigned long long tmp = 0ULL;
33  read_pod(in, &tmp);
34  buf->clear();
35  buf->seekp(0);
36 
37  const unsigned locLen = 4096;
38  char local[locLen];
39  std::streambuf *inbuf = in.rdbuf();
40  std::streambuf *outbuf = buf->rdbuf();
41 
42  while (tmp > locLen) {
43  inbuf->sgetn(local, locLen);
44  outbuf->sputn(local, locLen);
45  tmp -= locLen;
46  }
47  if (tmp) {
48  inbuf->sgetn(local, tmp);
49  outbuf->sputn(local, tmp);
50  }
51  if (in.fail())
52  throw IOReadFailure("In gs::CharBuffer::restore: input stream failure");
53  if (buf->fail())
54  throw IOWriteFailure("In gs::CharBuffer::restore: buffer stream failure");
55  }
56 
57  bool CharBuffer::operator==(const CharBuffer &r) const {
58  unsigned long long tmp = 0ULL;
59  const char *buf = buf_.getPutBuffer(&tmp);
60  unsigned long long tmp2 = 0ULL;
61  const char *buf2 = r.buf_.getPutBuffer(&tmp2);
62  if (tmp != tmp2)
63  return false;
64  return memcmp(buf, buf2, tmp) == 0;
65  }
66 } // namespace gs
assert(be >=bs)
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
tmp
align.sh
Definition: createJobs.py:716
tuple size
Write out results.