00001 #ifndef Candidate_CompositeRefCandidateT_h 00002 #define Candidate_CompositeRefCandidateT_h 00003 00014 #include "DataFormats/Candidate/interface/Candidate.h" 00015 #include "DataFormats/Candidate/interface/iterator_imp_specific.h" 00016 00017 namespace reco { 00018 00019 template<typename D> 00020 class CompositeRefCandidateT : public Candidate { 00021 public: 00023 typedef D daughters; 00025 typedef D mothers; 00027 CompositeRefCandidateT() : Candidate() { } 00029 CompositeRefCandidateT( Charge q, const LorentzVector & p4, const Point & vtx = Point( 0, 0, 0 ), 00030 int pdgId = 0, int status = 0, bool integerCharge = true ) : 00031 Candidate( q, p4, vtx, pdgId, status, integerCharge ) { } 00033 CompositeRefCandidateT( Charge q, const PolarLorentzVector & p4, const Point & vtx = Point( 0, 0, 0 ), 00034 int pdgId = 0, int status = 0, bool integerCharge = true ) : 00035 Candidate( q, p4, vtx, pdgId, status, integerCharge ) { } 00037 explicit CompositeRefCandidateT( const Particle & p ) : Candidate( p ) { } 00039 virtual ~CompositeRefCandidateT(); 00041 virtual CompositeRefCandidateT<D> * clone() const; 00043 virtual const_iterator begin() const; 00045 virtual const_iterator end() const; 00047 virtual iterator begin(); 00049 virtual iterator end(); 00051 virtual size_t numberOfDaughters() const; 00053 virtual size_t numberOfMothers() const; 00055 virtual const Candidate * daughter(size_type) const; 00057 virtual const Candidate * mother(size_type = 0) const; 00059 virtual Candidate * daughter(size_type); 00061 void addDaughter( const typename daughters::value_type & ); 00063 void addMother( const typename mothers::value_type & ); 00065 void clearDaughters() { dau.clear(); } 00067 void clearMothers() { mom.clear(); } 00069 typename daughters::value_type daughterRef( size_type i ) const { return dau[ i ]; } 00071 const daughters & daughterRefVector() const { return dau; } 00073 typename daughters::value_type motherRef( size_type i = 0 ) const { return mom[ i ]; } 00075 const mothers & motherRefVector() const { return mom; } 00077 void resetDaughters( const edm::ProductID & id ) { dau = daughters( id ); } 00079 void resetMothers( const edm::ProductID & id ) { mom = mothers( id ); } 00080 00081 00082 private: 00084 typedef candidate::const_iterator_imp_specific<daughters> const_iterator_imp_specific; 00086 typedef candidate::iterator_imp_specific_dummy<daughters> iterator_imp_specific; 00088 daughters dau; 00090 daughters mom; 00092 virtual bool overlap( const Candidate & ) const; 00093 }; 00094 00095 template<typename D> 00096 inline void CompositeRefCandidateT<D>::addDaughter( const typename daughters::value_type & cand ) { 00097 dau.push_back( cand ); 00098 } 00099 00100 template<typename D> 00101 inline void CompositeRefCandidateT<D>::addMother( const typename daughters::value_type & cand ) { 00102 mom.push_back( cand ); 00103 } 00104 00105 template<typename D> 00106 CompositeRefCandidateT<D>::~CompositeRefCandidateT() { 00107 } 00108 00109 template<typename D> 00110 CompositeRefCandidateT<D> * CompositeRefCandidateT<D>::clone() const { 00111 return new CompositeRefCandidateT( * this ); 00112 } 00113 00114 template<typename D> 00115 Candidate::const_iterator CompositeRefCandidateT<D>::begin() const { 00116 return const_iterator( new const_iterator_imp_specific( dau.begin() ) ); 00117 } 00118 00119 template<typename D> 00120 Candidate::const_iterator CompositeRefCandidateT<D>::end() const { 00121 return const_iterator( new const_iterator_imp_specific( dau.end() ) ); 00122 } 00123 00124 template<typename D> 00125 Candidate::iterator CompositeRefCandidateT<D>::begin() { 00126 return iterator( new iterator_imp_specific ); 00127 } 00128 00129 template<typename D> 00130 Candidate::iterator CompositeRefCandidateT<D>::end() { 00131 return iterator( new iterator_imp_specific ); 00132 } 00133 00134 template<typename D> 00135 const Candidate * CompositeRefCandidateT<D>::daughter( size_type i ) const { 00136 return ( i < numberOfDaughters() ) ? & * dau[ i ] : 0; 00137 } 00138 00139 template<typename D> 00140 const Candidate * CompositeRefCandidateT<D>::mother( size_type i ) const { 00141 return ( i < numberOfMothers() ) ? & * mom[ i ] : 0; 00142 } 00143 00144 template<typename D> 00145 Candidate * CompositeRefCandidateT<D>::daughter( size_type i ) { 00146 return 0; 00147 } 00148 00149 template<typename D> 00150 size_t CompositeRefCandidateT<D>::numberOfDaughters() const { 00151 return dau.size(); 00152 } 00153 00154 template<typename D> 00155 size_t CompositeRefCandidateT<D>::numberOfMothers() const { 00156 return mom.size(); 00157 } 00158 00159 template<typename D> 00160 bool CompositeRefCandidateT<D>::overlap( const Candidate & c2 ) const { 00161 throw cms::Exception( "Error" ) << "can't check overlap internally for CompositeRefCanddate"; 00162 } 00163 } 00164 00165 #endif