1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 Revision 1.4 2000/07/12 05:32:20 fca
19 Correcting several syntax problem with static members
24 #include <TClonesArray.h>
25 #include "AliITSpackageSSD.h"
27 //************************************************
28 //Piotr Krzysztof Skowronski
29 //Warsaw University of Technology
30 //skowron@if.pw.edu.pl
33 const Bool_t AliITSpackageSSD::fgkSIDEP=kTRUE;
34 const Bool_t AliITSpackageSSD::fgkSIDEN=kFALSE;
36 static const Int_t debug=0;
38 ClassImp(AliITSpackageSSD)
40 AliITSpackageSSD::AliITSpackageSSD()
47 if (debug) cout<<"Default Ctor was used\n>>>>>>>>>>>>>><<<<<<<<<<<<<";
51 /*******************************************************/
53 AliITSpackageSSD::AliITSpackageSSD
54 (TClonesArray *clustersP, TClonesArray *clustersN)
60 fClusterNIndexes = new TArrayI(300);
63 fClusterPIndexes = new TArrayI(300);
66 /*******************************************************/
69 AliITSpackageSSD::AliITSpackageSSD
70 ( Int_t len, TClonesArray *clustersP, TClonesArray *clustersN)
77 fClusterNIndexes = new TArrayI(len);
80 fClusterPIndexes = new TArrayI(len);
84 /*******************************************************/
86 AliITSpackageSSD::~AliITSpackageSSD()
89 delete fClusterNIndexes;
90 delete fClusterPIndexes;
92 /*******************************************************/
94 AliITSpackageSSD::AliITSpackageSSD(const AliITSpackageSSD &package)
99 if (this == &package) return;
100 fClustersN = package.fClustersN;
101 fClustersP = package.fClustersP;
103 fNclustersN= package.fNclustersN;
104 fNclustersP= package.fNclustersP;
106 for ( i =0; i<fNclustersN;i++)
108 fClusterNIndexes[i]= package.fClusterNIndexes[i];
111 for ( i =0; i<fNclustersP;i++)
113 fClusterPIndexes[i]= package.fClusterPIndexes[i];
116 if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
121 /*******************************************************/
124 AliITSpackageSSD::operator=( const AliITSpackageSSD & package)
129 if (this == &package) return *this;
130 fClustersN = package.fClustersN;
131 fClustersP = package.fClustersP;
133 fNclustersN= package.fNclustersN;
134 fNclustersP= package.fNclustersP;
136 for ( i =0; i<fNclustersN;i++)
138 fClusterNIndexes[i]= package.fClusterNIndexes[i];
141 for ( i =0; i<fNclustersP;i++)
143 fClusterPIndexes[i]= package.fClusterPIndexes[i];
146 if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
153 /*******************************************************/
156 AliITSpackageSSD::GetNSideClusterIdx(Int_t index)
159 if ((index>-1)&&(index<fNclustersN))
160 return (*fClusterNIndexes)[index];
163 cout << "AliITSpackageSSD::GetNSideClusterIdx : Out of Range\n";
167 /*******************************************************/
170 Int_t AliITSpackageSSD::GetPSideClusterIdx(Int_t index)
172 if ((index>-1)&&(index<fNclustersP))
173 return (*fClusterPIndexes)[index];
176 cout << "AliITSpackageSSD::GetPSideClusterIdx : Out of Range\n";
180 /*******************************************************/
182 AliITSpackageSSD::GetPSideCluster(Int_t index)
185 return (AliITSclusterSSD*)((*fClustersP)[GetPSideClusterIdx(index)]);
188 /*******************************************************/
191 AliITSpackageSSD::GetNSideCluster(Int_t index)
193 return (AliITSclusterSSD*)((*fClustersN)[GetNSideClusterIdx(index)]);
197 /*******************************************************/
202 AliITSpackageSSD::GetClusterWithOneCross
203 (Int_t & index, Bool_t& side)
207 if((fNclustersP==0)||(fNclustersN==0) )
209 printf("Empty package ((fNclustersP==0)||(fNclustersN==0))\n");
215 ind =(*fClusterPIndexes)[fNclustersP-1];
216 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
219 index =fNclustersP-1;
224 ind =(*fClusterNIndexes)[fNclustersN-1];
225 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
228 index = fNclustersN-1;
234 ind =(*fClusterPIndexes)[0];
235 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
244 ind =(*fClusterNIndexes)[0];
245 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
254 //Add for to be shure
259 /*******************************************************/
261 void AliITSpackageSSD::DelCluster(Int_t index, Bool_t side)
263 if(side==fgkSIDEP) DelPCluster(index); else DelNCluster(index);
265 /*******************************************************/
266 void AliITSpackageSSD::DelPCluster(Int_t index)
269 //it not deletes delete given cluster physically,
270 //but only complytely erase it from package
271 //all clusters are deleted automatically when TClonesArray is deleted
275 Int_t clToDelIdx = GetPSideClusterIdx(index); //Index of cluster in TClonesArray
276 AliITSclusterSSD *clToDel = GetPSideCluster(index); //cluster to be deleted
277 Int_t ncr = clToDel->GetCrossNo();
281 idx = clToDel->GetCross(i);
282 ((AliITSclusterSSD *)((*fClustersN)[idx]) )->DelCross(clToDelIdx);
286 for (i=index;i<fNclustersP-1;i++)
288 (*fClusterPIndexes)[i]=(*fClusterPIndexes)[i+1];
291 if (debug) cout<<"Cluster P ("<<index<<") deleted\n";
294 for (i=0;i<fNclustersN;i++)
296 if ( (GetNSideCluster(i)->GetCrossNo())==0) DelNCluster(i);
302 /*******************************************************/
303 void AliITSpackageSSD::DelNCluster(Int_t index)
306 //it not deletes delete given cluster physically,
307 //but only complytely erase it from package
308 //all clusters are deleted automatically when TClonesArray is deleted
312 Int_t clToDelIdx = GetNSideClusterIdx(index); //Index of cluster in TClonesArray
313 AliITSclusterSSD *clToDel = GetNSideCluster(index); //cluster to be deleted
314 Int_t ncr = clToDel->GetCrossNo();
318 idx = clToDel->GetCross(i);
319 ((AliITSclusterSSD *)((*fClustersP)[idx]) )->DelCross(clToDelIdx);
323 for (i=index;i<fNclustersN-1;i++)
325 (*fClusterNIndexes)[i]=(*fClusterNIndexes)[i+1];
328 if (debug) cout<<"Cluster N ("<<index<<") deleted\n";
330 for (i=0;i<fNclustersP;i++)
332 if ( (GetPSideCluster(i)->GetCrossNo())==0) DelPCluster(i);
338 /*******************************************************/
340 void AliITSpackageSSD::DelPClusterOI(Int_t index)
342 //This function looks like this,
343 //because probably cut cluster is
344 //on the beginning or on the end of package
346 if( ((*fClusterPIndexes)[0]) == index)
353 if( ((*fClusterPIndexes)[fNclustersP-1]) ==index)
355 DelPCluster(fNclustersP-1);
360 for (i=1;i<fNclustersP-1;i++)
362 if( ((*fClusterPIndexes)[i])==index)
371 cout<<"AliITSpackageSSD - DelPClusterOI: index "<<index<<" not found\n";
376 /*******************************************************/
378 void AliITSpackageSSD::DelNClusterOI(Int_t index)
380 //This function looks like this,
381 //because probably cluster to cut is
382 //on the beginning or on the end of package
385 if( ((*fClusterNIndexes)[0])==index)
392 if( ((*fClusterNIndexes)[fNclustersN-1])==index)
394 DelNCluster(fNclustersN-1);
399 for (i=1;i<fNclustersN-1;i++)
401 if( ((*fClusterNIndexes)[i])==index)
409 cout<<"AliITSpackageSSD - DelNClusterOI: index "<<index<<" not found\n";
413 /*******************************************************/
416 void AliITSpackageSSD::DelClusterOI(Int_t index, Bool_t side)
418 if (side == fgkSIDEP)
420 DelPClusterOI(index);
424 DelNClusterOI(index);
430 /**********************************************/
433 void AliITSpackageSSD::GetAllCombinations(Int_t**array,Int_t &num,Int_t sizet)
436 Int_t *takenNcl = new Int_t[fNclustersN];
440 if (debug) PrintClusters();
442 for (Int_t i=0;i<fNclustersP;i++)
446 //see comment on the beginning of MakeCombin
447 if (debug) cout<<"GetAllCombinations entered";
448 MakeCombin (array,num,0,takenNcl,sizet);
452 /**********************************************/
455 void AliITSpackageSSD::MakeCombin
456 (Int_t**arr,Int_t& nu, Int_t np, Int_t *occup, Int_t sizet)
460 //ATTENTION: anybody watching this function
461 //AliITSclusterSSD::GetCrossNo() returns index of cluster in main array belonging to AliITSmodulesSSD
462 //however, we have pointer to that array (TClonesArray)
464 //Get?SideCluster because it takes index from local look_up_table
469 AliITSclusterSSD *cl=GetPSideCluster(np);
471 Int_t NC = cl->GetCrossNo(); //number of crosses for this cluster
472 Int_t indcro; //index of given cluster on side N that
473 // this cluster crosses with
475 if (np == fNclustersP-1) {
477 indcro=cl->GetCross(i);
478 if(IsFree(indcro,np,occup)) {
480 for(j=0;j<fNclustersP;j++)
482 if (nu<sizet) arr[nu][j]=occup[j];
488 if (nu<sizet-1) nu++;
493 indcro=cl->GetCross(i);
494 if(IsFree(indcro,np,occup)) {
496 if (nu<sizet) MakeCombin(arr,nu,(np+1),occup,sizet);
497 //else printf("MakeComb - exceeding array size!\n");
505 /**********************************************/
506 Bool_t AliITSpackageSSD::IsFree(Int_t idx, Int_t nn, Int_t *lis)
509 for (Int_t i=0;i<nn;i++)
511 if (lis[i]==idx) return kFALSE;
516 /**********************************************/
517 void AliITSpackageSSD::PrintClusters()
522 for (i=0;i<fNclustersP;i++)
524 cout<<i<<". IO="<<GetPSideClusterIdx(i)<<" NC="<<GetPSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
525 for (j=0;j<GetPSideCluster(i)->GetCrossNo();j++)
527 cout<<GetPSideCluster(i)->GetCross(j)<<" ";
529 // if (GetPSideCluster(i)->GetSide()) cout<<" P\n";
530 // else cout<<"BAD SIDE ==N\n";
536 for (i=0;i<fNclustersN;i++)
538 cout<<i<<". IO="<<GetNSideClusterIdx(i)<<" NC="<<GetNSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
539 for (j=0;j<GetNSideCluster(i)->GetCrossNo();j++)
541 cout<<GetNSideCluster(i)->GetCross(j)<<" ";
543 // if (GetNSideCluster(i)->GetSide()) cout<<" N\n";
544 // else cout<<"BAD SIDE ==P\n";
551 /**********************************************/
552 void AliITSpackageSSD::ConsumeClusters()
556 for(i=0;i<fNclustersP;i++)
558 GetPSideCluster(i)->Consume();
561 for(i=0;i<fNclustersN;i++)
563 GetNSideCluster(i)->Consume();
568 /**********************************************/
570 Int_t AliITSpackageSSD::GetNextPIdx(Int_t OI)
572 //Returns index of next P cluster OI in package; OI == Original Inedx (in TClonesArray)
573 //if not egsist return -1;
574 for (Int_t i =0; i<fNclustersP-1;i++)
576 if(GetPSideClusterIdx(i) == OI)
577 return GetPSideClusterIdx(i+1);
581 /**********************************************/
582 Int_t AliITSpackageSSD::GetPrvPIdx(Int_t OI)
584 //Returns index of previous P cluster OI in package; OI == Original Inedx (in TClonesArray)
585 //if not egsist return -1;
587 for (Int_t i =1; i<fNclustersP;i++)
589 if(GetPSideClusterIdx(i) == OI)
590 return GetPSideClusterIdx(i-1);
594 /**********************************************/
595 Int_t AliITSpackageSSD::GetNextNIdx(Int_t OI)
597 //Returns index of next N cluster OI in package; OI == Original Inedx (in TClonesArray)
598 //if not egsist return -1;
599 for (Int_t i =0; i<fNclustersN-1;i++)
601 if(GetNSideClusterIdx(i) == OI)
602 return GetNSideClusterIdx(i+1);
607 /**********************************************/
608 Int_t AliITSpackageSSD::GetPrvNIdx(Int_t OI)
610 //Returns index of previous N cluster OI in package; OI == Original Inedx (in TClonesArray)
611 //if not egsist return -1;
613 for (Int_t i =1; i<fNclustersN;i++)
615 if(GetNSideClusterIdx(i) == OI)
616 return GetNSideClusterIdx(i-1);
622 void AliITSpackageSSD::SplitPackage(Int_t pi, Int_t ni, AliITSpackageSSD* pkg)
624 // split package of clusters
627 for (i=0;i<fNclustersN;i++)
629 if((*fClusterNIndexes)[i]==ni)
636 for (i=0;i<fNclustersP;i++)
638 if((*fClusterPIndexes)[i]==pi)
644 if (debug) cout<<" p = "<<p<<" n = "<<n;
645 if ((p==-1)||(n==-1)) return;
647 for (i=p;i<fNclustersP;i++)
649 pkg->AddPSideCluster(GetPSideClusterIdx(i));
653 for (i=n;i<fNclustersN;i++)
655 pkg->AddNSideCluster(GetNSideClusterIdx(i));
659 cout<<" After split: fNclustersP = "<< fNclustersP<< "fNclustersN = "<< fNclustersN<<"\n";