Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:20

0001 #ifndef GENERS_WRITEONLYCATALOG_HH_
0002 #define GENERS_WRITEONLYCATALOG_HH_
0003 
0004 #include <iostream>
0005 
0006 #include "Alignment/Geners/interface/AbsCatalog.hh"
0007 #include <memory>
0008 
0009 namespace gs {
0010   class WriteOnlyCatalog : public AbsCatalog {
0011   public:
0012     // The output stream should be dedicated exclusively to this catalog
0013     WriteOnlyCatalog(std::ostream &os, unsigned long long firstId = 1);
0014     WriteOnlyCatalog(const WriteOnlyCatalog &) = delete;
0015     WriteOnlyCatalog &operator=(const WriteOnlyCatalog &) = delete;
0016 
0017     inline ~WriteOnlyCatalog() override {}
0018 
0019     inline unsigned long long size() const override { return count_; }
0020     inline unsigned long long smallestId() const override { return smallestId_; }
0021     inline unsigned long long largestId() const override { return largestId_; }
0022     inline bool isContiguous() const override { return true; }
0023 
0024     // The following methods will cause a run-time error: there is
0025     // no way to read a write-only catalog or to search it
0026     std::shared_ptr<const CatalogEntry> retrieveEntry(unsigned long long) const override;
0027 
0028     bool retrieveStreampos(unsigned long long id,
0029                            unsigned *compressionCode,
0030                            unsigned long long *length,
0031                            std::streampos *pos) const override;
0032 
0033     void search(const SearchSpecifier &namePattern,
0034                 const SearchSpecifier &categoryPattern,
0035                 std::vector<unsigned long long> *idsFound) const override;
0036 
0037     // Added entries will be immediately written out
0038     unsigned long long makeEntry(const ItemDescriptor &descriptor,
0039                                  unsigned compressionCode,
0040                                  unsigned long long itemLength,
0041                                  const ItemLocation &loc,
0042                                  unsigned long long offset = 0ULL) override;
0043 
0044     inline const CatalogEntry *lastEntryMade() const override { return lastEntry_.get(); }
0045 
0046     // Methods needed for I/O (not really useful,
0047     //  but must be overriden anyway)
0048     ClassId classId() const override { return ClassId(*this); }
0049     bool write(std::ostream &) const override;
0050 
0051     static inline const char *classname() { return "gs::WriteOnlyCatalog"; }
0052     static inline unsigned version() { return 2; }
0053 
0054     // The following function works only if there is a dynamic cast
0055     // which can convert "in" into std::ostream.
0056     static WriteOnlyCatalog *read(const ClassId &id, std::istream &in);
0057 
0058   protected:
0059     inline bool isEqual(const AbsCatalog &) const override { return false; }
0060 
0061   private:
0062     std::ostream &os_;
0063     unsigned long long count_;
0064     unsigned long long smallestId_;
0065     unsigned long long largestId_;
0066     std::unique_ptr<const CatalogEntry> lastEntry_;
0067   };
0068 }  // namespace gs
0069 
0070 #endif  // GENERS_WRITEONLYCATALOG_HH_