StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSsdPointList.cc
1 // $Id: StSsdPointList.cc,v 1.1 2006/10/16 16:43:29 bouchet Exp $
2 //
3 // $Log: StSsdPointList.cc,v $
4 // Revision 1.1 2006/10/16 16:43:29 bouchet
5 // StSsdUtil regroups now methods for the classes StSsdStrip, StSsdCluster and StSsdPoint
6 //
7 // Revision 1.2 2005/03/18 14:19:05 lmartin
8 // missing CVS header added
9 //
10 
11 #include "StSsdPointList.hh"
12 
13 StSsdPointList::StSsdPointList()
14 {
15  mListLength = 0;
16  mFirstPoint = 0;
17  mLastPoint = 0;
18 }
19 
20 StSsdPointList::~StSsdPointList()
21 {
22  if (mListLength)
23  {
24  StSsdPoint *ptr = mLastPoint;
25  StSsdPoint *toDele;
26  while (mListLength)
27  {
28  toDele = ptr;
29  ptr = prev(ptr);
30  delete toDele;
31  mListLength--;
32  }
33  }
34 }
35 
36 StSsdPoint* StSsdPointList::next(StSsdPoint *ptr)
37 { return ptr->getNextPoint(); }
38 
39 StSsdPoint* StSsdPointList::prev(StSsdPoint *ptr)
40 { return ptr->getPrevPoint(); }
41 
42 StSsdPoint* StSsdPointList::first()
43 { return mFirstPoint; }
44 
45 StSsdPoint* StSsdPointList::last()
46 { return mLastPoint; }
47 
48 Int_t StSsdPointList::getSize()
49 { return mListLength; }
50 
51 Int_t StSsdPointList::addNewPoint(StSsdPoint *ptr)
52 {
53  if (!ptr) return 0;
54  if (mListLength == 0)
55  {
56  ptr->setPrevPoint(0);
57  ptr->setNextPoint(0);
58  mFirstPoint = ptr;
59  mLastPoint = ptr;
60  }
61  else
62  {
63  ptr->setPrevPoint(mLastPoint);
64  ptr->setNextPoint(0);
65  mLastPoint->setNextPoint(ptr);
66  mLastPoint = ptr;
67  }
68  mListLength++;
69  return 1;
70 }
71 
72 Int_t StSsdPointList::removePoint(StSsdPoint *ptr)
73 {
74  if (!this->getSize()) return 0;
75  StSsdPoint *ptBefore = ptr->getPrevPoint();
76  StSsdPoint *ptAfter = ptr->getNextPoint();
77 
78  if (ptBefore == 0)
79  {
80  if (ptAfter== 0)
81  {
82  // taille = 1
83  this->mFirstPoint = 0;
84  this->mLastPoint = 0;
85  this->mListLength = 0;
86  delete ptr;
87  return 1;
88  }
89  else
90  {
91  this->mFirstPoint = ptAfter;
92  ptAfter->setPrevPoint(0);
93  this->mListLength--;
94  delete ptr;
95  return 1;
96  }
97  }
98  else
99  {
100  if (ptAfter== 0)
101  {
102  this->mLastPoint = ptBefore;
103  ptBefore->setNextPoint(0);
104  this->mListLength--;
105  delete ptr;
106  return 1;
107  }
108  else
109  {
110  ptBefore->setNextPoint(ptAfter);
111  ptAfter->setPrevPoint(ptBefore);
112  this->mListLength--;
113  delete ptr;
114  return 1;
115  }
116  }
117 
118 }
119 
120 void StSsdPointList::exchangeTwoPoints(StSsdPoint *ptr1,StSsdPoint *ptr2)
121 {
122 
123  StSsdPoint *ptrTemp = ptr1->giveCopy();
124 
125  Int_t i =0;
126 
127  ptr1->setFlag(ptr2->getFlag()) ;
128  ptr1->setNPoint(ptr2->getNPoint()) ;
129  ptr1->setNCluster(ptr2->getNCluster()) ;
130  ptr1->setNMatched(ptr2->getNMatched());
131  for (i = 0; i < 5; i++)
132  ptr1->setNMchit(ptr2->getNMchit(i),i);
133  ptr1->setNWafer(ptr2->getNWafer());
134  for (i = 0; i < 3; i++)
135  {
136  ptr1->setXg(ptr2->getXg(i),i);
137  ptr1->setXl(ptr2->getXl(i),i);
138  }
139  for (i = 0; i < 2; i++)
140  {
141  ptr1->setDe(ptr2->getDe(i),i);
142  }
143 
144  /*
145  ptr2->setFlag(ptr1->getFlag()) ;
146  ptr2->setNPoint(ptr1->getNPoint()) ;
147  ptr2->setNCluster(ptr1->getNCluster()) ;
148  ptr2->setNMatched(ptr1->getNMatched());
149  for (i = 0; i < 5; i++)
150  ptr2->setNMchit(ptr1->getNMchit(i),i);
151  ptr2->setNWafer(ptr1->getNWafer());
152  for (i = 0; i < 3; i++)
153  {
154  ptr2->setXg(ptr1->getXg(i),i);
155  ptr2->setXl(ptr1->getXl(i),i);
156  }
157  for (i = 0; i < 2; i++)
158  {
159  ptr1->setDe(ptr2->getDe(i),i);
160  }
161  */
162 
163  ptr2->setFlag(ptrTemp->getFlag()) ;
164  ptr2->setNPoint(ptrTemp->getNPoint()) ;
165  ptr2->setNCluster(ptrTemp->getNCluster()) ;
166  ptr2->setNMatched(ptrTemp->getNMatched());
167  for (i = 0; i < 5; i++)
168  ptr2->setNMchit(ptrTemp->getNMchit(i),i);
169  ptr2->setNWafer(ptrTemp->getNWafer());
170  for (i = 0; i < 3; i++)
171  {
172  ptr2->setXg(ptrTemp->getXg(i),i);
173  ptr2->setXl(ptrTemp->getXl(i),i);
174  }
175  for (i = 0; i < 2; i++)
176  {
177  ptr2->setDe(ptrTemp->getDe(i),i);
178  }
179 }
180 
181 StSsdPointList* StSsdPointList::addPointList(StSsdPointList *list)
182 {
183  Int_t size2 = list->getSize();
184 
185  if (!size2) return this;
186  StSsdPoint *pt1 ;
187  StSsdPoint *pt2 = list->first();
188 
189  for (Int_t i = 0; i < size2; i++)
190  {
191  pt1 = pt2->giveCopy();
192  this->addNewPoint(pt1);
193  pt2 = list->next(pt2);
194  }
195  return this;
196 }
197 
198 StSsdPointList* StSsdPointList::substractPointList(StSsdPointList *list)
199 {
200 
201  Int_t localSizeToDelete = list->getSize();
202  Int_t localSizeToKeep = this->getSize();
203 
204  if((!localSizeToDelete)||(!localSizeToKeep)) return this;
205  StSsdPoint *currDele = list->first();
206 
207  for (Int_t iDele = 0; iDele < localSizeToDelete; iDele++)
208  {
209  StSsdPoint *currKeep = this->first();
210  Int_t iKeep = 0;
211  for (iKeep =0 ; ((iKeep < this->getSize())&&((currDele->getNId())!=(currKeep->getNId()))); iKeep++)
212  {
213  currKeep = list->next(currKeep);
214  }
215  //if (currDele->getNPoint()==currKeep->getNPoint())
216  //StSsdPoint->NId is used for the simulation, not NPoint
217  //this method is used only for simulation
218  if (currDele->getNId()==currKeep->getNId())
219  {
220  this->removePoint(currKeep);
221  }
222  currDele = list->next(currDele);
223  }
224  return this;
225 }
226 
227 StSsdPointList* StSsdPointList::removeMultipleCount()
228 {
229  Int_t localSize = this->getSize();
230  if (localSize < 2) return this;
231  StSsdPoint *ptBigLoop = this->first();
232 
233  while ((ptBigLoop != this->last())&&(ptBigLoop != 0))
234  {
235  StSsdPoint *ptSmallLoop = this->next(ptBigLoop);
236 
237  while (ptSmallLoop!=0)
238  {
239  //if (ptSmallLoop->getNPoint() == ptBigLoop->getNPoint())
240  //StSsdPoint->NId is used for the simulation, not NPoint
241  //this method is used only for simulation
242  if (ptSmallLoop->getNId() == ptBigLoop->getNId())
243  {
244  StSsdPoint *temp = ptSmallLoop;
245  ptSmallLoop = this->next(ptSmallLoop);
246  this->removePoint(temp);
247  }
248  else
249  {
250  ptSmallLoop = this->next(ptSmallLoop);
251  }
252  }
253  ptBigLoop = this->next(ptBigLoop);
254  }
255  return this;
256 }
257 
258 StSsdPointList* StSsdPointList::sortPoint()
259 {
260  Int_t localSize=this->getSize();
261  if (localSize<2) return this;
262 
263  StSsdPoint *ptCurr = this->first();
264  ptCurr = this->next(ptCurr);
265  for ( ; ptCurr!=0 ; )
266 
267  {
268  StSsdPoint *ptB1 = ptCurr;
269  StSsdPoint *ptB2;
270  Int_t isCont = 1;
271  while ((ptB1 != this->first())&&(isCont))
272  {
273  ptB2 = this->prev(ptB1);
274  if (ptB2->getNPoint() > ptB1->getNPoint())
275  {
276  this->exchangeTwoPoints(ptB1,ptB2);
277  ptB1 = ptB2;
278  }
279  else
280  {
281  isCont = 0;
282  }
283  }
284  ptCurr = this->next(ptCurr);
285 
286  }
287  return this;
288 }
289 
290 Int_t StSsdPointList::renumHits(Int_t last)
291 {
292  Int_t localSize = this->getSize();
293  if (!localSize) return last;
294  StSsdPoint *ptr = this->first();
295  for (Int_t iPt = 0; iPt < localSize; iPt++)
296  {
297  ptr->setNPoint(last + iPt + 1);
298  ptr = this->next(ptr);
299  }
300  return (last + localSize);
301 }
302 
303 StSsdPointList::StSsdPointList(const StSsdPointList & originalPointList)
304 {
305  mListLength = originalPointList.mListLength;
306  mFirstPoint = originalPointList.mFirstPoint;
307  mLastPoint = originalPointList.mLastPoint;
308 }
309 
310 StSsdPointList& StSsdPointList::operator=(const StSsdPointList originalPointList)
311 {
312  mListLength = originalPointList.mListLength;
313  mFirstPoint = originalPointList.mFirstPoint;
314  mLastPoint = originalPointList.mLastPoint;
315 
316  return *this;
317 }
318 
319