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

Go to the documentation of this file.
00001 #ifndef DCHAIN_CHARGEDVISIBLELIST_H
00002 #define DCHAIN_CHARGEDVISIBLELIST_H
00003 // -*- C++ -*-
00004 //
00005 // Package:     DChain
00006 // Module:      ChargedVisibleList
00007 // 
00008 // Description: List to hold Candidate subclasses generated from VisibleEvidence
00009 //
00010 // Usage:
00011 //    <usage>
00012 //
00013 // Author:      Simon Patton
00014 // Created:     Fri Oct  4 11:04:47 EDT 1996
00015 // $Id: ChargedVisibleList.h,v 1.1.1.1 2009/03/03 06:06:56 maqm Exp $
00016 //
00017 // Revision history
00018 //
00019 // $Log: ChargedVisibleList.h,v $
00020 // Revision 1.1.1.1  2009/03/03 06:06:56  maqm
00021 // first import of DecayChain
00022 //
00023 // Revision 1.1  2006/01/11 20:28:20  cdj
00024 // massive class renaming, addition of [] for selection and unit tests
00025 //
00026 // Revision 1.4  2003/08/01 13:48:40  mrs43
00027 // changed plus and minus methods of ChargedVisibleList to const
00028 //
00029 // Revision 1.3  2003/05/15 19:56:06  cdj
00030 // revamped memory handling so always use a ReferenceHolder to deal with the reference counting
00031 //
00032 // Revision 1.2  2000/12/30 19:43:29  cdj
00033 // no more missing symbols under OSF1
00034 //
00035 // Revision 1.1.1.1  2000/12/18 22:16:51  cdj
00036 // imported DChain
00037 //
00038 // Revision 1.11  1998/08/20 19:58:59  sjp
00039 // Modified to use DChainBoolean
00040 //
00041 // Revision 1.10  1998/04/17 19:10:59  sjp
00042 // Modified to use latest types
00043 //
00044 // Revision 1.9  1997/09/17 20:05:27  sjp
00045 // Removed filling to superclass
00046 //
00047 // Revision 1.8  1997/08/28 06:59:44  sjp
00048 // Modified files to handle complete templating
00049 //
00050 // Revision 1.7  1997/08/19 15:55:06  sjp
00051 // Modified list to have no dependence on any other
00052 //   structures except its contents, which must have
00053 //   certain `typedef' available to use.
00054 //
00055 // Revision 1.6  1997/08/15 21:32:09  sjp
00056 // Updated to use <package>/<file>.h include structure.
00057 // Updated to use bug flags specified in Experiement.h
00058 //
00059 // Revision 1.5  1997/01/31 20:17:00  sjp
00060 // Modified to use the new `bug' include files
00061 //
00062 // Revision 1.4  1997/01/22 16:27:09  sjp
00063 // Fixed error in pre-processor labels
00064 //
00065 // Revision 1.3  1997/01/21 20:33:37  sjp
00066 // Changed CPP flags and include because of library reorganization
00067 //
00068 // Revision 1.2  1996/12/20 21:19:00  sjp
00069 // Extended pathnames for Include files
00070 //
00071 // Revision 1.1  1996/11/04 19:35:48  sjp
00072 // New file for new `List' module
00073 //
00074 
00075 // system include files
00076 #include <memory>
00077 #include <iostream>
00078 //#include "boost/bind.hpp"
00079 //#include <boost/iterator/transform_iterator.hpp>
00080 
00081 // user include files
00082 #include "DecayChain/List/CandidateList.h" // superclass declaration
00083 #include "DecayChain/List/ChosenChargeList.h" // for return-by-value
00084 #include "DecayChain/Element/MutableReferenceHolder.h"
00085 //#include "DecayChain/Element/ReferenceHolder.h"
00086 
00087 //#include "DecayChain/Iterator/WholeCandidateItr.h"
00088 #include "DecayChain/Iterator/PartialItr.h"
00089 #include "DecayChain/Iterator/WholeItr.h"
00090 
00091 #include "DecayChain/Element/MakerTrait.h"
00092 #include "DecayChain/Iterator/SelectiveInserter.h"
00093 #include "DecayChain/Function/SelectAll.h"
00094 #include "DecayChain/List/FillListWithSelection.h"
00095 
00096 // forward declarations
00097 #include "DecayChain/List/LabeledParticleList.h"
00098 
00099 //
00100 //  Note: To avoid a myriad of compiler flags it is easier to
00101 //        have a two parameter template class.  The instantiation
00102 //        of this class must look like
00103 //
00104 //        template class LabeledDecayList< A , A::CandidateClass > ;
00105 
00106 namespace dchain {
00107 template < class T > class MuteWholeItr ;
00108 
00109 
00110    template<class T>
00111    int charge_sign(const T& iCharged) {
00112       return static_cast<int>(iCharged.charge());
00113    }
00114 
00115    template<class T>
00116    int charge_sign(const T* iCharged) {
00117       return static_cast<int>(iCharged->charge());
00118    }
00119 
00120    template<class T>
00121    int charge_sign(T* iCharged) {
00122       return static_cast<int>(iCharged->charge());
00123    }
00124 
00125    template<class T>
00126    int charge_sign(const std::auto_ptr<T>& iCharged) {
00127       return static_cast<int>(iCharged->charge());
00128    }
00129 
00130    template<class TPtr,class TRef>
00131    int charge_sign(const ReferenceHolderBase<TPtr,TRef>& iHolder) {
00132       return charge_sign(*iHolder);
00133    }
00134 
00135 
00136 template < class Charged , class CandidateClass = typename Charged::CandidateClass >
00137 class ChargedVisibleList : public CandidateList< CandidateClass >
00138 {
00139       // friend classses and functions
00140 
00141    public:
00142       // constants, enums and typedefs
00143       typedef MuteWholeItr< Charged > iterator ;
00144       typedef WholeItr< Charged > const_iterator ;
00145       typedef PartialItr< Charged > const_partial_iterator ;
00146 
00147       typedef Charged value_type ;
00148 
00149       typedef ChargedVisibleList<Charged,CandidateClass> self_type;
00150 
00154       // Constructors and destructor
00155       ChargedVisibleList();
00156       ChargedVisibleList( const self_type& aOtherList);
00157       template<class TSelector>
00158       ChargedVisibleList( const self_type& aOtherList,
00159                           const TSelector& aSel) :
00160          m_list( new LabeledParticleList<Charged,CandidateClass> ),
00161          m_plusList(0),
00162          m_minusList(0)
00163       {
00164          fill(*(aOtherList.m_list), 
00165               typename MakerTrait<Charged>::maker_type(), 
00166               aSel);
00167       }
00168 
00169       template <class WitnessIterator>
00170       ChargedVisibleList(WitnessIterator first, WitnessIterator last) : 
00171          m_list( new LabeledParticleList<Charged,CandidateClass> ),
00172          m_plusList(0),
00173          m_minusList(0)
00174       {
00175          fill(first, last, typename MakerTrait<Charged>::maker_type() ); }
00176 
00177       template<class WitnessIterator, class TSelector>
00178       ChargedVisibleList(WitnessIterator first, WitnessIterator last, 
00179                             const TSelector& aFunctionalObject ) :
00180          m_list( new LabeledParticleList<Charged,CandidateClass> ),
00181          m_plusList(0),
00182          m_minusList(0)
00183       {
00184          fill(first, last, 
00185               typename MakerTrait<Charged>::maker_type(), aFunctionalObject); }
00186 
00187       virtual ~ChargedVisibleList() ;
00188       
00189       // assignment operator(s)
00190       const self_type& operator=( const self_type& aOtherList ) ;
00191       template<class Witness>
00192       const self_type& operator=(const Witness& aWitnessList) {
00193          eraseContents();
00194          fill(aWitnessList.begin(), aWitnessList.end(),
00195               typename MakerTrait<Charged>::maker_type(),
00196               SelectAll<Charged>() );
00197          return ( *this ) ;
00198       }
00199 
00200       // member functions
00201       template<class TSelector>
00202       FillListWithSelection<self_type, TSelector> operator[](const TSelector& iSel) {
00203          return FillListWithSelection<self_type,TSelector>(*this, iSel);
00204       }
00205 
00206       iterator particle_begin() ;
00207       iterator particle_end() ;
00208       ChosenChargeList< Charged , CandidateClass >& plus() const;
00209       ChosenChargeList< Charged , CandidateClass >& minus() const;
00210 
00211       // const member functions
00212       const_iterator particle_begin() const ;
00213       const_iterator particle_end() const ;
00214 
00215 
00216       using CandidateList< CandidateClass >::iterate;
00217       template<class TAnalyze>
00218       void iterate( const TAnalyze& analyze) const {
00219          const_iterator finished ( particle_end() ) ;
00220          for ( const_iterator entry ( particle_begin() ) ;
00221                entry != finished ;
00222                ++entry ) {
00223             analyze( (*entry)() ) ;
00224          }
00225       }
00226 
00227       template<class TAnalyze>
00228       void iterate( TAnalyze& analyze) const {
00229          const_iterator finished ( particle_end() ) ;
00230          for ( const_iterator entry ( particle_begin() ) ;
00231                entry != finished ;
00232                ++entry ) {
00233             analyze( (*entry)() ) ;
00234          }
00235       }
00236 
00238       template<class TSelect>
00239       SelectiveInserter<self_type,TSelect> selectiveInserter(const TSelect& iSelect) {
00240          return SelectiveInserter<self_type,TSelect>(*this,iSelect); }
00241 
00242       template <class THolder, class TSelect>
00243       bool attempt_insert( THolder& pPossible,
00244                            const TSelect& aSelect) {
00245          //std::cout << " @ ChargedVisibleList::attempt_insert() " << __LINE__ << std::endl;
00246          bool returnValue = (aSelect)(*pPossible);
00247          if (returnValue) {
00248             this->insert(pPossible);
00249          }
00250          return returnValue;
00251       }
00252 
00253       template <class THolder>
00254       void insert(THolder& pPossible) {
00255          if (0 < charge_sign(pPossible)) {
00256             m_list->push_back( LabeledParticle< Charged >( pPossible ,
00257                                                           kPlus ) ) ;
00258          }
00259          else {
00260             m_list->push_back( LabeledParticle< Charged >( pPossible ,
00261                                                           kMinus ) ) ;
00262          }
00263       }
00264 
00265       void eraseContents() ;
00266       void erase() {
00267          eraseContents();
00268       }
00269 
00270       template<class TMaker, class TSelector>
00271       void fill( const LabeledParticleList< Charged , CandidateClass >& aList,
00272                  const TMaker& aMaker,
00273                  const TSelector& aSel) {
00274 
00275          for( const_iterator entry(aList.begin()); entry != aList.end(); ++entry){
00276             //NOTE: even though this is really just calling the copy constructor
00277             //it is best to use the maker since it allows further control
00278             const Charged& from((*entry)());
00279             typename ResultTypeTrait<TMaker>::type localCopy( aMaker(from) );
00280             
00281             attempt_insert(localCopy,aSel);
00282          }
00283  
00284       }
00285       template<class Iterator, class TMaker, class TSelector>
00286       void fill(Iterator first, Iterator last,
00287                 const TMaker& aMaker,
00288                 const TSelector& aSel = SelectAll<Charged>() ) {
00289          //std::cout << " @ ChargedVisibleList::fill() " << __LINE__ << std::endl;
00290          //std::cout << "size before transform: " << m_list->size() << std::endl;
00291          std::transform(first,last,
00292                         selectiveInserter(aSel),
00293                         aMaker);
00294          //std::cout << "size after transform: " << m_list->size() << std::endl;
00295       }
00296       // static member functions
00297 
00298    protected:
00299       // protected member functions
00300       virtual LabeledParticleList< Charged , CandidateClass >& labeledCandidateList();
00301       
00302 
00303       // protected const member functions
00304       virtual const LabeledParticleList< Charged , CandidateClass >& labeledCandidateList() const ;
00305 
00306    private:
00307       // Constructors and destructor
00308 
00309       // private member functions
00310 
00311       // private const member functions
00312 
00313       // data members
00314       MutableReferenceHolder<LabeledParticleList< Charged , CandidateClass > > m_list ;
00315 
00316       mutable ChosenChargeList< Charged, CandidateClass >* m_plusList;
00317       mutable ChosenChargeList< Charged, CandidateClass >* m_minusList;
00318 
00319       // static data members
00320       static const conjugation::Label kPlus = conjugation::kHeads;
00321       static const conjugation::Label kMinus = conjugation::kTails;
00322 
00323 } ;
00324 
00325 // inline function definitions
00326    
00327    template<class TIList, class TSelector, class T, class U>
00328    void fill_using_selector(const TIList& iList,
00329                             const TSelector& iSel,
00330                             ChargedVisibleList<T,U>& oList) {
00331       oList.fill(iList.begin(), iList.end(),
00332                  typename MakerTrait<T>::maker_type(),
00333                  iSel);
00334    }
00335 }
00336 
00337 // function definitions
00338 #include "DecayChain/List/Template/ChargedVisibleList.cc"
00339 
00340 #endif /* DCHAIN_CHARGEDVISIBLELIST_H */
00341 

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