]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDarrayDictionary.cxx
Changes in QA to be able to process separately different triggers (Ruben)
[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"
49c65af0 31#include "AliLog.h"
b65e5048 32
33ClassImp(AliTRDarrayDictionary)
34
f41a4d6a 35Short_t *AliTRDarrayDictionary::fgLutPadNumbering = 0x0;
acf20e8f 36
b65e5048 37//________________________________________________________________________________
38AliTRDarrayDictionary::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//________________________________________________________________________________
58AliTRDarrayDictionary::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//________________________________________________________________________________
79AliTRDarrayDictionary::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//________________________________________________________________________________
103AliTRDarrayDictionary::~AliTRDarrayDictionary()
104{
105 //
106 // AliTRDarrayDictionary destructor
107 //
108
109 if(fDictionary)
110 {
111 delete [] fDictionary;
112 fDictionary=0;
113 }
114
115}
116
117//________________________________________________________________________________
118AliTRDarrayDictionary &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//________________________________________________________________________________
150void 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//________________________________________________________________________________
178void 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
231 //Fill the buffer of the compressed array
232 Int_t* buffer = new Int_t[newDim];
233 Int_t counterTwo=0;
234 Int_t g=0;
235 if(buffer)
236 {
024c0422 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 }
888fa330 261 fDictionary = buffer;
024c0422 262 fNDdim = newDim;
024c0422 263 }
264
b65e5048 265 delete [] longArr;
266 longArr=0;
267 }
a32555a0 268 fFlag=kFALSE; // This way it can be expanded afterwards
b65e5048 269}
270
271//________________________________________________________________________________
272void AliTRDarrayDictionary::Expand()
273{
274 //
275 // Expand the array
276 //
277
49c65af0 278 if(fNDdim==0)
279 {
280 AliError("Called expand with dimension zero");
281 return;
282 }
283
284
b65e5048 285 Int_t dimexp=0;
49c65af0 286
b95b541e 287// if(WasExpandCalled())
288// return;
289
290 if(fNDdim==fNrow*fNumberOfChannels*fNtime)
641f6f80 291 return;
d1ec112d 292
641f6f80 293 if(fDictionary&&fNDdim==1)
294 {
295 dimexp = -fDictionary[0];
296 delete [] fDictionary;
297 fDictionary=0;
298 fDictionary = new Int_t[dimexp];
299 fNDdim = dimexp;
300 // Re-initialize the array
301 memset(fDictionary,-1,sizeof(Int_t)*dimexp);
49c65af0 302 fFlag=kTRUE; // Not expand again
d1ec112d 303 return;
304 }
305
641f6f80 306 Int_t *longArr = new Int_t[fNDdim];
af63084f 307 if(longArr && fDictionary)
b65e5048 308 {
af63084f 309 //Initialize the array
641f6f80 310 memset(longArr,0,sizeof(Int_t)*fNDdim);
af63084f 311
641f6f80 312 Int_t r2=0;
af63084f 313 for(Int_t i=0; i<fNDdim;i++)
314 {
315 if((fDictionary[i]<0)&&(fDictionary[i]!=-1))
b65e5048 316 {
af63084f 317 longArr[r2]=-fDictionary[i];
318 r2++;
b65e5048 319 }
af63084f 320 }
321
322 //Calculate new dimensions
323 for(Int_t i=0; i<fNDdim;i++)
324 {
325 if(longArr[i]!=0)
888fa330 326 dimexp=dimexp+longArr[i]-1;
327 if(longArr[i]==0)
328 break;
af63084f 329 }
330 dimexp=dimexp+fNDdim;
331
332 //Write in the buffer the new array
333 Int_t contaexp =0;
334 Int_t h=0;
335 Int_t* bufferE = new Int_t[dimexp];
336
337 if(bufferE)
338 {
b95b541e 339 memset(bufferE,-1,sizeof(Int_t)*dimexp);
af63084f 340 for(Int_t i=0; i<dimexp; i++)
341 {
342 if(fDictionary[contaexp]>=-1)
343 {
344 bufferE[i]=fDictionary[contaexp];
345 }
346 if(fDictionary[contaexp]<-1)
347 {
af63084f 348 i=i+longArr[h]-1;
349 h++;
350 }
351 contaexp++;
352 }
353
354 //Copy the buffer
355 delete [] fDictionary;
888fa330 356 fDictionary=bufferE;
af63084f 357 fNDdim = dimexp;
b65e5048 358 }
a987273c 359 }
a987273c 360 if (longArr)
361 {
362 delete [] longArr;
b65e5048 363 }
49c65af0 364 fFlag=kTRUE; // Not expand again
641f6f80 365
b65e5048 366}
705d9e7b 367//________________________________________________________________________________
368void AliTRDarrayDictionary::Reset()
369{
370 //
371 // Reset the array, the old contents are deleted
372 // and the data array elements are set to zero.
373 //
374
375 memset(fDictionary,0,sizeof(Int_t)*fNDdim);
376
377}
acf20e8f 378//________________________________________________________________________________
379Int_t AliTRDarrayDictionary::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const
380{
381 //
382 // Get the data using the pad numbering.
383 // To access data using the mcm scheme use instead
384 // the method GetDataByAdcCol
385 //
386
f41a4d6a 387 Int_t corrcolumn = fgLutPadNumbering[ncol];
acf20e8f 388
389 return fDictionary[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
390
391}
392//________________________________________________________________________________
393void AliTRDarrayDictionary::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Int_t value)
394{
395 //
396 // Set the data using the pad numbering.
397 // To write data using the mcm scheme use instead
398 // the method SetDataByAdcCol
399 //
400
f41a4d6a 401 Int_t colnumb = fgLutPadNumbering[ncol];
acf20e8f 402
403 fDictionary[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
404
405}
406
407//________________________________________________________________________________
408void AliTRDarrayDictionary::CreateLut()
409{
410 //
411 // Initializes the Look Up Table to relate
412 // pad numbering and mcm channel numbering
413 //
414
f41a4d6a 415 if(fgLutPadNumbering) return;
acf20e8f 416
f41a4d6a 417 fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
418 memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
acf20e8f 419
420 for(Int_t mcm=0; mcm<8; mcm++)
421 {
422 Int_t lowerlimit=0+mcm*18;
423 Int_t upperlimit=18+mcm*18;
424 Int_t shiftposition = 1+3*mcm;
425 for(Int_t index=lowerlimit;index<upperlimit;index++)
426 {
888fa330 427 fgLutPadNumbering[index]= index+shiftposition;
acf20e8f 428 }
429 }
430}