Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:05

0001 #ifndef CommonTools_ParticleFlow_PFCandidateFwdPtrFactory_h
0002 #define CommonTools_ParticleFlow_PFCandidateFwdPtrFactory_h
0003 
0004 /**
0005   \class    reco::PFCandidateFwdPtrFactory PFCandidateFwdPtrFactory.h  "CommonTools/ParticleFlow/interface/PFCandidateFwdPtrFactory.h"
0006   \brief    Creates a FwdPtr<PFCandidate> from an input PFCandidate. If the PFCandidate has a valid sourceCandidatePtr, that is
0007             used for the FwdPtr's "backPtr". 
0008 
0009 
0010   \author   Salvatore Rappoccio
0011 */
0012 
0013 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0014 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0015 
0016 namespace reco {
0017   struct PFCandidateFwdPtrFactory {
0018     edm::FwdPtr<reco::PFCandidate> operator()(edm::View<reco::PFCandidate> const& view, unsigned int i) const {
0019       edm::Ptr<reco::PFCandidate> ptr = view.ptrAt(i);
0020       edm::Ptr<reco::PFCandidate> backPtr = ptr;
0021       if (ptr.isNonnull() && ptr.isAvailable() && ptr->numberOfSourceCandidatePtrs() > 0) {
0022         edm::Ptr<reco::Candidate> basePtr = ptr->sourceCandidatePtr(0);
0023         if (basePtr.isNonnull() && basePtr.isAvailable())
0024           backPtr = edm::Ptr<reco::PFCandidate>(basePtr);  //this cast works only for available stuff
0025       }
0026       return edm::FwdPtr<reco::PFCandidate>(ptr, backPtr);
0027     }
0028   };
0029 }  // namespace reco
0030 
0031 #endif