]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PMD/AliPMDRawStream.cxx
Pedestal class
[u/mrichter/AliRoot.git] / PMD / AliPMDRawStream.cxx
CommitLineData
a09a2da4 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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$ */
17
18///////////////////////////////////////////////////////////////////////////////
19///
20/// This class provides access to PMD digits in raw data.
21///
22/// It loops over all PMD digits in the raw data given by the AliRawReader.
23/// The Next method goes to the next digit. If there are no digits left
24/// it returns kFALSE.
25/// Several getters provide information about the current digit.
26///
27///////////////////////////////////////////////////////////////////////////////
28
34ab69dd 29#include <Riostream.h>
30#include <TObjArray.h>
31#include <TString.h>
32#include <TSystem.h>
33
ecee2a1a 34#include "AliLog.h"
34ab69dd 35#include "AliPMDBlockHeader.h"
36#include "AliPMDDspHeader.h"
37#include "AliPMDPatchBusHeader.h"
38#include "AliPMDddldata.h"
a09a2da4 39#include "AliPMDRawStream.h"
40#include "AliRawReader.h"
41
42ClassImp(AliPMDRawStream)
43
44
45//_____________________________________________________________________________
46AliPMDRawStream::AliPMDRawStream(AliRawReader* rawReader) :
34ab69dd 47 fRawReader(rawReader)
a09a2da4 48{
49// create an object to read PMD raw digits
50
362c9d61 51 fRawReader->Select("PMD");
a09a2da4 52}
53
54//_____________________________________________________________________________
55AliPMDRawStream::AliPMDRawStream(const AliPMDRawStream& stream) :
56 TObject(stream),
34ab69dd 57 fRawReader(NULL)
a09a2da4 58{
59// copy constructor
60
ecee2a1a 61 AliFatal("Copy constructor not implemented");
a09a2da4 62}
63
64//_____________________________________________________________________________
65AliPMDRawStream& AliPMDRawStream::operator = (const AliPMDRawStream&
66 /* stream */)
67{
68// assignment operator
69
ecee2a1a 70 AliFatal("operator = assignment operator not implemented");
a09a2da4 71 return *this;
72}
73
74//_____________________________________________________________________________
75AliPMDRawStream::~AliPMDRawStream()
76{
77// destructor
78
79}
80
81
82//_____________________________________________________________________________
34ab69dd 83
9ac124a2 84Bool_t AliPMDRawStream::DdlData(Int_t indexDDL, TObjArray *pmdddlcont)
a09a2da4 85{
86// read the next raw digit
87// returns kFALSE if there is no digit left
88
34ab69dd 89 AliPMDddldata *pmdddldata;
90
35341ad3 91 if (!fRawReader->ReadHeader()) return kFALSE;
34ab69dd 92 Int_t iddl = fRawReader->GetDDLID();
93 Int_t dataSize = fRawReader->GetDataSize();
94 Int_t totaldataword = dataSize/4;
9ac124a2 95
96 if (dataSize <= 0) return kFALSE;
97 if (indexDDL != iddl)
98 {
608c1f27 99 AliWarning("Mismatch in the DDL index");
100 fRawReader->AddFatalErrorLog(kDDLIndexMismatch);
9ac124a2 101 return kFALSE;
102 }
a09a2da4 103
34ab69dd 104 UInt_t *buffer;
105 buffer = new UInt_t[totaldataword];
a09a2da4 106 UInt_t data;
34ab69dd 107 for (Int_t i = 0; i < totaldataword; i++)
108 {
109 fRawReader->ReadNextInt(data);
110 buffer[i] = data;
111 }
a09a2da4 112
34ab69dd 113 // --- Open the mapping file
a09a2da4 114
34ab69dd 115 TString fileName(gSystem->Getenv("ALICE_ROOT"));
116 if(iddl == 0)
117 {
118 fileName += "/PMD/PMD_Mapping_ddl0.dat";
119 }
120 else if(iddl == 1)
121 {
122 fileName += "/PMD/PMD_Mapping_ddl1.dat";
123 }
124 else if(iddl == 2)
125 {
126 fileName += "/PMD/PMD_Mapping_ddl2.dat";
127 }
128 else if(iddl == 3)
129 {
130 fileName += "/PMD/PMD_Mapping_ddl3.dat";
131 }
132 else if(iddl == 4)
133 {
134 fileName += "/PMD/PMD_Mapping_ddl4.dat";
135 }
136 else if(iddl == 5)
137 {
138 fileName += "/PMD/PMD_Mapping_ddl5.dat";
139 }
140
141 ifstream infile;
142 infile.open(fileName.Data(), ios::in); // ascii file
608c1f27 143 if(!infile) {
34ab69dd 144 AliError(Form("Could not read the mapping file for DDL No = %d",iddl));
608c1f27 145 fRawReader->AddFatalErrorLog(kNoMappingFile,Form("ddl=%d",iddl));
146 }
34ab69dd 147
148 Int_t modulePerDDL = 0;
149 if (iddl < 4)
150 {
151 modulePerDDL = 6;
152 }
153 else if (iddl == 4 || iddl == 5)
154 {
155 modulePerDDL = 12;
156 }
157
158 const Int_t kNPatchBus = 50;
159
160 Int_t modno, totPatchBus, bPatchBus, ePatchBus;
161 Int_t ibus, totmcm, rows, rowe, cols, cole;
162 Int_t moduleNo[kNPatchBus], mcmperBus[kNPatchBus];
163 Int_t startRowBus[kNPatchBus], endRowBus[kNPatchBus];
164 Int_t startColBus[kNPatchBus], endColBus[kNPatchBus];
165
34ab69dd 166 for (Int_t ibus = 0; ibus < kNPatchBus; ibus++)
167 {
168 mcmperBus[ibus] = -1;
169 startRowBus[ibus] = -1;
170 endRowBus[ibus] = -1;
171 startColBus[ibus] = -1;
172 endColBus[ibus] = -1;
173 }
174
34ab69dd 175 for (Int_t im = 0; im < modulePerDDL; im++)
176 {
177 infile >> modno;
178 infile >> totPatchBus >> bPatchBus >> ePatchBus;
9ac124a2 179
34ab69dd 180 for(Int_t i=0; i<totPatchBus; i++)
181 {
182 infile >> ibus >> totmcm >> rows >> rowe >> cols >> cole;
183
184 moduleNo[ibus] = modno;
185 mcmperBus[ibus] = totmcm;
186 startRowBus[ibus] = rows;
187 endRowBus[ibus] = rowe;
188 startColBus[ibus] = cols;
189 endColBus[ibus] = cole;
190 }
191 }
192
193 infile.close();
194
34ab69dd 195 AliPMDBlockHeader blockHeader;
196 AliPMDDspHeader dspHeader;
197 AliPMDPatchBusHeader pbusHeader;
198
0a666212 199 const Int_t kblHLen = blockHeader.GetHeaderLength();
200 const Int_t kdspHLen = dspHeader.GetHeaderLength();
201 const Int_t kpbusHLen = pbusHeader.GetHeaderLength();
202
a98f9d26 203 Int_t parity;
34ab69dd 204 Int_t idet, ismn;
205 Int_t irow = -1;
206 Int_t icol = -1;
207
0a666212 208 Int_t blHeaderWord[8];
209 Int_t dspHeaderWord[10];
210 Int_t pbusHeaderWord[4];
34ab69dd 211
93622f4a 212 Int_t ilowLimit = 0;
213 Int_t iuppLimit = 0;
9ac124a2 214 Int_t blRawDataLength = 0;
93622f4a 215 Int_t iwordcount = 0;
9ac124a2 216
217
34ab69dd 218 for (Int_t iblock = 0; iblock < 2; iblock++)
219 {
220 ilowLimit = iuppLimit;
0a666212 221 iuppLimit = ilowLimit + kblHLen;
34ab69dd 222
223 for (Int_t i = ilowLimit; i < iuppLimit; i++)
224 {
0a666212 225 blHeaderWord[i-ilowLimit] = (Int_t) buffer[i];
34ab69dd 226 }
9ac124a2 227
0a666212 228 blockHeader.SetHeader(blHeaderWord);
9ac124a2 229
230 blRawDataLength = blockHeader.GetRawDataLength();
231
34ab69dd 232 for (Int_t idsp = 0; idsp < 5; idsp++)
233 {
234 ilowLimit = iuppLimit;
0a666212 235 iuppLimit = ilowLimit + kdspHLen;
34ab69dd 236
237 for (Int_t i = ilowLimit; i < iuppLimit; i++)
238 {
9ac124a2 239 iwordcount++;
0a666212 240 dspHeaderWord[i-ilowLimit] = (Int_t) buffer[i];
34ab69dd 241 }
0a666212 242 dspHeader.SetHeader(dspHeaderWord);
34ab69dd 243
244 for (Int_t ibus = 0; ibus < 5; ibus++)
245 {
34ab69dd 246 ilowLimit = iuppLimit;
0a666212 247 iuppLimit = ilowLimit + kpbusHLen;
34ab69dd 248
249 for (Int_t i = ilowLimit; i < iuppLimit; i++)
250 {
9ac124a2 251 iwordcount++;
0a666212 252 pbusHeaderWord[i-ilowLimit] = (Int_t) buffer[i];
34ab69dd 253 }
0a666212 254 pbusHeader.SetHeader(pbusHeaderWord);
34ab69dd 255 Int_t rawdatalength = pbusHeader.GetRawDataLength();
256 Int_t pbusid = pbusHeader.GetPatchBusId();
257
258 ilowLimit = iuppLimit;
259 iuppLimit = ilowLimit + rawdatalength;
260
261 Int_t imodule = moduleNo[pbusid];
262
263
264 for (Int_t iword = ilowLimit; iword < iuppLimit; iword++)
265 {
9ac124a2 266 iwordcount++;
34ab69dd 267 data = buffer[iword];
268
269 Int_t isig = data & 0x0FFF;
270 Int_t ich = (data >> 12) & 0x003F;
271 Int_t imcm = (data >> 18) & 0x07FF;
272 Int_t ibit = (data >> 31) & 0x0001;
a98f9d26 273 parity = ComputeParity(data);
274 if (ibit != parity)
275 {
276 AliWarning("ComputeParity:: Parity Error");
608c1f27 277 fRawReader->AddMajorErrorLog(kParityError);
a98f9d26 278 }
34ab69dd 279 GetRowCol(iddl, pbusid, imcm, ich,
280 startRowBus, endRowBus,
281 startColBus, endColBus,
282 irow, icol);
283
284 ConvertDDL2SMN(iddl, imodule, ismn, idet);
285 TransformH2S(ismn, irow, icol);
286
287 pmdddldata = new AliPMDddldata();
288
289 pmdddldata->SetDetector(idet);
290 pmdddldata->SetSMN(ismn);
291 pmdddldata->SetModule(imodule);
292 pmdddldata->SetPatchBusId(pbusid);
293 pmdddldata->SetMCM(imcm);
294 pmdddldata->SetChannel(ich);
295 pmdddldata->SetRow(irow);
296 pmdddldata->SetColumn(icol);
297 pmdddldata->SetSignal(isig);
298 pmdddldata->SetParityBit(ibit);
299
300 pmdddlcont->Add(pmdddldata);
301
0a666212 302 } // data word loop
9ac124a2 303
304 if (iwordcount == blRawDataLength) break;
305
0a666212 306 } // patch bus loop
34ab69dd 307
0a666212 308 if (dspHeader.GetPaddingWord() == 1) iuppLimit++;
9ac124a2 309 if (iwordcount == blRawDataLength) break;
34ab69dd 310
0a666212 311 } // end of DSP
9ac124a2 312 if (iwordcount == blRawDataLength) break;
34ab69dd 313
314 } // end of BLOCK
34ab69dd 315
316 delete [] buffer;
a09a2da4 317
9ac124a2 318 return kTRUE;
a09a2da4 319}
a09a2da4 320//_____________________________________________________________________________
34ab69dd 321void AliPMDRawStream::GetRowCol(Int_t ddlno, Int_t pbusid,
322 UInt_t mcmno, UInt_t chno,
323 Int_t startRowBus[], Int_t endRowBus[],
324 Int_t startColBus[], Int_t endColBus[],
325 Int_t &row, Int_t &col) const
a09a2da4 326{
34ab69dd 327// decode: ddlno, patchbusid, mcmno, chno -> um, row, col
a09a2da4 328
a09a2da4 329
9ac124a2 330 static const UInt_t kCh[64] = { 53, 58, 57, 54, 61, 62, 60, 63,
331 49, 59, 56, 55, 52, 50, 48, 51,
332 44, 47, 45, 43, 40, 39, 36, 46,
333 32, 35, 33, 34, 41, 38, 37, 42,
334 21, 26, 25, 22, 29, 30, 28, 31,
335 17, 27, 24, 23, 20, 18, 16, 19,
336 12, 15, 13, 11, 8, 7, 4, 14,
337 0, 3, 1, 2, 9, 6, 5, 10 };
338
a09a2da4 339
34ab69dd 340 Int_t rowcol = kCh[chno];
341 Int_t irownew = rowcol/4;
342 Int_t icolnew = rowcol%4;
a09a2da4 343
a0a6a406 344 if (ddlno == 0 )
a09a2da4 345 {
a0a6a406 346 row = startRowBus[pbusid] + irownew;
347 col = startColBus[pbusid] + mcmno*4 + icolnew;
a09a2da4 348 }
34ab69dd 349 else if (ddlno == 1)
a09a2da4 350 {
a0a6a406 351 row = endRowBus[pbusid] - (15 - irownew);
352 col = startColBus[pbusid] + mcmno*4 + icolnew;
353
a09a2da4 354 }
a0a6a406 355 else if (ddlno == 2 )
e54787da 356 {
34ab69dd 357 row = startRowBus[pbusid] + irownew;
358 col = endColBus[pbusid] - mcmno*4 - (3 - icolnew);
359 }
360 else if (ddlno == 3)
361 {
a0a6a406 362 row = endRowBus[pbusid] - (15 - irownew);
363 col = endColBus[pbusid] - mcmno*4 - (3 - icolnew);
e54787da 364 }
a0a6a406 365 else if (ddlno == 4 )
e54787da 366 {
a0a6a406 367 if (pbusid < 18)
e54787da 368 {
93622f4a 369 if (mcmno <= 11)
34ab69dd 370 {
371 // Add 16 to skip the 1st 15 rows
372 row = startRowBus[pbusid] + irownew + 16;
a0a6a406 373 col = startColBus[pbusid] + (mcmno)*4 + icolnew;
34ab69dd 374 }
93622f4a 375 else if(mcmno > 11)
376 {
377 row = startRowBus[pbusid] + irownew;
378 col = startColBus[pbusid] + (mcmno-12)*4 + icolnew;
379 }
e54787da 380 }
a0a6a406 381 else if(pbusid > 17)
e54787da 382 {
93622f4a 383 if (mcmno <= 11)
a0a6a406 384 {
93622f4a 385 col = endColBus[pbusid] - mcmno*4 - (3 - icolnew);
386
a0a6a406 387 if(endRowBus[pbusid] - startRowBus[pbusid] > 16)
388 row = endRowBus[pbusid] - (15 - irownew) - 16 ;
389 else
390 row = endRowBus[pbusid] - (15 - irownew) ;
93622f4a 391
392
393 }
394 else if(mcmno > 11)
395 {
396 row = endRowBus[pbusid] - (15 - irownew) ;
397 col = endColBus[pbusid] - (mcmno - 12)*4 - (3 - icolnew);
a0a6a406 398 }
e54787da 399 }
e54787da 400 }
34ab69dd 401 else if (ddlno == 5)
e54787da 402 {
a0a6a406 403 if (pbusid <= 17)
34ab69dd 404 {
a0a6a406 405 if (mcmno > 11)
34ab69dd 406 {
a0a6a406 407 // Subtract 16 to skip the 1st 15 rows
408 row = endRowBus[pbusid] - 16 -(15 - irownew);
34ab69dd 409 col = startColBus[pbusid] + (mcmno-12)*4 + icolnew;
410 }
411 else
412 {
a0a6a406 413 row = endRowBus[pbusid] - (15 - irownew) ;
34ab69dd 414 col = startColBus[pbusid] + mcmno*4 + icolnew;
415 }
416 }
a0a6a406 417
418 else if (pbusid > 17)
e54787da 419 {
a0a6a406 420 if(mcmno > 11)
421 {
422 // Add 16 to skip the 1st 15 rows
423 row = startRowBus[pbusid] + irownew + 16;
424 col = endColBus[pbusid] - (mcmno - 12)*4 - (3 - icolnew);
425 }
426 else
427 {
428 row = startRowBus[pbusid] + irownew ;
429 col = endColBus[pbusid] - mcmno*4 - (3 - icolnew);
430 }
e54787da 431 }
34ab69dd 432 }
a0a6a406 433
34ab69dd 434}
435//_____________________________________________________________________________
436void AliPMDRawStream::ConvertDDL2SMN(Int_t iddl, Int_t imodule,
437 Int_t &smn, Int_t &detector) const
438{
439 // This converts the DDL number (0 to 5), Module Number (0-47)
440 // to Serial module number in one detector (SMN : 0-23) and
441 // detector number (0:PRE plane, 1:CPV plane)
442 if (iddl < 4)
443 {
444 smn = imodule;
445 detector = 0;
446 }
447 else
448 {
449 smn = imodule - 24;
e54787da 450 detector = 1;
451 }
452}
453//_____________________________________________________________________________
454void AliPMDRawStream::TransformH2S(Int_t smn, Int_t &row, Int_t &col) const
455{
34ab69dd 456 // This does the transformation of the hardware coordinate to
457 // software
458 // i.e., For SuperModule 0 &1, instead of 96x48(hardware),
459 // it is 48x96 (software)
e54787da 460 // For Supermodule 3 & 4, 48x96
461
e54787da 462 Int_t irownew = 0;
463 Int_t icolnew = 0;
34ab69dd 464
e54787da 465 if(smn < 12)
466 {
34ab69dd 467 irownew = col;
468 icolnew = row;
e54787da 469 }
34ab69dd 470 else if(smn >= 12 && smn < 24)
e54787da 471 {
34ab69dd 472 irownew = row;
473 icolnew = col;
e54787da 474 }
475
476 row = irownew;
477 col = icolnew;
478}
a98f9d26 479//_____________________________________________________________________________
a0a6a406 480Int_t AliPMDRawStream::ComputeParity(Int_t data)
a98f9d26 481{
482// Calculate the parity bit
483
484 Int_t count = 0;
485 for(Int_t j = 0; j<29; j++)
486 {
487 if (data & 0x01 ) count++;
488 data >>= 1;
489 }
490
491 Int_t parity = count%2;
492
493 return parity;
494}
495
e54787da 496//_____________________________________________________________________________