Go to the documentation of this file.00001 #ifndef DataFormats_Common_RefCore_h
00002 #define DataFormats_Common_RefCore_h
00003
00004
00005
00006
00007
00008
00009 #include "DataFormats/Common/interface/EDProductGetter.h"
00010 #include "DataFormats/Common/interface/EDProduct.h"
00011 #include "DataFormats/Provenance/interface/ProductID.h"
00012
00013 #include <algorithm>
00014 #include <typeinfo>
00015
00016 namespace edm {
00017 class RefCore {
00018 public:
00019 RefCore() : cachePtr_(0),processIndex_(0),productIndex_(0), transient_() {}
00020
00021 RefCore(ProductID const& theId, void const* prodPtr, EDProductGetter const* prodGetter, bool transient);
00022
00023 ProductID id() const {return ProductID(processIndex_,productIndex_);}
00024
00026 void const* productPtr() const {return cacheIsProductPtr()?cachePtr_:static_cast<void const*>(0);}
00027
00028 void setProductPtr(void const* prodPtr) const {
00029 cachePtr_=prodPtr;
00030 setCacheIsProductPtr(true);
00031 }
00032
00033
00034 bool isNull() const {return !isNonnull(); }
00035
00036
00037 bool isNonnull() const {return isTransient() ? productPtr() != 0 : id().isValid();}
00038
00039
00040 bool operator!() const {return isNull();}
00041
00042
00043
00044
00045 bool isAvailable() const;
00046
00047 EDProductGetter const* productGetter() const {
00048 return (!cacheIsProductPtr())? static_cast<EDProductGetter const*>(cachePtr_):
00049 static_cast<EDProductGetter const*>(0);
00050 }
00051
00052 void setProductGetter(EDProductGetter const* prodGetter) const;
00053
00054 EDProduct const* getProductPtr(std::type_info const& type) const;
00055
00056 void productNotFoundException(std::type_info const& type) const;
00057
00058 void wrongTypeException(std::type_info const& expectedType, std::type_info const& actualType) const;
00059
00060 void nullPointerForTransientException(std::type_info const& type) const;
00061
00062 void swap(RefCore &);
00063
00064 bool isTransient() const {return transient_.transient_;}
00065
00066 int isTransientInt() const {return transient_.transient_ ? 1 : 0;}
00067
00068 void pushBackItem(RefCore const& productToBeInserted, bool checkPointer);
00069
00070 struct CheckTransientOnWrite {
00071 explicit CheckTransientOnWrite(bool iValue=false, bool iIsProductPtr=false):
00072 transient_(iValue),
00073 cacheIsProductPtr_(iIsProductPtr){}
00074 bool transient_;
00075 mutable bool cacheIsProductPtr_;
00076 };
00077 private:
00078 void setId(ProductID const& iId) {
00079 processIndex_ = iId.processIndex();
00080 productIndex_ = iId.productIndex();
00081 }
00082 void setTransient() {transient_.transient_ = true;}
00083 void setCacheIsProductPtr(bool iState) const {transient_.cacheIsProductPtr_=iState;}
00084 bool cacheIsProductPtr() const {
00085 return transient_.cacheIsProductPtr_;
00086 }
00087
00088
00089 mutable void const* cachePtr_;
00090
00091 ProcessIndex processIndex_;
00092 ProductIndex productIndex_;
00093 CheckTransientOnWrite transient_;
00094
00095 };
00096
00097 inline
00098 bool
00099 operator==(RefCore const& lhs, RefCore const& rhs) {
00100 return lhs.isTransient() == rhs.isTransient() && (lhs.isTransient() ? lhs.productPtr() == rhs.productPtr() : lhs.id() == rhs.id());
00101 }
00102
00103 inline
00104 bool
00105 operator!=(RefCore const& lhs, RefCore const& rhs) {
00106 return !(lhs == rhs);
00107 }
00108
00109 inline
00110 bool
00111 operator<(RefCore const& lhs, RefCore const& rhs) {
00112 return lhs.isTransient() ? (rhs.isTransient() ? lhs.productPtr() < rhs.productPtr() : false) : (rhs.isTransient() ? true : lhs.id() < rhs.id());
00113 }
00114
00115 inline
00116 void
00117 RefCore::swap(RefCore & other) {
00118 std::swap(processIndex_, other.processIndex_);
00119 std::swap(productIndex_, other.productIndex_);
00120 std::swap(cachePtr_, other.cachePtr_);
00121 std::swap(transient_.transient_, other.transient_.transient_);
00122 std::swap(transient_.cacheIsProductPtr_, other.transient_.cacheIsProductPtr_);
00123 }
00124
00125 inline void swap(edm::RefCore & lhs, edm::RefCore & rhs) {
00126 lhs.swap(rhs);
00127 }
00128 }
00129
00130 #endif