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