CMS 3D CMS Logo

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, python.rootplot.argparse::category, GS_STREAM_COPY_BUFFER_SIZE, and dataset::name.

11 {
12  if (count)
13  {
14  const std::size_t bufsize = GS_STREAM_COPY_BUFFER_SIZE;
15  char buffer[bufsize];
16 
17  bool in_fail = in.fail();
18  bool out_fail = out.fail();
19  while (count > bufsize && !in_fail && !out_fail)
20  {
21  in.read(buffer, bufsize);
22  in_fail = in.fail();
23  if (!in_fail)
24  {
25  out.write(buffer, bufsize);
26  out_fail = out.fail();
27  }
28  count -= bufsize;
29  }
30  if (!in_fail && !out_fail)
31  {
32  in.read(buffer, count);
33  if (!in.fail())
34  out.write(buffer, count);
35  }
36  }
37 }
#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 143 of file AbsArchive.cc.

Referenced by operator<<().

146 {
147  std::ostringstream err;
148  err << "In operator<<(gs::AbsArchive& ar, const gs::AbsRecord& record): "
149  << "failed to " << failedAction << " to the archive \""
150  << ar.name() << "\" for item with type \""
151  << record.type().name() << "\", name \""
152  << record.name() << "\", and category \""
153  << record.category() << '"';
154  return err.str();
155 }
JetCorrectorParameters::Record record
Definition: classes.h:7
gs::AbsArchive& operator<< ( gs::AbsArchive &  ar,
const gs::AbsRecord &  record 
)

Definition at line 157 of file AbsArchive.cc.

References runEdmFileComparison::base, delta, hcalTTPDigis_cfi::id, and local_error_message().

158 {
159  // Do not reuse records
160  if (record.id()) throw gs::IOInvalidArgument(
161  "In operator<<(gs::AbsArchive& ar, const gs::AbsRecord& record): "
162  "records can not be reused");
163 
164  // Get the relevant streams. Do not change the order
165  // of the next three lines, some code which does
166  // not implement compression may actually rely on
167  // the fact that the "outputStream()" method
168  // is called before "compressedStream()".
169  std::ostream& os = ar.outputStream();
170  std::streampos base = os.tellp();
171  std::ostream& compressed = ar.compressedStream(os);
172 
173  // Write the data
174  if (!record.writeData(compressed))
175  throw gs::IOWriteFailure(local_error_message(ar, record, "write data"));
176 
177  const unsigned compressCode = ar.flushCompressedRecord(compressed);
178  if (os.fail())
179  throw gs::IOWriteFailure(local_error_message(
180  ar, record, "transfer compressed data"));
181 
182  // Figure out the record length. Naturally, can't have negative length.
183  std::streamoff off = os.tellp() - base;
184  const long long delta = off;
185  assert(delta >= 0LL);
186 
187  // Add the record to the catalog
188  const unsigned long long id = ar.addToCatalog(record, compressCode, delta);
189  if (id == 0ULL)
190  throw gs::IOWriteFailure(local_error_message(
191  ar, record, "add catalog entry"));
192 
193  // Mark record as written and give feedback about item length
194  record.itemId_ = id;
195  record.itemLength_ = delta;
196 
197  // Same thing for the archive
198  ar.lastItemId_ = id;
199  ar.lastItemLength_ = delta;
200 
201  return ar;
202 }
dbl * delta
Definition: mlp_gen.cc:36
JetCorrectorParameters::Record record
Definition: classes.h:7
base
Make Sure CMSSW is Setup ##.
static std::string local_error_message(gs::AbsArchive &ar, const gs::AbsRecord &record, const char *failedAction)
Definition: AbsArchive.cc:143