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