]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PMD/AliPMDRawStream.cxx
Updated version of the geometry
[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 Int_t equipId = fRawReader->GetEquipmentId();
96
97 if (dataSize <= 0) return kFALSE;
98 if (indexDDL != iddl)
99 {
100 AliError("Mismatch in the DDL index");
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
143 if(!infile)
144 AliError(Form("Could not read the mapping file for DDL No = %d",iddl));
145
146 Int_t modulePerDDL = 0;
147 if (iddl < 4)
148 {
149 modulePerDDL = 6;
150 }
151 else if (iddl == 4 || iddl == 5)
152 {
153 modulePerDDL = 12;
154 }
155
156 const Int_t kNPatchBus = 50;
157
158 Int_t modno, totPatchBus, bPatchBus, ePatchBus;
159 Int_t ibus, totmcm, rows, rowe, cols, cole;
160 Int_t moduleNo[kNPatchBus], mcmperBus[kNPatchBus];
161 Int_t startRowBus[kNPatchBus], endRowBus[kNPatchBus];
162 Int_t startColBus[kNPatchBus], endColBus[kNPatchBus];
163
164
165 for (Int_t ibus = 0; ibus < kNPatchBus; ibus++)
166 {
167 mcmperBus[ibus] = -1;
168 startRowBus[ibus] = -1;
169 endRowBus[ibus] = -1;
170 startColBus[ibus] = -1;
171 endColBus[ibus] = -1;
172 }
173
174
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
9ac124a2 193
194
34ab69dd 195 infile.close();
196
197
198 AliPMDBlockHeader blockHeader;
199 AliPMDDspHeader dspHeader;
200 AliPMDPatchBusHeader pbusHeader;
201
0a666212 202 const Int_t kblHLen = blockHeader.GetHeaderLength();
203 const Int_t kdspHLen = dspHeader.GetHeaderLength();
204 const Int_t kpbusHLen = pbusHeader.GetHeaderLength();
205
206
34ab69dd 207 Int_t idet, ismn;
208 Int_t irow = -1;
209 Int_t icol = -1;
210
0a666212 211 Int_t blHeaderWord[8];
212 Int_t dspHeaderWord[10];
213 Int_t pbusHeaderWord[4];
34ab69dd 214
215 Int_t ilowLimit = 0;
216 Int_t iuppLimit = 0;
9ac124a2 217
218 Int_t blRawDataLength = 0;
219 Int_t iwordcount = 0;
220
221
34ab69dd 222 for (Int_t iblock = 0; iblock < 2; iblock++)
223 {
224 ilowLimit = iuppLimit;
0a666212 225 iuppLimit = ilowLimit + kblHLen;
34ab69dd 226
9ac124a2 227
34ab69dd 228 for (Int_t i = ilowLimit; i < iuppLimit; i++)
229 {
0a666212 230 blHeaderWord[i-ilowLimit] = (Int_t) buffer[i];
34ab69dd 231 }
9ac124a2 232
0a666212 233 blockHeader.SetHeader(blHeaderWord);
9ac124a2 234
235 blRawDataLength = blockHeader.GetRawDataLength();
236
34ab69dd 237 for (Int_t idsp = 0; idsp < 5; idsp++)
238 {
239 ilowLimit = iuppLimit;
0a666212 240 iuppLimit = ilowLimit + kdspHLen;
34ab69dd 241
242 for (Int_t i = ilowLimit; i < iuppLimit; i++)
243 {
9ac124a2 244 iwordcount++;
0a666212 245 dspHeaderWord[i-ilowLimit] = (Int_t) buffer[i];
34ab69dd 246 }
0a666212 247 dspHeader.SetHeader(dspHeaderWord);
34ab69dd 248
249 for (Int_t ibus = 0; ibus < 5; ibus++)
250 {
251
252 ilowLimit = iuppLimit;
0a666212 253 iuppLimit = ilowLimit + kpbusHLen;
34ab69dd 254
255 for (Int_t i = ilowLimit; i < iuppLimit; i++)
256 {
9ac124a2 257 iwordcount++;
0a666212 258 pbusHeaderWord[i-ilowLimit] = (Int_t) buffer[i];
34ab69dd 259 }
0a666212 260 pbusHeader.SetHeader(pbusHeaderWord);
34ab69dd 261 Int_t rawdatalength = pbusHeader.GetRawDataLength();
262 Int_t pbusid = pbusHeader.GetPatchBusId();
263
264 ilowLimit = iuppLimit;
265 iuppLimit = ilowLimit + rawdatalength;
266
267 Int_t imodule = moduleNo[pbusid];
268
269
270 for (Int_t iword = ilowLimit; iword < iuppLimit; iword++)
271 {
9ac124a2 272 iwordcount++;
34ab69dd 273 data = buffer[iword];
274
275 Int_t isig = data & 0x0FFF;
276 Int_t ich = (data >> 12) & 0x003F;
277 Int_t imcm = (data >> 18) & 0x07FF;
278 Int_t ibit = (data >> 31) & 0x0001;
279
280 GetRowCol(iddl, pbusid, imcm, ich,
281 startRowBus, endRowBus,
282 startColBus, endColBus,
283 irow, icol);
284
285 ConvertDDL2SMN(iddl, imodule, ismn, idet);
286 TransformH2S(ismn, irow, icol);
287
288 pmdddldata = new AliPMDddldata();
289
290 pmdddldata->SetDetector(idet);
291 pmdddldata->SetSMN(ismn);
292 pmdddldata->SetModule(imodule);
293 pmdddldata->SetPatchBusId(pbusid);
294 pmdddldata->SetMCM(imcm);
295 pmdddldata->SetChannel(ich);
296 pmdddldata->SetRow(irow);
297 pmdddldata->SetColumn(icol);
298 pmdddldata->SetSignal(isig);
299 pmdddldata->SetParityBit(ibit);
300
301 pmdddlcont->Add(pmdddldata);
302
0a666212 303 } // data word loop
9ac124a2 304
305 if (iwordcount == blRawDataLength) break;
306
0a666212 307 } // patch bus loop
34ab69dd 308
0a666212 309 if (dspHeader.GetPaddingWord() == 1) iuppLimit++;
9ac124a2 310 if (iwordcount == blRawDataLength) break;
34ab69dd 311
0a666212 312 } // end of DSP
9ac124a2 313 if (iwordcount == blRawDataLength) break;
34ab69dd 314
315 } // end of BLOCK
316
317
318 delete [] buffer;
a09a2da4 319
9ac124a2 320 return kTRUE;
a09a2da4 321}
a09a2da4 322//_____________________________________________________________________________
34ab69dd 323void AliPMDRawStream::GetRowCol(Int_t ddlno, Int_t pbusid,
324 UInt_t mcmno, UInt_t chno,
325 Int_t startRowBus[], Int_t endRowBus[],
326 Int_t startColBus[], Int_t endColBus[],
327 Int_t &row, Int_t &col) const
a09a2da4 328{
34ab69dd 329// decode: ddlno, patchbusid, mcmno, chno -> um, row, col
a09a2da4 330
a09a2da4 331
9ac124a2 332 static const UInt_t kCh[64] = { 53, 58, 57, 54, 61, 62, 60, 63,
333 49, 59, 56, 55, 52, 50, 48, 51,
334 44, 47, 45, 43, 40, 39, 36, 46,
335 32, 35, 33, 34, 41, 38, 37, 42,
336 21, 26, 25, 22, 29, 30, 28, 31,
337 17, 27, 24, 23, 20, 18, 16, 19,
338 12, 15, 13, 11, 8, 7, 4, 14,
339 0, 3, 1, 2, 9, 6, 5, 10 };
340
a09a2da4 341
34ab69dd 342 Int_t rowcol = kCh[chno];
343 Int_t irownew = rowcol/4;
344 Int_t icolnew = rowcol%4;
a09a2da4 345
34ab69dd 346 if (ddlno == 0)
a09a2da4 347 {
34ab69dd 348 if (pbusid <= 2)
349 {
350 if (mcmno >= 12)
351 {
352 row = startRowBus[pbusid] + irownew;
353 col = startColBus[pbusid] + (mcmno-12)*4 + icolnew;
354 }
355 else
356 {
357 // Add 16 to skip the 1st 15 rows
358 row = startRowBus[pbusid] + irownew + 16;
359 col = startColBus[pbusid] + mcmno*4 + icolnew;
360 }
361 }
362 else if (pbusid > 2)
363 {
364 row = startRowBus[pbusid] + irownew;
365 col = startColBus[pbusid] + mcmno*4 + icolnew;
366
367 }
a09a2da4 368 }
34ab69dd 369 else if (ddlno == 1)
a09a2da4 370 {
34ab69dd 371 if (pbusid <= 2)
a09a2da4 372 {
34ab69dd 373 if (mcmno >= 12)
374 {
375 row = endRowBus[pbusid] - (15 - irownew);
376 col = startColBus[pbusid] + (mcmno-12)*4 + icolnew;
377 }
378 else
379 {
380 // Subtract 16 to skip the 1st 15 rows
381 row = endRowBus[pbusid] - 16 - (15 - irownew) ;
382 col = startColBus[pbusid] + mcmno*4 + icolnew;
383 }
a09a2da4 384 }
34ab69dd 385 else if (pbusid > 2)
a09a2da4 386 {
34ab69dd 387 row = endRowBus[pbusid] - (15 - irownew);
388 col = startColBus[pbusid] + mcmno*4 + icolnew;
a09a2da4 389 }
a09a2da4 390 }
34ab69dd 391 else if (ddlno == 2)
e54787da 392 {
34ab69dd 393 row = startRowBus[pbusid] + irownew;
394 col = endColBus[pbusid] - mcmno*4 - (3 - icolnew);
395 }
396 else if (ddlno == 3)
397 {
398 row = endRowBus[pbusid] - (15 - irownew);
399 col = endColBus[pbusid] - mcmno*4 - (3 - icolnew);
e54787da 400 }
34ab69dd 401 else if (ddlno == 4)
e54787da 402 {
34ab69dd 403 if (pbusid <= 16)
e54787da 404 {
34ab69dd 405 if (mcmno >= 12)
406 {
407 row = startRowBus[pbusid] + irownew;
408 col = startColBus[pbusid] + (mcmno-12)*4 + icolnew;
409 }
410 else
411 {
412 // Add 16 to skip the 1st 15 rows
413 row = startRowBus[pbusid] + irownew + 16;
414 col = startColBus[pbusid] + mcmno*4 + icolnew;
415 }
e54787da 416 }
34ab69dd 417 else if (pbusid > 16 && pbusid <= 20)
e54787da 418 {
34ab69dd 419 row = startRowBus[pbusid] + irownew;
420 col = startColBus[pbusid] + mcmno*4 + icolnew;
421
422 }
423 else if(pbusid > 20)
424 {
425 row = endRowBus[pbusid] - (15 - irownew);
426 col = endColBus[pbusid] - mcmno*4 - (3 - icolnew);
e54787da 427 }
e54787da 428 }
34ab69dd 429 else if (ddlno == 5)
e54787da 430 {
34ab69dd 431 if (pbusid <= 16)
432 {
433 if (mcmno >= 12)
434 {
435 row = endRowBus[pbusid] - (15 - irownew);
436 col = startColBus[pbusid] + (mcmno-12)*4 + icolnew;
437 }
438 else
439 {
440 // Subtract 16 to skip the 1st 15 rows
441 row = endRowBus[pbusid] - 16 - (15 - irownew) ;
442 col = startColBus[pbusid] + mcmno*4 + icolnew;
443 }
444 }
445 else if (pbusid > 16 && pbusid <= 20)
e54787da 446 {
34ab69dd 447 row = endRowBus[pbusid] - (15 - irownew);
448 col = startColBus[pbusid] + mcmno*4 + icolnew;
e54787da 449 }
34ab69dd 450 else if (pbusid > 20)
e54787da 451 {
34ab69dd 452 row = startRowBus[pbusid] + irownew;
453 col = endColBus[pbusid] - mcmno*4 - (3 - icolnew);
e54787da 454 }
34ab69dd 455 }
456}
457//_____________________________________________________________________________
458void AliPMDRawStream::ConvertDDL2SMN(Int_t iddl, Int_t imodule,
459 Int_t &smn, Int_t &detector) const
460{
461 // This converts the DDL number (0 to 5), Module Number (0-47)
462 // to Serial module number in one detector (SMN : 0-23) and
463 // detector number (0:PRE plane, 1:CPV plane)
464 if (iddl < 4)
465 {
466 smn = imodule;
467 detector = 0;
468 }
469 else
470 {
471 smn = imodule - 24;
e54787da 472 detector = 1;
473 }
474}
475//_____________________________________________________________________________
476void AliPMDRawStream::TransformH2S(Int_t smn, Int_t &row, Int_t &col) const
477{
34ab69dd 478 // This does the transformation of the hardware coordinate to
479 // software
480 // i.e., For SuperModule 0 &1, instead of 96x48(hardware),
481 // it is 48x96 (software)
e54787da 482 // For Supermodule 3 & 4, 48x96
483
e54787da 484 Int_t irownew = 0;
485 Int_t icolnew = 0;
34ab69dd 486
e54787da 487 if(smn < 12)
488 {
34ab69dd 489 irownew = col;
490 icolnew = row;
e54787da 491 }
34ab69dd 492 else if(smn >= 12 && smn < 24)
e54787da 493 {
34ab69dd 494 irownew = row;
495 icolnew = col;
e54787da 496 }
497
498 row = irownew;
499 col = icolnew;
500}
501//_____________________________________________________________________________