]>
Commit | Line | Data |
---|---|---|
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 | ||
16 | #include <iostream.h> | |
17 | #include "AliITSTableSSD.h" | |
18 | ||
19 | ClassImp(AliITSTableSSD); | |
20 | //////////////////////////////////////////////////////////////////////// | |
21 | // Version: 0 | |
22 | // Origin: Massimo Masera | |
23 | // March 2002 | |
24 | // | |
25 | // AliITSTableSSD is used by AliITSsimulationSSD class to fill the AliITSpList | |
26 | // object starting from the map with energy depositions | |
27 | ||
28 | //---------------------------------------------------------------------- | |
29 | AliITSTableSSD::AliITSTableSSD(){ | |
30 | // Default Constructor | |
31 | fDim=0; | |
32 | fArray=0; | |
33 | for(Int_t i=0;i<2;i++){ | |
34 | fCurrUse[i]=0; | |
35 | fCurrFil[i]=0; | |
36 | } | |
37 | } | |
38 | //---------------------------------------------------------------------- | |
39 | AliITSTableSSD::AliITSTableSSD(const AliITSTableSSD & source){ | |
40 | // Copy constructor | |
41 | fDim=source.fDim; | |
42 | fArray = new Int_t [fDim]; | |
43 | fCurrUse[0]=(source.fCurrUse)[0]; | |
44 | fCurrUse[1]=(source.fCurrUse)[1]; | |
45 | fCurrFil[0]=(source.fCurrFil)[0]; | |
46 | fCurrFil[1]=(source.fCurrFil)[1]; | |
47 | for(Int_t i=0;i<fDim;i++)fArray[i]=(source.fArray)[i]; | |
48 | } | |
49 | //---------------------------------------------------------------------- | |
50 | AliITSTableSSD::AliITSTableSSD(Int_t noelem){ | |
51 | // Standard constructor | |
52 | fDim=noelem*2; | |
53 | fArray = new Int_t [fDim]; | |
54 | Clear(); | |
55 | } | |
56 | //---------------------------------------------------------------------- | |
57 | AliITSTableSSD::~AliITSTableSSD(){ | |
58 | // Destructor | |
59 | delete [] fArray; | |
60 | fArray=0; | |
61 | } | |
62 | //---------------------------------------------------------------------- | |
63 | void AliITSTableSSD::Add(Int_t side,Int_t strip){ | |
64 | // Add an element to the table | |
65 | if(strip>=fDim/2){ | |
66 | cerr<<" Error in AliITSTableSSD::Add. "<<strip<<" is out of range\n"; | |
67 | return; | |
68 | } | |
69 | if((side!=0) && (side!=1)){ | |
70 | cerr<<" Error in AliITSTableSSD::Add. side="<<side<<endl; | |
71 | cerr<<" side must be 0 or 1\n"; | |
72 | return; | |
73 | } | |
74 | if(fCurrFil[side]>(fDim/2-1)){ | |
75 | cerr<<" Error in AliITSTableSSD::Add. Trying to fill an element out of range\n"; | |
76 | cerr<<" Element="<<fCurrFil[side]<<" while max limit is "<<(fDim/2-1)<<endl; | |
77 | fCurrFil[side]++; | |
78 | return; | |
79 | } | |
80 | // P side = 0 and N side =1 | |
81 | Int_t index=(fDim/2)*side+fCurrFil[side]; | |
82 | Int_t * ptr= &fArray[(fDim/2)*side]; | |
83 | if(SearchValue(ptr,strip,fCurrFil[side])>=0)return; | |
84 | fArray[index]=strip; | |
85 | fCurrFil[side]++; | |
86 | } | |
87 | //---------------------------------------------------------------------- | |
88 | void AliITSTableSSD::Clear(){ | |
89 | fCurrUse[0]= 0; | |
90 | fCurrUse[1] = 0; | |
91 | fCurrFil[0]= 0; | |
92 | fCurrFil[1] = 0; | |
93 | for(Int_t i=0;i<fDim;i++)fArray[i]=-1; | |
94 | } | |
95 | //---------------------------------------------------------------------- | |
96 | void AliITSTableSSD::DumpTable(){ | |
97 | // Dumps the contents of the table | |
98 | cout<<"==============================================================\n"; | |
99 | cout<<" AliITSTableSSD::DumpTable \n"; | |
100 | cout<<" Dimension of the table "<<fDim<<" ("<<fDim/2<<" per side)\n"; | |
101 | cout<<" Current element to be filled for P side "<<fCurrFil[0]<<endl; | |
102 | cout<<" Current element to be filled for N side "<<fCurrFil[1]<<endl; | |
103 | cout<<" Current element in use for P side "<<fCurrUse[0]<<endl; | |
104 | cout<<" Current element in use for N side "<<fCurrUse[1]<<endl; | |
105 | cout<<"\n Elements for P side: \n"; | |
106 | for(Int_t i=0; i<fCurrFil[0];i++){ | |
107 | printf("%6d ",fArray[i]); | |
108 | if(i%6==0 && i>0)printf("\n"); | |
109 | } | |
110 | printf("\n"); | |
111 | cout<<"\n Elements for N side: \n"; | |
112 | for(Int_t i=0; i<fCurrFil[1];i++){ | |
113 | printf("%6d ",fArray[fDim/2+i]); | |
114 | if(i%6==0 && i>0)printf("\n"); | |
115 | } | |
116 | printf("\n"); | |
117 | } | |
118 | ||
119 | //---------------------------------------------------------------------- | |
120 | Int_t AliITSTableSSD::Use(Int_t side){ | |
121 | // uses the current element. This means that the current element is returned | |
122 | // and its content is replaced by -1. Hence each element can be used only | |
123 | // once. | |
124 | Int_t elem=-1; | |
125 | if((side!=0) && (side!=1)){ | |
126 | cerr<<" Error in AliITSTableSSD::Use. side="<<side<<endl; | |
127 | cerr<<" side must be 0 or 1\n"; | |
128 | return elem; | |
129 | } | |
130 | if(fCurrUse[side]>(fDim/2-1)){ | |
131 | cerr<<" Error in AliITSTableSSD::Use. Trying to use an element out of range\n"; | |
132 | cerr<<" Element="<<fCurrUse[side]<<" while max limit is "<<(fDim/2-1)<<endl; | |
133 | fCurrUse[side]++; | |
134 | return elem; | |
135 | } | |
136 | Int_t index=(fDim/2)*side+fCurrUse[side]; | |
137 | elem=fArray[index]; | |
138 | fArray[index]=-1; | |
139 | fCurrUse[side]++; | |
140 | return elem; | |
141 | } |