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

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 131 of file AbsArchive.cc.

Referenced by operator<<().

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

Definition at line 139 of file AbsArchive.cc.

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

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