CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Namespaces | 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
 

Functions

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)
 

Function Documentation

static std::string local_error_message ( gs::AbsArchive &  ar,
const gs::AbsRecord &  record,
const char *  failedAction 
)
static

Definition at line 22 of file AbsArchive.cc.

Referenced by operator<<().

25 {
26  std::ostringstream err;
27  err << "In operator<<(gs::AbsArchive& ar, const gs::AbsRecord& record): "
28  << "failed to " << failedAction << " to the archive \""
29  << ar.name() << "\" for item with type \""
30  << record.type().name() << "\", name \""
31  << record.name() << "\", and category \""
32  << record.category() << '"';
33  return err.str();
34 }
gs::AbsArchive& operator<< ( gs::AbsArchive &  ar,
const gs::AbsRecord &  record 
)

Definition at line 36 of file AbsArchive.cc.

References newFWLiteAna::base, delta, and local_error_message().

37 {
38  // Do not reuse records
39  if (record.id()) throw gs::IOInvalidArgument(
40  "In operator<<(gs::AbsArchive& ar, const gs::AbsRecord& record): "
41  "records can not be reused");
42 
43  // Get the relevant streams. Do not change the order
44  // of the next three lines, some code which does
45  // not implement compression may actually rely on
46  // the fact that the "outputStream()" method
47  // is called before "compressedStream()".
48  std::ostream& os = ar.outputStream();
49  std::streampos base = os.tellp();
50  std::ostream& compressed = ar.compressedStream(os);
51 
52  // Write the data
53  if (!record.writeData(compressed))
54  throw gs::IOWriteFailure(local_error_message(ar, record, "write data"));
55 
56  const unsigned compressCode = ar.flushCompressedRecord(compressed);
57  if (os.fail())
58  throw gs::IOWriteFailure(local_error_message(
59  ar, record, "transfer compressed data"));
60 
61  // Figure out the record length. Naturally, can't have negative length.
62  std::streamoff off = os.tellp() - base;
63  long long delta = off;
64  assert(delta >= 0LL);
65 
66  // Add the record to the catalog
67  const unsigned long long id = ar.addToCatalog(record, compressCode, delta);
68  if (id == 0ULL)
69  throw gs::IOWriteFailure(local_error_message(
70  ar, record, "add catalog entry"));
71 
72  // Mark record as written and give feedback about item length
73  record.itemId_ = id;
74  record.itemLength_ = delta;
75 
76  // Same thing for the archive
77  ar.lastItemId_ = id;
78  ar.lastItemLength_ = delta;
79 
80  return ar;
81 }
dbl * delta
Definition: mlp_gen.cc:36
tuple base
Main Program
Definition: newFWLiteAna.py:92
static std::string local_error_message(gs::AbsArchive &ar, const gs::AbsRecord &record, const char *failedAction)
Definition: AbsArchive.cc:22