00001 #ifndef DCHAIN_DECAYLIST_H
00002 #define DCHAIN_DECAYLIST_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <assert.h>
00033 #include <iostream>
00034
00035
00036 #include "DecayChain/List/ConjugateList.h"
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
00068
00069
00070
00071
00072
00073 template < class DecayClass , class CandidateClass = typename DecayClass::CandidateClass >
00074 class DecayList : public ConjugateList< CandidateClass >
00075 {
00076
00077 friend DecayList< DecayClass, CandidateClass > operator+ <DecayClass, CandidateClass> (
00078 const DecayList< DecayClass, CandidateClass >& iList1,
00079 const DecayList< DecayClass, CandidateClass >& iList2 );
00080
00081 public:
00082
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
00092 DecayList();
00093
00094 DecayList( const self_type& aOtherList);
00095 virtual ~DecayList() ;
00096
00097
00098
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
00116
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
00130 virtual iterator particle_begin() ;
00131 virtual iterator particle_end() ;
00132
00133
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
00141
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
00191
00192 DecayList(
00193 LabeledParticleList< DecayClass , CandidateClass >& aLabeledDecayList ,
00194 conjugation::Label aLabel ) ;
00195 protected:
00196
00197
00198 virtual LabeledCandidateList< CandidateClass >& labeledCandidateList() ;
00199 virtual LabeledParticleList< DecayClass , CandidateClass >& labeledParticleList() ;
00200
00201
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
00224
00225
00226 template<class TDecayList, class TSelector>
00227 void fill( const TDecayList& aList, const TSelector& aSel = SelectAll<DecayClass>() ) {
00228
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
00235 DecayClass* localCopy = new DecayClass( (*entry).particle() ) ;
00236 attempt_insert( localCopy ,
00237 (*entry).label(),
00238 aSel ) ;
00239 }
00240 }
00241
00242 private:
00243
00244
00245
00246
00247 MutableReferenceHolder<LabeledParticleList< DecayClass , CandidateClass > > m_list ;
00248 } ;
00249
00250
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
00310 #include "DecayChain/List/Template/DecayList.cc"
00311
00312 #endif