CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DataFormats/Candidate/interface/CandidateWithRef.h

Go to the documentation of this file.
00001 #ifndef Candidate_CandidateWithRef_h
00002 #define Candidate_CandidateWithRef_h
00003 
00012 #include "DataFormats/CaloRecHit/interface/CaloRecHit.h"
00013 #include "DataFormats/Common/interface/RefToBase.h"
00014 
00015 namespace reco {
00016 
00017   template<typename Ref>
00018   class CandidateWithRef : public LeafCandidate {
00019   public:
00020     typedef Ref reference;
00022     CandidateWithRef() : LeafCandidate() { }
00024     CandidateWithRef( const LorentzVector & p4, Charge q = 0, const Point & vtx = Point( 0, 0, 0 ) ) :
00025       LeafCandidate( q, p4, vtx ) { }
00027     virtual ~CandidateWithRef();
00029     virtual CandidateWithRef * clone() const;
00031     void setRef( const Ref & r ) { ref_ = r; }
00033     reference ref() const { return ref_; }
00034 
00035   private:
00037     virtual bool overlap( const Candidate & ) const;
00039     reference ref_;
00040   };
00041 
00042   // the following has to be added for any single Ref type
00043   // GET_DEFAULT_CANDIDATE_COMPONENT( CandidateWithRef<Ref>, CandidateWithRef<Ref>::reference, ref )
00044 
00045   template<typename Ref>
00046     CandidateWithRef<Ref>::~CandidateWithRef() { 
00047   }
00048   
00049   template<typename Ref>
00050     CandidateWithRef<Ref> * CandidateWithRef<Ref>::clone() const {
00051     return new CandidateWithRef<Ref>( * this );
00052   }
00053   
00054   template<typename Ref>
00055     bool CandidateWithRef<Ref>::overlap( const Candidate & c ) const {
00056     const CandidateWithRef * o = dynamic_cast<const CandidateWithRef *>( & c );
00057     if ( o == 0 ) return false;
00058     if ( ref().isNull() ) return false;
00059     if ( o->ref().isNull() ) return false;
00060     return ( ref() != o->ref() );
00061   }
00062   
00063 }
00064 
00065 #endif