![]() |
![]() |
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.6 2008/12/18 04:53:08 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 #include <ostream> 00023 00024 // 00025 // constants, enums and typedefs 00026 // 00027 namespace edm { 00028 // 00029 // static data member definitions 00030 // 00031 00032 // 00033 // constructor and destructor 00034 // 00035 PtrVectorBase::PtrVectorBase() 00036 { 00037 } 00038 00039 PtrVectorBase::~PtrVectorBase() 00040 { 00041 } 00042 00043 // 00044 // assignment operators 00045 // 00046 00047 // 00048 // member functions 00049 // 00050 00052 void 00053 PtrVectorBase::swap(PtrVectorBase& other){ 00054 core_.swap(other.core_); 00055 indicies_.swap(other.indicies_); 00056 cachedItems_.swap(other.cachedItems_); 00057 } 00058 00059 void 00060 PtrVectorBase::push_back_base(RefCore const& core, key_type iKey, void const* iData) { 00061 core_.pushBackItem(core, false); 00062 //Did we already push a 'non-cached' Ptr into the container or is this a 'non-cached' Ptr? 00063 if(indicies_.size() == cachedItems_.size()) { 00064 if(iData) { 00065 cachedItems_.push_back(iData); 00066 } else if(key_traits<key_type>::value == iKey) { 00067 cachedItems_.push_back(0); 00068 } else { 00069 cachedItems_.clear(); 00070 } 00071 } 00072 indicies_.push_back(iKey); 00073 } 00074 00075 // 00076 // const member functions 00077 // 00078 void 00079 PtrVectorBase::getProduct_() const { 00080 if(hasCache()) { 00081 return; 00082 } 00083 if(indicies_.size() == 0) { 00084 return; 00085 } 00086 if(0 == productGetter()) { 00087 throw edm::Exception(edm::errors::LogicError) << "Tried to get data for a PtrVector which has no EDProductGetter\n"; 00088 } 00089 EDProduct const* product = productGetter()->getIt(id()); 00090 00091 if(0==product) { 00092 throw edm::Exception(edm::errors::InvalidReference) << "Asked for data from a PtrVector which refers to a non-existent product which id " << id() << "\n"; 00093 } 00094 product->fillPtrVector(typeInfo(), 00095 indicies_, 00096 cachedItems_); 00097 } 00098 00099 bool 00100 PtrVectorBase::operator==(PtrVectorBase const& iRHS) const { 00101 if (core_ != iRHS.core_) { 00102 return false; 00103 } 00104 if (indicies_.size() != iRHS.indicies_.size()){ 00105 return false; 00106 } 00107 return std::equal(indicies_.begin(), 00108 indicies_.end(), 00109 iRHS.indicies_.begin()); 00110 return true; 00111 } 00112 00113 // 00114 // static member functions 00115 // 00116 }