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.6 2002/10/22 14:45:42 alibrary
19 Introducing Riostream.h
21 Revision 1.5 2001/11/19 16:17:03 nilsen
22 Applyed fixes to bugs found by Rene Brun. With many thanks. Some additonal
23 bugs found by Rene require more work to fix. Will be fixed soon.
25 Revision 1.4 2000/07/12 05:32:20 fca
26 Correcting several syntax problem with static members
30 #include <Riostream.h>
31 #include <TClonesArray.h>
32 #include "AliITSpackageSSD.h"
34 //************************************************
35 //Piotr Krzysztof Skowronski
36 //Warsaw University of Technology
37 //skowron@if.pw.edu.pl
40 const Bool_t AliITSpackageSSD::fgkSIDEP=kTRUE;
41 const Bool_t AliITSpackageSSD::fgkSIDEN=kFALSE;
43 static const Int_t debug=0;
45 ClassImp(AliITSpackageSSD)
47 AliITSpackageSSD::AliITSpackageSSD()
54 if (debug) cout<<"Default Ctor was used\n>>>>>>>>>>>>>><<<<<<<<<<<<<";
58 /*******************************************************/
60 AliITSpackageSSD::AliITSpackageSSD
61 (TClonesArray *clustersP, TClonesArray *clustersN)
67 fClusterNIndexes = new TArrayI(300);
70 fClusterPIndexes = new TArrayI(300);
73 /*******************************************************/
76 AliITSpackageSSD::AliITSpackageSSD
77 ( Int_t len, TClonesArray *clustersP, TClonesArray *clustersN)
84 fClusterNIndexes = new TArrayI(len);
87 fClusterPIndexes = new TArrayI(len);
91 /*******************************************************/
93 AliITSpackageSSD::~AliITSpackageSSD()
96 delete fClusterNIndexes;
97 delete fClusterPIndexes;
99 /*******************************************************/
101 AliITSpackageSSD::AliITSpackageSSD(const AliITSpackageSSD &package)
106 if (this == &package) return;
107 fClustersN = package.fClustersN;
108 fClustersP = package.fClustersP;
110 fNclustersN= package.fNclustersN;
111 fNclustersP= package.fNclustersP;
113 for ( i =0; i<fNclustersN;i++)
115 fClusterNIndexes[i]= package.fClusterNIndexes[i];
118 for ( i =0; i<fNclustersP;i++)
120 fClusterPIndexes[i]= package.fClusterPIndexes[i];
123 if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
128 /*******************************************************/
131 AliITSpackageSSD::operator=( const AliITSpackageSSD & package)
136 if (this == &package) return *this;
137 fClustersN = package.fClustersN;
138 fClustersP = package.fClustersP;
140 fNclustersN= package.fNclustersN;
141 fNclustersP= package.fNclustersP;
143 for ( i =0; i<fNclustersN;i++)
145 fClusterNIndexes[i]= package.fClusterNIndexes[i];
148 for ( i =0; i<fNclustersP;i++)
150 fClusterPIndexes[i]= package.fClusterPIndexes[i];
153 if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
160 /*******************************************************/
163 AliITSpackageSSD::GetNSideClusterIdx(Int_t index)
166 if ((index>-1)&&(index<fNclustersN))
167 return (*fClusterNIndexes)[index];
170 cout << "AliITSpackageSSD::GetNSideClusterIdx : Out of Range\n";
174 /*******************************************************/
177 Int_t AliITSpackageSSD::GetPSideClusterIdx(Int_t index)
179 if ((index>-1)&&(index<fNclustersP))
180 return (*fClusterPIndexes)[index];
183 cout << "AliITSpackageSSD::GetPSideClusterIdx : Out of Range\n";
187 /*******************************************************/
189 AliITSpackageSSD::GetPSideCluster(Int_t index)
192 return (AliITSclusterSSD*)((*fClustersP)[GetPSideClusterIdx(index)]);
195 /*******************************************************/
198 AliITSpackageSSD::GetNSideCluster(Int_t index)
200 return (AliITSclusterSSD*)((*fClustersN)[GetNSideClusterIdx(index)]);
204 /*******************************************************/
209 AliITSpackageSSD::GetClusterWithOneCross
210 (Int_t & index, Bool_t& side)
214 if((fNclustersP==0)||(fNclustersN==0) )
216 printf("Empty package ((fNclustersP==0)||(fNclustersN==0))\n");
222 ind =(*fClusterPIndexes)[fNclustersP-1];
223 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
226 index =fNclustersP-1;
231 ind =(*fClusterNIndexes)[fNclustersN-1];
232 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
235 index = fNclustersN-1;
241 ind =(*fClusterPIndexes)[0];
242 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
251 ind =(*fClusterNIndexes)[0];
252 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
261 //Add for to be shure
266 /*******************************************************/
268 void AliITSpackageSSD::DelCluster(Int_t index, Bool_t side)
270 if(side==fgkSIDEP) DelPCluster(index); else DelNCluster(index);
272 /*******************************************************/
273 void AliITSpackageSSD::DelPCluster(Int_t index)
276 //it not deletes delete given cluster physically,
277 //but only complytely erase it from package
278 //all clusters are deleted automatically when TClonesArray is deleted
282 Int_t clToDelIdx = GetPSideClusterIdx(index); //Index of cluster in TClonesArray
283 AliITSclusterSSD *clToDel = GetPSideCluster(index); //cluster to be deleted
284 Int_t ncr = clToDel->GetCrossNo();
288 idx = clToDel->GetCross(i);
289 ((AliITSclusterSSD *)((*fClustersN)[idx]) )->DelCross(clToDelIdx);
293 for (i=index;i<fNclustersP-1;i++)
295 (*fClusterPIndexes)[i]=(*fClusterPIndexes)[i+1];
298 if (debug) cout<<"Cluster P ("<<index<<") deleted\n";
301 for (i=0;i<fNclustersN;i++)
303 if ( (GetNSideCluster(i)->GetCrossNo())==0) DelNCluster(i);
309 /*******************************************************/
310 void AliITSpackageSSD::DelNCluster(Int_t index)
313 //it not deletes delete given cluster physically,
314 //but only complytely erase it from package
315 //all clusters are deleted automatically when TClonesArray is deleted
319 Int_t clToDelIdx = GetNSideClusterIdx(index); //Index of cluster in TClonesArray
320 AliITSclusterSSD *clToDel = GetNSideCluster(index); //cluster to be deleted
321 Int_t ncr = clToDel->GetCrossNo();
325 idx = clToDel->GetCross(i);
326 ((AliITSclusterSSD *)((*fClustersP)[idx]) )->DelCross(clToDelIdx);
330 for (i=index;i<fNclustersN-1;i++)
332 (*fClusterNIndexes)[i]=(*fClusterNIndexes)[i+1];
335 if (debug) cout<<"Cluster N ("<<index<<") deleted\n";
337 for (i=0;i<fNclustersP;i++)
339 if ( (GetPSideCluster(i)->GetCrossNo())==0) DelPCluster(i);
345 /*******************************************************/
347 void AliITSpackageSSD::DelPClusterOI(Int_t index)
349 //This function looks like this,
350 //because probably cut cluster is
351 //on the beginning or on the end of package
353 if( ((*fClusterPIndexes)[0]) == index)
360 if( ((*fClusterPIndexes)[fNclustersP-1]) ==index)
362 DelPCluster(fNclustersP-1);
367 for (i=1;i<fNclustersP-1;i++)
369 if( ((*fClusterPIndexes)[i])==index)
378 cout<<"AliITSpackageSSD - DelPClusterOI: index "<<index<<" not found\n";
383 /*******************************************************/
385 void AliITSpackageSSD::DelNClusterOI(Int_t index)
387 //This function looks like this,
388 //because probably cluster to cut is
389 //on the beginning or on the end of package
392 if( ((*fClusterNIndexes)[0])==index)
399 if( ((*fClusterNIndexes)[fNclustersN-1])==index)
401 DelNCluster(fNclustersN-1);
406 for (i=1;i<fNclustersN-1;i++)
408 if( ((*fClusterNIndexes)[i])==index)
416 cout<<"AliITSpackageSSD - DelNClusterOI: index "<<index<<" not found\n";
420 /*******************************************************/
423 void AliITSpackageSSD::DelClusterOI(Int_t index, Bool_t side)
425 if (side == fgkSIDEP)
427 DelPClusterOI(index);
431 DelNClusterOI(index);
437 /**********************************************/
440 void AliITSpackageSSD::GetAllCombinations(Int_t**array,Int_t &num,Int_t sizet)
443 Int_t *takenNcl = new Int_t[fNclustersN];
447 if (debug) PrintClusters();
449 for (Int_t i=0;i<fNclustersP;i++)
453 //see comment on the beginning of MakeCombin
454 if (debug) cout<<"GetAllCombinations entered";
455 MakeCombin (array,num,0,takenNcl,sizet);
459 /**********************************************/
462 void AliITSpackageSSD::MakeCombin
463 (Int_t**arr,Int_t& nu, Int_t np, Int_t *occup, Int_t sizet)
467 //ATTENTION: anybody watching this function
468 //AliITSclusterSSD::GetCrossNo() returns index of cluster in main array belonging to AliITSmodulesSSD
469 //however, we have pointer to that array (TClonesArray)
471 //Get?SideCluster because it takes index from local look_up_table
476 AliITSclusterSSD *cl=GetPSideCluster(np);
478 Int_t NC = cl->GetCrossNo(); //number of crosses for this cluster
479 Int_t indcro; //index of given cluster on side N that
480 // this cluster crosses with
482 if (np == fNclustersP-1) {
484 indcro=cl->GetCross(i);
485 if(IsFree(indcro,np,occup)) {
487 for(j=0;j<fNclustersP;j++)
489 if (nu<sizet) arr[nu][j]=occup[j];
495 if (nu<sizet-1) nu++;
500 indcro=cl->GetCross(i);
501 if(IsFree(indcro,np,occup)) {
503 if (nu<sizet) MakeCombin(arr,nu,(np+1),occup,sizet);
504 //else printf("MakeComb - exceeding array size!\n");
512 /**********************************************/
513 Bool_t AliITSpackageSSD::IsFree(Int_t idx, Int_t nn, Int_t *lis)
516 for (Int_t i=0;i<nn;i++)
518 if (lis[i]==idx) return kFALSE;
523 /**********************************************/
524 void AliITSpackageSSD::PrintClusters()
529 for (i=0;i<fNclustersP;i++)
531 cout<<i<<". IO="<<GetPSideClusterIdx(i)<<" NC="<<GetPSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
532 for (j=0;j<GetPSideCluster(i)->GetCrossNo();j++)
534 cout<<GetPSideCluster(i)->GetCross(j)<<" ";
536 // if (GetPSideCluster(i)->GetSide()) cout<<" P\n";
537 // else cout<<"BAD SIDE ==N\n";
543 for (i=0;i<fNclustersN;i++)
545 cout<<i<<". IO="<<GetNSideClusterIdx(i)<<" NC="<<GetNSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
546 for (j=0;j<GetNSideCluster(i)->GetCrossNo();j++)
548 cout<<GetNSideCluster(i)->GetCross(j)<<" ";
550 // if (GetNSideCluster(i)->GetSide()) cout<<" N\n";
551 // else cout<<"BAD SIDE ==P\n";
558 /**********************************************/
559 void AliITSpackageSSD::ConsumeClusters()
563 for(i=0;i<fNclustersP;i++)
565 GetPSideCluster(i)->Consume();
568 for(i=0;i<fNclustersN;i++)
570 GetNSideCluster(i)->Consume();
575 /**********************************************/
577 Int_t AliITSpackageSSD::GetNextPIdx(Int_t OI)
579 //Returns index of next P cluster OI in package; OI == Original Inedx (in TClonesArray)
580 //if not egsist return -1;
581 for (Int_t i =0; i<fNclustersP-1;i++)
583 if(GetPSideClusterIdx(i) == OI)
584 return GetPSideClusterIdx(i+1);
588 /**********************************************/
589 Int_t AliITSpackageSSD::GetPrvPIdx(Int_t OI)
591 //Returns index of previous P cluster OI in package; OI == Original Inedx (in TClonesArray)
592 //if not egsist return -1;
594 for (Int_t i =1; i<fNclustersP;i++)
596 if(GetPSideClusterIdx(i) == OI)
597 return GetPSideClusterIdx(i-1);
601 /**********************************************/
602 Int_t AliITSpackageSSD::GetNextNIdx(Int_t OI)
604 //Returns index of next N cluster OI in package; OI == Original Inedx (in TClonesArray)
605 //if not egsist return -1;
606 for (Int_t i =0; i<fNclustersN-1;i++)
608 if(GetNSideClusterIdx(i) == OI)
609 return GetNSideClusterIdx(i+1);
614 /**********************************************/
615 Int_t AliITSpackageSSD::GetPrvNIdx(Int_t OI)
617 //Returns index of previous N cluster OI in package; OI == Original Inedx (in TClonesArray)
618 //if not egsist return -1;
620 for (Int_t i =1; i<fNclustersN;i++)
622 if(GetNSideClusterIdx(i) == OI)
623 return GetNSideClusterIdx(i-1);
629 void AliITSpackageSSD::SplitPackage(Int_t pi, Int_t ni, AliITSpackageSSD* pkg)
631 // split package of clusters
634 for (i=0;i<fNclustersN;i++)
636 if((*fClusterNIndexes)[i]==ni)
643 for (i=0;i<fNclustersP;i++)
645 if((*fClusterPIndexes)[i]==pi)
652 cout<<" p = "<<p<<" n = "<<n;
654 if ((p==-1)||(n==-1)) return;
656 for (i=p;i<fNclustersP;i++)
658 pkg->AddPSideCluster(GetPSideClusterIdx(i));
662 for (i=n;i<fNclustersN;i++)
664 pkg->AddNSideCluster(GetNSideClusterIdx(i));
668 cout<<" After split: fNclustersP = "<< fNclustersP<< "fNclustersN = "<< fNclustersN<<"\n";