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