Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef GENERS_CONTIGUOUSCATALOG_HH_
0002 #define GENERS_CONTIGUOUSCATALOG_HH_
0003 
0004 #include "Alignment/Geners/interface/AbsCatalog.hh"
0005 
0006 #include <map>
0007 #include <memory>
0008 #include <vector>
0009 
0010 namespace gs {
0011   class ContiguousCatalog : public AbsCatalog {
0012   public:
0013     // Default constructor creates an empty catalog
0014     inline ContiguousCatalog(const unsigned long long firstId = 1) : firstId_(firstId ? firstId : 1ULL) {}
0015     inline ~ContiguousCatalog() override {}
0016 
0017     inline unsigned long long size() const override { return records_.size(); }
0018     inline unsigned long long smallestId() const override { return firstId_; }
0019     inline unsigned long long largestId() const override { return firstId_ + records_.size() - 1; }
0020     inline bool isContiguous() const override { return true; }
0021 
0022     std::shared_ptr<const CatalogEntry> retrieveEntry(unsigned long long id) const override;
0023 
0024     bool retrieveStreampos(unsigned long long id,
0025                            unsigned *compressionCode,
0026                            unsigned long long *length,
0027                            std::streampos *pos) const override;
0028 
0029     // Add a new entry without an id (id will be generated internally
0030     // and returned)
0031     unsigned long long makeEntry(const ItemDescriptor &descriptor,
0032                                  unsigned compressionCode,
0033                                  unsigned long long itemLength,
0034                                  const ItemLocation &loc,
0035                                  unsigned long long offset = 0ULL) override;
0036 
0037     inline const CatalogEntry *lastEntryMade() const override { return lastEntry_.get(); }
0038 
0039     // Search for matching entries based on item name and category
0040     void search(const SearchSpecifier &namePattern,
0041                 const SearchSpecifier &categoryPattern,
0042                 std::vector<unsigned long long> *idsFound) const override;
0043 
0044     // Methods needed for I/O
0045     ClassId classId() const override { return ClassId(*this); }
0046     bool write(std::ostream &os) const override;
0047 
0048     static inline const char *classname() { return "gs::ContiguousCatalog"; }
0049     static inline unsigned version() { return 2; }
0050     static ContiguousCatalog *read(const ClassId &id, std::istream &in);
0051 
0052   protected:
0053     bool isEqual(const AbsCatalog &) const override;
0054 
0055   private:
0056     typedef std::shared_ptr<const CatalogEntry> SPtr;
0057 
0058     // In the following multimap, item name is the key and
0059     // item id is the value
0060     typedef std::multimap<std::string, unsigned long long> NameMap;
0061 
0062     // In the following map, item category is the key
0063     typedef std::map<std::string, NameMap> RecordMap;
0064 
0065     void findByName(const NameMap &nmap,
0066                     const SearchSpecifier &namePattern,
0067                     std::vector<unsigned long long> *found) const;
0068 
0069     std::vector<SPtr> records_;
0070     unsigned long long firstId_;
0071     RecordMap recordMap_;
0072     SPtr lastEntry_;
0073 
0074     static ContiguousCatalog *read_v1(std::istream &in);
0075   };
0076 }  // namespace gs
0077 
0078 #endif  // GENERS_CONTIGUOUSCATALOG_HH_