/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/DecayChain/DecayChain-00-00-03-slc6tag/DecayChain/List/DecayList.h

Go to the documentation of this file.
00001 #ifndef DCHAIN_DECAYLIST_H
00002 #define DCHAIN_DECAYLIST_H
00003 // -*- C++ -*-
00004 //
00005 // Package:     DChain
00006 // Module:      DecayList
00007 // 
00008 // Description: container of subclasses of Decay, used for iteration
00009 //
00010 // Usage:
00011 //    <usage>
00012 //
00013 // Author:      Simon Patton
00014 // Created:     Fri Oct  4 11:04:47 EDT 1996
00015 // $Id: DecayList.h,v 1.1.1.1 2009/03/03 06:06:56 maqm Exp $
00016 //
00017 // Revision history
00018 //
00019 // $Log: DecayList.h,v $
00020 // Revision 1.1.1.1  2009/03/03 06:06:56  maqm
00021 // first import of DecayChain
00022 //
00023 // Revision 1.2  2006/04/09 13:32:10  cdj
00024 // added back missing operator+
00025 //
00026 // Revision 1.1  2006/01/11 20:28:27  cdj
00027 // massive class renaming, addition of [] for selection and unit tests
00028 //
00029 //
00030 
00031 // system include files
00032 #include <assert.h>
00033 #include <iostream>
00034 
00035 // user include files
00036 #include "DecayChain/List/ConjugateList.h" // superclass declaration
00037 #include "DecayChain/List/NeutralVisibleList.h"
00038 #include "DecayChain/List/LabeledParticleList.h"
00039 #include "DecayChain/Iterator/WholeItr.h"
00040 #include "DecayChain/Element/MutableReferenceHolder.h"
00041 #include "DecayChain/Function/SelectAll.h"
00042 #include "DecayChain/List/FillListWithSelection.h"
00043 
00044 namespace dchain {
00045    template < class DecayClass , class CandidateClass > class LabeledParticleList ;template < class DecayClass > class MuteWholeItr ;
00046    template < class DecayClass > class WholeItr ;
00047    template < class DecayClass > class PartialItr ;
00048 }
00049 
00050 namespace dchain {
00051    template < class CandidateClass > class CombinatoricList ;
00052    template < class DecayClass , class CandidateClass > class DecayList;
00053 
00054 template < class DecayClass , class CandidateClass >
00055 DecayList< DecayClass, CandidateClass > operator+(
00056    const DecayList< DecayClass, CandidateClass >& iList1,
00057    const DecayList< DecayClass, CandidateClass >& iList2 );
00058 template < class DecayClass , class CandidateClass, class NeutralClass >
00059 DecayList< DecayClass, CandidateClass > operator+(
00060    const DecayList< DecayClass, CandidateClass >& iList1,
00061    const NeutralVisibleList< NeutralClass >& iList2 );
00062 template < class DecayClass , class CandidateClass, class NeutralClass >
00063 DecayList< DecayClass, CandidateClass > operator+(
00064    const NeutralVisibleList< NeutralClass >& iList1 ,
00065    const DecayList< DecayClass, CandidateClass >& iList2);
00066 //
00067 //  Note: To avoid a myriad of conpiler flags it is easier to
00068 //        have a two parameter template class.  The instantiation
00069 //        of this class must look like
00070 //
00071 //        template class DCDecayList< A , A::CandidateClass > ;
00072 
00073 template < class DecayClass , class CandidateClass = typename DecayClass::CandidateClass >
00074 class DecayList : public ConjugateList< CandidateClass >
00075 {
00076    // friend classses and functions
00077    friend DecayList< DecayClass, CandidateClass > operator+ <DecayClass, CandidateClass> (
00078          const DecayList< DecayClass, CandidateClass >& iList1,
00079          const DecayList< DecayClass, CandidateClass >& iList2 );
00080 
00081    public:
00082    // constants, enums and typedefs
00083    typedef MuteWholeItr< DecayClass > iterator ;
00084    typedef WholeItr< DecayClass > const_iterator  ;
00085    typedef PartialItr< DecayClass > const_partial_iterator  ;
00086 
00087    typedef DecayClass value_type ;
00088 
00089    typedef DecayList< DecayClass , CandidateClass > self_type;
00090 
00091    // Constructors and destructor
00092    DecayList();
00093    // need this function to stop default copy constructor
00094    DecayList( const self_type& aOtherList);
00095    virtual ~DecayList() ;
00096 
00097    // assignment operator(s)
00098    // need this function to stop default assignment operator
00099    template< class TDecay>
00100       const self_type& operator=( const DecayList< TDecay , CandidateClass >& aOtherList ) {
00101          m_list->erase( m_list->begin() ,
00102                m_list->end() ) ;
00103          fill( aOtherList, SelectAll<DecayClass>() ) ;
00104          return ( *this ) ;
00105       }
00106 
00107    const self_type& operator=( const CombinatoricList< CandidateClass >& aOtherList );
00108 
00109    const self_type& operator=( const DecayList< DecayClass , CandidateClass >& aOtherList );
00110    //
00111    template<class TList>
00112       void operator+=( const TList& aOtherList) {
00113 
00114          if(this->size() != 0 ) {
00115             //only check compatable conjugation if something already in
00116             // this list, otherwise could have problem with default value
00117             bool can_only_add_lists_with_same_conjugation =
00118                this->isSelfConjugate()== aOtherList.isSelfConjugate();
00119             assert(can_only_add_lists_with_same_conjugation);
00120          }
00121          fill(aOtherList);
00122       }
00123 
00124    template<class TSelector>
00125       FillListWithSelection<self_type, TSelector> operator[](const TSelector& iSel) {
00126          return FillListWithSelection<self_type,TSelector>(*this, iSel);
00127       }
00128 
00129    // member functions
00130    virtual iterator particle_begin() ;
00131    virtual iterator particle_end() ;
00132 
00133    // const member functions
00134    const DecayList< DecayClass , CandidateClass > bar() const ;
00135    const DecayList< DecayClass , CandidateClass >& operator()() const ;
00136    virtual const_iterator particle_begin() const ;
00137    virtual const_iterator particle_end() const ;
00138    virtual const_partial_iterator partial_particle_begin() const ;
00139    virtual const_partial_iterator partial_particle_end() const ;
00140    // The for following redeclarations are required because of function hidding
00141    //   ( See ARM p310 )
00142    using ConjugateList< CandidateClass >::iterate;
00143    template<class TAnalyze>
00144       void iterate( const TAnalyze& analyze) const {
00145          const_iterator finished ( particle_end() ) ;
00146          for ( const_iterator entry ( particle_begin() ) ;
00147                entry != finished ;
00148                ++entry ) {
00149             analyze( (*entry).particle() ) ;
00150          }
00151       }
00152 
00153    template < class TAnalyzer>
00154       void conjugation_iterate( const TAnalyzer& analyzer) const 
00155       {
00156          const_iterator finished ( particle_end() ) ;
00157          for ( const_iterator entry ( particle_begin() ) ;
00158                entry != finished ;
00159                ++entry ) {
00160             analyze( (*entry)() , (*entry).label() == this->label() ) ;
00161          }
00162       }
00163 
00164    template<class TAnalyze>
00165       void iterate( TAnalyze& analyze) const {
00166          const_iterator finished ( particle_end() ) ;
00167          for ( const_iterator entry ( particle_begin() ) ;
00168                entry != finished ;
00169                ++entry ) {
00170             analyze( (*entry).particle() ) ;
00171          }
00172       }
00173 
00174    using ConjugateList< CandidateClass >::iterate;
00175    template<class TAnalyze>
00176       void partial_iterate( TAnalyze& analyze ) const
00177       {
00178          const_partial_iterator finished ( partial_particle_end() ) ;
00179          for ( const_partial_iterator entry ( partial_particle_begin() ) ;
00180                entry != finished ;
00181                ++entry ) {
00182             analyze( (*entry).particle() ) ;
00183          }
00184       }
00185    void eraseContents() ;
00186 
00187    void erase() {
00188       eraseContents();
00189    }
00190    // static member functions
00191 
00192    DecayList(
00193          LabeledParticleList< DecayClass , CandidateClass >& aLabeledDecayList ,
00194          conjugation::Label aLabel ) ;
00195    protected:
00196 
00197    // protected member functions
00198    virtual LabeledCandidateList< CandidateClass >& labeledCandidateList() ;
00199    virtual LabeledParticleList< DecayClass , CandidateClass >& labeledParticleList() ;
00200 
00201    // protected const member functions
00202    virtual const LabeledCandidateList< CandidateClass >& labeledCandidateList() const ;
00203    virtual const LabeledParticleList< DecayClass , CandidateClass >& labeledParticleList() const ;
00204    public:
00205    template <class TSelect>
00206       bool attempt_insert( DecayClass* pPossible ,
00207             const conjugation::Label aLabel,
00208             const TSelect& aSelect ) {
00209          ReferenceHolder<DecayClass> pHolder( pPossible );
00210          bool returnValue = aSelect(*pPossible);
00211          if (returnValue) {
00212             this->insert(pPossible,aLabel);
00213          }
00214          return returnValue;
00215       }
00216 
00217    template <class THolder>
00218       void insert(THolder& pPossible,
00219             const conjugation::Label aLabel) {
00220          m_list->push_back( LabeledParticle< DecayClass >( pPossible ,
00221                   aLabel ) ) ;
00222       }
00223    // Constructors and destructor
00224 
00225    // private member functions
00226    template<class TDecayList, class TSelector>
00227       void fill( const TDecayList& aList, const TSelector& aSel = SelectAll<DecayClass>() ) {
00228          //std::cout << "@DecayList::fill()" << std::endl;
00229          setLabel( aList.label() ) ;
00230          typename TDecayList::const_iterator finished( aList.particle_end() ) ;
00231          for ( typename TDecayList::const_iterator entry( aList.particle_begin() ) ;
00232                entry != finished ;
00233                ++entry ) {
00234             //std::cout << "@ DecayList::fill()" << std::endl;
00235             DecayClass* localCopy = new DecayClass( (*entry).particle() ) ;
00236             attempt_insert( localCopy ,
00237                   (*entry).label(),
00238                   aSel ) ;
00239          }
00240       }
00241 
00242    private:
00243 
00244    // private const member functions
00245 
00246    // data members
00247    MutableReferenceHolder<LabeledParticleList< DecayClass , CandidateClass > > m_list ;
00248 } ;
00249 
00250 // inline function definitions
00251 
00252 
00253 
00254 #include <assert.h>
00255 
00256 template < class DecayClass , class CandidateClass >
00257 inline
00258 DecayList< DecayClass, CandidateClass > operator+(
00259    const DecayList< DecayClass, CandidateClass >& iList1,
00260    const DecayList< DecayClass, CandidateClass >& iList2 )
00261 {
00262    bool can_only_add_lists_with_same_conjugation =
00263       iList1.isSelfConjugate()== iList2.isSelfConjugate();
00264    assert(can_only_add_lists_with_same_conjugation);
00265 
00266    DecayList< DecayClass, CandidateClass> returnValue( iList1 );
00267    if( &iList1 != &iList2 ) {
00268       returnValue.fill( iList2, SelectAll<DecayClass>() );
00269    }
00270    return returnValue;
00271 }
00272 
00273 template < class DecayClass , class CandidateClass, class NeutralClass >
00274 inline
00275 DecayList< DecayClass, CandidateClass > operator+(
00276    const DecayList< DecayClass, CandidateClass >& iList1,
00277    const NeutralVisibleList< NeutralClass >& iList2 )
00278 {
00279    bool can_only_add_lists_with_same_conjugation =
00280       iList1.isSelfConjugate()== iList2.isSelfConjugate();
00281    assert(can_only_add_lists_with_same_conjugation);
00282 
00283    
00284    DecayList< DecayClass, CandidateClass> returnValue =iList1 ;
00285    typename LabeledParticleList< NeutralClass , CandidateClass >::const_iterator finished( iList2.particle_end() ) ;
00286    for( typename LabeledParticleList< NeutralClass , CandidateClass >::const_iterator entry(iList2.particle_begin()) ;
00287         entry != finished ;
00288         ++entry ){
00289      NeutralClass* localCopy = new NeutralClass( (*entry).particle() ) ;
00290      returnValue.attempt_insert( localCopy, (*entry).label(),SelectAll<DecayClass>() ) ;
00291    }
00292    return returnValue;
00293 }
00294 
00295 
00296 template < class DecayClass , class CandidateClass, class NeutralClass >
00297 inline
00298 DecayList< DecayClass, CandidateClass > operator+(
00299    const NeutralVisibleList< NeutralClass >& iList1 ,
00300    const DecayList< DecayClass, CandidateClass >& iList2)
00301 {
00302      DecayList< DecayClass, CandidateClass> returnValue;
00303      returnValue = iList2 + iList1;
00304      return returnValue;
00305 }
00306 
00307 }
00308    
00309 // function definitions
00310 #include "DecayChain/List/Template/DecayList.cc"
00311 
00312 #endif /* DCHAIN_DECAYLIST_H */

Generated on Tue Nov 29 22:58:22 2016 for BOSS_7.0.2 by  doxygen 1.4.7