CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DataFormats/Candidate/interface/CompositeRefCandidateT.h

Go to the documentation of this file.
00001 #ifndef Candidate_CompositeRefCandidateT_h
00002 #define Candidate_CompositeRefCandidateT_h
00003 
00014 #include "DataFormats/Candidate/interface/LeafCandidate.h"
00015 #include "DataFormats/Candidate/interface/iterator_imp_specific.h"
00016 
00017 namespace reco {
00018 
00019   template<typename D>
00020   class CompositeRefCandidateT : public LeafCandidate {
00021   public:
00023     typedef D daughters;
00025     typedef D mothers;
00027     CompositeRefCandidateT() : LeafCandidate() { }
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       LeafCandidate( 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       LeafCandidate( q, p4, vtx, pdgId, status, integerCharge ) { }
00037     explicit CompositeRefCandidateT( const LeafCandidate& c ) : LeafCandidate( c ) { }
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;
00056     using ::reco::LeafCandidate::daughter; // avoid hiding the base
00058     virtual const Candidate * mother(size_type = 0) const;
00060     virtual Candidate * daughter(size_type);
00062     void addDaughter( const typename daughters::value_type & );    
00064     void addMother( const typename mothers::value_type & );    
00066     void clearDaughters() { dau.clear(); }
00068     void clearMothers() { mom.clear(); }
00070     typename daughters::value_type daughterRef( size_type i ) const { return dau[ i ]; }
00072     const daughters & daughterRefVector() const { return dau; }
00074     typename daughters::value_type motherRef( size_type i = 0 ) const { return mom[ i ]; }
00076     const mothers & motherRefVector() const { return mom; }
00078     void resetDaughters( const edm::ProductID & id ) { dau = daughters( id ); }
00080     void resetMothers( const edm::ProductID & id ) { mom = mothers( id ); }
00081 
00082 
00083   private:
00085     typedef candidate::const_iterator_imp_specific<daughters> const_iterator_imp_specific;
00087     typedef candidate::iterator_imp_specific_dummy<daughters> iterator_imp_specific;
00089     daughters dau;
00091     daughters mom;
00093     virtual bool overlap( const Candidate & ) const;
00094   };
00095 
00096   template<typename D>
00097   inline void CompositeRefCandidateT<D>::addDaughter( const typename daughters::value_type & cand ) { 
00098     dau.push_back( cand ); 
00099   }
00100 
00101   template<typename D>
00102   inline void CompositeRefCandidateT<D>::addMother( const typename daughters::value_type & cand ) { 
00103     mom.push_back( cand ); 
00104   }
00105 
00106   template<typename D>
00107   CompositeRefCandidateT<D>::~CompositeRefCandidateT() { 
00108   }
00109   
00110   template<typename D>
00111   CompositeRefCandidateT<D> * CompositeRefCandidateT<D>::clone() const { 
00112     return new CompositeRefCandidateT( * this ); 
00113   }
00114   
00115   template<typename D>
00116   Candidate::const_iterator CompositeRefCandidateT<D>::begin() const { 
00117     return const_iterator( new const_iterator_imp_specific( dau.begin() ) ); 
00118   }
00119   
00120   template<typename D>
00121   Candidate::const_iterator CompositeRefCandidateT<D>::end() const { 
00122     return const_iterator( new const_iterator_imp_specific( dau.end() ) ); 
00123   }    
00124   
00125   template<typename D>
00126   Candidate::iterator CompositeRefCandidateT<D>::begin() { 
00127     return iterator( new iterator_imp_specific ); 
00128   }
00129   
00130   template<typename D>
00131   Candidate::iterator CompositeRefCandidateT<D>::end() { 
00132     return iterator( new iterator_imp_specific ); 
00133   }    
00134   
00135   template<typename D>
00136   const Candidate * CompositeRefCandidateT<D>::daughter( size_type i ) const { 
00137     return ( i < numberOfDaughters() ) ? & * dau[ i ] : 0;
00138   }
00139   
00140   template<typename D>
00141   const Candidate * CompositeRefCandidateT<D>::mother( size_type i ) const { 
00142     return ( i < numberOfMothers() ) ? & * mom[ i ] : 0;
00143   }
00144   
00145   template<typename D>
00146   Candidate * CompositeRefCandidateT<D>::daughter( size_type i ) { 
00147     return 0;
00148   }
00149   
00150   template<typename D>
00151   size_t CompositeRefCandidateT<D>::numberOfDaughters() const { 
00152     return dau.size(); 
00153   }
00154   
00155   template<typename D>
00156   size_t CompositeRefCandidateT<D>::numberOfMothers() const { 
00157     return mom.size(); 
00158   }
00159   
00160   template<typename D>
00161   bool CompositeRefCandidateT<D>::overlap( const Candidate & c2 ) const {
00162     throw cms::Exception( "Error" ) << "can't check overlap internally for CompositeRefCanddate";
00163   }
00164 }
00165 
00166 #endif