StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSsdPackage.cc
1 // $Id: StSsdPackage.cc,v 1.1 2006/10/16 16:43:29 bouchet Exp $
2 //
3 // $Log: StSsdPackage.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:21:44 lmartin
8 // missing CVS header added
9 //
10 
11 #include "StSsdUtil/StSsdPackage.hh"
12 #include <Stiostream.h>
13 #include "StSsdUtil/StSsdCluster.hh"
14 #include "StSsdUtil/StSsdClusterControl.h"
15 #include <string.h>
16 
17 StSsdPackage::StSsdPackage(Int_t rNPackage, StSsdClusterControl *control)
18 {
19  Int_t maxMatcheds = control->getClusterTreat();
20  mNPackage = rNPackage;
21  mListLengthM = 0;
22  mFirstMatched = 0;
23  mLastMatched = 0;
24  mMatcheds = new StSsdCluster*[maxMatcheds];
25  for(Int_t i=0;i<maxMatcheds;i++) mMatcheds[i]=0;
26  mKind = new char[2*maxMatcheds+1];
27  mKind[0] = '\0';
28  mPrevPackage = 0;
29  mNextPackage = 0;
30 }
31 
32 StSsdPackage::StSsdPackage(Int_t rNPackage, Int_t rNMatched)
33 {
34  mNPackage = rNPackage;
35  mListLengthM = rNMatched;
36  mFirstMatched = 0;
37  mLastMatched = 0;
38  mMatcheds = new StSsdCluster*[rNMatched];
39  for(Int_t i=0;i<rNMatched;i++) mMatcheds[i]=0;
40  mKind = new char[2*rNMatched+1];
41  mKind[0] = '\0';
42  mPrevPackage = 0;
43  mNextPackage = 0;
44 }
45 
46 StSsdPackage::StSsdPackage(const StSsdPackage & originalPackage)
47 {
48  Int_t i = 0;
49  mNPackage = originalPackage.mNPackage;
50  mListLengthM = originalPackage.mListLengthM;
51  mFirstMatched = originalPackage.mFirstMatched;
52  mLastMatched = originalPackage.mLastMatched;
53  mMatcheds = new StSsdCluster*[mListLengthM];
54  for(i=0;i<mListLengthM;i++) mMatcheds[i] = originalPackage.mMatcheds[i];
55  mKind = new char[2*mListLengthM+1];
56  for(i=0;i<2*mListLengthM+1;i++) mKind[i] = originalPackage.mKind[i];
57  mPrevPackage = originalPackage.mPrevPackage;
58  mNextPackage = originalPackage.mNextPackage;
59 }
60 
61 StSsdPackage::~StSsdPackage()
62 {
63  delete [ ] mMatcheds;
64  delete [ ] mKind;
65 }
66 
67 StSsdPackage& StSsdPackage::operator=(const StSsdPackage originalPackage)
68 {
69  Int_t i = 0;
70  mNPackage = originalPackage.mNPackage;
71  mListLengthM = originalPackage.mListLengthM;
72  mFirstMatched = originalPackage.mFirstMatched;
73  mLastMatched = originalPackage.mLastMatched;
74  for(i=0;i<mListLengthM;i++) mMatcheds[i] = originalPackage.mMatcheds[i];
75  for(i=0;i<2*mListLengthM+1;i++) mKind[i] = originalPackage.mKind[i];
76  mPrevPackage = originalPackage.mPrevPackage;
77  mNextPackage = originalPackage.mNextPackage;
78 
79  return *this;
80 }
81 
82 StSsdCluster* StSsdPackage::next(StSsdCluster *ptr)
83 { return ptr->getNextCluster(); }
84 
85 StSsdCluster* StSsdPackage::prev(StSsdCluster *ptr)
86 { return ptr->getPrevCluster(); }
87 
88 StSsdCluster* StSsdPackage::first()
89 { return mFirstMatched; }
90 
91 StSsdCluster* StSsdPackage::last()
92 { return mLastMatched; }
93 
94 void StSsdPackage::purgePackage()
95 {
96  mKind[0] = '\0';
97  mListLengthM = 0;
98  mPrevPackage=0;
99  mNextPackage=0;
100 }
101 
102 void StSsdPackage::takeMatcheds(StSsdPackage *ptr)
103 {
104  if (this->mListLengthM == ptr->mListLengthM)
105  {
106  this->mFirstMatched = ptr->mFirstMatched;
107  this->mLastMatched = ptr->mLastMatched;
108  strcpy(this->mKind, ptr->mKind);
109  for(Int_t i = 0;i < this->mListLengthM;i++)
110  { this->mMatcheds[i] = ptr->mMatcheds[i]; }
111  }
112  else
113  cout<<"Problem to transfer matched clusters (not enough room) !!\n";
114 }
115 
116 void StSsdPackage::setNPackage(Int_t rNPackage)
117 { this->mNPackage = rNPackage; }
118 
119 void StSsdPackage::setKind(char *rKind)
120 { this->mKind = rKind ; }
121 
122 void StSsdPackage::setPrevPackage(StSsdPackage *rPrevPackage)
123 { this->mPrevPackage = rPrevPackage ; }
124 
125 void StSsdPackage::setNextPackage(StSsdPackage *rNextPackage)
126 { this->mNextPackage = rNextPackage ; }
127 
128 Int_t StSsdPackage::getNPackage()
129 { return this->mNPackage; }
130 
131 StSsdCluster* StSsdPackage::getMatched(Int_t numMatched)
132 {
133  if (numMatched>mListLengthM) return 0;
134  return this->mMatcheds[numMatched];
135 }
136 
137 char* StSsdPackage::getKind()
138 { return this->mKind; }
139 
140 StSsdPackage* StSsdPackage::getPrevPackage()
141 { return this->mPrevPackage; }
142 
143 StSsdPackage* StSsdPackage::getNextPackage()
144 { return this->mNextPackage; }
145 
146 
147 Int_t StSsdPackage::addNewMatched(StSsdCluster *ptr, Int_t maxMatcheds)
148 {
149  if ( (!ptr) || (mListLengthM == maxMatcheds) ) return 0;
150  if (mListLengthM == 0)
151  {
152  mFirstMatched = ptr;
153  mLastMatched = ptr;
154  }
155  else
156  {
157  mLastMatched = ptr;
158  }
159  mMatcheds[mListLengthM] = ptr;
160  mListLengthM++;
161  return 1;
162 }
163 
164 Int_t StSsdPackage::addKindPackage(Int_t numMatched, Int_t rSide, Int_t maxMatcheds)
165 {
166  if ( (!this->getSize()) || (mListLengthM == maxMatcheds)) return 0;
167  mKind[2*(this->mListLengthM-1)]=char(48+numMatched);
168  if (rSide==0)
169  {
170  mKind[2*(this->mListLengthM)-1]='p';
171  mKind[2*(this->mListLengthM)]='\0';
172  }
173  else
174  {
175  mKind[2*(this->mListLengthM)-1]='n';
176  mKind[2*(this->mListLengthM)]='\0';
177  }
178  return 1;
179 }
180 
181 Int_t StSsdPackage::removeMatched(StSsdCluster *ptr)
182 {
183  if (!this->getSize()) return 0;
184  StSsdCluster *ptBefore = ptr->getPrevCluster();
185  StSsdCluster *ptAfter = ptr->getNextCluster();
186 
187  if (ptBefore == 0)
188  {
189  if (ptAfter== 0)
190  {
191  // taille = 1
192  this->mFirstMatched = 0;
193  this->mLastMatched = 0;
194  this->mListLengthM = 0;
195  delete ptr;
196  return 1;
197  }
198  else
199  {
200  this->mFirstMatched = ptAfter;
201  ptAfter->setPrevCluster(0);
202  this->mListLengthM--;
203  delete ptr;
204  return 1;
205  }
206  }
207  else
208  {
209  if (ptAfter== 0)
210  {
211  this->mLastMatched = ptBefore;
212  ptBefore->setNextCluster(0);
213  this->mListLengthM--;
214  delete ptr;
215  return 1;
216  }
217  else
218  {
219  ptBefore->setNextCluster(ptAfter);
220  ptAfter->setPrevCluster(ptBefore);
221  this->mListLengthM--;
222  delete ptr;
223  return 1;
224  }
225  }
226 
227 }
228 
229 
230 void StSsdPackage::exchangeTwoMatcheds(StSsdCluster *ptr1, StSsdCluster *ptr2)
231 {
232  StSsdCluster *ptrTmp = ptr1->giveCopy();
233 
234  ptr1->setNCluster(ptr2->getNCluster()) ;
235  ptr1->setFirstStrip(ptr2->getFirstStrip()) ;
236  ptr1->setClusterSize(ptr2->getClusterSize());
237  ptr1->setTotAdc(ptr2->getTotAdc());
238  ptr1->setFirstAdc(ptr2->getFirstAdc());
239  ptr1->setLastAdc(ptr2->getLastAdc());
240  ptr1->setTotNoise(ptr2->getTotNoise());
241  ptr1->setFlag(ptr2->getFlag());
242 
243  ptr2->setNCluster(ptrTmp->getNCluster()) ;
244  ptr2->setFirstStrip(ptrTmp->getFirstStrip()) ;
245  ptr2->setClusterSize(ptrTmp->getClusterSize());
246  ptr2->setTotAdc(ptrTmp->getTotAdc());
247  ptr2->setFirstAdc(ptrTmp->getFirstAdc());
248  ptr2->setLastAdc(ptrTmp->getLastAdc());
249  ptr2->setTotNoise(ptrTmp->getTotNoise());
250  ptr2->setFlag(ptrTmp->getFlag());
251 
252 }
253 
254 void StSsdPackage::sortMatched()
255 {
256  Int_t localSize=this->getSize();
257  if (localSize<2) return;
258 
259  StSsdCluster *ptCurr = this->first();
260  ptCurr = this->next(ptCurr);
261  for ( ; ptCurr!=0 ; )
262 
263  {
264  StSsdCluster *ptB1 = ptCurr;
265  StSsdCluster *ptB2;
266  Int_t isCont = 1;
267  while ((ptB1 != this->first())&&(isCont))
268  {
269  ptB2 = this->prev(ptB1);
270  if (ptB2->getFirstStrip() > ptB1->getFirstStrip())
271  {
272  this->exchangeTwoMatcheds(ptB1,ptB2);
273  ptB1 = ptB2;
274  }
275  else
276  {
277  isCont = 0;
278  }
279  }
280  ptCurr = this->next(ptCurr);
281 
282  }
283  return;
284 }
285 
286 void StSsdPackage::renumMatched()
287 {
288  Int_t CurrentListSize = this->getSize();
289  if (!CurrentListSize) return;
290  StSsdCluster *CurrCluster = this->first();
291  for (Int_t i = 0; i < CurrentListSize; i++)
292  {
293  CurrCluster->setNCluster(i);
294  CurrCluster = this->next(CurrCluster);
295  }
296  return;
297 }
298 
299 Int_t StSsdPackage::getSize()
300 { return mListLengthM; }
301 
302 Int_t StSsdPackage::isSorted()
303 {
304  StSsdCluster *ptr1 = this->first();
305  StSsdCluster *ptr2 = 0;
306 
307  while(ptr1 != this->last())
308  {
309  ptr2 = this->next(ptr1);
310  if (ptr1->getFirstStrip()>ptr2->getFirstStrip()) return 0;
311  ptr1 = this->next(ptr1);
312  }
313  return 1;
314 }