00001 // -*- C++ -*- 00002 // 00003 // Package: Common 00004 // Class : PtrVectorBase 00005 // 00006 // Implementation: 00007 // <Notes on implementation> 00008 // 00009 // Original Author: Chris Jones 00010 // Created: Wed Oct 24 15:49:27 EDT 2007 00011 // $Id: PtrVectorBase.cc,v 1.4 2008/02/15 20:06:21 wmtan Exp $ 00012 // 00013 00014 // system include files 00015 00016 // user include files 00017 #include "DataFormats/Common/interface/PtrVectorBase.h" 00018 #include "FWCore/Utilities/interface/Exception.h" 00019 #include "FWCore/Utilities/interface/EDMException.h" 00020 #include "DataFormats/Common/interface/EDProduct.h" 00021 #include "DataFormats/Common/interface/traits.h" 00022 00023 // 00024 // constants, enums and typedefs 00025 // 00026 namespace edm { 00027 // 00028 // static data member definitions 00029 // 00030 00031 // 00032 // constructor and destructor 00033 // 00034 PtrVectorBase::PtrVectorBase() 00035 { 00036 } 00037 00038 PtrVectorBase::~PtrVectorBase() 00039 { 00040 } 00041 00042 // 00043 // assignment operators 00044 // 00045 00046 // 00047 // member functions 00048 // 00049 00051 void 00052 PtrVectorBase::swap(PtrVectorBase& other){ 00053 core_.swap(other.core_); 00054 indicies_.swap(other.indicies_); 00055 cachedItems_.swap(other.cachedItems_); 00056 } 00057 00058 void 00059 PtrVectorBase::push_back_base(RefCore const& core, key_type iKey, void const* iData) { 00060 core_.pushBackItem(core, false); 00061 //Did we already push a 'non-cached' Ptr into the container or is this a 'non-cached' Ptr? 00062 if(indicies_.size() == cachedItems_.size()) { 00063 if(iData) { 00064 cachedItems_.push_back(iData); 00065 } else if(key_traits<key_type>::value == iKey) { 00066 cachedItems_.push_back(0); 00067 } else { 00068 cachedItems_.clear(); 00069 } 00070 } 00071 indicies_.push_back(iKey); 00072 } 00073 00074 // 00075 // const member functions 00076 // 00077 void 00078 PtrVectorBase::getProduct_() const { 00079 if(hasCache()) { 00080 return; 00081 } 00082 if(indicies_.size() == 0) { 00083 return; 00084 } 00085 if(0 == productGetter()) { 00086 throw edm::Exception(edm::errors::LogicError) << "Tried to get data for a PtrVector which has no EDProductGetter\n"; 00087 } 00088 EDProduct const* product = productGetter()->getIt(id()); 00089 00090 if(0==product) { 00091 throw edm::Exception(edm::errors::InvalidReference) << "Asked for data from a PtrVector which refers to a non-existent product which id " << id() << "\n"; 00092 } 00093 product->fillPtrVector(typeInfo(), 00094 indicies_, 00095 cachedItems_); 00096 } 00097 00098 bool 00099 PtrVectorBase::operator==(PtrVectorBase const& iRHS) const { 00100 if (core_ != iRHS.core_) { 00101 return false; 00102 } 00103 if (indicies_.size() != iRHS.indicies_.size()){ 00104 return false; 00105 } 00106 return std::equal(indicies_.begin(), 00107 indicies_.end(), 00108 iRHS.indicies_.begin()); 00109 return true; 00110 } 00111 00112 // 00113 // static member functions 00114 // 00115 }