CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/CommonTools/CandAlgos/interface/CandDecaySelector.h

Go to the documentation of this file.
00001 #ifndef CandAlgos_CandDecaySelector_h
00002 #define CandAlgos_CandDecaySelector_h
00003 /* \class helper::CandDecayStoreManager
00004  *
00005  * \author: Luca Lista, INFN
00006  *
00007  */
00008 #include "DataFormats/Candidate/interface/CompositeRefCandidate.h"
00009 #include "CommonTools/UtilAlgos/interface/ObjectSelector.h"
00010 
00011 namespace helper {
00012   class CandDecayStoreManager {
00013   public:
00014     typedef reco::CandidateCollection collection;
00015     CandDecayStoreManager( const edm::Handle<reco::CandidateCollection> & ) :
00016       selCands_( new reco::CandidateCollection ) {
00017     }
00018     template<typename I>
00019     void cloneAndStore( const I & begin, const I & end, edm::Event & evt ) {
00020       using namespace reco;
00021       CandidateRefProd cands = evt.getRefBeforePut<CandidateCollection>();
00022       for( I i = begin; i != end; ++ i )
00023         add( cands, * * i );
00024     }
00025     edm::OrphanHandle<reco::CandidateCollection> put( edm::Event & evt ) {
00026       return evt.put( selCands_ );
00027     }
00028     size_t size() const { return selCands_->size(); }
00029     
00030   private:
00031     reco::CandidateRef add( reco::CandidateRefProd cands, const reco::Candidate & c ) {
00032       using namespace reco;
00033       using namespace std;
00034       std::auto_ptr<CompositeRefCandidate> cmp( new CompositeRefCandidate( c ) );
00035       CompositeRefCandidate * p = cmp.get();
00036       CandidateRef ref( cands, selCands_->size() );
00037       selCands_->push_back( cmp );
00038       size_t n = c.numberOfDaughters(); 
00039       for( size_t i = 0; i < n; ++ i )
00040         p->addDaughter( add( cands, * c.daughter( i ) ) );
00041       return ref;
00042     }
00043     std::auto_ptr<reco::CandidateCollection> selCands_;
00044   };
00045   
00046   template<>
00047   struct StoreManagerTrait<reco::CandidateCollection> {
00048     typedef CandDecayStoreManager type;
00049     typedef ObjectSelectorBase<reco::CandidateCollection> base;
00050   };
00051 
00052 }
00053 
00054 #endif