Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef GENERS_ABSCATALOG_HH_
0002 #define GENERS_ABSCATALOG_HH_
0003 
0004 #include "Alignment/Geners/interface/CatalogEntry.hh"
0005 #include "Alignment/Geners/interface/ItemDescriptor.hh"
0006 #include "Alignment/Geners/interface/SearchSpecifier.hh"
0007 
0008 #include <cassert>
0009 #include <memory>
0010 #include <vector>
0011 
0012 namespace gs {
0013   //
0014   // This abstract class defines interfaces for adding entries to
0015   // a catalog but not for removing them. Of course, derived classes
0016   // can also implement catalog entry removal if necessary.
0017   //
0018   struct AbsCatalog {
0019     virtual ~AbsCatalog() {}
0020 
0021     // The number of entries in the catalog
0022     virtual unsigned long long size() const = 0;
0023 
0024     // Smallest and largest ids of any item in the catalog
0025     virtual unsigned long long smallestId() const = 0;
0026     virtual unsigned long long largestId() const = 0;
0027     virtual bool isContiguous() const = 0;
0028 
0029     // Check if an item with the given id is actually present in
0030     // the catalog. Catalogs which support non-contiguous item ids
0031     // (for example, if items can be removed) MUST override this.
0032     virtual bool itemExists(const unsigned long long id) const {
0033       if (id == 0ULL)
0034         return false;
0035       assert(isContiguous());
0036       return id >= smallestId() && id <= largestId();
0037     }
0038 
0039     // The following function should return the id of the new entry
0040     virtual unsigned long long makeEntry(const ItemDescriptor &descriptor,
0041                                          unsigned compressionCode,
0042                                          unsigned long long itemLength,
0043                                          const ItemLocation &loc,
0044                                          unsigned long long offset = 0ULL) = 0;
0045 
0046     // It must be possible to retrieve the entry made by the last
0047     // "makeEntry" call. If no "makeEntry" calls were made in this
0048     // program (e.g., the catalog was only read and not written),
0049     // null pointer should be returned. The entry should be owned
0050     // by the catalog itself.
0051     virtual const CatalogEntry *lastEntryMade() const = 0;
0052 
0053     // The following function returns a shared pointer to the entry.
0054     // The pointer will contain NULL in case the item is not found.
0055     virtual std::shared_ptr<const CatalogEntry> retrieveEntry(unsigned long long id) const = 0;
0056 
0057     // The following function fetches just the stream position
0058     // associated with the entry. "true" is returned on success.
0059     // Useful for catalogs which serve a single stream.
0060     virtual bool retrieveStreampos(unsigned long long id,
0061                                    unsigned *compressionCode,
0062                                    unsigned long long *length,
0063                                    std::streampos *pos) const = 0;
0064 
0065     // Search for matching entries based on item name and category
0066     virtual void search(const SearchSpecifier &namePattern,
0067                         const SearchSpecifier &categoryPattern,
0068                         std::vector<unsigned long long> *idsFound) const = 0;
0069 
0070     inline bool operator==(const AbsCatalog &r) const { return (typeid(*this) == typeid(r)) && this->isEqual(r); }
0071     inline bool operator!=(const AbsCatalog &r) const { return !(*this == r); }
0072 
0073     // Prototypes needed for I/O
0074     virtual ClassId classId() const = 0;
0075     virtual bool write(std::ostream &) const = 0;
0076 
0077   protected:
0078     virtual bool isEqual(const AbsCatalog &) const = 0;
0079   };
0080 }  // namespace gs
0081 
0082 #endif  // GENERS_ABSCATALOG_HH_