BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
ChargedVisibleList.h
Go to the documentation of this file.
1#ifndef DCHAIN_CHARGEDVISIBLELIST_H
2#define DCHAIN_CHARGEDVISIBLELIST_H
3// -*- C++ -*-
4//
5// Package: DChain
6// Module: ChargedVisibleList
7//
8// Description: List to hold Candidate subclasses generated from VisibleEvidence
9//
10// Usage:
11// <usage>
12//
13// Author: Simon Patton
14// Created: Fri Oct 4 11:04:47 EDT 1996
15// $Id: ChargedVisibleList.h,v 1.1.1.1 2009/03/03 06:06:56 maqm Exp $
16//
17// Revision history
18//
19// $Log: ChargedVisibleList.h,v $
20// Revision 1.1.1.1 2009/03/03 06:06:56 maqm
21// first import of DecayChain
22//
23// Revision 1.1 2006/01/11 20:28:20 cdj
24// massive class renaming, addition of [] for selection and unit tests
25//
26// Revision 1.4 2003/08/01 13:48:40 mrs43
27// changed plus and minus methods of ChargedVisibleList to const
28//
29// Revision 1.3 2003/05/15 19:56:06 cdj
30// revamped memory handling so always use a ReferenceHolder to deal with the reference counting
31//
32// Revision 1.2 2000/12/30 19:43:29 cdj
33// no more missing symbols under OSF1
34//
35// Revision 1.1.1.1 2000/12/18 22:16:51 cdj
36// imported DChain
37//
38// Revision 1.11 1998/08/20 19:58:59 sjp
39// Modified to use DChainBoolean
40//
41// Revision 1.10 1998/04/17 19:10:59 sjp
42// Modified to use latest types
43//
44// Revision 1.9 1997/09/17 20:05:27 sjp
45// Removed filling to superclass
46//
47// Revision 1.8 1997/08/28 06:59:44 sjp
48// Modified files to handle complete templating
49//
50// Revision 1.7 1997/08/19 15:55:06 sjp
51// Modified list to have no dependence on any other
52// structures except its contents, which must have
53// certain `typedef' available to use.
54//
55// Revision 1.6 1997/08/15 21:32:09 sjp
56// Updated to use <package>/<file>.h include structure.
57// Updated to use bug flags specified in Experiement.h
58//
59// Revision 1.5 1997/01/31 20:17:00 sjp
60// Modified to use the new `bug' include files
61//
62// Revision 1.4 1997/01/22 16:27:09 sjp
63// Fixed error in pre-processor labels
64//
65// Revision 1.3 1997/01/21 20:33:37 sjp
66// Changed CPP flags and include because of library reorganization
67//
68// Revision 1.2 1996/12/20 21:19:00 sjp
69// Extended pathnames for Include files
70//
71// Revision 1.1 1996/11/04 19:35:48 sjp
72// New file for new `List' module
73//
74
75// system include files
76#include <memory>
77#include <iostream>
78//#include "boost/bind.hpp"
79//#include <boost/iterator/transform_iterator.hpp>
80
81// user include files
82#include "DecayChain/List/CandidateList.h" // superclass declaration
83#include "DecayChain/List/ChosenChargeList.h" // for return-by-value
85//#include "DecayChain/Element/ReferenceHolder.h"
86
87//#include "DecayChain/Iterator/WholeCandidateItr.h"
90
95
96// forward declarations
98
99//
100// Note: To avoid a myriad of compiler flags it is easier to
101// have a two parameter template class. The instantiation
102// of this class must look like
103//
104// template class LabeledDecayList< A , A::CandidateClass > ;
105
106namespace dchain {
107template < class T > class MuteWholeItr ;
108
109
110 template<class T>
111 int charge_sign(const T& iCharged) {
112 return static_cast<int>(iCharged.charge());
113 }
114
115 template<class T>
116 int charge_sign(const T* iCharged) {
117 return static_cast<int>(iCharged->charge());
118 }
119
120 template<class T>
121 int charge_sign(T* iCharged) {
122 return static_cast<int>(iCharged->charge());
123 }
124
125 template<class T>
126 int charge_sign(const std::auto_ptr<T>& iCharged) {
127 return static_cast<int>(iCharged->charge());
128 }
129
130 template<class TPtr,class TRef>
132 return charge_sign(*iHolder);
133 }
134
135
136template < class Charged , class CandidateClass = typename Charged::CandidateClass >
137class ChargedVisibleList : public CandidateList< CandidateClass >
138{
139 // friend classses and functions
140
141 public:
142 // constants, enums and typedefs
146
147 typedef Charged value_type ;
148
150
151 /**
152 inserts into the list only if the the selector returns true
153 */
154 // Constructors and destructor
156 ChargedVisibleList( const self_type& aOtherList);
157 template<class TSelector>
158 ChargedVisibleList( const self_type& aOtherList,
159 const TSelector& aSel) :
160 m_list( new LabeledParticleList<Charged,CandidateClass> ),
161 m_plusList(0),
162 m_minusList(0)
163 {
164 fill(*(aOtherList.m_list),
166 aSel);
167 }
168
169 template <class WitnessIterator>
170 ChargedVisibleList(WitnessIterator first, WitnessIterator last) :
171 m_list( new LabeledParticleList<Charged,CandidateClass> ),
172 m_plusList(0),
173 m_minusList(0)
174 {
175 fill(first, last, typename MakerTrait<Charged>::maker_type() ); }
176
177 template<class WitnessIterator, class TSelector>
178 ChargedVisibleList(WitnessIterator first, WitnessIterator last,
179 const TSelector& aFunctionalObject ) :
180 m_list( new LabeledParticleList<Charged,CandidateClass> ),
181 m_plusList(0),
182 m_minusList(0)
183 {
184 fill(first, last,
185 typename MakerTrait<Charged>::maker_type(), aFunctionalObject); }
186
187 virtual ~ChargedVisibleList() ;
188
189 // assignment operator(s)
190 const self_type& operator=( const self_type& aOtherList ) ;
191 template<class Witness>
192 const self_type& operator=(const Witness& aWitnessList) {
194 fill(aWitnessList.begin(), aWitnessList.end(),
197 return ( *this ) ;
198 }
199
200 // member functions
201 template<class TSelector>
205
210
211 // const member functions
214
215
216 using CandidateList< CandidateClass >::iterate;
217 template<class TAnalyze>
218 void iterate( const TAnalyze& analyze) const {
219 const_iterator finished ( particle_end() ) ;
220 for ( const_iterator entry ( particle_begin() ) ;
221 entry != finished ;
222 ++entry ) {
223 analyze( (*entry)() ) ;
224 }
225 }
226
227 template<class TAnalyze>
228 void iterate( TAnalyze& analyze) const {
229 const_iterator finished ( particle_end() ) ;
230 for ( const_iterator entry ( particle_begin() ) ;
231 entry != finished ;
232 ++entry ) {
233 analyze( (*entry)() ) ;
234 }
235 }
236
237 ///creates an insert iterator that filters based on iSelect
238 template<class TSelect>
241
242 template <class THolder, class TSelect>
243 bool attempt_insert( THolder& pPossible,
244 const TSelect& aSelect) {
245 //std::cout << " @ ChargedVisibleList::attempt_insert() " << __LINE__ << std::endl;
246 bool returnValue = (aSelect)(*pPossible);
247 if (returnValue) {
248 this->insert(pPossible);
249 }
250 return returnValue;
251 }
252
253 template <class THolder>
254 void insert(THolder& pPossible) {
255 if (0 < charge_sign(pPossible)) {
256 m_list->push_back( LabeledParticle< Charged >( pPossible ,
257 kPlus ) ) ;
258 }
259 else {
260 m_list->push_back( LabeledParticle< Charged >( pPossible ,
261 kMinus ) ) ;
262 }
263 }
264
265 void eraseContents() ;
266 void erase() {
268 }
269
270 template<class TMaker, class TSelector>
272 const TMaker& aMaker,
273 const TSelector& aSel) {
274
275 for( const_iterator entry(aList.begin()); entry != aList.end(); ++entry){
276 //NOTE: even though this is really just calling the copy constructor
277 //it is best to use the maker since it allows further control
278 const Charged& from((*entry)());
279 typename ResultTypeTrait<TMaker>::type localCopy( aMaker(from) );
280
281 attempt_insert(localCopy,aSel);
282 }
283
284 }
285 template<class Iterator, class TMaker, class TSelector>
286 void fill(Iterator first, Iterator last,
287 const TMaker& aMaker,
288 const TSelector& aSel = SelectAll<Charged>() ) {
289 //std::cout << " @ ChargedVisibleList::fill() " << __LINE__ << std::endl;
290 //std::cout << "size before transform: " << m_list->size() << std::endl;
291 std::transform(first,last,
292 selectiveInserter(aSel),
293 aMaker);
294 //std::cout << "size after transform: " << m_list->size() << std::endl;
295 }
296 // static member functions
297
298 protected:
299 // protected member functions
301
302
303 // protected const member functions
305
306 private:
307 // Constructors and destructor
308
309 // private member functions
310
311 // private const member functions
312
313 // data members
315
318
319 // static data members
320 static const conjugation::Label kPlus = conjugation::kHeads;
321 static const conjugation::Label kMinus = conjugation::kTails;
322
323} ;
324
325// inline function definitions
326
327 template<class TIList, class TSelector, class T, class U>
328 void fill_using_selector(const TIList& iList,
329 const TSelector& iSel,
331 oList.fill(iList.begin(), iList.end(),
332 typename MakerTrait<T>::maker_type(),
333 iSel);
334 }
335}
336
337// function definitions
339
340#endif /* DCHAIN_CHARGEDVISIBLELIST_H */
341
ChargedVisibleList(const self_type &aOtherList, const TSelector &aSel)
PartialItr< Charged > const_partial_iterator
FillListWithSelection< self_type, TSelector > operator[](const TSelector &iSel)
ChargedVisibleList< Charged, CandidateClass > self_type
void fill(const LabeledParticleList< Charged, CandidateClass > &aList, const TMaker &aMaker, const TSelector &aSel)
const self_type & operator=(const Witness &aWitnessList)
void iterate(TAnalyze &analyze) const
ChosenChargeList< Charged, CandidateClass > & plus() const
void fill(Iterator first, Iterator last, const TMaker &aMaker, const TSelector &aSel=SelectAll< Charged >())
ChosenChargeList< Charged, CandidateClass > & minus() const
SelectiveInserter< self_type, TSelect > selectiveInserter(const TSelect &iSelect)
creates an insert iterator that filters based on iSelect
void insert(THolder &pPossible)
virtual LabeledParticleList< Charged, CandidateClass > & labeledCandidateList()
bool attempt_insert(THolder &pPossible, const TSelect &aSelect)
MuteWholeItr< Charged > iterator
void iterate(const TAnalyze &analyze) const
WholeItr< Charged > const_iterator
ChargedVisibleList(WitnessIterator first, WitnessIterator last, const TSelector &aFunctionalObject)
ChargedVisibleList(WitnessIterator first, WitnessIterator last)
const self_type & operator=(const self_type &aOtherList)
void fill_using_selector(const TIList &iList, const TSelector &iSel, ChargedVisibleList< T, U > &oList)
int charge_sign(const T &iCharged)
T::result_type type
Definition MakerTrait.h:55