]>
Commit | Line | Data |
---|---|---|
b65e5048 | 1 | /************************************************************************* |
2 | * Copyright(c) 1998-2008, 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 | /* $Id: AliTRDarrayDictionary.cxx 25392 2008-04-23 19:40:29Z cblume $ */ | |
17 | ||
18 | ///////////////////////////////////////////////////////// | |
19 | // // | |
20 | // Container Class for Dictionary Info // | |
21 | // // | |
22 | // Author: // | |
23 | // Hermes Leon Vargas (hleon@ikf.uni-frankfurt.de) // | |
24 | // // | |
25 | ///////////////////////////////////////////////////////// | |
26 | ||
27 | #include "AliTRDarrayDictionary.h" | |
705d9e7b | 28 | #include "TArray.h" |
b65e5048 | 29 | |
30 | ClassImp(AliTRDarrayDictionary) | |
31 | ||
32 | //________________________________________________________________________________ | |
33 | AliTRDarrayDictionary::AliTRDarrayDictionary() | |
34 | :TObject() | |
35 | ,fNdet(0) | |
36 | ,fNrow(0) | |
37 | ,fNcol(0) | |
38 | ,fNtime(0) | |
39 | ,fNDdim(0) | |
40 | ,fDictionary(0) | |
41 | { | |
42 | // | |
43 | // AliTRDarrayDictionary default contructor | |
44 | // | |
45 | ||
46 | } | |
47 | ||
48 | //________________________________________________________________________________ | |
49 | AliTRDarrayDictionary::AliTRDarrayDictionary(Int_t nrow, Int_t ncol, Int_t ntime) | |
50 | :TObject() | |
51 | ,fNdet(0) | |
52 | ,fNrow(0) | |
53 | ,fNcol(0) | |
54 | ,fNtime(0) | |
55 | ,fNDdim(0) | |
56 | ,fDictionary(0) | |
57 | ||
58 | { | |
59 | // | |
60 | // AliTRDarrayDictionary contructor | |
61 | // | |
62 | ||
63 | Allocate(nrow,ncol,ntime); | |
64 | ||
65 | } | |
66 | ||
67 | //________________________________________________________________________________ | |
68 | AliTRDarrayDictionary::AliTRDarrayDictionary(const AliTRDarrayDictionary &a) | |
69 | :TObject() | |
70 | ,fNdet(a.fNdet) | |
71 | ,fNrow(a.fNrow) | |
72 | ,fNcol(a.fNcol) | |
73 | ,fNtime(a.fNtime) | |
74 | ,fNDdim(a.fNDdim) | |
75 | ,fDictionary(0) | |
76 | { | |
77 | // | |
78 | // AliTRDarrayDictionary copy constructor | |
79 | // | |
80 | ||
81 | fDictionary = new Int_t[fNDdim]; | |
82 | for(Int_t i=0; i<fNDdim; i++) | |
83 | { | |
84 | fDictionary[i]=a.fDictionary[i]; | |
85 | } | |
86 | ||
87 | } | |
88 | ||
89 | //________________________________________________________________________________ | |
90 | AliTRDarrayDictionary::~AliTRDarrayDictionary() | |
91 | { | |
92 | // | |
93 | // AliTRDarrayDictionary destructor | |
94 | // | |
95 | ||
96 | if(fDictionary) | |
97 | { | |
98 | delete [] fDictionary; | |
99 | fDictionary=0; | |
100 | } | |
101 | ||
102 | } | |
103 | ||
104 | //________________________________________________________________________________ | |
105 | AliTRDarrayDictionary &AliTRDarrayDictionary::operator=(const AliTRDarrayDictionary &a) | |
106 | { | |
107 | // | |
108 | // Assignment operator | |
109 | // | |
110 | ||
111 | if(this==&a) | |
112 | { | |
113 | return *this; | |
114 | } | |
115 | ||
116 | if(fDictionary) | |
117 | { | |
118 | delete [] fDictionary; | |
119 | } | |
120 | fNdet=a.fNdet; | |
121 | fNDdim=a.fNDdim; | |
122 | fNrow=a.fNrow; | |
123 | fNcol=a.fNcol; | |
124 | fNtime=a.fNtime; | |
125 | fDictionary = new Int_t[fNDdim]; | |
126 | for(Int_t i=0; i<fNDdim; i++) | |
127 | { | |
128 | fDictionary[i]=a.fDictionary[i]; | |
129 | } | |
130 | return *this; | |
131 | ||
132 | } | |
133 | ||
134 | //________________________________________________________________________________ | |
135 | void AliTRDarrayDictionary::Allocate(Int_t nrow, Int_t ncol, Int_t ntime) | |
136 | { | |
137 | // | |
138 | // Allocates memory for the dictionary array with dimensions | |
139 | // Row*Col*Time | |
140 | // Object initialized to -1 | |
141 | // | |
142 | ||
143 | fNrow=nrow; | |
144 | fNcol=ncol; | |
145 | fNtime=ntime; | |
146 | fNDdim=nrow*ncol*ntime; | |
147 | if(fDictionary) | |
148 | { | |
149 | delete [] fDictionary; | |
150 | fDictionary=0; | |
151 | } | |
152 | fDictionary = new Int_t[fNDdim]; | |
153 | for(Int_t i=0; i<fNDdim; i++) | |
154 | { | |
155 | fDictionary[i] = -1; | |
156 | } | |
157 | ||
158 | } | |
159 | ||
160 | //________________________________________________________________________________ | |
161 | void AliTRDarrayDictionary::Compress() | |
162 | { | |
163 | // | |
164 | // Compress the array | |
165 | // | |
166 | ||
167 | ||
168 | // AliDebug(1,"Compressing"); | |
169 | Int_t counter=0; | |
170 | Int_t newDim=0; | |
171 | Int_t j; | |
172 | Int_t r=0; | |
173 | Int_t *longArr; | |
174 | longArr = new Int_t[fNDdim]; | |
175 | Int_t k=0; | |
176 | for(Int_t i=0; i<fNDdim;i++) | |
177 | { | |
178 | longArr[i]=0; | |
179 | } | |
180 | for(Int_t i=0;i<fNDdim; i++) | |
181 | { | |
182 | j=0; | |
183 | if(fDictionary[i]==-1) | |
184 | { | |
185 | for(k=i;k<fNDdim;k++) | |
186 | { | |
187 | if(fDictionary[k]==-1) | |
188 | { | |
189 | j=j+1; | |
190 | longArr[r]=j; | |
191 | } | |
192 | else | |
193 | { | |
194 | break; | |
195 | } | |
196 | } | |
197 | r=r+1; | |
198 | } | |
199 | i=i+j; | |
200 | } | |
201 | //Calculate the size of the compressed array | |
202 | for(Int_t i=0; i<fNDdim;i++) | |
203 | { | |
204 | if(longArr[i]!=0) | |
205 | { | |
206 | counter=counter+longArr[i]-1; | |
207 | } | |
208 | } | |
209 | newDim=fNDdim-counter; //Size of the compressed array | |
210 | //Fill the buffer of the compressed array | |
211 | Int_t* buffer; | |
212 | buffer = new Int_t[newDim]; | |
213 | Int_t counterTwo=0; | |
214 | Int_t g=0; | |
215 | for(Int_t i=0; i<newDim; i++) | |
216 | { | |
217 | if(counterTwo<fNDdim) | |
218 | { | |
219 | if(fDictionary[counterTwo]!=-1) | |
220 | { | |
221 | buffer[i]=fDictionary[counterTwo]; | |
222 | } | |
223 | if(fDictionary[counterTwo]==-1) | |
224 | { | |
225 | buffer[i]=-(longArr[g]); | |
226 | counterTwo=counterTwo+longArr[g]-1; | |
227 | g++; | |
228 | } | |
229 | counterTwo++; | |
230 | } | |
231 | } | |
232 | ||
233 | //Copy the buffer | |
234 | if(fDictionary) | |
235 | { | |
236 | delete [] fDictionary; | |
237 | fDictionary=0; | |
238 | } | |
239 | fDictionary = new Int_t[newDim]; | |
240 | fNDdim = newDim; | |
241 | for(Int_t i=0; i<newDim; i++) | |
242 | { | |
243 | fDictionary[i] = buffer[i]; | |
244 | } | |
245 | if(buffer) | |
246 | { | |
247 | delete [] buffer; | |
248 | buffer=0; | |
249 | } | |
250 | if(longArr) | |
251 | { | |
252 | delete [] longArr; | |
253 | longArr=0; | |
254 | } | |
255 | ||
256 | } | |
257 | ||
258 | //________________________________________________________________________________ | |
259 | void AliTRDarrayDictionary::Expand() | |
260 | { | |
261 | // | |
262 | // Expand the array | |
263 | // | |
264 | ||
265 | Int_t *longArr; | |
266 | longArr = new Int_t[fNDdim]; | |
267 | Int_t dimexp=0; | |
268 | for(Int_t i=0; i<fNDdim;i++) | |
269 | { | |
270 | longArr[i]=0; | |
271 | } | |
272 | Int_t r2=0; | |
273 | for(Int_t i=0; i<fNDdim;i++) | |
274 | { | |
275 | if((fDictionary[i]<0)&&(fDictionary[i]!=-1)) | |
276 | { | |
277 | longArr[r2]=-fDictionary[i]; | |
278 | r2++; | |
279 | } | |
280 | } | |
281 | ||
282 | //Calculate new dimensions | |
283 | for(Int_t i=0; i<fNDdim;i++) | |
284 | { | |
285 | if(longArr[i]!=0) | |
286 | { | |
287 | dimexp=dimexp+longArr[i]-1; | |
288 | } | |
289 | } | |
290 | dimexp=dimexp+fNDdim; | |
291 | ||
292 | //Write in the buffer the new array | |
293 | Int_t* bufferE; | |
294 | bufferE = new Int_t[dimexp]; | |
295 | Int_t contaexp =0; | |
296 | Int_t h=0; | |
297 | for(Int_t i=0; i<dimexp; i++) | |
298 | { | |
299 | if(fDictionary[contaexp]>=-1) | |
300 | { | |
301 | bufferE[i]=fDictionary[contaexp]; | |
302 | } | |
303 | if(fDictionary[contaexp]<-1) | |
304 | { | |
305 | for(Int_t j=0; j<longArr[h];j++) | |
306 | { | |
307 | bufferE[i+j]=-1; | |
308 | } | |
309 | i=i+longArr[h]-1; | |
310 | h++; | |
311 | } | |
312 | contaexp++; | |
313 | } | |
314 | ||
315 | //Copy the buffer | |
316 | if(fDictionary) | |
317 | { | |
318 | delete [] fDictionary; | |
319 | fDictionary=0; | |
320 | } | |
321 | ||
322 | fDictionary = new Int_t[dimexp]; | |
323 | fNDdim = dimexp; | |
324 | for(Int_t i=0; i<dimexp; i++) | |
325 | { | |
326 | fDictionary[i] = bufferE[i]; | |
327 | } | |
328 | if(bufferE) delete [] bufferE; | |
329 | if(longArr) delete [] longArr; | |
330 | ||
331 | } | |
705d9e7b | 332 | //________________________________________________________________________________ |
333 | void AliTRDarrayDictionary::Reset() | |
334 | { | |
335 | // | |
336 | // Reset the array, the old contents are deleted | |
337 | // and the data array elements are set to zero. | |
338 | // | |
339 | ||
340 | memset(fDictionary,0,sizeof(Int_t)*fNDdim); | |
341 | ||
342 | } |