CMS 3D CMS Logo

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