![]() |
![]() |
00001 #ifndef DataFormats_Common_BaseHolder_h 00002 #define DataFormats_Common_BaseHolder_h 00003 00004 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h" 00005 #include "DataFormats/Common/interface/EDProductGetter.h" 00006 #include <string> 00007 #include <memory> 00008 00009 namespace edm { 00010 class ProductID; 00011 class RefHolderBase; 00012 00013 namespace reftobase { 00014 template<typename T> class BaseVectorHolder; 00015 class RefVectorHolderBase; 00016 00017 //------------------------------------------------------------------ 00018 // Class template BaseHolder<T> 00019 // 00020 // BaseHolder<T> is an abstract base class that manages a single 00021 // edm::Ref to an element of type T in a collection in the Event; 00022 // the purpose of this abstraction is to hide the type of the 00023 // collection from code that can not know about that type. 00024 // 00025 //------------------------------------------------------------------ 00026 template <typename T> 00027 class BaseHolder { 00028 public: 00029 BaseHolder(); 00030 virtual ~BaseHolder(); 00031 virtual BaseHolder<T>* clone() const = 0; 00032 00033 void swap(BaseHolder&); 00034 00035 // Return the address of the element to which the hidden Ref 00036 // refers. 00037 virtual T const* getPtr() const = 0; 00038 00039 // Return the ProductID of the collection to which the hidden 00040 // Ref refers. 00041 virtual ProductID id() const = 0; 00042 virtual size_t key() const = 0; 00043 // Check to see if the Ref hidden in 'rhs' is equal to the Ref 00044 // hidden in 'this'. They can not be equal if they are of 00045 // different types. Note that the equality test also returns 00046 // false if dynamic type of 'rhs' is different from the dynamic 00047 // type of 'this', *even when the hiddens Refs are actually 00048 // equivalent*. 00049 virtual bool isEqualTo(BaseHolder<T> const& rhs) const = 0; 00050 00051 // If the type of Ref I contain matches the type contained in 00052 // 'fillme', set the Ref in 'fillme' equal to mine and return 00053 // true. If not, write the name of the type I really contain to 00054 // msg, and return false. 00055 virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme, 00056 std::string& msg) const = 0; 00057 virtual std::auto_ptr<RefHolderBase> holder() const = 0; 00058 00059 virtual std::auto_ptr<BaseVectorHolder<T> > makeVectorHolder() const = 0; 00060 virtual std::auto_ptr<RefVectorHolderBase> makeVectorBaseHolder() const = 0; 00061 00062 virtual EDProductGetter const* productGetter() const = 0; 00063 virtual bool hasProductCache() const = 0; 00064 virtual void const * product() const = 0; 00065 00068 virtual bool isAvailable() const = 0; 00069 00070 //Used by ROOT storage 00071 CMS_CLASS_VERSION(10) 00072 00073 protected: 00074 // We want the following called only by derived classes. 00075 BaseHolder(BaseHolder const& other); 00076 BaseHolder& operator= (BaseHolder const& rhs); 00077 00078 private: 00079 }; 00080 00081 //------------------------------------------------------------------ 00082 // Implementation of BaseHolder<T> 00083 //------------------------------------------------------------------ 00084 00085 template <typename T> 00086 BaseHolder<T>::BaseHolder() 00087 { } 00088 00089 template <typename T> 00090 BaseHolder<T>::BaseHolder(BaseHolder const& other) 00091 { 00092 // Nothing to do. 00093 } 00094 00095 template <typename T> 00096 BaseHolder<T>& 00097 BaseHolder<T>::operator= (BaseHolder<T> const& other) 00098 { 00099 // No data to assign. 00100 return *this; 00101 } 00102 00103 template <typename T> 00104 BaseHolder<T>::~BaseHolder() 00105 { 00106 // nothing to do. 00107 } 00108 00109 template <typename T> 00110 void 00111 BaseHolder<T>::swap(BaseHolder<T>& other) { 00112 // nothing to do. 00113 } 00114 00115 // Free swap function 00116 template <typename T> 00117 inline 00118 void 00119 swap(BaseHolder<T>& lhs, BaseHolder<T>& rhs) { 00120 lhs.swap(rhs); 00121 } 00122 } 00123 } 00124 00125 #endif