CMS 3D CMS Logo

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