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  {
27  if (!id) throw gs::IOInvalidArgument(
28  "In gs::StringArchive::inputStream: invalid item id");
29  unsigned cCode;
30  std::streampos pos;
31  unsigned long long itemLen;
32  if (!catalog_.retrieveStreampos(id, &cCode, &itemLen, &pos))
33  {
34  std::ostringstream os;
35  os << "In gs::StringArchive::inputStream: "
36  << "failed to locate item with id " << id;
37  throw gs::IOInvalidArgument(os.str());
38  }
39  stream_.seekg(pos);
40  return stream_;
41  }
42 
43  bool StringArchive::isEqual(const AbsArchive& cata) const
44  {
45  const StringArchive& r = static_cast<const StringArchive&>(cata);
46  return lastpos_ == r.lastpos_ &&
47  name() == r.name() &&
48  stream_ == r.stream_ &&
49  catalog_ == r.catalog_;
50  }
51 
52  bool StringArchive::write(std::ostream& of) const
53  {
54  write_pod(of, lastpos_);
55  write_pod(of, name());
56  return !of.fail() &&
57  stream_.classId().write(of) &&
58  stream_.write(of) &&
59  catalog_.classId().write(of) &&
60  catalog_.write(of);
61  }
62 
63  StringArchive* StringArchive::read(const ClassId& id, std::istream& in)
64  {
65  static const ClassId current(ClassId::makeId<StringArchive>());
66  current.ensureSameId(id);
67 
68  std::streampos lastpos;
69  read_pod(in, &lastpos);
70  std::string nam;
71  read_pod(in, &nam);
72  if (in.fail()) throw IOReadFailure(
73  "In gs::StringArchive::read: input stream failure");
74  CPP11_auto_ptr<StringArchive> archive(new StringArchive(nam.c_str()));
75  archive->lastpos_ = lastpos;
76  ClassId streamId(in, 1);
77  CharBuffer::restore(streamId, in, &archive->stream_);
78  ClassId catId(in, 1);
79  CPP11_auto_ptr<ContiguousCatalog> p(ContiguousCatalog::read(catId, in));
80  assert(p.get());
81  archive->catalog_ = *p;
82  return archive.release();
83  }
84 }
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:224