]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSTableSSD.cxx
Correction for
[u/mrichter/AliRoot.git] / ITS / AliITSTableSSD.cxx
CommitLineData
d895ac37 1/**************************************************************************
2 * Copyright(c) 2002-2003, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
4ae5bbc4 16#include <Riostream.h>
d895ac37 17#include "AliITSTableSSD.h"
18
925e6570 19ClassImp(AliITSTableSSD)
d895ac37 20////////////////////////////////////////////////////////////////////////
7537d03c 21// Version: 0 //
22// Origin: Massimo Masera //
23// March 2002 //
24// //
d895ac37 25// AliITSTableSSD is used by AliITSsimulationSSD class to fill the AliITSpList
26// object starting from the map with energy depositions
7537d03c 27////////////////////////////////////////////////////////////////////////
d895ac37 28//----------------------------------------------------------------------
7537d03c 29AliITSTableSSD::AliITSTableSSD() : TObject(),
30fDim(0),
31fArray(0){
d895ac37 32 // Default Constructor
d895ac37 33 for(Int_t i=0;i<2;i++){
34 fCurrUse[i]=0;
35 fCurrFil[i]=0;
36 }
37}
38//----------------------------------------------------------------------
7537d03c 39AliITSTableSSD::AliITSTableSSD(const AliITSTableSSD & source):TObject(source),
40fDim(source.fDim),
41fArray(source.fArray){
d895ac37 42 // Copy constructor
25393432 43
44 if(this == &source) return;
25393432 45 fArray = new Int_t [fDim];
46 fCurrUse[0]=(source.fCurrUse)[0];
47 fCurrUse[1]=(source.fCurrUse)[1];
48 fCurrFil[0]=(source.fCurrFil)[0];
49 fCurrFil[1]=(source.fCurrFil)[1];
50 for(Int_t i=0;i<fDim;i++)fArray[i]=(source.fArray)[i];
51}
52//----------------------------------------------------------------------
53AliITSTableSSD& AliITSTableSSD::operator=(const AliITSTableSSD & source){
54 // = opporator constructor
55
56 if(this == &source) return *this;
57 fDim=source.fDim;
58 fArray = new Int_t [fDim];
59 fCurrUse[0]=(source.fCurrUse)[0];
60 fCurrUse[1]=(source.fCurrUse)[1];
61 fCurrFil[0]=(source.fCurrFil)[0];
62 fCurrFil[1]=(source.fCurrFil)[1];
63 for(Int_t i=0;i<fDim;i++)fArray[i]=(source.fArray)[i];
64 return *this;
d895ac37 65}
66//----------------------------------------------------------------------
7537d03c 67AliITSTableSSD::AliITSTableSSD(Int_t noelem) : TObject(),
68fDim(0),
69fArray(0){
d895ac37 70 // Standard constructor
71 fDim=noelem*2;
72 fArray = new Int_t [fDim];
73 Clear();
74}
75//----------------------------------------------------------------------
76AliITSTableSSD::~AliITSTableSSD(){
77 // Destructor
78 delete [] fArray;
79 fArray=0;
80}
81//----------------------------------------------------------------------
82void AliITSTableSSD::Add(Int_t side,Int_t strip){
83 // Add an element to the table
84 if(strip>=fDim/2){
85 cerr<<" Error in AliITSTableSSD::Add. "<<strip<<" is out of range\n";
86 return;
87 }
88 if((side!=0) && (side!=1)){
89 cerr<<" Error in AliITSTableSSD::Add. side="<<side<<endl;
90 cerr<<" side must be 0 or 1\n";
91 return;
92 }
93 if(fCurrFil[side]>(fDim/2-1)){
94 cerr<<" Error in AliITSTableSSD::Add. Trying to fill an element out of range\n";
95 cerr<<" Element="<<fCurrFil[side]<<" while max limit is "<<(fDim/2-1)<<endl;
96 fCurrFil[side]++;
97 return;
98 }
99 // P side = 0 and N side =1
100 Int_t index=(fDim/2)*side+fCurrFil[side];
101 Int_t * ptr= &fArray[(fDim/2)*side];
102 if(SearchValue(ptr,strip,fCurrFil[side])>=0)return;
103 fArray[index]=strip;
104 fCurrFil[side]++;
105}
106//----------------------------------------------------------------------
107void AliITSTableSSD::Clear(){
7537d03c 108 //clear arrays
d895ac37 109 fCurrUse[0]= 0;
110 fCurrUse[1] = 0;
111 fCurrFil[0]= 0;
112 fCurrFil[1] = 0;
113 for(Int_t i=0;i<fDim;i++)fArray[i]=-1;
114}
115//----------------------------------------------------------------------
116void AliITSTableSSD::DumpTable(){
117 // Dumps the contents of the table
118 cout<<"==============================================================\n";
119 cout<<" AliITSTableSSD::DumpTable \n";
120 cout<<" Dimension of the table "<<fDim<<" ("<<fDim/2<<" per side)\n";
121 cout<<" Current element to be filled for P side "<<fCurrFil[0]<<endl;
122 cout<<" Current element to be filled for N side "<<fCurrFil[1]<<endl;
123 cout<<" Current element in use for P side "<<fCurrUse[0]<<endl;
124 cout<<" Current element in use for N side "<<fCurrUse[1]<<endl;
125 cout<<"\n Elements for P side: \n";
126 for(Int_t i=0; i<fCurrFil[0];i++){
127 printf("%6d ",fArray[i]);
128 if(i%6==0 && i>0)printf("\n");
129 }
130 printf("\n");
131 cout<<"\n Elements for N side: \n";
132 for(Int_t i=0; i<fCurrFil[1];i++){
133 printf("%6d ",fArray[fDim/2+i]);
134 if(i%6==0 && i>0)printf("\n");
135 }
136 printf("\n");
137}
138
139//----------------------------------------------------------------------
140Int_t AliITSTableSSD::Use(Int_t side){
141 // uses the current element. This means that the current element is returned
142 // and its content is replaced by -1. Hence each element can be used only
143 // once.
144 Int_t elem=-1;
145 if((side!=0) && (side!=1)){
146 cerr<<" Error in AliITSTableSSD::Use. side="<<side<<endl;
147 cerr<<" side must be 0 or 1\n";
148 return elem;
149 }
150 if(fCurrUse[side]>(fDim/2-1)){
151 cerr<<" Error in AliITSTableSSD::Use. Trying to use an element out of range\n";
152 cerr<<" Element="<<fCurrUse[side]<<" while max limit is "<<(fDim/2-1)<<endl;
153 fCurrUse[side]++;
154 return elem;
155 }
156 Int_t index=(fDim/2)*side+fCurrUse[side];
157 elem=fArray[index];
158 fArray[index]=-1;
159 fCurrUse[side]++;
160 return elem;
161}