Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef GENERS_CPREFERENCE_HH_
0002 #define GENERS_CPREFERENCE_HH_
0003 
0004 #include "Alignment/Geners/interface/CPP11_config.hh"
0005 #ifdef CPP11_STD_AVAILABLE
0006 
0007 #include <memory>
0008 
0009 #include "Alignment/Geners/interface/ClassId.hh"
0010 #include "Alignment/Geners/interface/AbsReference.hh"
0011 #include "Alignment/Geners/interface/collectTupleNames.hh"
0012 
0013 namespace gs {
0014     template <class T>
0015     class CPReference : public AbsReference
0016     {
0017     public:
0018         inline CPReference(const std::vector<std::string>& columnNames,
0019                            AbsArchive& ar, const unsigned long long itemId)
0020             : AbsReference(ar, ClassId::makeId<T>(), "gs::CPHeader", itemId),
0021               colNames_(columnNames), namesProvided_(true) {}
0022 
0023         inline CPReference(const typename T::value_type& protoPack,
0024                            AbsArchive& ar, const unsigned long long itemId)
0025             : AbsReference(ar, ClassId::makeId<T>(), "gs::CPHeader", itemId),
0026               colNames_(collectTupleNames(protoPack)), namesProvided_(true) {}
0027 
0028         // Compatibility constructor. It acts in the same manner
0029         // as the RPReference constructor: the column names will
0030         // be figured out from the archive, while the input types
0031         // must be compatible with the archived types.
0032         inline CPReference(AbsArchive& ar, const unsigned long long itemId)
0033             : AbsReference(ar, ClassId::makeId<T>(), "gs::CPHeader", itemId),
0034               colNames_(), namesProvided_(false) {}
0035 
0036         inline CPReference(
0037             const std::vector<std::string>& columnNames,
0038             AbsArchive& ar, const SearchSpecifier& namePattern,
0039             const SearchSpecifier& categPattern)
0040             : AbsReference(ar, ClassId::makeId<T>(), "gs::CPHeader",
0041                            namePattern, categPattern),
0042               colNames_(columnNames), namesProvided_(true) {}
0043 
0044         inline CPReference(
0045             const typename T::value_type& protoPack,
0046             AbsArchive& ar, const SearchSpecifier& namePattern,
0047             const SearchSpecifier& categPattern)
0048             : AbsReference(ar, ClassId::makeId<T>(), "gs::CPHeader",
0049                            namePattern, categPattern),
0050               colNames_(collectTupleNames(protoPack)), namesProvided_(true) {}
0051 
0052         // Compatibility constructor
0053         inline CPReference(
0054             AbsArchive& ar, const SearchSpecifier& namePattern,
0055             const SearchSpecifier& categPattern)
0056             : AbsReference(ar, ClassId::makeId<T>(), "gs::CPHeader",
0057                            namePattern, categPattern),
0058               colNames_(), namesProvided_(false) {}
0059 
0060         // Disable class id comparison
0061         inline bool isIOCompatible(const CatalogEntry& r) const
0062             {return this->isSameIOPrototype(r);}
0063 
0064         // Methods which retrieve the object
0065         inline std::unique_ptr<T> get(const unsigned long index) const
0066             {return std::unique_ptr<T>(getPtr(index));}
0067 
0068         inline std::shared_ptr<T> getShared(
0069             const unsigned long index) const
0070             {return std::shared_ptr<T>(getPtr(index));}
0071 
0072     private:
0073         inline T* getPtr(const unsigned long number) const
0074         {
0075             const unsigned long long itemId = this->id(number);
0076             assert(itemId);
0077             return T::read(archive(),
0078                            this->positionInputStream(itemId),
0079                            itemId, colNames_, namesProvided_);
0080         }
0081 
0082         std::vector<std::string> colNames_;
0083         bool namesProvided_;
0084     };
0085 }
0086 
0087 #endif // CPP11_STD_AVAILABLE
0088 #endif // GENERS_CPREFERENCE_HH_
0089