CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StringArchive.cc
Go to the documentation of this file.
1 #include "Alignment/Geners/interface/IOException.hh"
2 #include <cassert>
3 #include <sstream>
4 
5 #include "Alignment/Geners/interface/StringArchive.hh"
6 #include "Alignment/Geners/interface/streamposIO.hh"
7 
8 namespace gs {
9  void StringArchive::search(AbsReference &reference) {
10  std::vector<unsigned long long> idlist;
11  catalog_.search(reference.namePattern(), reference.categoryPattern(), &idlist);
12  const unsigned long nfound = idlist.size();
13  for (unsigned long i = 0; i < nfound; ++i) {
14  std::shared_ptr<const CatalogEntry> pentry = catalog_.retrieveEntry(idlist[i]);
15  if (reference.isIOCompatible(*pentry))
16  addItemToReference(reference, idlist[i]);
17  }
18  }
19 
20  std::istream &StringArchive::inputStream(const unsigned long long id, long long *sz) {
21  if (!id)
22  throw gs::IOInvalidArgument("In gs::StringArchive::inputStream: invalid item id");
23  unsigned cCode;
24  std::streampos pos;
25  unsigned long long itemLen;
26  if (!catalog_.retrieveStreampos(id, &cCode, &itemLen, &pos)) {
27  std::ostringstream os;
28  os << "In gs::StringArchive::inputStream: "
29  << "failed to locate item with id " << id;
30  throw gs::IOInvalidArgument(os.str());
31  }
32  if (sz)
33  *sz = -1LL;
34  stream_.seekg(pos);
35  return stream_;
36  }
37 
38  bool StringArchive::isEqual(const AbsArchive &cata) const {
39  const StringArchive &r = static_cast<const StringArchive &>(cata);
40  return lastpos_ == r.lastpos_ && name() == r.name() && stream_ == r.stream_ && catalog_ == r.catalog_;
41  }
42 
43  bool StringArchive::write(std::ostream &of) const {
44  write_pod(of, lastpos_);
45  write_pod(of, name());
46  return !of.fail() && stream_.classId().write(of) && stream_.write(of) && catalog_.classId().write(of) &&
47  catalog_.write(of);
48  }
49 
50  StringArchive *StringArchive::read(const ClassId &id, std::istream &in) {
51  static const ClassId current(ClassId::makeId<StringArchive>());
52  current.ensureSameId(id);
53 
54  std::streampos lastpos;
55  read_pod(in, &lastpos);
56  std::string nam;
57  read_pod(in, &nam);
58  if (in.fail())
59  throw IOReadFailure("In gs::StringArchive::read: input stream failure");
60  CPP11_auto_ptr<StringArchive> archive(new StringArchive(nam.c_str()));
61  archive->lastpos_ = lastpos;
62  ClassId streamId(in, 1);
63  CharBuffer::restore(streamId, in, &archive->stream_);
64  ClassId catId(in, 1);
65  CPP11_auto_ptr<ContiguousCatalog> p(ContiguousCatalog::read(catId, in));
66  assert(p.get());
67  archive->catalog_ = *p;
68  return archive.release();
69  }
70 } // namespace gs
uint16_t *__restrict__ id
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:21
assert(be >=bs)
tuple of
Definition: haddnano.py:40