Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-30 02:32:39

0001 #ifndef GENERS_ABSREFERENCE_HH_
0002 #define GENERS_ABSREFERENCE_HH_
0003 
0004 #include "Alignment/Geners/interface/ClassId.hh"
0005 #include "Alignment/Geners/interface/SearchSpecifier.hh"
0006 
0007 #include <iostream>
0008 #include <memory>
0009 #include <vector>
0010 
0011 namespace gs {
0012   class AbsArchive;
0013   class CatalogEntry;
0014 
0015   class AbsReference {
0016   public:
0017     AbsReference() = delete;
0018     inline virtual ~AbsReference() {}
0019 
0020     inline AbsArchive &archive() const { return archive_; }
0021     inline const ClassId &type() const { return classId_; }
0022     inline const std::string &ioPrototype() const { return ioProto_; }
0023     inline const SearchSpecifier &namePattern() const { return namePattern_; }
0024     inline const SearchSpecifier &categoryPattern() const { return categoryPattern_; }
0025 
0026     // Determine if the item in the catalog is compatible for I/O
0027     // purposes with the one referenced here
0028     virtual bool isIOCompatible(const CatalogEntry &r) const;
0029 
0030     // Check I/O prototype only allowing for class id mismatch
0031     bool isSameIOPrototype(const CatalogEntry &r) const;
0032 
0033     // Are there any items referenced?
0034     bool empty() const;
0035 
0036     // Exactly one item referenced?
0037     bool unique() const;
0038 
0039     // How many items are referenced?
0040     unsigned long size() const;
0041 
0042     // The following function throws gs::IOOutOfRange exception
0043     // if the index is out of range
0044     unsigned long long id(unsigned long index) const;
0045 
0046     // Catalog entry retrieval by index in the list of referenced items.
0047     // Throws gs::IOOutOfRange exception if the index is out of range.
0048     std::shared_ptr<const CatalogEntry> indexedCatalogEntry(unsigned long index) const;
0049 
0050   protected:
0051     // Use the following constructor to retrieve an item with
0052     // a known id
0053     AbsReference(AbsArchive &ar, const ClassId &classId, const char *ioProto, unsigned long long itemId);
0054 
0055     // Use the following constructor to search for items which
0056     // match name and category patterns
0057     AbsReference(AbsArchive &ar,
0058                  const ClassId &classId,
0059                  const char *ioProto,
0060                  const SearchSpecifier &namePattern,
0061                  const SearchSpecifier &categoryPattern);
0062 
0063     std::istream &positionInputStream(unsigned long long id) const;
0064 
0065   private:
0066     friend class AbsArchive;
0067 
0068     void initialize() const;
0069     void addItemId(unsigned long long id);
0070 
0071     AbsArchive &archive_;
0072     ClassId classId_;
0073     std::string ioProto_;
0074 
0075     // The following items will be filled or not,
0076     // depending on which constructor was called
0077     unsigned long long searchId_;
0078     SearchSpecifier namePattern_;
0079     SearchSpecifier categoryPattern_;
0080 
0081     // Id for a unique verified item
0082     unsigned long long itemId_;
0083 
0084     // The item list in case ids are not unique
0085     std::vector<unsigned long long> idList_;
0086 
0087     // We can't talk to the archive from the constructor
0088     // because we need correct "isIOCompatible" which
0089     // can be overriden by derived classes. Therefore,
0090     // we will delay archive searching until the first
0091     // function call.
0092     bool initialized_;
0093   };
0094 }  // namespace gs
0095 
0096 #endif  // GENERS_ABSREFERENCE_HH_