CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Namespaces | Macros | Functions
AbsArchive.cc File Reference
#include <cassert>
#include <sstream>
#include "Alignment/Geners/interface/AbsArchive.hh"
#include "Alignment/Geners/interface/IOException.hh"

Go to the source code of this file.

Namespaces

 gs
 

Macros

#define GS_STREAM_COPY_BUFFER_SIZE   65536
 

Functions

static void archive_stream_copy (std::istream &in, std::size_t count, std::ostream &out)
 
static std::string local_error_message (gs::AbsArchive &ar, const gs::AbsRecord &record, const char *failedAction)
 
gs::AbsArchive & operator<< (gs::AbsArchive &ar, const gs::AbsRecord &record)
 

Macro Definition Documentation

#define GS_STREAM_COPY_BUFFER_SIZE   65536

Definition at line 7 of file AbsArchive.cc.

Referenced by archive_stream_copy().

Function Documentation

static void archive_stream_copy ( std::istream &  in,
std::size_t  count,
std::ostream &  out 
)
static

Definition at line 9 of file AbsArchive.cc.

References edmScanValgrind::buffer, and GS_STREAM_COPY_BUFFER_SIZE.

9  {
10  if (count) {
11  const std::size_t bufsize = GS_STREAM_COPY_BUFFER_SIZE;
12  char buffer[bufsize];
13 
14  bool in_fail = in.fail();
15  bool out_fail = out.fail();
16  while (count > bufsize && !in_fail && !out_fail) {
17  in.read(buffer, bufsize);
18  in_fail = in.fail();
19  if (!in_fail) {
20  out.write(buffer, bufsize);
21  out_fail = out.fail();
22  }
23  count -= bufsize;
24  }
25  if (!in_fail && !out_fail) {
26  in.read(buffer, count);
27  if (!in.fail())
28  out.write(buffer, count);
29  }
30  }
31 }
#define GS_STREAM_COPY_BUFFER_SIZE
Definition: AbsArchive.cc:7
static std::string local_error_message ( gs::AbsArchive &  ar,
const gs::AbsRecord &  record,
const char *  failedAction 
)
static

Definition at line 132 of file AbsArchive.cc.

References submitPVValidationJobs::err.

Referenced by operator<<().

132  {
133  std::ostringstream err;
134  err << "In operator<<(gs::AbsArchive& ar, const gs::AbsRecord& record): "
135  << "failed to " << failedAction << " to the archive \"" << ar.name() << "\" for item with type \""
136  << record.type().name() << "\", name \"" << record.name() << "\", and category \"" << record.category() << '"';
137  return err.str();
138 }
gs::AbsArchive& operator<< ( gs::AbsArchive &  ar,
const gs::AbsRecord &  record 
)

Definition at line 140 of file AbsArchive.cc.

References cms::cuda::assert(), newFWLiteAna::base, CommonMethods::delta(), gpuClustering::id, and local_error_message().

140  {
141  // Do not reuse records
142  if (record.id())
143  throw gs::IOInvalidArgument(
144  "In operator<<(gs::AbsArchive& ar, const gs::AbsRecord& record): "
145  "records can not be reused");
146 
147  // Get the relevant streams. Do not change the order
148  // of the next three lines, some code which does
149  // not implement compression may actually rely on
150  // the fact that the "outputStream()" method
151  // is called before "compressedStream()".
152  std::ostream &os = ar.outputStream();
153  std::streampos base = os.tellp();
154  std::ostream &compressed = ar.compressedStream(os);
155 
156  // Write the data
157  if (!record.writeData(compressed))
158  throw gs::IOWriteFailure(local_error_message(ar, record, "write data"));
159 
160  const unsigned compressCode = ar.flushCompressedRecord(compressed);
161  if (os.fail())
162  throw gs::IOWriteFailure(local_error_message(ar, record, "transfer compressed data"));
163 
164  // Figure out the record length. Naturally, can't have negative length.
165  std::streamoff off = os.tellp() - base;
166  const long long delta = off;
167  assert(delta >= 0LL);
168 
169  // Add the record to the catalog
170  const unsigned long long id = ar.addToCatalog(record, compressCode, delta);
171  if (id == 0ULL)
172  throw gs::IOWriteFailure(local_error_message(ar, record, "add catalog entry"));
173 
174  // Mark record as written and give feedback about item length
175  record.itemId_ = id;
176  record.itemLength_ = delta;
177 
178  // Same thing for the archive
179  ar.lastItemId_ = id;
180  ar.lastItemLength_ = delta;
181 
182  return ar;
183 }
tuple base
Main Program
Definition: newFWLiteAna.py:92
uint16_t *__restrict__ id
assert(be >=bs)
static std::string local_error_message(gs::AbsArchive &ar, const gs::AbsRecord &record, const char *failedAction)
Definition: AbsArchive.cc:132