CMS 3D CMS Logo

Classes | Public Member Functions | Private Member Functions | Private Attributes

edm::RefCore Class Reference

#include <RefCore.h>

List of all members.

Classes

struct  CheckTransientOnWrite

Public Member Functions

EDProduct const * getProductPtr (std::type_info const &type) const
ProductID id () const
bool isAvailable () const
bool isNonnull () const
bool isNull () const
bool isTransient () const
int isTransientInt () const
void nullPointerForTransientException (std::type_info const &type) const
bool operator! () const
EDProductGetter const * productGetter () const
void productNotFoundException (std::type_info const &type) const
void const * productPtr () const
void pushBackItem (RefCore const &productToBeInserted, bool checkPointer)
 RefCore ()
 RefCore (ProductID const &theId, void const *prodPtr, EDProductGetter const *prodGetter, bool transient)
void setProductGetter (EDProductGetter const *prodGetter) const
void setProductPtr (void const *prodPtr) const
void swap (RefCore &)
void wrongTypeException (std::type_info const &expectedType, std::type_info const &actualType) const

Private Member Functions

bool cacheIsProductPtr () const
void setCacheIsProductPtr (bool iState) const
void setId (ProductID const &iId)
void setTransient ()

Private Attributes

void const * cachePtr_
ProcessIndex processIndex_
ProductIndex productIndex_
CheckTransientOnWrite transient_

Detailed Description

Definition at line 17 of file RefCore.h.


Constructor & Destructor Documentation

edm::RefCore::RefCore ( ) [inline]

Definition at line 19 of file RefCore.h.

edm::RefCore::RefCore ( ProductID const &  theId,
void const *  prodPtr,
EDProductGetter const *  prodGetter,
bool  transient 
)

Definition at line 34 of file RefCore.cc.

                                                                                                                 :
      cachePtr_(prodPtr?prodPtr:prodGetter),
      processIndex_(theId.processIndex()),
      productIndex_(theId.productIndex()),
      transient_(transient,prodPtr!=0 || prodGetter==0)
      {}

Member Function Documentation

bool edm::RefCore::cacheIsProductPtr ( ) const [inline, private]
EDProduct const * edm::RefCore::getProductPtr ( std::type_info const &  type) const

Definition at line 42 of file RefCore.cc.

References cachePtr_, edm::EDProductGetter::getIt(), id(), isTransient(), edm::ProductID::isValid(), productGetter(), productNotFoundException(), throwInvalidRefFromNoCache(), and throwInvalidRefFromNullOrInvalidRef().

Referenced by edm::refcore::getProductPtr_().

                                                       {
    // The following invariant would be nice to establish in all
    // constructors, but we can not be sure that the context in which
    // EDProductGetter::instance() is called will be one where a
    // non-null pointer is returned. The biggest question in the
    // various times at which Root makes RefCore instances, and how
    // old ones might be recycled.
    //
    // If our ProductID is non-null, we must have a way to get at the
    // product (unless it has been dropped). This means either we
    // already have the pointer to the product, or we have a valid
    // EDProductGetter to use.
    //
    //     assert(!id_.isValid() || productGetter() || prodPtr_);

    ProductID tId = id();
    assert (!isTransient());
    if (!tId.isValid()) {
      throwInvalidRefFromNullOrInvalidRef(TypeID(type));
    }

    //if (productPtr() == 0 && productGetter() == 0) {
    if (cachePtr_ == 0) {
      throwInvalidRefFromNoCache(TypeID(type),tId);
    }
    EDProduct const* product = productGetter()->getIt(tId);
    if ( 0 == product) {
      productNotFoundException(type);
    }
    return product;
  }
ProductID edm::RefCore::id ( void  ) const [inline]
bool edm::RefCore::isAvailable ( ) const
bool edm::RefCore::isNonnull ( ) const [inline]
bool edm::RefCore::isNull ( ) const [inline]

Definition at line 34 of file RefCore.h.

References isNonnull().

Referenced by operator!(), and pushBackItem().

{return !isNonnull(); }
bool edm::RefCore::isTransient ( ) const [inline]
int edm::RefCore::isTransientInt ( ) const [inline]

Definition at line 66 of file RefCore.h.

References transient_, and edm::RefCore::CheckTransientOnWrite::transient_.

{return transient_.transient_ ? 1 : 0;}
void edm::RefCore::nullPointerForTransientException ( std::type_info const &  type) const

Definition at line 95 of file RefCore.cc.

References Exception, and edm::errors::InvalidReference.

Referenced by edm::getProduct().

                                                                          {
    throw edm::Exception(errors::InvalidReference)
        << "RefCore: A request to resolve a transient reference to a product of type: "
        << TypeID(type)
        << "\ncan not be satisfied because the pointer to the product is null.\n";
  }
bool edm::RefCore::operator! ( ) const [inline]

Definition at line 40 of file RefCore.h.

References isNull().

{return isNull();}
EDProductGetter const* edm::RefCore::productGetter ( ) const [inline]
void edm::RefCore::productNotFoundException ( std::type_info const &  type) const

Definition at line 75 of file RefCore.cc.

References Exception, id(), and edm::errors::ProductNotFound.

Referenced by edm::Ptr< pat::MET >::getData_(), and getProductPtr().

                                                                  {
    throw edm::Exception(errors::ProductNotFound)
      << "RefCore: A request to resolve a reference to a product of type '"
      << TypeID(type)
      << "' with ProductID '" << id() << "'"
      << "\ncan not be satisfied because the product cannot be found."
      << "\nProbably the branch containing the product is not stored in the input file.\n";
  }
void const* edm::RefCore::productPtr ( ) const [inline]
void edm::RefCore::pushBackItem ( RefCore const &  productToBeInserted,
bool  checkPointer 
)

Definition at line 115 of file RefCore.cc.

References Exception, id(), edm::errors::InvalidReference, isNonnull(), isNull(), isTransient(), productGetter(), productPtr(), setId(), setProductGetter(), setProductPtr(), and setTransient().

Referenced by edm::PtrVectorBase::push_back_base(), and edm::RefVectorBase< key_type >::pushBack().

                                                                             {
    if (productToBeInserted.isNull() && !productToBeInserted.isTransient()) {
      throw edm::Exception(errors::InvalidReference,"Inconsistency")
        << "RefCore::pushBackItem: Ref or Ptr has invalid (zero) product ID, so it cannot be added to RefVector (PtrVector). "
        << "id should be (" << id() << ")\n";
    }
    if (isNonnull()) {
      if (isTransient() != productToBeInserted.isTransient()) {
        if (productToBeInserted.isTransient()) {
          throw edm::Exception(errors::InvalidReference,"Inconsistency")
            << "RefCore::pushBackItem: Transient Ref or Ptr cannot be added to persistable RefVector (PtrVector). "
            << "id should be (" << id() << ")\n";
        } else {
          throw edm::Exception(errors::InvalidReference,"Inconsistency")
            << "RefCore::pushBackItem: Persistable Ref or Ptr cannot be added to transient RefVector (PtrVector). "
            << "id is (" << productToBeInserted.id() << ")\n";
        }
      }
      if (!productToBeInserted.isTransient() && id() != productToBeInserted.id()) {
        throw edm::Exception(errors::InvalidReference,"Inconsistency")
          << "RefCore::pushBackItem: Ref or Ptr is inconsistent with RefVector (PtrVector)"
          << "id = (" << productToBeInserted.id() << ") should be (" << id() << ")\n";
      }
      if (productToBeInserted.isTransient() && checkPointer && productToBeInserted.isNonnull() && productToBeInserted != *this) {
        throw edm::Exception(errors::InvalidReference,"Inconsistency")
           << "RefCore::pushBackItem: Ref points into different collection than the RefVector.\n";
      }
    } else {
      if (productToBeInserted.isTransient()) {
        setTransient();
      }
      if (productToBeInserted.isNonnull()) {
        setId(productToBeInserted.id());
      }
    }
    //Since productPtr and productGetter actually share the same pointer internally,
    // we want to be sure that if the productPtr is set we use that one and only if
    // it isn't set do we set the productGetter if available
    if (productPtr() == 0 && productToBeInserted.productPtr() != 0) {
      setProductPtr(productToBeInserted.productPtr());
    } else if (productPtr() == 0 && productGetter() == 0 && productToBeInserted.productGetter() != 0) {
      setProductGetter(productToBeInserted.productGetter());
    }
  }
void edm::RefCore::setCacheIsProductPtr ( bool  iState) const [inline, private]
void edm::RefCore::setId ( ProductID const &  iId) [inline, private]

Definition at line 78 of file RefCore.h.

References edm::ProductID::processIndex(), processIndex_, edm::ProductID::productIndex(), and productIndex_.

Referenced by pushBackItem().

                                     {
      processIndex_ = iId.processIndex();
      productIndex_ = iId.productIndex();
    }
void edm::RefCore::setProductGetter ( EDProductGetter const *  prodGetter) const
void edm::RefCore::setProductPtr ( void const *  prodPtr) const [inline]
void edm::RefCore::setTransient ( ) [inline, private]

Definition at line 82 of file RefCore.h.

References transient_, and edm::RefCore::CheckTransientOnWrite::transient_.

Referenced by pushBackItem().

void edm::RefCore::swap ( RefCore other) [inline]
void edm::RefCore::wrongTypeException ( std::type_info const &  expectedType,
std::type_info const &  actualType 
) const

Definition at line 85 of file RefCore.cc.

References Exception, id(), and edm::errors::InvalidReference.

Referenced by edm::refcore::getProductPtr_().

                                                                                                    {
    throw edm::Exception(errors::InvalidReference,"WrongType")
        << "RefCore: A request to convert a contained product of type '"
        << TypeID(actualType) << "'\n"
        << " to type '" << TypeID(expectedType) << "'"
        << "\nfor ProductID '" << id()
        << "' can not be satisfied\n";
  }

Member Data Documentation

void const* edm::RefCore::cachePtr_ [mutable, private]

Definition at line 91 of file RefCore.h.

Referenced by id(), setId(), and swap().

Definition at line 92 of file RefCore.h.

Referenced by id(), setId(), and swap().