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 //************************************************
19 //Piotr Krzysztof Skowronski
20 //Warsaw University of Technology
21 //skowron@if.pw.edu.pl
24 #include <Riostream.h>
25 #include <TClonesArray.h>
26 #include "AliITSpackageSSD.h"
28 const Bool_t AliITSpackageSSD::fgkSIDEP=kTRUE;
29 const Bool_t AliITSpackageSSD::fgkSIDEN=kFALSE;
31 static const Int_t debug=0;
33 ClassImp(AliITSpackageSSD)
35 AliITSpackageSSD::AliITSpackageSSD()
42 if (debug) cout<<"Default Ctor was used\n>>>>>>>>>>>>>><<<<<<<<<<<<<";
46 /*******************************************************/
48 AliITSpackageSSD::AliITSpackageSSD
49 (TClonesArray *clustersP, TClonesArray *clustersN)
55 fClusterNIndexes = new TArrayI(300);
58 fClusterPIndexes = new TArrayI(300);
61 /*******************************************************/
64 AliITSpackageSSD::AliITSpackageSSD
65 ( Int_t len, TClonesArray *clustersP, TClonesArray *clustersN)
72 fClusterNIndexes = new TArrayI(len);
75 fClusterPIndexes = new TArrayI(len);
79 /*******************************************************/
81 AliITSpackageSSD::~AliITSpackageSSD()
84 delete fClusterNIndexes;
85 delete fClusterPIndexes;
87 /*******************************************************/
89 AliITSpackageSSD::AliITSpackageSSD(const AliITSpackageSSD &package)
94 if (this == &package) return;
95 fClustersN = package.fClustersN;
96 fClustersP = package.fClustersP;
98 fNclustersN= package.fNclustersN;
99 fNclustersP= package.fNclustersP;
101 for ( i =0; i<fNclustersN;i++)
103 fClusterNIndexes[i]= package.fClusterNIndexes[i];
106 for ( i =0; i<fNclustersP;i++)
108 fClusterPIndexes[i]= package.fClusterPIndexes[i];
111 if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
116 /*******************************************************/
119 AliITSpackageSSD::operator=( const AliITSpackageSSD & package)
124 if (this == &package) return *this;
125 fClustersN = package.fClustersN;
126 fClustersP = package.fClustersP;
128 fNclustersN= package.fNclustersN;
129 fNclustersP= package.fNclustersP;
131 for ( i =0; i<fNclustersN;i++)
133 fClusterNIndexes[i]= package.fClusterNIndexes[i];
136 for ( i =0; i<fNclustersP;i++)
138 fClusterPIndexes[i]= package.fClusterPIndexes[i];
141 if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
148 /*******************************************************/
151 AliITSpackageSSD::GetNSideClusterIdx(Int_t index)
154 if ((index>-1)&&(index<fNclustersN))
155 return (*fClusterNIndexes)[index];
158 cout << "AliITSpackageSSD::GetNSideClusterIdx : Out of Range\n";
162 /*******************************************************/
165 Int_t AliITSpackageSSD::GetPSideClusterIdx(Int_t index)
167 if ((index>-1)&&(index<fNclustersP))
168 return (*fClusterPIndexes)[index];
171 cout << "AliITSpackageSSD::GetPSideClusterIdx : Out of Range\n";
175 /*******************************************************/
177 AliITSpackageSSD::GetPSideCluster(Int_t index)
180 return (AliITSclusterSSD*)((*fClustersP)[GetPSideClusterIdx(index)]);
183 /*******************************************************/
186 AliITSpackageSSD::GetNSideCluster(Int_t index)
188 return (AliITSclusterSSD*)((*fClustersN)[GetNSideClusterIdx(index)]);
192 /*******************************************************/
197 AliITSpackageSSD::GetClusterWithOneCross
198 (Int_t & index, Bool_t& side)
202 if((fNclustersP==0)||(fNclustersN==0) )
204 printf("Empty package ((fNclustersP==0)||(fNclustersN==0))\n");
210 ind =(*fClusterPIndexes)[fNclustersP-1];
211 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
214 index =fNclustersP-1;
219 ind =(*fClusterNIndexes)[fNclustersN-1];
220 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
223 index = fNclustersN-1;
229 ind =(*fClusterPIndexes)[0];
230 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
239 ind =(*fClusterNIndexes)[0];
240 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
249 //Add for to be shure
254 /*******************************************************/
256 void AliITSpackageSSD::DelCluster(Int_t index, Bool_t side)
258 if(side==fgkSIDEP) DelPCluster(index); else DelNCluster(index);
260 /*******************************************************/
261 void AliITSpackageSSD::DelPCluster(Int_t index)
264 //it not deletes delete given cluster physically,
265 //but only complytely erase it from package
266 //all clusters are deleted automatically when TClonesArray is deleted
270 Int_t clToDelIdx = GetPSideClusterIdx(index); //Index of cluster in TClonesArray
271 AliITSclusterSSD *clToDel = GetPSideCluster(index); //cluster to be deleted
272 Int_t ncr = clToDel->GetCrossNo();
276 idx = clToDel->GetCross(i);
277 ((AliITSclusterSSD *)((*fClustersN)[idx]) )->DelCross(clToDelIdx);
281 for (i=index;i<fNclustersP-1;i++)
283 (*fClusterPIndexes)[i]=(*fClusterPIndexes)[i+1];
286 if (debug) cout<<"Cluster P ("<<index<<") deleted\n";
289 for (i=0;i<fNclustersN;i++)
291 if ( (GetNSideCluster(i)->GetCrossNo())==0) DelNCluster(i);
297 /*******************************************************/
298 void AliITSpackageSSD::DelNCluster(Int_t index)
301 //it not deletes delete given cluster physically,
302 //but only complytely erase it from package
303 //all clusters are deleted automatically when TClonesArray is deleted
307 Int_t clToDelIdx = GetNSideClusterIdx(index); //Index of cluster in TClonesArray
308 AliITSclusterSSD *clToDel = GetNSideCluster(index); //cluster to be deleted
309 Int_t ncr = clToDel->GetCrossNo();
313 idx = clToDel->GetCross(i);
314 ((AliITSclusterSSD *)((*fClustersP)[idx]) )->DelCross(clToDelIdx);
318 for (i=index;i<fNclustersN-1;i++)
320 (*fClusterNIndexes)[i]=(*fClusterNIndexes)[i+1];
323 if (debug) cout<<"Cluster N ("<<index<<") deleted\n";
325 for (i=0;i<fNclustersP;i++)
327 if ( (GetPSideCluster(i)->GetCrossNo())==0) DelPCluster(i);
333 /*******************************************************/
335 void AliITSpackageSSD::DelPClusterOI(Int_t index)
337 //This function looks like this,
338 //because probably cut cluster is
339 //on the beginning or on the end of package
341 if( ((*fClusterPIndexes)[0]) == index)
348 if( ((*fClusterPIndexes)[fNclustersP-1]) ==index)
350 DelPCluster(fNclustersP-1);
355 for (i=1;i<fNclustersP-1;i++)
357 if( ((*fClusterPIndexes)[i])==index)
366 cout<<"AliITSpackageSSD - DelPClusterOI: index "<<index<<" not found\n";
371 /*******************************************************/
373 void AliITSpackageSSD::DelNClusterOI(Int_t index)
375 //This function looks like this,
376 //because probably cluster to cut is
377 //on the beginning or on the end of package
380 if( ((*fClusterNIndexes)[0])==index)
387 if( ((*fClusterNIndexes)[fNclustersN-1])==index)
389 DelNCluster(fNclustersN-1);
394 for (i=1;i<fNclustersN-1;i++)
396 if( ((*fClusterNIndexes)[i])==index)
404 cout<<"AliITSpackageSSD - DelNClusterOI: index "<<index<<" not found\n";
408 /*******************************************************/
411 void AliITSpackageSSD::DelClusterOI(Int_t index, Bool_t side)
413 if (side == fgkSIDEP)
415 DelPClusterOI(index);
419 DelNClusterOI(index);
425 /**********************************************/
428 void AliITSpackageSSD::GetAllCombinations(Int_t**array,Int_t &num,Int_t sizet)
431 Int_t *takenNcl = new Int_t[fNclustersN];
435 if (debug) PrintClusters();
437 for (Int_t i=0;i<fNclustersP;i++)
441 //see comment on the beginning of MakeCombin
442 if (debug) cout<<"GetAllCombinations entered";
443 MakeCombin (array,num,0,takenNcl,sizet);
447 /**********************************************/
450 void AliITSpackageSSD::MakeCombin
451 (Int_t**arr,Int_t& nu, Int_t np, Int_t *occup, Int_t sizet)
455 //ATTENTION: anybody watching this function
456 //AliITSclusterSSD::GetCrossNo() returns index of cluster in main array belonging to AliITSmodulesSSD
457 //however, we have pointer to that array (TClonesArray)
459 //Get?SideCluster because it takes index from local look_up_table
464 AliITSclusterSSD *cl=GetPSideCluster(np);
466 Int_t NC = cl->GetCrossNo(); //number of crosses for this cluster
467 Int_t indcro; //index of given cluster on side N that
468 // this cluster crosses with
470 if (np == fNclustersP-1) {
472 indcro=cl->GetCross(i);
473 if(IsFree(indcro,np,occup)) {
475 for(j=0;j<fNclustersP;j++)
477 if (nu<sizet) arr[nu][j]=occup[j];
483 if (nu<sizet-1) nu++;
488 indcro=cl->GetCross(i);
489 if(IsFree(indcro,np,occup)) {
491 if (nu<sizet) MakeCombin(arr,nu,(np+1),occup,sizet);
492 //else printf("MakeComb - exceeding array size!\n");
500 /**********************************************/
501 Bool_t AliITSpackageSSD::IsFree(Int_t idx, Int_t nn, Int_t *lis)
504 for (Int_t i=0;i<nn;i++)
506 if (lis[i]==idx) return kFALSE;
511 /**********************************************/
512 void AliITSpackageSSD::PrintClusters()
517 for (i=0;i<fNclustersP;i++)
519 cout<<i<<". IO="<<GetPSideClusterIdx(i)<<" NC="<<GetPSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
520 for (j=0;j<GetPSideCluster(i)->GetCrossNo();j++)
522 cout<<GetPSideCluster(i)->GetCross(j)<<" ";
524 // if (GetPSideCluster(i)->GetSide()) cout<<" P\n";
525 // else cout<<"BAD SIDE ==N\n";
531 for (i=0;i<fNclustersN;i++)
533 cout<<i<<". IO="<<GetNSideClusterIdx(i)<<" NC="<<GetNSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
534 for (j=0;j<GetNSideCluster(i)->GetCrossNo();j++)
536 cout<<GetNSideCluster(i)->GetCross(j)<<" ";
538 // if (GetNSideCluster(i)->GetSide()) cout<<" N\n";
539 // else cout<<"BAD SIDE ==P\n";
546 /**********************************************/
547 void AliITSpackageSSD::ConsumeClusters()
551 for(i=0;i<fNclustersP;i++)
553 GetPSideCluster(i)->Consume();
556 for(i=0;i<fNclustersN;i++)
558 GetNSideCluster(i)->Consume();
563 /**********************************************/
565 Int_t AliITSpackageSSD::GetNextPIdx(Int_t OI)
567 //Returns index of next P cluster OI in package; OI == Original Inedx (in TClonesArray)
568 //if not egsist return -1;
569 for (Int_t i =0; i<fNclustersP-1;i++)
571 if(GetPSideClusterIdx(i) == OI)
572 return GetPSideClusterIdx(i+1);
576 /**********************************************/
577 Int_t AliITSpackageSSD::GetPrvPIdx(Int_t OI)
579 //Returns index of previous P cluster OI in package; OI == Original Inedx (in TClonesArray)
580 //if not egsist return -1;
582 for (Int_t i =1; i<fNclustersP;i++)
584 if(GetPSideClusterIdx(i) == OI)
585 return GetPSideClusterIdx(i-1);
589 /**********************************************/
590 Int_t AliITSpackageSSD::GetNextNIdx(Int_t OI)
592 //Returns index of next N cluster OI in package; OI == Original Inedx (in TClonesArray)
593 //if not egsist return -1;
594 for (Int_t i =0; i<fNclustersN-1;i++)
596 if(GetNSideClusterIdx(i) == OI)
597 return GetNSideClusterIdx(i+1);
602 /**********************************************/
603 Int_t AliITSpackageSSD::GetPrvNIdx(Int_t OI)
605 //Returns index of previous N cluster OI in package; OI == Original Inedx (in TClonesArray)
606 //if not egsist return -1;
608 for (Int_t i =1; i<fNclustersN;i++)
610 if(GetNSideClusterIdx(i) == OI)
611 return GetNSideClusterIdx(i-1);
617 void AliITSpackageSSD::SplitPackage(Int_t pi, Int_t ni, AliITSpackageSSD* pkg)
619 // split package of clusters
622 for (i=0;i<fNclustersN;i++)
624 if((*fClusterNIndexes)[i]==ni)
631 for (i=0;i<fNclustersP;i++)
633 if((*fClusterPIndexes)[i]==pi)
640 cout<<" p = "<<p<<" n = "<<n;
642 if ((p==-1)||(n==-1)) return;
644 for (i=p;i<fNclustersP;i++)
646 pkg->AddPSideCluster(GetPSideClusterIdx(i));
650 for (i=n;i<fNclustersN;i++)
652 pkg->AddNSideCluster(GetNSideClusterIdx(i));
656 cout<<" After split: fNclustersP = "<< fNclustersP<< "fNclustersN = "<< fNclustersN<<"\n";