00001 #ifndef CommonTools_ParticleFlow_PFCandidateFwdPtrFactory_h 00002 #define CommonTools_ParticleFlow_PFCandidateFwdPtrFactory_h 00003 00013 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" 00014 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" 00015 00016 namespace reco { 00017 class PFCandidateFwdPtrFactory : public std::binary_function<edm::FwdPtr<reco::PFCandidate>, edm::View<reco::PFCandidate>, unsigned int > { 00018 public : 00019 edm::FwdPtr<reco::PFCandidate> operator() (edm::View<reco::PFCandidate> const & view, unsigned int i) const { 00020 edm::Ptr<reco::PFCandidate> ptr = view.ptrAt(i); 00021 edm::Ptr<reco::PFCandidate> backPtr = ptr; 00022 if ( ptr.isNonnull() && ptr.isAvailable() && ptr->numberOfSourceCandidatePtrs() > 0 ) { 00023 edm::Ptr<reco::Candidate> basePtr = ptr->sourceCandidatePtr(0); 00024 if (basePtr.isNonnull() && basePtr.isAvailable()) 00025 backPtr = edm::Ptr<reco::PFCandidate>( basePtr );//this cast works only for available stuff 00026 } 00027 return edm::FwdPtr<reco::PFCandidate>(ptr,backPtr); 00028 } 00029 00030 }; 00031 } 00032 00033 #endif