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

◆ GS_STREAM_COPY_BUFFER_SIZE

#define GS_STREAM_COPY_BUFFER_SIZE   65536

Definition at line 7 of file AbsArchive.cc.

Function Documentation

◆ archive_stream_copy()

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

Definition at line 9 of file AbsArchive.cc.

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 }

References edmScanValgrind::buffer, submitPVResolutionJobs::count, GS_STREAM_COPY_BUFFER_SIZE, recoMuon::in, and MillePedeFileConverter_cfg::out.

◆ local_error_message()

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.

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 }

References submitPVResolutionJobs::err, and GlobalPosition_Frontier_DevDB_cff::record.

Referenced by operator<<().

◆ operator<<()

gs::AbsArchive& operator<< ( gs::AbsArchive &  ar,
const gs::AbsRecord &  record 
)

Definition at line 139 of file AbsArchive.cc.

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 }

References cms::cuda::assert(), newFWLiteAna::base, dumpMFGeometry_cfg::delta, triggerObjects_cff::id, L1DTConfigBti_cff::LL, local_error_message(), and GlobalPosition_Frontier_DevDB_cff::record.

GS_STREAM_COPY_BUFFER_SIZE
#define GS_STREAM_COPY_BUFFER_SIZE
Definition: AbsArchive.cc:7
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
cms::cuda::assert
assert(be >=bs)
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
recoMuon::in
Definition: RecoMuonEnumerators.h:6
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
L1DTConfigBti_cff.LL
LL
Definition: L1DTConfigBti_cff.py:25
local_error_message
static std::string local_error_message(gs::AbsArchive &ar, const gs::AbsRecord &record, const char *failedAction)
Definition: AbsArchive.cc:131
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
newFWLiteAna.base
base
Definition: newFWLiteAna.py:92