]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSpackageSSD.cxx
Casting to eliminate constructor ambiguity
[u/mrichter/AliRoot.git] / ITS / AliITSpackageSSD.cxx
CommitLineData
e8189707 1#include <iostream.h>
2#include <TClonesArray.h>
3
b0f5e3fc 4#include "AliITSpackageSSD.h"
e8189707 5
b0f5e3fc 6//************************************************
7//Piotr Krzysztof Skowronski
8//Warsaw University of Technology
9//skowron@if.pw.edu.pl
10//
11
12const Int_t debug=0;
13
14ClassImp(AliITSpackageSSD)
15
16AliITSpackageSSD::AliITSpackageSSD()
17{
18 fNclustersN=0;
19 fClusterNIndexes = new TArrayI(300);
20
21 fNclustersP=0;
22 fClusterPIndexes = new TArrayI(300);
23 if (debug) cout<<"Default Ctor was used\n>>>>>>>>>>>>>><<<<<<<<<<<<<";
24}
25
26
27/*******************************************************/
28
29AliITSpackageSSD::AliITSpackageSSD
30 (TClonesArray *clustersP, TClonesArray *clustersN)
31{
32 fClustersP=clustersP;
33 fClustersN=clustersN;
34
35 fNclustersN=0;
36 fClusterNIndexes = new TArrayI(300);
37
38 fNclustersP=0;
39 fClusterPIndexes = new TArrayI(300);
40}
41
42/*******************************************************/
43
44
45AliITSpackageSSD::AliITSpackageSSD
46 ( Int_t len, TClonesArray *clustersP, TClonesArray *clustersN)
47
48{
49 fClustersP=clustersP;
50 fClustersN=clustersN;
51
52 fNclustersN=0;
53 fClusterNIndexes = new TArrayI(len);
54
55 fNclustersP=0;
56 fClusterPIndexes = new TArrayI(len);
57}
58
59
60/*******************************************************/
61
62AliITSpackageSSD::~AliITSpackageSSD()
63{
64 // destructor
65 delete fClusterNIndexes;
66 delete fClusterPIndexes;
67}
68/*******************************************************/
69
70AliITSpackageSSD::AliITSpackageSSD(const AliITSpackageSSD &package)
71{
72 // copy constractor
73 Int_t i; //iterator
74
75 if (this == &package) return;
76 fClustersN = package.fClustersN;
77 fClustersP = package.fClustersP;
78
79 fNclustersN= package.fNclustersN;
80 fNclustersP= package.fNclustersP;
81
e8189707 82 for ( i =0; i<fNclustersN;i++)
b0f5e3fc 83 {
84 fClusterNIndexes[i]= package.fClusterNIndexes[i];
85 }
86
e8189707 87 for ( i =0; i<fNclustersP;i++)
b0f5e3fc 88 {
89 fClusterPIndexes[i]= package.fClusterPIndexes[i];
90 }
91
92 if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
93
94 return;
95
96}
97/*******************************************************/
98
99AliITSpackageSSD&
100AliITSpackageSSD::operator=( const AliITSpackageSSD & package)
101{
102
103Int_t i; //iterator
104
105if (this == &package) return *this;
106fClustersN = package.fClustersN;
107fClustersP = package.fClustersP;
108
109fNclustersN= package.fNclustersN;
110fNclustersP= package.fNclustersP;
111
e8189707 112for ( i =0; i<fNclustersN;i++)
b0f5e3fc 113 {
114 fClusterNIndexes[i]= package.fClusterNIndexes[i];
115 }
116
e8189707 117for ( i =0; i<fNclustersP;i++)
b0f5e3fc 118 {
119 fClusterPIndexes[i]= package.fClusterPIndexes[i];
120 }
121
122if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
123
124return *this;
125
126}
127
128
129/*******************************************************/
130
131Int_t
132AliITSpackageSSD::GetNSideClusterIdx(Int_t index)
133
134{
135 if ((index>-1)&&(index<fNclustersN))
136 return (*fClusterNIndexes)[index];
137 else
138 {
139 cout << "AliITSpackageSSD::GetNSideClusterIdx : Out of Range\n";
140 return -1;
141 }
142}
143/*******************************************************/
144
145
146Int_t AliITSpackageSSD::GetPSideClusterIdx(Int_t index)
147{
148 if ((index>-1)&&(index<fNclustersP))
149 return (*fClusterPIndexes)[index];
150 else
151 {
152 cout << "AliITSpackageSSD::GetPSideClusterIdx : Out of Range\n";
153 return -1;
154 }
155}
156/*******************************************************/
157AliITSclusterSSD*
158AliITSpackageSSD::GetPSideCluster(Int_t index)
159{
160
161return (AliITSclusterSSD*)((*fClustersP)[GetPSideClusterIdx(index)]);
162}
163
164/*******************************************************/
165
166AliITSclusterSSD*
167AliITSpackageSSD::GetNSideCluster(Int_t index)
168{
169return (AliITSclusterSSD*)((*fClustersN)[GetNSideClusterIdx(index)]);
170}
171
172
173/*******************************************************/
174
175
176
177Bool_t
178AliITSpackageSSD::GetClusterWithOneCross
179 (Int_t & index, Bool_t& side)
180{
181
182
183 if((fNclustersP==0)||(fNclustersN==0) )
184 {
185 printf("Empty package ((fNclustersP==0)||(fNclustersN==0))\n");
186 index = -2;
187 return kFALSE;
188 }
189 Int_t ind;
190
191 ind =(*fClusterPIndexes)[fNclustersP-1];
192 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
193 {
194 //index=ind;
195 index =fNclustersP-1;
e8189707 196 side=fgkSIDEP;
b0f5e3fc 197 return kTRUE;
198 }
199
200 ind =(*fClusterNIndexes)[fNclustersN-1];
201 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
202 {
203 //index=ind;
204 index = fNclustersN-1;
e8189707 205 side=fgkSIDEN;
b0f5e3fc 206 return kTRUE;
207 }
208
209
210 ind =(*fClusterPIndexes)[0];
211 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
212 {
213 //index=ind;
214 index = 0;
e8189707 215 side=fgkSIDEP;
b0f5e3fc 216 return kTRUE;
217 }
218
219
220 ind =(*fClusterNIndexes)[0];
221 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
222 {
223// index=ind;
224 index = 0;
e8189707 225 side=fgkSIDEN;
b0f5e3fc 226 return kTRUE;
227 }
228
229
230 //Add for to be shure
231 index = -1;
232 return kFALSE;
233
234}
235/*******************************************************/
236
237void AliITSpackageSSD::DelCluster(Int_t index, Bool_t side)
238{
e8189707 239 if(side==fgkSIDEP) DelPCluster(index); else DelNCluster(index);
b0f5e3fc 240}
241/*******************************************************/
242void AliITSpackageSSD::DelPCluster(Int_t index)
243{
244
245//it not deletes delete given cluster physically,
246//but only complytely erase it from package
247//all clusters are deleted automatically when TClonesArray is deleted
248
249 Int_t i;
250 Int_t idx;
251 Int_t clToDelIdx = GetPSideClusterIdx(index); //Index of cluster in TClonesArray
252 AliITSclusterSSD *clToDel = GetPSideCluster(index); //cluster to be deleted
253 Int_t ncr = clToDel->GetCrossNo();
254
e8189707 255 for (i =0;i<ncr;i++)
b0f5e3fc 256 {
257 idx = clToDel->GetCross(i);
258 ((AliITSclusterSSD *)((*fClustersN)[idx]) )->DelCross(clToDelIdx);
259 }
260
261
e8189707 262 for (i=index;i<fNclustersP-1;i++)
b0f5e3fc 263 {
264 (*fClusterPIndexes)[i]=(*fClusterPIndexes)[i+1];
265 }
266 fNclustersP--;
267 if (debug) cout<<"Cluster P ("<<index<<") deleted\n";
268
269
e8189707 270 for (i=0;i<fNclustersN;i++)
b0f5e3fc 271 {
272 if ( (GetNSideCluster(i)->GetCrossNo())==0) DelNCluster(i);
273 }
274}
275
276
277
278/*******************************************************/
279void AliITSpackageSSD::DelNCluster(Int_t index)
280{
281
282//it not deletes delete given cluster physically,
283//but only complytely erase it from package
284//all clusters are deleted automatically when TClonesArray is deleted
285
286 Int_t i;
287 Int_t idx;
288 Int_t clToDelIdx = GetNSideClusterIdx(index); //Index of cluster in TClonesArray
289 AliITSclusterSSD *clToDel = GetNSideCluster(index); //cluster to be deleted
290 Int_t ncr = clToDel->GetCrossNo();
291
e8189707 292 for (i =0;i<ncr;i++)
b0f5e3fc 293 {
294 idx = clToDel->GetCross(i);
295 ((AliITSclusterSSD *)((*fClustersP)[idx]) )->DelCross(clToDelIdx);
296 }
297
298
e8189707 299 for (i=index;i<fNclustersN-1;i++)
b0f5e3fc 300 {
301 (*fClusterNIndexes)[i]=(*fClusterNIndexes)[i+1];
302 }
303 fNclustersN--;
304 if (debug) cout<<"Cluster N ("<<index<<") deleted\n";
305
e8189707 306 for (i=0;i<fNclustersP;i++)
b0f5e3fc 307 {
308 if ( (GetPSideCluster(i)->GetCrossNo())==0) DelPCluster(i);
309 }
310
311}
312
313
314/*******************************************************/
315
316void AliITSpackageSSD::DelPClusterOI(Int_t index)
317{
318//This function looks like this,
319//because probably cut cluster is
320//on the beginning or on the end of package
321 Int_t i;
322 if( ((*fClusterPIndexes)[0]) == index)
323 {
324 DelPCluster(0);
325 return;
326 }
327 else
328 {
329 if( ((*fClusterPIndexes)[fNclustersP-1]) ==index)
330 {
331 DelPCluster(fNclustersP-1);
332 return;
333 }
334 else
335 {
e8189707 336 for (i=1;i<fNclustersP-1;i++)
b0f5e3fc 337 {
338 if( ((*fClusterPIndexes)[i])==index)
339 {
340 DelPCluster(i);
341 return;
342 }
343 }
344 }
345 }
346
347 cout<<"AliITSpackageSSD - DelPClusterOI: index "<<index<<" not found\n";
348
349}
350
351
352/*******************************************************/
353
354void AliITSpackageSSD::DelNClusterOI(Int_t index)
355{
356//This function looks like this,
357//because probably cluster to cut is
358//on the beginning or on the end of package
359
360 Int_t i;
361 if( ((*fClusterNIndexes)[0])==index)
362 {
363 DelNCluster(0);
364 return;
365 }
366 else
367 {
368 if( ((*fClusterNIndexes)[fNclustersN-1])==index)
369 {
370 DelNCluster(fNclustersN-1);
371 return;
372 }
373 else
374 {
e8189707 375 for (i=1;i<fNclustersN-1;i++)
b0f5e3fc 376 {
377 if( ((*fClusterNIndexes)[i])==index)
378 {
379 DelNCluster(i);
380 return;
381 }
382 }
383 }
384 }
385 cout<<"AliITSpackageSSD - DelNClusterOI: index "<<index<<" not found\n";
386}
387
388
389/*******************************************************/
390
391
392void AliITSpackageSSD::DelClusterOI(Int_t index, Bool_t side)
393{
e8189707 394 if (side == fgkSIDEP)
b0f5e3fc 395 {
396 DelPClusterOI(index);
397 }
398 else
399 {
400 DelNClusterOI(index);
401 }
402
403}
404
405
406/**********************************************/
407
408
409void AliITSpackageSSD::GetAllCombinations(Int_t**array,Int_t &num,Int_t sizet)
410{
411
412 Int_t *takenNcl = new Int_t[fNclustersN];
413
414 num=0;
415
416 if (debug) PrintClusters();
417
e8189707 418 for (Int_t i=0;i<fNclustersP;i++)
b0f5e3fc 419 {
420 takenNcl[i]=-1;
421 }
422 //see comment on the beginning of MakeCombin
423 if (debug) cout<<"GetAllCombinations entered";
424 MakeCombin (array,num,0,takenNcl,sizet);
425
426 delete []takenNcl;
427}
428/**********************************************/
429
430
431void AliITSpackageSSD::MakeCombin
432 (Int_t**arr,Int_t& nu, Int_t np, Int_t *occup, Int_t sizet)
433
434{
435
436//ATTENTION: anybody watching this function
437//AliITSclusterSSD::GetCrossNo() returns index of cluster in main array belonging to AliITSmodulesSSD
438//however, we have pointer to that array (TClonesArray)
439//we can not use
440//Get?SideCluster because it takes index from local look_up_table
441
442 Int_t i,j;
443
444 //this cluster
445 AliITSclusterSSD *cl=GetPSideCluster(np);
446
b0f5e3fc 447 Int_t NC = cl->GetCrossNo(); //number of crosses for this cluster
448 Int_t indcro; //index of given cluster on side N that
449 // this cluster crosses with
450
b0f5e3fc 451 if (np == fNclustersP-1) {
e8189707 452 for (i=0;i<NC;i++) {
b0f5e3fc 453 indcro=cl->GetCross(i);
b0f5e3fc 454 if(IsFree(indcro,np,occup)) {
455 occup[np]=indcro;
b0f5e3fc 456 for(j=0;j<fNclustersP;j++)
457 {
b0f5e3fc 458 if (nu<sizet) arr[nu][j]=occup[j];
459 else {
b0f5e3fc 460 continue;}
b0f5e3fc 461 }
462
463 occup[np]=-1;
464 if (nu<sizet-1) nu++;
b0f5e3fc 465 }
466 }
467 } else {
e8189707 468 for (i=0;i<NC;i++) {
b0f5e3fc 469 indcro=cl->GetCross(i);
b0f5e3fc 470 if(IsFree(indcro,np,occup)) {
471 occup[np]=indcro;
b0f5e3fc 472 if (nu<sizet) MakeCombin(arr,nu,(np+1),occup,sizet);
473 //else printf("MakeComb - exceeding array size!\n");
474 }
475 }
476 occup[np]=-1;
477 }
478
479}
480
481/**********************************************/
482Bool_t AliITSpackageSSD::IsFree(Int_t idx, Int_t nn, Int_t *lis)
483{
484
e8189707 485 for (Int_t i=0;i<nn;i++)
b0f5e3fc 486 {
487 if (lis[i]==idx) return kFALSE;
488 }
489 return kTRUE;
490}
491
492/**********************************************/
493void AliITSpackageSSD::PrintClusters()
494{
495
496Int_t i,j;
497cout<<"SIDE P\n";
e8189707 498for (i=0;i<fNclustersP;i++)
b0f5e3fc 499 {
500 cout<<i<<". IO="<<GetPSideClusterIdx(i)<<" NC="<<GetPSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
e8189707 501 for (j=0;j<GetPSideCluster(i)->GetCrossNo();j++)
b0f5e3fc 502 {
503 cout<<GetPSideCluster(i)->GetCross(j)<<" ";
504 }
505 // if (GetPSideCluster(i)->GetSide()) cout<<" P\n";
506 // else cout<<"BAD SIDE ==N\n";
507 cout<<"\n";
508
509 }
510
511cout <<"SIDE N\n";
e8189707 512for (i=0;i<fNclustersN;i++)
b0f5e3fc 513 {
514 cout<<i<<". IO="<<GetNSideClusterIdx(i)<<" NC="<<GetNSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
e8189707 515 for (j=0;j<GetNSideCluster(i)->GetCrossNo();j++)
b0f5e3fc 516 {
517 cout<<GetNSideCluster(i)->GetCross(j)<<" ";
518 }
519 // if (GetNSideCluster(i)->GetSide()) cout<<" N\n";
520 // else cout<<"BAD SIDE ==P\n";
521 cout<<"\n";
522 }
523
524
525
526}
527/**********************************************/
528void AliITSpackageSSD::ConsumeClusters()
529{
530register Int_t i;
531
532for(i=0;i<fNclustersP;i++)
533 {
534 GetPSideCluster(i)->Consume();
535 }
536
537for(i=0;i<fNclustersN;i++)
538 {
539 GetNSideCluster(i)->Consume();
540 }
541
542}
543
544/**********************************************/
545
546Int_t AliITSpackageSSD::GetNextPIdx(Int_t OI)
547{
548 //Returns index of next P cluster OI in package; OI == Original Inedx (in TClonesArray)
549 //if not egsist return -1;
e8189707 550 for (Int_t i =0; i<fNclustersP-1;i++)
b0f5e3fc 551 {
552 if(GetPSideClusterIdx(i) == OI)
553 return GetPSideClusterIdx(i+1);
554 }
555 return -1;
556}
557/**********************************************/
558Int_t AliITSpackageSSD::GetPrvPIdx(Int_t OI)
559{
560 //Returns index of previous P cluster OI in package; OI == Original Inedx (in TClonesArray)
561 //if not egsist return -1;
562
e8189707 563 for (Int_t i =1; i<fNclustersP;i++)
b0f5e3fc 564 {
565 if(GetPSideClusterIdx(i) == OI)
566 return GetPSideClusterIdx(i-1);
567 }
568 return -1;
569}
570/**********************************************/
571Int_t AliITSpackageSSD::GetNextNIdx(Int_t OI)
572{
573//Returns index of next N cluster OI in package; OI == Original Inedx (in TClonesArray)
574 //if not egsist return -1;
e8189707 575 for (Int_t i =0; i<fNclustersN-1;i++)
b0f5e3fc 576 {
577 if(GetNSideClusterIdx(i) == OI)
578 return GetNSideClusterIdx(i+1);
579 }
580 return -1;
581
582}
583/**********************************************/
584Int_t AliITSpackageSSD::GetPrvNIdx(Int_t OI)
585{
586 //Returns index of previous N cluster OI in package; OI == Original Inedx (in TClonesArray)
587 //if not egsist return -1;
588
e8189707 589 for (Int_t i =1; i<fNclustersN;i++)
b0f5e3fc 590 {
591 if(GetNSideClusterIdx(i) == OI)
592 return GetNSideClusterIdx(i-1);
593 }
594 return -1;
595
596}
597
598void AliITSpackageSSD::SplitPackage(Int_t pi, Int_t ni, AliITSpackageSSD* pkg)
599{
600 // split package of clusters
601 Int_t p=-1, n=-1;
602 Int_t i;
e8189707 603 for (i=0;i<fNclustersN;i++)
b0f5e3fc 604 {
605 if((*fClusterNIndexes)[i]==ni)
606 {
607 n = i;
608 break;
609 }
610 }
611
e8189707 612 for (i=0;i<fNclustersP;i++)
b0f5e3fc 613 {
614 if((*fClusterPIndexes)[i]==pi)
615 {
616 p = i;
617 break;
618 }
619 }
620 if (debug) cout<<" p = "<<p<<" n = "<<n;
621 if ((p==-1)||(n==-1)) return;
622
e8189707 623 for (i=p;i<fNclustersP;i++)
b0f5e3fc 624 {
625 pkg->AddPSideCluster(GetPSideClusterIdx(i));
626 }
627 fNclustersP = p;
628
e8189707 629 for (i=n;i<fNclustersN;i++)
b0f5e3fc 630 {
631 pkg->AddNSideCluster(GetNSideClusterIdx(i));
632 }
633 fNclustersN = n;
634
635 cout<<" After split: fNclustersP = "<< fNclustersP<< "fNclustersN = "<< fNclustersN<<"\n";
636}