Line data Source code
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 <TArray.h>
28 :
29 : #include "AliTRDarrayDictionary.h"
30 : #include "AliTRDfeeParam.h"
31 : #include "AliLog.h"
32 :
33 48 : ClassImp(AliTRDarrayDictionary)
34 :
35 : Short_t *AliTRDarrayDictionary::fgLutPadNumbering = 0x0;
36 :
37 : //________________________________________________________________________________
38 : AliTRDarrayDictionary::AliTRDarrayDictionary()
39 43744 : :TObject()
40 43744 : ,fNdet(0)
41 43744 : ,fNrow(0)
42 43744 : ,fNcol(0)
43 43744 : ,fNumberOfChannels(0)
44 43744 : ,fNtime(0)
45 43744 : ,fNDdim(0)
46 43744 : ,fDictionary(0)
47 43744 : ,fFlag(kFALSE)
48 218720 : {
49 : //
50 : // AliTRDarrayDictionary default contructor
51 : //
52 :
53 43744 : CreateLut();
54 :
55 87488 : }
56 :
57 : //________________________________________________________________________________
58 : AliTRDarrayDictionary::AliTRDarrayDictionary(Int_t nrow, Int_t ncol, Int_t ntime)
59 0 : :TObject()
60 0 : ,fNdet(0)
61 0 : ,fNrow(0)
62 0 : ,fNcol(0)
63 0 : ,fNumberOfChannels(0)
64 0 : ,fNtime(0)
65 0 : ,fNDdim(0)
66 0 : ,fDictionary(0)
67 0 : ,fFlag(kFALSE)
68 0 : {
69 : //
70 : // AliTRDarrayDictionary contructor
71 : //
72 :
73 0 : CreateLut();
74 0 : Allocate(nrow,ncol,ntime);
75 :
76 0 : }
77 :
78 : //________________________________________________________________________________
79 : AliTRDarrayDictionary::AliTRDarrayDictionary(const AliTRDarrayDictionary &a)
80 0 : :TObject()
81 0 : ,fNdet(a.fNdet)
82 0 : ,fNrow(a.fNrow)
83 0 : ,fNcol(a.fNcol)
84 0 : ,fNumberOfChannels(a.fNumberOfChannels)
85 0 : ,fNtime(a.fNtime)
86 0 : ,fNDdim(a.fNDdim)
87 0 : ,fDictionary(0)
88 0 : ,fFlag(a.fFlag)
89 0 : {
90 : //
91 : // AliTRDarrayDictionary copy constructor
92 : //
93 :
94 0 : fDictionary = new Int_t[fNDdim];
95 0 : for(Int_t i=0; i<fNDdim; i++)
96 : {
97 0 : fDictionary[i]=a.fDictionary[i];
98 : }
99 :
100 0 : }
101 :
102 : //________________________________________________________________________________
103 : AliTRDarrayDictionary::~AliTRDarrayDictionary()
104 262464 : {
105 : //
106 : // AliTRDarrayDictionary destructor
107 : //
108 :
109 47275 : delete [] fDictionary;
110 43744 : fDictionary=0;
111 :
112 131232 : }
113 :
114 : //________________________________________________________________________________
115 : AliTRDarrayDictionary &AliTRDarrayDictionary::operator=(const AliTRDarrayDictionary &a)
116 : {
117 : //
118 : // Assignment operator
119 : //
120 :
121 0 : if(this==&a)
122 : {
123 0 : return *this;
124 : }
125 :
126 0 : if(fDictionary)
127 : {
128 0 : delete [] fDictionary;
129 : }
130 0 : fNdet=a.fNdet;
131 0 : fNDdim=a.fNDdim;
132 0 : fNrow=a.fNrow;
133 0 : fNcol=a.fNcol;
134 0 : fNumberOfChannels = a.fNumberOfChannels;
135 0 : fNtime=a.fNtime;
136 0 : fDictionary = new Int_t[fNDdim];
137 0 : for(Int_t i=0; i<fNDdim; i++)
138 : {
139 0 : fDictionary[i]=a.fDictionary[i];
140 : }
141 0 : fFlag=a.fFlag;
142 0 : return *this;
143 :
144 0 : }
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
151 : // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
152 : // To be consistent with AliTRDarrayADC
153 : // Object initialized to -1
154 : //
155 :
156 2256 : fNrow=nrow;
157 1128 : fNcol=ncol;
158 1128 : fNtime=ntime;
159 1128 : Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm();
160 1128 : Int_t padspermcm = AliTRDfeeParam::GetNcolMcm();
161 1128 : Int_t numberofmcms = fNcol/padspermcm;
162 1128 : fNumberOfChannels = numberofmcms*adcchannelspermcm;
163 1128 : fNDdim=nrow*fNumberOfChannels*ntime;
164 1128 : if(fDictionary)
165 : {
166 0 : delete [] fDictionary;
167 0 : fDictionary=0;
168 0 : }
169 1128 : fDictionary = new Int_t[fNDdim];
170 1128 : memset(fDictionary,-1,sizeof(Int_t)*fNDdim);
171 :
172 1128 : }
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;
187 : Int_t k=0;
188 :
189 2256 : Int_t *longArr = new Int_t[fNDdim];
190 :
191 1128 : if(longArr)
192 : {
193 :
194 1128 : memset(longArr,0,sizeof(Int_t)*fNDdim);
195 :
196 291972 : for(Int_t i=0;i<fNDdim; i++)
197 : {
198 : j=0;
199 144858 : if(fDictionary[i]==-1)
200 : {
201 141246644 : for(k=i;k<fNDdim;k++)
202 : {
203 70622194 : if(fDictionary[k]==-1)
204 : {
205 70617870 : j=j+1;
206 70617870 : longArr[r]=j;
207 : }
208 : else
209 : {
210 : break;
211 : }
212 : }
213 5452 : r=r+1;
214 5452 : }
215 144858 : i=i+j;
216 : }
217 :
218 : //Calculate the size of the compressed array
219 141525456 : for(Int_t i=0; i<fNDdim;i++)
220 : {
221 70761600 : if(longArr[i]!=0)
222 : {
223 5452 : counter=counter+longArr[i]-1;
224 5452 : }
225 : }
226 1128 : newDim=fNDdim-counter; //Size of the compressed array
227 :
228 : //Fill the buffer of the compressed array
229 1128 : Int_t* buffer = new Int_t[newDim];
230 : Int_t counterTwo=0;
231 : Int_t g=0;
232 1128 : if(buffer)
233 : {
234 300620 : for(Int_t i=0; i<newDim; i++)
235 : {
236 149182 : if(counterTwo<fNDdim)
237 : {
238 149182 : if(fDictionary[counterTwo]!=-1)
239 : {
240 143730 : buffer[i]=fDictionary[counterTwo];
241 143730 : }
242 149182 : if(fDictionary[counterTwo]==-1)
243 : {
244 5452 : buffer[i]=-(longArr[g]);
245 5452 : counterTwo=counterTwo+longArr[g]-1;
246 5452 : g++;
247 5452 : }
248 149182 : counterTwo++;
249 149182 : }
250 : }
251 :
252 : //Copy the buffer
253 1128 : if(fDictionary)
254 : {
255 2256 : delete [] fDictionary;
256 1128 : fDictionary=0;
257 1128 : }
258 1128 : fDictionary = buffer;
259 1128 : fNDdim = newDim;
260 1128 : }
261 :
262 2256 : delete [] longArr;
263 : longArr=0;
264 1128 : }
265 1128 : fFlag=kFALSE; // This way it can be expanded afterwards
266 1128 : }
267 :
268 : //________________________________________________________________________________
269 : void AliTRDarrayDictionary::Expand()
270 : {
271 : //
272 : // Expand the array
273 : //
274 :
275 127056 : if(fNDdim==0)
276 : {
277 0 : AliError("Called expand with dimension zero");
278 0 : return;
279 : }
280 :
281 :
282 : Int_t dimexp=0;
283 :
284 : // if(WasExpandCalled())
285 : // return;
286 :
287 63528 : if(fNDdim==fNrow*fNumberOfChannels*fNtime)
288 62400 : return;
289 :
290 2256 : if(fDictionary&&fNDdim==1)
291 : {
292 584 : dimexp = -fDictionary[0];
293 1168 : delete [] fDictionary;
294 584 : fDictionary=0;
295 584 : fDictionary = new Int_t[dimexp];
296 584 : fNDdim = dimexp;
297 : // Re-initialize the array
298 584 : memset(fDictionary,-1,sizeof(Int_t)*dimexp);
299 584 : fFlag=kTRUE; // Not expand again
300 584 : return;
301 : }
302 :
303 544 : Int_t *longArr = new Int_t[fNDdim];
304 1088 : if(longArr && fDictionary)
305 : {
306 : //Initialize the array
307 544 : memset(longArr,0,sizeof(Int_t)*fNDdim);
308 :
309 : Int_t r2=0;
310 298284 : for(Int_t i=0; i<fNDdim;i++)
311 : {
312 153466 : if((fDictionary[i]<0)&&(fDictionary[i]!=-1))
313 : {
314 4564 : longArr[r2]=-fDictionary[i];
315 4564 : r2++;
316 4564 : }
317 : }
318 :
319 : //Calculate new dimensions
320 10216 : for(Int_t i=0; i<fNDdim;i++)
321 : {
322 5108 : if(longArr[i]!=0)
323 4564 : dimexp=dimexp+longArr[i]-1;
324 5108 : if(longArr[i]==0)
325 544 : break;
326 : }
327 544 : dimexp=dimexp+fNDdim;
328 :
329 : //Write in the buffer the new array
330 : Int_t contaexp =0;
331 : Int_t h=0;
332 544 : Int_t* bufferE = new Int_t[dimexp];
333 :
334 544 : if(bufferE)
335 : {
336 544 : memset(bufferE,-1,sizeof(Int_t)*dimexp);
337 298284 : for(Int_t i=0; i<dimexp; i++)
338 : {
339 148598 : if(fDictionary[contaexp]>=-1)
340 : {
341 144034 : bufferE[i]=fDictionary[contaexp];
342 144034 : }
343 148598 : if(fDictionary[contaexp]<-1)
344 : {
345 4564 : i=i+longArr[h]-1;
346 4564 : h++;
347 4564 : }
348 148598 : contaexp++;
349 : }
350 :
351 : //Copy the buffer
352 1088 : delete [] fDictionary;
353 544 : fDictionary=bufferE;
354 544 : fNDdim = dimexp;
355 544 : }
356 544 : }
357 544 : if (longArr)
358 : {
359 1088 : delete [] longArr;
360 : }
361 544 : fFlag=kTRUE; // Not expand again
362 :
363 64072 : }
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 1128 : memset(fDictionary,0,sizeof(Int_t)*fNDdim);
373 :
374 564 : }
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 :
384 142392038 : Int_t corrcolumn = fgLutPadNumbering[ncol];
385 :
386 71196019 : 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 :
398 60796530 : Int_t colnumb = fgLutPadNumbering[ncol];
399 :
400 30398265 : fDictionary[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
401 :
402 30398265 : }
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 :
412 87488 : if(fgLutPadNumbering) return;
413 :
414 3 : fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
415 3 : memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
416 :
417 54 : for(Int_t mcm=0; mcm<8; mcm++)
418 : {
419 24 : Int_t lowerlimit=0+mcm*18;
420 24 : Int_t upperlimit=18+mcm*18;
421 24 : Int_t shiftposition = 1+3*mcm;
422 912 : for(Int_t index=lowerlimit;index<upperlimit;index++)
423 : {
424 432 : fgLutPadNumbering[index]= index+shiftposition;
425 : }
426 : }
427 43744 : }
|