]>
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 | ||
a9151110 | 27 | #include <TArray.h> |
28 | ||
b65e5048 | 29 | #include "AliTRDarrayDictionary.h" |
acf20e8f | 30 | #include "AliTRDfeeParam.h" |
49c65af0 | 31 | #include "AliLog.h" |
b65e5048 | 32 | |
33 | ClassImp(AliTRDarrayDictionary) | |
34 | ||
f41a4d6a | 35 | Short_t *AliTRDarrayDictionary::fgLutPadNumbering = 0x0; |
acf20e8f | 36 | |
b65e5048 | 37 | //________________________________________________________________________________ |
38 | AliTRDarrayDictionary::AliTRDarrayDictionary() | |
39 | :TObject() | |
40 | ,fNdet(0) | |
41 | ,fNrow(0) | |
42 | ,fNcol(0) | |
acf20e8f | 43 | ,fNumberOfChannels(0) |
b65e5048 | 44 | ,fNtime(0) |
45 | ,fNDdim(0) | |
46 | ,fDictionary(0) | |
641f6f80 | 47 | ,fFlag(kFALSE) |
b65e5048 | 48 | { |
49 | // | |
50 | // AliTRDarrayDictionary default contructor | |
51 | // | |
52 | ||
acf20e8f | 53 | CreateLut(); |
54 | ||
b65e5048 | 55 | } |
56 | ||
57 | //________________________________________________________________________________ | |
58 | AliTRDarrayDictionary::AliTRDarrayDictionary(Int_t nrow, Int_t ncol, Int_t ntime) | |
59 | :TObject() | |
60 | ,fNdet(0) | |
61 | ,fNrow(0) | |
62 | ,fNcol(0) | |
acf20e8f | 63 | ,fNumberOfChannels(0) |
b65e5048 | 64 | ,fNtime(0) |
65 | ,fNDdim(0) | |
66 | ,fDictionary(0) | |
641f6f80 | 67 | ,fFlag(kFALSE) |
b65e5048 | 68 | { |
69 | // | |
70 | // AliTRDarrayDictionary contructor | |
71 | // | |
72 | ||
acf20e8f | 73 | CreateLut(); |
b65e5048 | 74 | Allocate(nrow,ncol,ntime); |
75 | ||
76 | } | |
77 | ||
78 | //________________________________________________________________________________ | |
79 | AliTRDarrayDictionary::AliTRDarrayDictionary(const AliTRDarrayDictionary &a) | |
80 | :TObject() | |
81 | ,fNdet(a.fNdet) | |
82 | ,fNrow(a.fNrow) | |
83 | ,fNcol(a.fNcol) | |
acf20e8f | 84 | ,fNumberOfChannels(a.fNumberOfChannels) |
b65e5048 | 85 | ,fNtime(a.fNtime) |
86 | ,fNDdim(a.fNDdim) | |
87 | ,fDictionary(0) | |
d1ec112d | 88 | ,fFlag(a.fFlag) |
b65e5048 | 89 | { |
90 | // | |
91 | // AliTRDarrayDictionary copy constructor | |
92 | // | |
93 | ||
94 | fDictionary = new Int_t[fNDdim]; | |
95 | for(Int_t i=0; i<fNDdim; i++) | |
96 | { | |
97 | fDictionary[i]=a.fDictionary[i]; | |
98 | } | |
99 | ||
100 | } | |
101 | ||
102 | //________________________________________________________________________________ | |
103 | AliTRDarrayDictionary::~AliTRDarrayDictionary() | |
104 | { | |
105 | // | |
106 | // AliTRDarrayDictionary destructor | |
107 | // | |
108 | ||
04e58504 | 109 | delete [] fDictionary; |
110 | fDictionary=0; | |
b65e5048 | 111 | |
112 | } | |
113 | ||
114 | //________________________________________________________________________________ | |
115 | AliTRDarrayDictionary &AliTRDarrayDictionary::operator=(const AliTRDarrayDictionary &a) | |
116 | { | |
117 | // | |
118 | // Assignment operator | |
119 | // | |
120 | ||
121 | if(this==&a) | |
122 | { | |
123 | return *this; | |
124 | } | |
125 | ||
126 | if(fDictionary) | |
127 | { | |
128 | delete [] fDictionary; | |
129 | } | |
130 | fNdet=a.fNdet; | |
131 | fNDdim=a.fNDdim; | |
132 | fNrow=a.fNrow; | |
133 | fNcol=a.fNcol; | |
acf20e8f | 134 | fNumberOfChannels = a.fNumberOfChannels; |
b65e5048 | 135 | fNtime=a.fNtime; |
136 | fDictionary = new Int_t[fNDdim]; | |
137 | for(Int_t i=0; i<fNDdim; i++) | |
138 | { | |
139 | fDictionary[i]=a.fDictionary[i]; | |
140 | } | |
d1ec112d | 141 | fFlag=a.fFlag; |
b65e5048 | 142 | return *this; |
143 | ||
144 | } | |
145 | ||
146 | //________________________________________________________________________________ | |
147 | void AliTRDarrayDictionary::Allocate(Int_t nrow, Int_t ncol, Int_t ntime) | |
148 | { | |
149 | // | |
150 | // Allocates memory for the dictionary array with dimensions | |
acf20e8f | 151 | // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time |
152 | // To be consistent with AliTRDarrayADC | |
b65e5048 | 153 | // Object initialized to -1 |
154 | // | |
155 | ||
156 | fNrow=nrow; | |
157 | fNcol=ncol; | |
158 | fNtime=ntime; | |
acf20e8f | 159 | Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm(); |
160 | Int_t padspermcm = AliTRDfeeParam::GetNcolMcm(); | |
161 | Int_t numberofmcms = fNcol/padspermcm; | |
162 | fNumberOfChannels = numberofmcms*adcchannelspermcm; | |
163 | fNDdim=nrow*fNumberOfChannels*ntime; | |
b65e5048 | 164 | if(fDictionary) |
165 | { | |
166 | delete [] fDictionary; | |
167 | fDictionary=0; | |
168 | } | |
169 | fDictionary = new Int_t[fNDdim]; | |
888fa330 | 170 | memset(fDictionary,-1,sizeof(Int_t)*fNDdim); |
b65e5048 | 171 | |
172 | } | |
173 | ||
174 | //________________________________________________________________________________ | |
175 | void AliTRDarrayDictionary::Compress() | |
176 | { | |
177 | // | |
178 | // Compress the array | |
179 | // | |
180 | ||
181 | ||
182 | // AliDebug(1,"Compressing"); | |
183 | Int_t counter=0; | |
184 | Int_t newDim=0; | |
185 | Int_t j; | |
186 | Int_t r=0; | |
b65e5048 | 187 | Int_t k=0; |
fac7fac0 | 188 | |
024c0422 | 189 | Int_t *longArr = new Int_t[fNDdim]; |
b65e5048 | 190 | |
b65e5048 | 191 | if(longArr) |
192 | { | |
024c0422 | 193 | |
194 | memset(longArr,0,sizeof(Int_t)*fNDdim); | |
195 | ||
196 | for(Int_t i=0;i<fNDdim; i++) | |
197 | { | |
198 | j=0; | |
199 | if(fDictionary[i]==-1) | |
200 | { | |
201 | for(k=i;k<fNDdim;k++) | |
202 | { | |
203 | if(fDictionary[k]==-1) | |
204 | { | |
205 | j=j+1; | |
206 | longArr[r]=j; | |
207 | } | |
208 | else | |
209 | { | |
210 | break; | |
211 | } | |
212 | } | |
213 | r=r+1; | |
214 | } | |
215 | i=i+j; | |
216 | } | |
217 | ||
218 | //Calculate the size of the compressed array | |
219 | for(Int_t i=0; i<fNDdim;i++) | |
220 | { | |
221 | if(longArr[i]!=0) | |
222 | { | |
223 | counter=counter+longArr[i]-1; | |
224 | } | |
225 | } | |
226 | newDim=fNDdim-counter; //Size of the compressed array | |
227 | ||
228 | //Fill the buffer of the compressed array | |
229 | Int_t* buffer = new Int_t[newDim]; | |
230 | Int_t counterTwo=0; | |
231 | Int_t g=0; | |
232 | if(buffer) | |
233 | { | |
024c0422 | 234 | for(Int_t i=0; i<newDim; i++) |
235 | { | |
236 | if(counterTwo<fNDdim) | |
237 | { | |
238 | if(fDictionary[counterTwo]!=-1) | |
239 | { | |
240 | buffer[i]=fDictionary[counterTwo]; | |
241 | } | |
242 | if(fDictionary[counterTwo]==-1) | |
243 | { | |
244 | buffer[i]=-(longArr[g]); | |
245 | counterTwo=counterTwo+longArr[g]-1; | |
246 | g++; | |
247 | } | |
248 | counterTwo++; | |
249 | } | |
250 | } | |
251 | ||
252 | //Copy the buffer | |
253 | if(fDictionary) | |
254 | { | |
255 | delete [] fDictionary; | |
256 | fDictionary=0; | |
257 | } | |
888fa330 | 258 | fDictionary = buffer; |
024c0422 | 259 | fNDdim = newDim; |
024c0422 | 260 | } |
261 | ||
b65e5048 | 262 | delete [] longArr; |
263 | longArr=0; | |
264 | } | |
a32555a0 | 265 | fFlag=kFALSE; // This way it can be expanded afterwards |
b65e5048 | 266 | } |
267 | ||
268 | //________________________________________________________________________________ | |
269 | void AliTRDarrayDictionary::Expand() | |
270 | { | |
271 | // | |
272 | // Expand the array | |
273 | // | |
274 | ||
49c65af0 | 275 | if(fNDdim==0) |
276 | { | |
277 | AliError("Called expand with dimension zero"); | |
278 | return; | |
279 | } | |
280 | ||
281 | ||
b65e5048 | 282 | Int_t dimexp=0; |
49c65af0 | 283 | |
b95b541e | 284 | // if(WasExpandCalled()) |
285 | // return; | |
286 | ||
287 | if(fNDdim==fNrow*fNumberOfChannels*fNtime) | |
641f6f80 | 288 | return; |
d1ec112d | 289 | |
641f6f80 | 290 | if(fDictionary&&fNDdim==1) |
291 | { | |
292 | dimexp = -fDictionary[0]; | |
293 | delete [] fDictionary; | |
294 | fDictionary=0; | |
295 | fDictionary = new Int_t[dimexp]; | |
296 | fNDdim = dimexp; | |
297 | // Re-initialize the array | |
298 | memset(fDictionary,-1,sizeof(Int_t)*dimexp); | |
49c65af0 | 299 | fFlag=kTRUE; // Not expand again |
d1ec112d | 300 | return; |
301 | } | |
302 | ||
641f6f80 | 303 | Int_t *longArr = new Int_t[fNDdim]; |
af63084f | 304 | if(longArr && fDictionary) |
b65e5048 | 305 | { |
af63084f | 306 | //Initialize the array |
641f6f80 | 307 | memset(longArr,0,sizeof(Int_t)*fNDdim); |
af63084f | 308 | |
641f6f80 | 309 | Int_t r2=0; |
af63084f | 310 | for(Int_t i=0; i<fNDdim;i++) |
311 | { | |
312 | if((fDictionary[i]<0)&&(fDictionary[i]!=-1)) | |
b65e5048 | 313 | { |
af63084f | 314 | longArr[r2]=-fDictionary[i]; |
315 | r2++; | |
b65e5048 | 316 | } |
af63084f | 317 | } |
318 | ||
319 | //Calculate new dimensions | |
320 | for(Int_t i=0; i<fNDdim;i++) | |
321 | { | |
322 | if(longArr[i]!=0) | |
888fa330 | 323 | dimexp=dimexp+longArr[i]-1; |
324 | if(longArr[i]==0) | |
325 | break; | |
af63084f | 326 | } |
327 | dimexp=dimexp+fNDdim; | |
328 | ||
329 | //Write in the buffer the new array | |
330 | Int_t contaexp =0; | |
331 | Int_t h=0; | |
332 | Int_t* bufferE = new Int_t[dimexp]; | |
333 | ||
334 | if(bufferE) | |
335 | { | |
b95b541e | 336 | memset(bufferE,-1,sizeof(Int_t)*dimexp); |
af63084f | 337 | for(Int_t i=0; i<dimexp; i++) |
338 | { | |
339 | if(fDictionary[contaexp]>=-1) | |
340 | { | |
341 | bufferE[i]=fDictionary[contaexp]; | |
342 | } | |
343 | if(fDictionary[contaexp]<-1) | |
344 | { | |
af63084f | 345 | i=i+longArr[h]-1; |
346 | h++; | |
347 | } | |
348 | contaexp++; | |
349 | } | |
350 | ||
351 | //Copy the buffer | |
352 | delete [] fDictionary; | |
888fa330 | 353 | fDictionary=bufferE; |
af63084f | 354 | fNDdim = dimexp; |
b65e5048 | 355 | } |
a987273c | 356 | } |
a987273c | 357 | if (longArr) |
358 | { | |
359 | delete [] longArr; | |
b65e5048 | 360 | } |
49c65af0 | 361 | fFlag=kTRUE; // Not expand again |
641f6f80 | 362 | |
b65e5048 | 363 | } |
705d9e7b | 364 | //________________________________________________________________________________ |
365 | void AliTRDarrayDictionary::Reset() | |
366 | { | |
367 | // | |
368 | // Reset the array, the old contents are deleted | |
369 | // and the data array elements are set to zero. | |
370 | // | |
371 | ||
372 | memset(fDictionary,0,sizeof(Int_t)*fNDdim); | |
373 | ||
374 | } | |
acf20e8f | 375 | //________________________________________________________________________________ |
376 | Int_t AliTRDarrayDictionary::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const | |
377 | { | |
378 | // | |
379 | // Get the data using the pad numbering. | |
380 | // To access data using the mcm scheme use instead | |
381 | // the method GetDataByAdcCol | |
382 | // | |
383 | ||
f41a4d6a | 384 | Int_t corrcolumn = fgLutPadNumbering[ncol]; |
acf20e8f | 385 | |
386 | return fDictionary[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime]; | |
387 | ||
388 | } | |
389 | //________________________________________________________________________________ | |
390 | void AliTRDarrayDictionary::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Int_t value) | |
391 | { | |
392 | // | |
393 | // Set the data using the pad numbering. | |
394 | // To write data using the mcm scheme use instead | |
395 | // the method SetDataByAdcCol | |
396 | // | |
397 | ||
f41a4d6a | 398 | Int_t colnumb = fgLutPadNumbering[ncol]; |
acf20e8f | 399 | |
400 | fDictionary[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value; | |
401 | ||
402 | } | |
403 | ||
404 | //________________________________________________________________________________ | |
405 | void AliTRDarrayDictionary::CreateLut() | |
406 | { | |
407 | // | |
408 | // Initializes the Look Up Table to relate | |
409 | // pad numbering and mcm channel numbering | |
410 | // | |
411 | ||
f41a4d6a | 412 | if(fgLutPadNumbering) return; |
acf20e8f | 413 | |
f41a4d6a | 414 | fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()]; |
415 | memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol()); | |
acf20e8f | 416 | |
417 | for(Int_t mcm=0; mcm<8; mcm++) | |
418 | { | |
419 | Int_t lowerlimit=0+mcm*18; | |
420 | Int_t upperlimit=18+mcm*18; | |
421 | Int_t shiftposition = 1+3*mcm; | |
422 | for(Int_t index=lowerlimit;index<upperlimit;index++) | |
423 | { | |
888fa330 | 424 | fgLutPadNumbering[index]= index+shiftposition; |
acf20e8f | 425 | } |
426 | } | |
427 | } |