CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DataFormats/Common/src/PtrVectorBase.cc

Go to the documentation of this file.
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 //
00012 
00013 // user include files
00014 #include "DataFormats/Common/interface/WrapperHolder.h"
00015 #include "DataFormats/Common/interface/PtrVectorBase.h"
00016 #include "DataFormats/Common/interface/traits.h"
00017 #include "FWCore/Utilities/interface/EDMException.h"
00018 #include "FWCore/Utilities/interface/Exception.h"
00019 
00020 // system include files
00021 #include <ostream>
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   PtrVectorBase::~PtrVectorBase() {
00038   }
00039 
00040 //
00041 // assignment operators
00042 //
00043 
00044 //
00045 // member functions
00046 //
00047 
00049   void
00050   PtrVectorBase::swap(PtrVectorBase& other) {
00051     core_.swap(other.core_);
00052     indicies_.swap(other.indicies_);
00053     cachedItems_.swap(other.cachedItems_);
00054   }
00055 
00056   void
00057   PtrVectorBase::push_back_base(RefCore const& core, key_type iKey, void const* iData) {
00058     core_.pushBackItem(core, false);
00059     //Did we already push a 'non-cached' Ptr into the container or is this a 'non-cached' Ptr?
00060     if(indicies_.size() == cachedItems_.size()) {
00061       if(iData) {
00062         cachedItems_.push_back(iData);
00063       } else if(key_traits<key_type>::value == iKey) {
00064         cachedItems_.push_back(0);
00065       } else {
00066         cachedItems_.clear();
00067       }
00068     }
00069     indicies_.push_back(iKey);
00070   }
00071 
00072 //
00073 // const member functions
00074 //
00075   void
00076   PtrVectorBase::getProduct_() const {
00077     if(hasCache()) {
00078       return;
00079     }
00080     if(indicies_.size() == 0) {
00081       return;
00082     }
00083     if(0 == productGetter()) {
00084       throw Exception(errors::LogicError) << "Tried to get data for a PtrVector which has no EDProductGetter\n";
00085     }
00086     WrapperHolder product = productGetter()->getIt(id());
00087 
00088     if(!product.isValid()) {
00089       throw Exception(errors::InvalidReference) << "Asked for data from a PtrVector which refers to a non-existent product which id " << id() << "\n";
00090     }
00091     product.fillPtrVector(typeInfo(), indicies_, cachedItems_);
00092   }
00093 
00094   bool
00095   PtrVectorBase::operator==(PtrVectorBase const& iRHS) const {
00096     if(core_ != iRHS.core_) {
00097       return false;
00098     }
00099     if(indicies_.size() != iRHS.indicies_.size()){
00100       return false;
00101     }
00102     return std::equal(indicies_.begin(),
00103                       indicies_.end(),
00104                       iRHS.indicies_.begin());
00105     return true;
00106   }
00107 
00108 //
00109 // static member functions
00110 //
00111 }