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