Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-24 02:18:29

0001 #ifndef DataFormats_Common_BaseHolder_h
0002 #define DataFormats_Common_BaseHolder_h
0003 
0004 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h"
0005 #include "DataFormats/Common/interface/EDProductGetter.h"
0006 
0007 #include <memory>
0008 
0009 namespace edm {
0010   class ProductID;
0011 
0012   namespace reftobase {
0013     class RefHolderBase;
0014     template <typename T>
0015     class BaseVectorHolder;
0016     class RefVectorHolderBase;
0017 
0018     //------------------------------------------------------------------
0019     // Class template BaseHolder<T>
0020     //
0021     // BaseHolder<T> is an abstract base class that manages a single
0022     // edm::Ref to an element of type T in a collection in the Event;
0023     // the purpose of this abstraction is to hide the type of the
0024     // collection from code that can not know about that type.
0025     //
0026     //------------------------------------------------------------------
0027     template <typename T>
0028     class BaseHolder {
0029     public:
0030       BaseHolder();
0031       virtual ~BaseHolder();
0032       virtual BaseHolder<T>* clone() const = 0;
0033 
0034       void swap(BaseHolder&);
0035 
0036       // Return the address of the element to which the hidden Ref
0037       // refers.
0038       virtual T const* getPtr() const = 0;
0039 
0040       // Return the ProductID of the collection to which the hidden
0041       // Ref refers.
0042       virtual ProductID id() const = 0;
0043       virtual size_t key() const = 0;
0044       // Check to see if the Ref hidden in 'rhs' is equal to the Ref
0045       // hidden in 'this'. They can not be equal if they are of
0046       // different types. Note that the equality test also returns
0047       // false if dynamic type of 'rhs' is different from the dynamic
0048       // type of 'this', *even when the hiddens Refs are actually
0049       // equivalent*.
0050       virtual bool isEqualTo(BaseHolder<T> const& rhs) const = 0;
0051 
0052       virtual std::unique_ptr<RefHolderBase> holder() const = 0;
0053 
0054       virtual std::unique_ptr<BaseVectorHolder<T> > makeVectorHolder() const = 0;
0055 
0056       virtual EDProductGetter const* productGetter() const = 0;
0057 
0058       /// Checks if product collection is in memory or available
0059       /// in the Event. No type checking is done.
0060       virtual bool isAvailable() const = 0;
0061 
0062       virtual bool isTransient() const = 0;
0063 
0064       //Used by ROOT storage
0065       CMS_CLASS_VERSION(10)
0066 
0067     protected:
0068       // We want the following called only by derived classes.
0069       BaseHolder(BaseHolder const& other);
0070       BaseHolder& operator=(BaseHolder const& rhs);
0071 
0072     private:
0073     };
0074 
0075     //------------------------------------------------------------------
0076     // Implementation of BaseHolder<T>
0077     //------------------------------------------------------------------
0078 
0079     template <typename T>
0080     BaseHolder<T>::BaseHolder() {}
0081 
0082     template <typename T>
0083     BaseHolder<T>::BaseHolder(BaseHolder const& /*other*/) {
0084       // Nothing to do.
0085     }
0086 
0087     template <typename T>
0088     BaseHolder<T>& BaseHolder<T>::operator=(BaseHolder<T> const& /*other*/) {
0089       // No data to assign.
0090       return *this;
0091     }
0092 
0093     template <typename T>
0094     BaseHolder<T>::~BaseHolder() {
0095       // nothing to do.
0096     }
0097 
0098     template <typename T>
0099     void BaseHolder<T>::swap(BaseHolder<T>& /*other*/) {
0100       // nothing to do.
0101     }
0102 
0103     // Free swap function
0104     template <typename T>
0105     inline void swap(BaseHolder<T>& lhs, BaseHolder<T>& rhs) {
0106       lhs.swap(rhs);
0107     }
0108   }  // namespace reftobase
0109 }  // namespace edm
0110 
0111 #endif