Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:44:56

0001 #include "Alignment/Geners/interface/IOException.hh"
0002 #include <cassert>
0003 #include <sstream>
0004 
0005 #include "Alignment/Geners/interface/StringArchive.hh"
0006 #include "Alignment/Geners/interface/streamposIO.hh"
0007 
0008 namespace gs {
0009   void StringArchive::search(AbsReference &reference) {
0010     std::vector<unsigned long long> idlist;
0011     catalog_.search(reference.namePattern(), reference.categoryPattern(), &idlist);
0012     const unsigned long nfound = idlist.size();
0013     for (unsigned long i = 0; i < nfound; ++i) {
0014       std::shared_ptr<const CatalogEntry> pentry = catalog_.retrieveEntry(idlist[i]);
0015       if (reference.isIOCompatible(*pentry))
0016         addItemToReference(reference, idlist[i]);
0017     }
0018   }
0019 
0020   std::istream &StringArchive::inputStream(const unsigned long long id, long long *sz) {
0021     if (!id)
0022       throw gs::IOInvalidArgument("In gs::StringArchive::inputStream: invalid item id");
0023     unsigned cCode;
0024     std::streampos pos;
0025     unsigned long long itemLen;
0026     if (!catalog_.retrieveStreampos(id, &cCode, &itemLen, &pos)) {
0027       std::ostringstream os;
0028       os << "In gs::StringArchive::inputStream: "
0029          << "failed to locate item with id " << id;
0030       throw gs::IOInvalidArgument(os.str());
0031     }
0032     if (sz)
0033       *sz = -1LL;
0034     stream_.seekg(pos);
0035     return stream_;
0036   }
0037 
0038   bool StringArchive::isEqual(const AbsArchive &cata) const {
0039     const StringArchive &r = static_cast<const StringArchive &>(cata);
0040     return lastpos_ == r.lastpos_ && name() == r.name() && stream_ == r.stream_ && catalog_ == r.catalog_;
0041   }
0042 
0043   bool StringArchive::write(std::ostream &of) const {
0044     write_pod(of, lastpos_);
0045     write_pod(of, name());
0046     return !of.fail() && stream_.classId().write(of) && stream_.write(of) && catalog_.classId().write(of) &&
0047            catalog_.write(of);
0048   }
0049 
0050   StringArchive *StringArchive::read(const ClassId &id, std::istream &in) {
0051     static const ClassId current(ClassId::makeId<StringArchive>());
0052     current.ensureSameId(id);
0053 
0054     std::streampos lastpos;
0055     read_pod(in, &lastpos);
0056     std::string nam;
0057     read_pod(in, &nam);
0058     if (in.fail())
0059       throw IOReadFailure("In gs::StringArchive::read: input stream failure");
0060     CPP11_auto_ptr<StringArchive> archive(new StringArchive(nam.c_str()));
0061     archive->lastpos_ = lastpos;
0062     ClassId streamId(in, 1);
0063     CharBuffer::restore(streamId, in, &archive->stream_);
0064     ClassId catId(in, 1);
0065     CPP11_auto_ptr<ContiguousCatalog> p(ContiguousCatalog::read(catId, in));
0066     assert(p.get());
0067     archive->catalog_ = *p;
0068     return archive.release();
0069   }
0070 }  // namespace gs