Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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